Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove inference model pytorch from onnx #661

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions server/clip_server/executors/clip_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ async def encode(self, docs: 'DocumentArray', **kwargs):
_img_da = docs.find({'blob': {'$exists': True}})
_txt_da = docs.find({'text': {'$exists': True}})

with torch.inference_mode():
# for image
if _img_da:
_img_da.apply(self._preproc_image)
_img_da.embeddings = self._model.encode_image(_img_da.tensors)
# for image
if _img_da:
_img_da.apply(self._preproc_image)
_img_da.embeddings = self._model.encode_image(_img_da.tensors)

# for text
if _txt_da:
texts = self._preproc_text(_txt_da)
_txt_da.embeddings = self._model.encode_text(_txt_da.tensors)
_txt_da.texts = texts
# for text
if _txt_da:
texts = self._preproc_text(_txt_da)
_txt_da.embeddings = self._model.encode_text(_txt_da.tensors)
_txt_da.texts = texts

# drop tensors
docs.tensors = None