gimlet-api 0.0.7__py3-none-any.whl → 0.0.9__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.
- {gimlet_api-0.0.7.dist-info → gimlet_api-0.0.9.dist-info}/METADATA +1 -1
- {gimlet_api-0.0.7.dist-info → gimlet_api-0.0.9.dist-info}/RECORD +19 -18
- gml/client.py +9 -8
- gml/compile.py +13 -93
- gml/device.py +5 -7
- gml/hf.py +302 -32
- gml/model.py +2 -1
- gml/pipelines.py +146 -7
- gml/preprocessing.py +2 -1
- gml/proto/src/api/corepb/v1/controlplane_pb2.py +40 -20
- gml/proto/src/api/corepb/v1/cp_edge_pb2.py +43 -49
- gml/proto/src/api/corepb/v1/device_info_pb2.py +19 -7
- gml/proto/src/api/corepb/v1/gem_config_pb2.py +24 -15
- gml/proto/src/api/corepb/v1/mediastream_pb2.py +23 -19
- gml/proto/src/api/corepb/v1/model_exec_pb2.py +131 -112
- gml/proto/src/controlplane/compiler/cpb/v1/cpb_pb2.py +10 -11
- gml/register_submodules.py +134 -0
- gml/tensor.py +6 -1
- {gimlet_api-0.0.7.dist-info → gimlet_api-0.0.9.dist-info}/WHEEL +0 -0
@@ -1,14 +1,14 @@
|
|
1
1
|
gml/__init__.py,sha256=H3WQZ_RaN7VNeb__qeHEbKLEwkaG7gpL5FQ8s1IotUA,773
|
2
2
|
gml/_utils.py,sha256=mSCWHhCdzcUvHqmJIB2FS215K1LMgJCWcZ6e6FWK3hQ,1184
|
3
3
|
gml/asset_manager.py,sha256=VnbqUZHPOgPrAh6ri9C0EuNhS8tAHIrbUyJPAJuD9po,2053
|
4
|
-
gml/client.py,sha256=
|
5
|
-
gml/compile.py,sha256=
|
6
|
-
gml/device.py,sha256=
|
7
|
-
gml/hf.py,sha256=
|
8
|
-
gml/model.py,sha256=
|
4
|
+
gml/client.py,sha256=jPA71PTbv-4DX2FsfFcj1VPN-eMGdF4tKCj2NnOW7ZE,13862
|
5
|
+
gml/compile.py,sha256=Ih43r_zU07p91w9aiA0lrPJfmACpAWg0x_HFddMSy7Q,8346
|
6
|
+
gml/device.py,sha256=Iw71NnuLcgjY32ZMXHlnlPkosTuHEmL9E98utmNChlM,2650
|
7
|
+
gml/hf.py,sha256=pp215wNmaPyCVy4DqFJbe_vEe1BRJ1GAJEURZnLuU0g,28220
|
8
|
+
gml/model.py,sha256=xESdD7tlqn93ym67Lyyk7TZdM3wUqyn7qWdP2AbgdkI,7261
|
9
9
|
gml/model_utils.py,sha256=vZvE5cHZIDkUkeZ4Pk4hhV-zOYMiREluv4b8kdqQ3Ig,1375
|
10
|
-
gml/pipelines.py,sha256=
|
11
|
-
gml/preprocessing.py,sha256=
|
10
|
+
gml/pipelines.py,sha256=LKj_lh5I5HzyUUIPG4CImiqBnQPrJsj0CHPKhLiOOGo,8374
|
11
|
+
gml/preprocessing.py,sha256=MaKkEW4ZP9fjpkJQfpc0X3rCUuSuSmJnGMClHamKmZU,3210
|
12
12
|
gml/proto/gogoproto/gogo_pb2.py,sha256=WVMIAR8K--mCUkTPM7mEeeXGpQlRRtt_kco10iP3CZs,15728
|
13
13
|
gml/proto/mediapipe/framework/calculator_contract_test_pb2.py,sha256=hNjyZCBz3RYa6rN4xR3FOCZKA24gq_LsJ3EMegl5wK4,2031
|
14
14
|
gml/proto/mediapipe/framework/calculator_options_pb2.py,sha256=Nq1BQRtLdsIgfkw7ymD3eg2p2_RSlZhiHS7YbDhNHR0,1563
|
@@ -25,16 +25,16 @@ gml/proto/mediapipe/framework/thread_pool_executor_pb2.py,sha256=9TJ66fqSo1BiJmE
|
|
25
25
|
gml/proto/opentelemetry/proto/common/v1/common_pb2.py,sha256=wQjeDti-C8JiNwRn-z5M5p-Fqxm-SmnbPaoitJcSK-4,2860
|
26
26
|
gml/proto/opentelemetry/proto/metrics/v1/metrics_pb2.py,sha256=t2Far6oVcUFQIimzgAkZ8vQd0asMIlvECp4osC0ujgg,9735
|
27
27
|
gml/proto/opentelemetry/proto/resource/v1/resource_pb2.py,sha256=cbNmE12Nm3PjW4NXU7-Z-9m_0Zs3Ab8R1xLkDnvclCg,1730
|
28
|
-
gml/proto/src/api/corepb/v1/controlplane_pb2.py,sha256=
|
29
|
-
gml/proto/src/api/corepb/v1/cp_edge_pb2.py,sha256=
|
30
|
-
gml/proto/src/api/corepb/v1/device_info_pb2.py,sha256=
|
31
|
-
gml/proto/src/api/corepb/v1/gem_config_pb2.py,sha256=
|
32
|
-
gml/proto/src/api/corepb/v1/mediastream_pb2.py,sha256=
|
33
|
-
gml/proto/src/api/corepb/v1/model_exec_pb2.py,sha256=
|
28
|
+
gml/proto/src/api/corepb/v1/controlplane_pb2.py,sha256=BosvQ6GYaUGsNTkRZH7osP2dZGWP6U9WyxItIQ_QS-8,9769
|
29
|
+
gml/proto/src/api/corepb/v1/cp_edge_pb2.py,sha256=oIpxq13C1ynK3alzDNZTOL5URxz5qzbDLD9NOM5xxjE,14511
|
30
|
+
gml/proto/src/api/corepb/v1/device_info_pb2.py,sha256=5orIOJAkvtH9pWBSXveDASFi4Rn59YWdOSnVLdj891A,5356
|
31
|
+
gml/proto/src/api/corepb/v1/gem_config_pb2.py,sha256=2ljfF16Xeqgj9TM3gHN54BqRHqS3SQNhOCenEY9K9qU,4718
|
32
|
+
gml/proto/src/api/corepb/v1/mediastream_pb2.py,sha256=Un9OwDUmWdqv92QP66K-WVOAzxP_4hMoz33JI4W1G5Y,7868
|
33
|
+
gml/proto/src/api/corepb/v1/model_exec_pb2.py,sha256=o0drstrDssejqCFo8Cmm9F0zDw_bmzeOUHiYFrruOqE,29877
|
34
34
|
gml/proto/src/common/typespb/jwt_pb2.py,sha256=lxy-bqbyg96i9n_xr2JbkuWX-ldnoJavXPMnApzVSio,5580
|
35
35
|
gml/proto/src/common/typespb/status_pb2.py,sha256=IbBJnbsAlvsuTtyT285ZuW6k5VaPfl5kRSOnBxD_H8M,2109
|
36
36
|
gml/proto/src/common/typespb/uuid_pb2.py,sha256=5Fm3jYpCPX7sMrP6RhRYsF0SnuZNIBEQJk9f0jwZ2Rw,1188
|
37
|
-
gml/proto/src/controlplane/compiler/cpb/v1/cpb_pb2.py,sha256=
|
37
|
+
gml/proto/src/controlplane/compiler/cpb/v1/cpb_pb2.py,sha256=R8jcxOlR1iz4Y7MnxIKoJ2RaNayqWPiBSt0W496QT-c,3262
|
38
38
|
gml/proto/src/controlplane/compiler/cpb/v1/cpb_pb2_grpc.py,sha256=l-gTK9nYpTlVb7QGAckSQXlHhkRdKe2-nrxXc8NQavY,2912
|
39
39
|
gml/proto/src/controlplane/directory/directorypb/v1/directory_pb2.py,sha256=KgoUT8ccF-yJPe1r4otQjAPQoKBaQzdBlHoIUSkk0yE,11445
|
40
40
|
gml/proto/src/controlplane/directory/directorypb/v1/directory_pb2_grpc.py,sha256=p3OpT8-hfNHu4-29qr-ZahRwO-LoCYM9Q4jomAHTXGA,24572
|
@@ -44,7 +44,8 @@ gml/proto/src/controlplane/logicalpipeline/lppb/v1/lppb_pb2.py,sha256=wvLQvoh2UA
|
|
44
44
|
gml/proto/src/controlplane/logicalpipeline/lppb/v1/lppb_pb2_grpc.py,sha256=-snjW7n6JveUzJVPFcm25XlL19kowPSKgd61l_jPnHA,9541
|
45
45
|
gml/proto/src/controlplane/model/mpb/v1/mpb_pb2.py,sha256=RVedXkNYu2iF5OHiXoYyRw9AGRCUWG7qNyY-5QY71Go,3762
|
46
46
|
gml/proto/src/controlplane/model/mpb/v1/mpb_pb2_grpc.py,sha256=KSdb6V04qUHDsb1R2o3wixwTyZgrhwnPYobjnRgWX4I,4735
|
47
|
-
gml/
|
48
|
-
|
49
|
-
gimlet_api-0.0.
|
50
|
-
gimlet_api-0.0.
|
47
|
+
gml/register_submodules.py,sha256=U8IwjVygX2vxNi_aK6ljHOD4mmrOhbyVczvy4wwulqU,5027
|
48
|
+
gml/tensor.py,sha256=aPLm3I3qkYNDcJmntaUycqqN5rsZmcj8ql0EkupJudY,14977
|
49
|
+
gimlet_api-0.0.9.dist-info/WHEEL,sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us,91
|
50
|
+
gimlet_api-0.0.9.dist-info/METADATA,sha256=P5wOKzPZyJroiZTPRpWsDdjiS5XQL21GK-heo5Set_E,531
|
51
|
+
gimlet_api-0.0.9.dist-info/RECORD,,
|
gml/client.py
CHANGED
@@ -19,6 +19,8 @@ import uuid
|
|
19
19
|
from pathlib import Path
|
20
20
|
from typing import BinaryIO, List, Optional, TextIO, Union
|
21
21
|
|
22
|
+
import grpc
|
23
|
+
|
22
24
|
import gml.proto.src.api.corepb.v1.model_exec_pb2 as modelexecpb
|
23
25
|
import gml.proto.src.common.typespb.uuid_pb2 as uuidpb
|
24
26
|
import gml.proto.src.controlplane.compiler.cpb.v1.cpb_pb2 as cpb
|
@@ -31,7 +33,6 @@ import gml.proto.src.controlplane.logicalpipeline.lppb.v1.lppb_pb2 as lppb
|
|
31
33
|
import gml.proto.src.controlplane.logicalpipeline.lppb.v1.lppb_pb2_grpc as lppb_grpc
|
32
34
|
import gml.proto.src.controlplane.model.mpb.v1.mpb_pb2 as mpb
|
33
35
|
import gml.proto.src.controlplane.model.mpb.v1.mpb_pb2_grpc as mpb_grpc
|
34
|
-
import grpc
|
35
36
|
from gml._utils import chunk_file, sha256sum
|
36
37
|
from gml.device import DeviceCapabilities
|
37
38
|
from gml.model import Model
|
@@ -252,7 +253,7 @@ class Client:
|
|
252
253
|
raise Exception("file status is deleted or unknown, cannot re-upload")
|
253
254
|
return file_info
|
254
255
|
|
255
|
-
def _get_model_if_exists(self, name: str) -> Optional[
|
256
|
+
def _get_model_if_exists(self, name: str) -> Optional[modelexecpb.Model]:
|
256
257
|
req = mpb.GetModelRequest(
|
257
258
|
name=name,
|
258
259
|
org_id=self._get_org_id(),
|
@@ -260,13 +261,13 @@ class Client:
|
|
260
261
|
stub = self._ms_stub()
|
261
262
|
try:
|
262
263
|
resp = stub.GetModel(req, metadata=self._get_request_metadata())
|
263
|
-
return
|
264
|
+
return modelexecpb.Model(id=resp.id, info=resp.model_info)
|
264
265
|
except grpc.RpcError as e:
|
265
266
|
if e.code() != grpc.StatusCode.NOT_FOUND:
|
266
267
|
raise e
|
267
268
|
return None
|
268
269
|
|
269
|
-
def _create_model(self, model_info: modelexecpb.ModelInfo) ->
|
270
|
+
def _create_model(self, model_info: modelexecpb.ModelInfo) -> modelexecpb.Model:
|
270
271
|
req = mpb.CreateModelRequest(
|
271
272
|
org_id=self._get_org_id(),
|
272
273
|
name=model_info.name,
|
@@ -276,9 +277,9 @@ class Client:
|
|
276
277
|
resp = stub.CreateModel(
|
277
278
|
req, metadata=self._get_request_metadata(idempotent=True)
|
278
279
|
)
|
279
|
-
return
|
280
|
+
return modelexecpb.Model(id=resp.id, info=model_info)
|
280
281
|
|
281
|
-
def create_model(self, model: Model) ->
|
282
|
+
def create_model(self, model: Model) -> modelexecpb.Model:
|
282
283
|
existing_model = self._get_model_if_exists(model.name)
|
283
284
|
if existing_model is not None:
|
284
285
|
print(
|
@@ -350,8 +351,8 @@ class Client:
|
|
350
351
|
models: List[Model],
|
351
352
|
pipeline_file: Optional[Path] = None,
|
352
353
|
pipeline: Optional[Union[str, Pipeline]] = None,
|
353
|
-
runtimes
|
354
|
-
cameras
|
354
|
+
runtimes: List[str],
|
355
|
+
cameras: List[str],
|
355
356
|
):
|
356
357
|
model_with_assets = []
|
357
358
|
for model in models:
|
gml/compile.py
CHANGED
@@ -21,7 +21,6 @@ from typing import Any, Dict, List, Optional, Sequence, Union
|
|
21
21
|
import safetensors_mlir
|
22
22
|
import torch
|
23
23
|
import torch_mlir
|
24
|
-
from gml.asset_manager import AssetManager
|
25
24
|
from mlir.ir import (
|
26
25
|
BF16Type,
|
27
26
|
ComplexType,
|
@@ -39,9 +38,12 @@ from torch._decomp import remove_decompositions
|
|
39
38
|
from torch.export._trace import _export
|
40
39
|
from torch_mlir.dialects import torch as torch_d
|
41
40
|
from torch_mlir.extras.fx_decomp_util import get_decomposition_table
|
42
|
-
from torch_mlir.extras.fx_importer import FxImporter, FxImporterHooks
|
41
|
+
from torch_mlir.extras.fx_importer import FxImporter, FxImporterHooks, InputInfo
|
43
42
|
from torch_mlir.fx import export_and_import
|
44
43
|
|
44
|
+
from gml.asset_manager import AssetManager
|
45
|
+
from gml.register_submodules import submodule_registration_workarounds
|
46
|
+
|
45
47
|
|
46
48
|
def _default_decomposition_denylist():
|
47
49
|
"""These ops will not be decomposed by default."""
|
@@ -130,7 +132,10 @@ class SafetensorImporterHooks(FxImporterHooks):
|
|
130
132
|
self._tensors = TensorSet()
|
131
133
|
|
132
134
|
def resolve_literal(
|
133
|
-
self,
|
135
|
+
self,
|
136
|
+
gni: "torch_mlir.extras.fx_importer.GraphNodeImporter",
|
137
|
+
literal: Any,
|
138
|
+
info: Optional[InputInfo],
|
134
139
|
) -> Optional[Value]:
|
135
140
|
if not isinstance(literal, torch.Tensor):
|
136
141
|
return None
|
@@ -166,92 +171,6 @@ class SafetensorImporterHooks(FxImporterHooks):
|
|
166
171
|
save_file(tensors, file_path)
|
167
172
|
|
168
173
|
|
169
|
-
def _to_module_list(val):
|
170
|
-
if isinstance(val, torch.nn.Module):
|
171
|
-
return val
|
172
|
-
|
173
|
-
converted = []
|
174
|
-
for item in val:
|
175
|
-
c = _to_module_container(item)
|
176
|
-
if c is None:
|
177
|
-
return None
|
178
|
-
converted.append(c)
|
179
|
-
if not converted:
|
180
|
-
return None
|
181
|
-
return torch.nn.ModuleList(converted)
|
182
|
-
|
183
|
-
|
184
|
-
def _to_module_dict(val):
|
185
|
-
if isinstance(val, torch.nn.Module):
|
186
|
-
return val
|
187
|
-
|
188
|
-
converted = dict()
|
189
|
-
for k, v in val.items():
|
190
|
-
c = _to_module_container(v)
|
191
|
-
if c is None:
|
192
|
-
return None
|
193
|
-
converted[k] = v
|
194
|
-
if not converted:
|
195
|
-
return None
|
196
|
-
return torch.nn.ModuleDict(converted)
|
197
|
-
|
198
|
-
|
199
|
-
def _to_module_container(val, root=False):
|
200
|
-
if isinstance(val, torch.nn.Module) and not root:
|
201
|
-
return val
|
202
|
-
if isinstance(val, dict):
|
203
|
-
return _to_module_dict(val)
|
204
|
-
if isinstance(val, list) or isinstance(val, tuple):
|
205
|
-
return _to_module_list(val)
|
206
|
-
|
207
|
-
return None
|
208
|
-
|
209
|
-
|
210
|
-
def _replace_containers_with_torch_containers(mod: torch.nn.Module):
|
211
|
-
"""Replaces any lists, dict, or nested combinations of lists/dicts that are attributes of `mod` with torch.nn.ModuleList/torch.nn.ModuleDict
|
212
|
-
|
213
|
-
This fixes some `module is not installed as a submodule` errors.
|
214
|
-
."""
|
215
|
-
_excludes = set(["_modules"])
|
216
|
-
replacements = dict()
|
217
|
-
for name, val in mod.__dict__.items():
|
218
|
-
if name in _excludes:
|
219
|
-
continue
|
220
|
-
c = _to_module_container(val, root=True)
|
221
|
-
if c is None:
|
222
|
-
continue
|
223
|
-
replacements[name] = c
|
224
|
-
|
225
|
-
for name, repl in replacements.items():
|
226
|
-
setattr(mod, name, repl)
|
227
|
-
|
228
|
-
|
229
|
-
def _ensure_submodules_accessed_through_getattr(mod: torch.nn.Module):
|
230
|
-
"""This removes any registered modules from `mod.__dict__`.
|
231
|
-
|
232
|
-
This ensures that all accesses of submodules go through torch's __getattr__ infra,
|
233
|
-
preventing certain cases of `module is not installed as a submodule` errors.
|
234
|
-
"""
|
235
|
-
if not hasattr(mod, "_modules"):
|
236
|
-
return
|
237
|
-
for name in mod._modules:
|
238
|
-
if name in mod.__dict__:
|
239
|
-
del mod.__dict__[name]
|
240
|
-
|
241
|
-
|
242
|
-
def _submodule_registration_workarounds(mod: torch.nn.Module):
|
243
|
-
"""Apply submodule registration workarounds recursively to all submodules of `mod`."""
|
244
|
-
_ensure_submodules_accessed_through_getattr(mod)
|
245
|
-
_replace_containers_with_torch_containers(mod)
|
246
|
-
# We intentionally don't use `mod.modules()` (which returns all recursive submodules) here because we want only
|
247
|
-
# the direct dependencies of `mod`. So that we get a pre-order traversal, ensuring the workarounds are applied
|
248
|
-
# before we check for submodules.
|
249
|
-
for submod in mod._modules.values():
|
250
|
-
if submod is mod:
|
251
|
-
continue
|
252
|
-
_submodule_registration_workarounds(submod)
|
253
|
-
|
254
|
-
|
255
174
|
def to_torch_mlir(
|
256
175
|
model: torch.nn.Module,
|
257
176
|
example_inputs: Sequence[torch.Tensor],
|
@@ -266,16 +185,17 @@ def to_torch_mlir(
|
|
266
185
|
if not isinstance(shape, dict):
|
267
186
|
continue
|
268
187
|
for idx in shape:
|
269
|
-
|
188
|
+
# Assign the value so that pyright understands the type.
|
189
|
+
value = shape[idx]
|
190
|
+
if isinstance(value, torch.export.dynamic_shapes._Dim):
|
270
191
|
continue
|
271
|
-
shape[idx] = torch.export.Dim(
|
272
|
-
|
192
|
+
shape[idx] = torch.export.Dim(value)
|
273
193
|
if decomposition_denylist is None:
|
274
194
|
decomposition_denylist = _default_decomposition_denylist()
|
275
195
|
|
276
196
|
model = model.eval().to("cpu")
|
277
197
|
|
278
|
-
|
198
|
+
submodule_registration_workarounds(model)
|
279
199
|
|
280
200
|
try:
|
281
201
|
# Running the model a few times on the inputs, leads to more consistent compiled results.
|
gml/device.py
CHANGED
@@ -51,16 +51,14 @@ class DeviceCapabilities:
|
|
51
51
|
|
52
52
|
def _runtime_str_to_runtime_protos(
|
53
53
|
runtime: str,
|
54
|
-
) -> deviceinfopb.
|
54
|
+
) -> deviceinfopb.ModelRuntimeType:
|
55
55
|
match runtime.lower():
|
56
56
|
case "tensorrt":
|
57
|
-
return
|
58
|
-
deviceinfopb.ModelRuntimeInfo.ModelRuntimeType.MODEL_RUNTIME_TYPE_TENSORRT
|
59
|
-
)
|
57
|
+
return deviceinfopb.ModelRuntimeType.MODEL_RUNTIME_TYPE_TENSORRT
|
60
58
|
case "openvino":
|
61
|
-
return
|
62
|
-
|
63
|
-
|
59
|
+
return deviceinfopb.ModelRuntimeType.MODEL_RUNTIME_TYPE_OPENVINO
|
60
|
+
case "hailort":
|
61
|
+
return deviceinfopb.ModelRuntimeType.MODEL_RUNTIME_TYPE_HAILORT
|
64
62
|
case _:
|
65
63
|
raise ValueError("invalid runtime: {}".format(runtime))
|
66
64
|
|