Skip to content

Commit fbbd827

Browse files
Valerio Sofimorgoth95
authored andcommitted
fix: added support for dynamic shape
1 parent 638e538 commit fbbd827

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

server/clip_server/model/clip_nebullvm.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from pathlib import Path
33

4+
import numpy as np
45
import torch.cuda
56

67
from .clip import _download, available_models
@@ -37,24 +38,45 @@ def optimize_models(
3738
):
3839
from nebullvm.api.functions import optimize_model
3940

40-
save_dir = os.path.expanduser("~/.cache/clip/nebullvm")
41-
Path(save_dir).mkdir(exist_ok=True)
42-
visual_save_dir = os.path.join(save_dir, "visual")
43-
Path(visual_save_dir).mkdir(exist_ok=True)
44-
text_save_dir = os.path.join(save_dir, "text")
45-
Path(text_save_dir).mkdir(exist_ok=True)
4641
general_kwargs = {}
4742
general_kwargs.update(kwargs)
4843

44+
dynamic_info = {
45+
"inputs": [
46+
{0: 'batch', 1: 'num_channels', 2: 'pixel_size', 3: 'pixel_size'}
47+
],
48+
"outputs": [{0: 'batch'}],
49+
}
50+
4951
self._visual_model = optimize_model(
5052
self._visual_path,
51-
input_data=[((torch.randn(1, 3, self.pixel_size, self.pixel_size),), 0)],
53+
input_data=[
54+
(
55+
(
56+
np.random.randn(1, 3, self.pixel_size, self.pixel_size).astype(
57+
np.float32
58+
),
59+
),
60+
0,
61+
)
62+
],
63+
dynamic_info=dynamic_info,
5264
**general_kwargs,
5365
)
5466

67+
dynamic_info = {
68+
"inputs": [
69+
{0: 'batch', 1: 'num_tokens'},
70+
],
71+
"outputs": [
72+
{0: 'batch'},
73+
],
74+
}
75+
5576
self._textual_model = optimize_model(
5677
self._textual_path,
57-
input_data=[((torch.randint(0, 100, (1, 77)),), 0)],
78+
input_data=[((np.random.randint(0, 100, (1, 77)),), 0)],
79+
dynamic_info=dynamic_info,
5880
**general_kwargs,
5981
)
6082

0 commit comments

Comments
 (0)