Skip to content

Commit

Permalink
refactor: remove inference model pytorch from onnx (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwanglzu authored and numb3r3 committed May 4, 2022
1 parent 665deb3 commit 2c1f32a
Showing 1 changed file with 9 additions and 10 deletions.
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

0 comments on commit 2c1f32a

Please sign in to comment.