clarifai 10.0.0__py3-none-any.whl → 10.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clarifai/client/base.py +8 -1
- clarifai/client/dataset.py +77 -21
- clarifai/client/input.py +6 -6
- clarifai/client/model.py +1 -1
- clarifai/client/module.py +1 -1
- clarifai/client/workflow.py +1 -1
- clarifai/datasets/upload/features.py +3 -0
- clarifai/datasets/upload/image.py +57 -26
- clarifai/datasets/upload/loaders/xview_detection.py +4 -0
- clarifai/datasets/upload/utils.py +23 -7
- clarifai/models/model_serving/README.md +113 -121
- clarifai/models/model_serving/__init__.py +2 -0
- clarifai/models/model_serving/cli/_utils.py +53 -0
- clarifai/models/model_serving/cli/base.py +14 -0
- clarifai/models/model_serving/cli/build.py +79 -0
- clarifai/models/model_serving/cli/clarifai_clis.py +33 -0
- clarifai/models/model_serving/cli/create.py +171 -0
- clarifai/models/model_serving/cli/example_cli.py +34 -0
- clarifai/models/model_serving/cli/login.py +26 -0
- clarifai/models/model_serving/cli/upload.py +182 -0
- clarifai/models/model_serving/constants.py +20 -0
- clarifai/models/model_serving/docs/cli.md +150 -0
- clarifai/models/model_serving/docs/concepts.md +229 -0
- clarifai/models/model_serving/docs/dependencies.md +1 -1
- clarifai/models/model_serving/docs/inference_parameters.md +112 -107
- clarifai/models/model_serving/docs/model_types.md +16 -17
- clarifai/models/model_serving/model_config/__init__.py +4 -2
- clarifai/models/model_serving/model_config/base.py +369 -0
- clarifai/models/model_serving/model_config/config.py +219 -224
- clarifai/models/model_serving/model_config/inference_parameter.py +5 -0
- clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +25 -24
- clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +19 -18
- clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +20 -18
- clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +19 -18
- clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +19 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +22 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +32 -28
- clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +19 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +19 -18
- clarifai/models/model_serving/{models → model_config}/output.py +8 -0
- clarifai/models/model_serving/model_config/triton/__init__.py +14 -0
- clarifai/models/model_serving/model_config/{serializer.py → triton/serializer.py} +3 -1
- clarifai/models/model_serving/model_config/triton/triton_config.py +182 -0
- clarifai/models/model_serving/{models/model_types.py → model_config/triton/wrappers.py} +4 -4
- clarifai/models/model_serving/{models → repo_build}/__init__.py +2 -0
- clarifai/models/model_serving/repo_build/build.py +198 -0
- clarifai/models/model_serving/repo_build/static_files/_requirements.txt +2 -0
- clarifai/models/model_serving/repo_build/static_files/base_test.py +169 -0
- clarifai/models/model_serving/repo_build/static_files/inference.py +26 -0
- clarifai/models/model_serving/repo_build/static_files/sample_clarifai_config.yaml +25 -0
- clarifai/models/model_serving/repo_build/static_files/test.py +40 -0
- clarifai/models/model_serving/{models/pb_model.py → repo_build/static_files/triton/model.py} +15 -14
- clarifai/models/model_serving/utils.py +21 -0
- clarifai/rag/rag.py +45 -12
- clarifai/rag/utils.py +3 -2
- clarifai/utils/logging.py +7 -0
- clarifai/versions.py +1 -1
- {clarifai-10.0.0.dist-info → clarifai-10.1.0.dist-info}/METADATA +28 -5
- clarifai-10.1.0.dist-info/RECORD +114 -0
- clarifai-10.1.0.dist-info/entry_points.txt +2 -0
- clarifai/models/model_serving/cli/deploy_cli.py +0 -123
- clarifai/models/model_serving/cli/model_zip.py +0 -61
- clarifai/models/model_serving/cli/repository.py +0 -89
- clarifai/models/model_serving/docs/custom_config.md +0 -33
- clarifai/models/model_serving/docs/output.md +0 -28
- clarifai/models/model_serving/models/default_test.py +0 -281
- clarifai/models/model_serving/models/inference.py +0 -50
- clarifai/models/model_serving/models/test.py +0 -64
- clarifai/models/model_serving/pb_model_repository.py +0 -108
- clarifai-10.0.0.dist-info/RECORD +0 -103
- clarifai-10.0.0.dist-info/entry_points.txt +0 -4
- {clarifai-10.0.0.dist-info → clarifai-10.1.0.dist-info}/LICENSE +0 -0
- {clarifai-10.0.0.dist-info → clarifai-10.1.0.dist-info}/WHEEL +0 -0
- {clarifai-10.0.0.dist-info → clarifai-10.1.0.dist-info}/top_level.txt +0 -0
@@ -1,180 +1,25 @@
|
|
1
|
-
# Copyright 2023 Clarifai, Inc.
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
-
# you may not use this file except in compliance with the License.
|
4
|
-
# You may obtain a copy of the License at
|
5
|
-
#
|
6
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
-
#
|
8
|
-
# Unless required by applicable law or agreed to in writing, software
|
9
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
-
# See the License for the specific language governing permissions and
|
12
|
-
# limitations under the License.
|
13
|
-
""" Model Config classes."""
|
14
|
-
|
15
1
|
import logging
|
2
|
+
from copy import deepcopy
|
16
3
|
from dataclasses import asdict, dataclass, field
|
17
|
-
from typing import List
|
4
|
+
from typing import Any, List
|
18
5
|
|
19
6
|
import yaml
|
20
7
|
|
21
|
-
from
|
22
|
-
from
|
8
|
+
from .inference_parameter import InferParam
|
9
|
+
from .output import * # noqa: F403
|
10
|
+
from .triton import DType # noqa
|
11
|
+
from .triton import Device, DynamicBatching, InputConfig, OutputConfig, TritonModelConfig
|
23
12
|
|
24
13
|
logger = logging.getLogger(__name__)
|
25
14
|
|
26
|
-
__all__ = ["
|
27
|
-
|
28
|
-
### Triton Model Config classes.###
|
29
|
-
|
30
|
-
|
31
|
-
@dataclass
|
32
|
-
class DType:
|
33
|
-
"""
|
34
|
-
Triton Model Config data types.
|
35
|
-
"""
|
36
|
-
# https://github.com/triton-inference-server/common/blob/main/protobuf/model_config.proto
|
37
|
-
TYPE_UINT8: int = 2
|
38
|
-
TYPE_INT8: int = 6
|
39
|
-
TYPE_INT16: int = 7
|
40
|
-
TYPE_INT32: int = 8
|
41
|
-
TYPE_INT64: int = 9
|
42
|
-
TYPE_FP16: int = 10
|
43
|
-
TYPE_FP32: int = 11
|
44
|
-
TYPE_STRING: int = 13
|
45
|
-
KIND_GPU: int = 1
|
46
|
-
KIND_CPU: int = 2
|
47
|
-
|
48
|
-
|
49
|
-
@dataclass
|
50
|
-
class InputConfig:
|
51
|
-
"""
|
52
|
-
Triton Input definition.
|
53
|
-
Params:
|
54
|
-
-------
|
55
|
-
name: input name
|
56
|
-
data_type: input data type
|
57
|
-
dims: Pre-defined input data shape(s).
|
58
|
-
|
59
|
-
Returns:
|
60
|
-
--------
|
61
|
-
InputConfig
|
62
|
-
"""
|
63
|
-
name: str
|
64
|
-
data_type: int
|
65
|
-
dims: List = field(default_factory=list)
|
66
|
-
optional: bool = False
|
67
|
-
|
68
|
-
|
69
|
-
@dataclass
|
70
|
-
class OutputConfig:
|
71
|
-
"""
|
72
|
-
Triton Output definition.
|
73
|
-
Params:
|
74
|
-
-------
|
75
|
-
name: output name
|
76
|
-
data_type: output data type
|
77
|
-
dims: Pre-defined output data shape(s).
|
78
|
-
labels (bool): If labels file is required for inference.
|
79
|
-
|
80
|
-
Returns:
|
81
|
-
--------
|
82
|
-
OutputConfig
|
83
|
-
"""
|
84
|
-
name: str
|
85
|
-
data_type: int
|
86
|
-
dims: List = field(default_factory=list)
|
87
|
-
labels: bool = False
|
88
|
-
|
89
|
-
def __post_init__(self):
|
90
|
-
if self.labels:
|
91
|
-
self.label_filename = "labels.txt"
|
92
|
-
del self.labels
|
93
|
-
|
94
|
-
|
95
|
-
@dataclass
|
96
|
-
class Device:
|
97
|
-
"""
|
98
|
-
Triton instance_group.
|
99
|
-
Define the type of inference device and number of devices to use.
|
100
|
-
Params:
|
101
|
-
-------
|
102
|
-
count: number of devices
|
103
|
-
use_gpu: whether to use cpu or gpu.
|
104
|
-
|
105
|
-
Returns:
|
106
|
-
--------
|
107
|
-
Device object
|
108
|
-
"""
|
109
|
-
count: int = 1
|
110
|
-
use_gpu: bool = True
|
111
|
-
|
112
|
-
def __post_init__(self):
|
113
|
-
if self.use_gpu:
|
114
|
-
self.kind: str = DType.KIND_GPU
|
115
|
-
else:
|
116
|
-
self.kind: str = DType.KIND_CPU
|
117
|
-
|
118
|
-
|
119
|
-
@dataclass
|
120
|
-
class DynamicBatching:
|
121
|
-
"""
|
122
|
-
Triton dynamic_batching config.
|
123
|
-
Params:
|
124
|
-
-------
|
125
|
-
preferred_batch_size: batch size
|
126
|
-
max_queue_delay_microseconds: max queue delay for a request batch
|
127
|
-
|
128
|
-
Returns:
|
129
|
-
--------
|
130
|
-
DynamicBatching object
|
131
|
-
"""
|
132
|
-
#preferred_batch_size: List[int] = [1] # recommended not to set
|
133
|
-
max_queue_delay_microseconds: int = 500
|
134
|
-
|
135
|
-
|
136
|
-
@dataclass
|
137
|
-
class TritonModelConfig:
|
138
|
-
"""
|
139
|
-
Triton Model Config base.
|
140
|
-
Params:
|
141
|
-
-------
|
142
|
-
name: triton inference model name
|
143
|
-
input: a list of an InputConfig field
|
144
|
-
output: a list of OutputConfig fields/dicts
|
145
|
-
instance_group: Device. see Device
|
146
|
-
dynamic_batching: Triton dynamic batching settings.
|
147
|
-
max_batch_size: max request batch size
|
148
|
-
backend: Triton Python Backend. Constant
|
149
|
-
|
150
|
-
Returns:
|
151
|
-
--------
|
152
|
-
TritonModelConfig
|
153
|
-
"""
|
154
|
-
model_type: str
|
155
|
-
model_name: str
|
156
|
-
model_version: str
|
157
|
-
image_shape: List #(H, W)
|
158
|
-
input: List[InputConfig] = field(default_factory=list)
|
159
|
-
output: List[OutputConfig] = field(default_factory=list)
|
160
|
-
instance_group: Device = field(default_factory=Device)
|
161
|
-
dynamic_batching: DynamicBatching = field(default_factory=DynamicBatching)
|
162
|
-
max_batch_size: int = 1
|
163
|
-
backend: str = "python"
|
164
|
-
|
165
|
-
def __post_init__(self):
|
166
|
-
if "image" in [each.name for each in self.input]:
|
167
|
-
image_dims = self.image_shape
|
168
|
-
image_dims.append(3) # add channel dim
|
169
|
-
self.input[0].dims = image_dims
|
170
|
-
|
171
|
-
|
172
|
-
### General Model Config classes & functions ###
|
15
|
+
__all__ = ["ModelTypes", "ModelConfigClass", "MODEL_TYPES", "get_model_config", "load_user_config"]
|
173
16
|
|
174
17
|
|
175
18
|
# Clarifai model types
|
176
19
|
@dataclass
|
177
20
|
class ModelTypes:
|
21
|
+
""" All supported Clarifai model type names
|
22
|
+
"""
|
178
23
|
visual_detector: str = "visual-detector"
|
179
24
|
visual_classifier: str = "visual-classifier"
|
180
25
|
text_classifier: str = "text-classifier"
|
@@ -188,31 +33,86 @@ class ModelTypes:
|
|
188
33
|
def __post_init__(self):
|
189
34
|
self.all = list(asdict(self).values())
|
190
35
|
|
36
|
+
@property
|
37
|
+
def image_input_models(self):
|
38
|
+
""" Return list of model types having image as input or one of inputs"""
|
39
|
+
_visual = [each for each in self.all if each.startswith("visual")]
|
191
40
|
|
192
|
-
|
193
|
-
class InferenceConfig:
|
194
|
-
wrap_func: callable
|
195
|
-
return_type: dataclass
|
41
|
+
return _visual + [self.multimodal_embedder]
|
196
42
|
|
197
43
|
|
198
44
|
@dataclass
|
199
45
|
class FieldMapsConfig:
|
200
|
-
input_fields_map: dict
|
201
|
-
output_fields_map: dict
|
46
|
+
input_fields_map: dict = field(default_factory=dict)
|
47
|
+
output_fields_map: dict = field(default_factory=dict)
|
48
|
+
|
49
|
+
|
50
|
+
@dataclass
|
51
|
+
class ServingBackendConfig:
|
52
|
+
"""
|
53
|
+
"""
|
54
|
+
triton: TritonModelConfig = None
|
202
55
|
|
203
56
|
|
204
57
|
@dataclass
|
205
|
-
class
|
206
|
-
|
207
|
-
|
58
|
+
class ClarifaiModelConfig:
|
59
|
+
"""Clarifai necessary configs for building/uploading/creation
|
60
|
+
|
61
|
+
Args:
|
62
|
+
field_maps (FieldMapsConfig): Field maps config
|
63
|
+
output_type (dataclass): model output type
|
64
|
+
labels (List[str]): list of concept names
|
65
|
+
inference_parameters (List[InferParam]): list of inference parameters
|
66
|
+
clarifai_model_id (str): Clarifai model id on the platform
|
67
|
+
type (str): one of `MODEL_TYPES`
|
68
|
+
clarifai_user_app_id (str): User ID and App ID separated by '/', e.g., <user_id>/<app_id>
|
69
|
+
description (str): model description
|
70
|
+
|
71
|
+
"""
|
72
|
+
field_maps: FieldMapsConfig = None
|
73
|
+
output_type: str = None
|
74
|
+
labels: List[str] = field(default_factory=list)
|
75
|
+
inference_parameters: List[InferParam] = field(default_factory=list)
|
76
|
+
clarifai_model_id: str = ""
|
77
|
+
type: str = ""
|
78
|
+
clarifai_user_app_id: str = ""
|
79
|
+
description: str = ""
|
80
|
+
|
81
|
+
def _checking(self, var_name: str, var_value: Any):
|
82
|
+
if var_name == "type":
|
83
|
+
_model_types = MODEL_TYPES + [""]
|
84
|
+
assert self.type in _model_types
|
85
|
+
elif var_name == "clarifai_model_id" and var_value:
|
86
|
+
# TODO: Must ensure name is valid
|
87
|
+
pass
|
88
|
+
elif var_name == "clarifai_user_app_id" and var_value:
|
89
|
+
_user_app = var_value.split("/")
|
90
|
+
assert len(_user_app) == 2, ValueError(
|
91
|
+
f"id must be combination of user_id and app_id separated by `/`, e.g. <user_id>/<app_id>. Got {var_value}"
|
92
|
+
)
|
93
|
+
elif var_name == "labels":
|
94
|
+
if var_value:
|
95
|
+
assert isinstance(var_value, tuple) or isinstance(
|
96
|
+
var_value, list), f"labels must be tuple or list, got {type(var_value)}"
|
97
|
+
var_value = [str(each) for each in var_value]
|
98
|
+
|
99
|
+
return var_value
|
100
|
+
|
101
|
+
def __setattr__(self, __name: str, __value: Any) -> None:
|
102
|
+
__value = self._checking(__name, __value)
|
103
|
+
|
104
|
+
super().__setattr__(__name, __value)
|
208
105
|
|
209
106
|
|
210
107
|
@dataclass
|
211
|
-
class ModelConfigClass:
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
108
|
+
class ModelConfigClass():
|
109
|
+
"""All config of model
|
110
|
+
Args:
|
111
|
+
clarifai_model (ClarifaiModelConfig): Clarifai model config
|
112
|
+
serving_backend (ServingBackendConfig): Custom serving backend config. Only support triton for now
|
113
|
+
"""
|
114
|
+
clarifai_model: ClarifaiModelConfig
|
115
|
+
serving_backend: ServingBackendConfig
|
216
116
|
|
217
117
|
def make_triton_model_config(
|
218
118
|
self,
|
@@ -226,7 +126,6 @@ class ModelConfigClass:
|
|
226
126
|
) -> TritonModelConfig:
|
227
127
|
|
228
128
|
return TritonModelConfig(
|
229
|
-
model_type=self.type,
|
230
129
|
model_name=model_name,
|
231
130
|
model_version=model_version,
|
232
131
|
image_shape=image_shape,
|
@@ -234,45 +133,98 @@ class ModelConfigClass:
|
|
234
133
|
dynamic_batching=dynamic_batching,
|
235
134
|
max_batch_size=max_batch_size,
|
236
135
|
backend=backend,
|
237
|
-
input=self.triton.input,
|
238
|
-
output=self.triton.output)
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
136
|
+
input=self.serving_backend.triton.input,
|
137
|
+
output=self.serving_backend.triton.output)
|
138
|
+
|
139
|
+
def dump_to_user_config(self):
|
140
|
+
data = asdict(self)
|
141
|
+
_self = deepcopy(self)
|
142
|
+
# dump backend
|
143
|
+
if hasattr(_self.serving_backend, "triton"):
|
144
|
+
dict_triton_config = asdict(_self.serving_backend.triton)
|
145
|
+
for k, v in dict_triton_config.items():
|
146
|
+
if (k == "max_batch_size" and v > 1) \
|
147
|
+
or (k == "image_shape" and v != [-1, -1] and self.clarifai_model.type in ModelTypes().image_input_models):
|
148
|
+
continue
|
149
|
+
else:
|
150
|
+
data["serving_backend"]["triton"].pop(k, None)
|
151
|
+
|
152
|
+
if not data["serving_backend"]["triton"]:
|
153
|
+
data["serving_backend"].pop("triton", None)
|
154
|
+
if not data["serving_backend"]:
|
155
|
+
data.pop("serving_backend", None)
|
156
|
+
|
157
|
+
# dump clarifai model
|
158
|
+
data["clarifai_model"].pop("field_maps", None)
|
159
|
+
data["clarifai_model"].pop("output_type", None)
|
160
|
+
|
161
|
+
return data
|
162
|
+
|
163
|
+
@classmethod
|
164
|
+
def custom_doc(cls):
|
165
|
+
msg = f"{cls.__doc__}\nWhere: \n\n"
|
166
|
+
for k, v in cls.__annotations__.items():
|
167
|
+
msg += f"* {k}:\n------\n {v.__doc__}\n"
|
168
|
+
return msg
|
169
|
+
|
170
|
+
|
171
|
+
def read_yaml(path: str) -> dict:
|
172
|
+
with open(path, encoding="utf-8") as f:
|
243
173
|
config = yaml.safe_load(f) # model dict
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
174
|
+
return config
|
175
|
+
|
176
|
+
|
177
|
+
def parse_config(config: dict):
|
178
|
+
clarifai_model = config.get("clarifai_model", {})
|
179
|
+
serving_backend = config.get("serving_backend", {})
|
180
|
+
if serving_backend:
|
181
|
+
if serving_backend.get("triton", {}):
|
182
|
+
# parse triton input/output
|
183
|
+
triton = serving_backend["triton"]
|
184
|
+
input_triton_configs = triton.pop("input", {})
|
185
|
+
triton.update(
|
186
|
+
dict(input=[
|
187
|
+
InputConfig(
|
188
|
+
name=input["name"],
|
189
|
+
data_type=eval(f"DType.{input['data_type']}") if isinstance(
|
190
|
+
input['data_type'], str) else input['data_type'],
|
191
|
+
dims=input["dims"],
|
192
|
+
optional=input.get("optional", False),
|
193
|
+
) for input in input_triton_configs
|
194
|
+
]))
|
195
|
+
output_triton_configs = triton.pop("output", {})
|
196
|
+
triton.update(
|
197
|
+
dict(output=[
|
198
|
+
OutputConfig(
|
199
|
+
name=output["name"],
|
200
|
+
data_type=eval(f"DType.{output['data_type']}") if isinstance(
|
201
|
+
output['data_type'], str) else output['data_type'],
|
202
|
+
dims=output["dims"],
|
203
|
+
label_filename=output["label_filename"],
|
204
|
+
) for output in output_triton_configs
|
205
|
+
]))
|
206
|
+
serving_backend.update(dict(triton=TritonModelConfig(**triton)))
|
207
|
+
serving_backend = ServingBackendConfig(**serving_backend)
|
271
208
|
|
272
209
|
# parse field maps for deployment
|
273
|
-
field_maps =
|
274
|
-
|
275
|
-
|
210
|
+
field_maps = clarifai_model.pop("field_maps", {})
|
211
|
+
clarifai_model.update(dict(field_maps=FieldMapsConfig(**field_maps)))
|
212
|
+
# parse inference_parameters
|
213
|
+
inference_parameters = clarifai_model.pop("inference_parameters", [])
|
214
|
+
if inference_parameters is None:
|
215
|
+
inference_parameters = []
|
216
|
+
clarifai_model.update(
|
217
|
+
dict(inference_parameters=[InferParam(**each) for each in inference_parameters]))
|
218
|
+
# parse output type
|
219
|
+
output_type = clarifai_model.pop("output_type", None)
|
220
|
+
if output_type:
|
221
|
+
#if isinstance(output_type, str):
|
222
|
+
# output_type = eval(output_type)
|
223
|
+
clarifai_model.update(dict(output_type=output_type))
|
224
|
+
|
225
|
+
clarifai_model = ClarifaiModelConfig(**clarifai_model)
|
226
|
+
|
227
|
+
return ModelConfigClass(clarifai_model=clarifai_model, serving_backend=serving_backend)
|
276
228
|
|
277
229
|
|
278
230
|
def get_model_config(model_type: str) -> ModelConfigClass:
|
@@ -287,31 +239,74 @@ def get_model_config(model_type: str) -> ModelConfigClass:
|
|
287
239
|
ModelConfigClass
|
288
240
|
|
289
241
|
### Example:
|
290
|
-
>>> from clarifai.models.model_serving.models.output import ClassifierOutput
|
291
242
|
>>> from clarifai.models.model_serving.model_config import get_model_config, ModelTypes
|
292
243
|
>>> cfg = get_model_config(ModelTypes.text_classifier)
|
293
244
|
>>> custom_triton_config = cfg.make_triton_model_config(**kwargs)
|
294
|
-
>>> cfg.inference.return_type is ClassifierOutput # True
|
295
|
-
|
296
245
|
|
297
246
|
"""
|
298
247
|
if model_type == "MODEL_TYPE_PLACEHOLDER":
|
299
248
|
logger.warning(
|
300
249
|
"Warning: A placeholder value has been detected for obtaining the model configuration. This will result in empty `ModelConfigClass` object."
|
301
250
|
)
|
302
|
-
return ModelConfigClass(
|
303
|
-
triton=None,
|
304
|
-
inference=InferenceConfig(wrap_func=lambda x: x, return_type=None),
|
305
|
-
field_maps=None)
|
251
|
+
return ModelConfigClass(clarifai_model=None, serving_backend=None)
|
306
252
|
|
307
253
|
import os
|
308
254
|
assert model_type in MODEL_TYPES, f"`model_type` must be in {MODEL_TYPES}"
|
309
|
-
cfg =
|
255
|
+
cfg = read_yaml(
|
310
256
|
os.path.join(os.path.dirname(__file__), "model_types_config", f"{model_type}.yaml"))
|
311
|
-
cfg
|
257
|
+
cfg = parse_config(cfg)
|
258
|
+
cfg.clarifai_model.type = model_type
|
312
259
|
return cfg
|
313
260
|
|
314
261
|
|
315
262
|
_model_types = ModelTypes()
|
316
263
|
MODEL_TYPES = _model_types.all
|
317
264
|
del _model_types
|
265
|
+
|
266
|
+
|
267
|
+
def load_user_config(cfg_path: str) -> ModelConfigClass:
|
268
|
+
"""Read `clarifai_config.yaml` in user working dir
|
269
|
+
|
270
|
+
Args:
|
271
|
+
cfg_path (str): path to config
|
272
|
+
|
273
|
+
Returns:
|
274
|
+
ModelConfigClass
|
275
|
+
"""
|
276
|
+
cfg = read_yaml(cfg_path)
|
277
|
+
return _ensure_user_config(cfg)
|
278
|
+
|
279
|
+
|
280
|
+
def _ensure_user_config(user_config: dict) -> ModelConfigClass:
|
281
|
+
"""Ensure user config with default one
|
282
|
+
|
283
|
+
Args:
|
284
|
+
user_config (dict): ModelConfigClass as dict
|
285
|
+
|
286
|
+
Raises:
|
287
|
+
e: Exception when loading user config
|
288
|
+
|
289
|
+
Returns:
|
290
|
+
ModelConfigClass
|
291
|
+
"""
|
292
|
+
|
293
|
+
try:
|
294
|
+
user_config_obj: ModelConfigClass = parse_config(user_config)
|
295
|
+
except Exception as e:
|
296
|
+
raise e
|
297
|
+
|
298
|
+
default_config = get_model_config(user_config_obj.clarifai_model.type)
|
299
|
+
|
300
|
+
for _model_cfg, value in asdict(user_config_obj.clarifai_model).items():
|
301
|
+
|
302
|
+
if value and _model_cfg != "field_maps":
|
303
|
+
setattr(default_config.clarifai_model, _model_cfg, value)
|
304
|
+
|
305
|
+
if hasattr(user_config_obj, "serving_backend"):
|
306
|
+
if hasattr(user_config_obj.serving_backend, "triton"):
|
307
|
+
if user_config_obj.serving_backend.triton.max_batch_size > 1:
|
308
|
+
default_config.serving_backend.triton.max_batch_size = user_config_obj.serving_backend.triton.max_batch_size
|
309
|
+
if user_config_obj.serving_backend.triton.image_shape != [-1, -1]:
|
310
|
+
default_config.serving_backend.triton.image_shape = user_config_obj.serving_backend.triton.image_shape
|
311
|
+
|
312
|
+
return default_config
|
@@ -35,6 +35,11 @@ class InferParam:
|
|
35
35
|
value,
|
36
36
|
str), f"`field_type` is `STRING` or `ENCRYPTED_STRING` (str), however got {type(value)}"
|
37
37
|
|
38
|
+
def __setattr__(self, __name: str, __value: Any) -> None:
|
39
|
+
if __name == "default_value":
|
40
|
+
self.validate_type(__value)
|
41
|
+
super().__setattr__(__name, __value)
|
42
|
+
|
38
43
|
def todict(self):
|
39
44
|
return {k: v for k, v in asdict(self).items()}
|
40
45
|
|
@@ -1,24 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
serving_backend:
|
2
|
+
triton:
|
3
|
+
input:
|
4
|
+
- name: image
|
5
|
+
data_type: TYPE_UINT8
|
6
|
+
dims: [-1, -1, 3]
|
7
|
+
optional: true
|
8
|
+
- name: text
|
9
|
+
data_type: TYPE_STRING
|
10
|
+
dims: [1]
|
11
|
+
optional: true
|
12
|
+
output:
|
13
|
+
- name: embeddings
|
14
|
+
data_type: TYPE_FP32
|
15
|
+
dims: [-1]
|
16
|
+
label_filename: null
|
17
|
+
clarifai_model:
|
18
|
+
type: multimodal-embedder
|
19
|
+
output_type: EmbeddingOutput
|
20
|
+
field_maps:
|
21
|
+
input_fields_map:
|
22
|
+
image: image
|
23
|
+
text: text
|
24
|
+
output_fields_map:
|
25
|
+
embeddings: embeddings
|
@@ -1,18 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
serving_backend:
|
2
|
+
triton:
|
3
|
+
input:
|
4
|
+
- name: text
|
5
|
+
data_type: TYPE_STRING
|
6
|
+
dims: [1]
|
7
|
+
output:
|
8
|
+
- name: softmax_predictions
|
9
|
+
data_type: TYPE_FP32
|
10
|
+
dims: [-1]
|
11
|
+
label_filename: "labels.txt"
|
12
|
+
clarifai_model:
|
13
|
+
type: text-classifier
|
14
|
+
output_type: ClassifierOutput
|
15
|
+
field_maps:
|
16
|
+
input_fields_map:
|
17
|
+
text: text
|
18
|
+
output_fields_map:
|
19
|
+
concepts: softmax_predictions
|
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
serving_backend:
|
2
|
+
triton:
|
3
|
+
input:
|
4
|
+
- name: text
|
5
|
+
data_type: TYPE_STRING
|
6
|
+
dims: [1]
|
7
|
+
output:
|
8
|
+
- name: embeddings
|
9
|
+
data_type: TYPE_FP32
|
10
|
+
dims: [-1]
|
11
|
+
label_filename: null
|
12
|
+
|
13
|
+
clarifai_model:
|
14
|
+
type: text-embedder
|
15
|
+
output_type: EmbeddingOutput
|
16
|
+
field_maps:
|
17
|
+
input_fields_map:
|
18
|
+
text: text
|
19
|
+
output_fields_map:
|
20
|
+
embeddings: embeddings
|