Skip to content

Commit

Permalink
feat: update nebullvm api
Browse files Browse the repository at this point in the history
Update nebullvm api calls to new interface & fix dynamic shape for openvino
  • Loading branch information
diegofiori authored Oct 10, 2022
2 parents 932cfe6 + de7d372 commit b2fd227
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/ambv/black
rev: 20.8b1
rev: 22.10.0
hooks:
- id: black
types: [python]
Expand Down
56 changes: 36 additions & 20 deletions server/clip_server/model/clip_nebullvm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path

import numpy as np
import torch.cuda

from .clip import _download, available_models
Expand Down Expand Up @@ -35,32 +36,47 @@ def optimize_models(
self,
**kwargs,
):
from nebullvm.api.frontend.onnx import optimize_onnx_model

save_dir = os.path.expanduser("~/.cache/clip/nebullvm")
Path(save_dir).mkdir(exist_ok=True)
visual_save_dir = os.path.join(save_dir, "visual")
Path(visual_save_dir).mkdir(exist_ok=True)
text_save_dir = os.path.join(save_dir, "text")
Path(text_save_dir).mkdir(exist_ok=True)
general_kwargs = {
"batch_size": 1,
}
from nebullvm.api.functions import optimize_model

general_kwargs = {}
general_kwargs.update(kwargs)
self._visual_model = optimize_onnx_model(

dynamic_info = {
"inputs": [
{0: 'batch', 1: 'num_channels', 2: 'pixel_size', 3: 'pixel_size'}
],
"outputs": [{0: 'batch'}],
}

self._visual_model = optimize_model(
self._visual_path,
input_sizes=[(3, self.pixel_size, self.pixel_size)],
save_dir=visual_save_dir,
ignore_compilers=["tvm"],
input_data=[
(
(
np.random.randn(1, 3, self.pixel_size, self.pixel_size).astype(
np.float32
),
),
0,
)
],
dynamic_info=dynamic_info,
**general_kwargs,
)

self._textual_model = optimize_onnx_model(
dynamic_info = {
"inputs": [
{0: 'batch', 1: 'num_tokens'},
],
"outputs": [
{0: 'batch'},
],
}

self._textual_model = optimize_model(
self._textual_path,
input_sizes=[(77,)],
save_dir=text_save_dir,
input_types=["int"],
ignore_compilers=["tvm"],
input_data=[((np.random.randint(0, 100, (1, 77)),), 0)],
dynamic_info=dynamic_info,
**general_kwargs,
)

Expand Down
2 changes: 1 addition & 1 deletion server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'onnx',
]
+ (['onnxruntime-gpu>=1.8.0'] if sys.platform != 'darwin' else []),
'nebullvm': ['nebullvm>=0.2.1'],
'nebullvm': ['nebullvm>=0.4.3'],
'tensorrt': ['nvidia-tensorrt'],
},
classifiers=[
Expand Down

0 comments on commit b2fd227

Please sign in to comment.