Skip to content

Commit 5ed52fb

Browse files
gcarranza-1copybara-github
authored andcommitted
Rename to aot_types.py
LiteRT-PiperOrigin-RevId: 883235059
1 parent 85d3747 commit 5ed52fb

35 files changed

+243
-238
lines changed

ci/tools/python/wheel/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ALL_PY_SRC_MODULES = [
115115
"//litert/python/aot:aot_compile",
116116
"//litert/python/aot/ai_pack:export_lib",
117117
"//litert/python/aot/core:common",
118-
"//litert/python/aot/core:types",
118+
"//litert/python/aot/core:aot_types",
119119
"//litert/python/aot/core:apply_plugin",
120120
"//litert/python/aot/core:mlir_transforms",
121121
"//litert/python/aot/core:components",

litert/python/aot/BUILD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ pytype_strict_library(
2525
visibility = ["//visibility:public"],
2626
deps = [
2727
":prepare_for_npu",
28+
"//litert/python/aot/core:aot_types",
2829
"//litert/python/aot/core:apply_plugin",
2930
"//litert/python/aot/core:components",
3031
"//litert/python/aot/core:mlir_transforms",
31-
"//litert/python/aot/core:types",
3232
"//litert/python/aot/vendors:import_vendor",
3333
],
3434
)
@@ -51,9 +51,9 @@ pytype_strict_contrib_test(
5151
],
5252
deps = [
5353
":aot_compile",
54+
"//litert/python/aot/core:aot_types",
5455
"//litert/python/aot/core:common",
5556
"//litert/python/aot/core:test_common",
56-
"//litert/python/aot/core:types",
5757
"//litert/python/aot/vendors/mediatek:target",
5858
"//litert/python/aot/vendors/qualcomm:target",
5959
"@absl_py//absl/testing:absltest",
@@ -64,9 +64,9 @@ pytype_strict_library(
6464
name = "prepare_for_npu",
6565
srcs = ["prepare_for_npu.py"],
6666
deps = [
67+
"//litert/python/aot/core:aot_types",
6768
"//litert/python/aot/core:common",
6869
"//litert/python/aot/core:components",
69-
"//litert/python/aot/core:types",
7070
"//litert/python/aot/vendors", # buildcleaner: keep
7171
"//litert/python/aot/vendors:import_vendor",
7272
"@tqdm",
@@ -78,10 +78,10 @@ pytype_strict_contrib_test(
7878
srcs = ["prepare_for_npu_test.py"],
7979
deps = [
8080
":prepare_for_npu",
81+
"//litert/python/aot/core:aot_types",
8182
"//litert/python/aot/core:common",
8283
"//litert/python/aot/core:components",
8384
"//litert/python/aot/core:test_common",
84-
"//litert/python/aot/core:types",
8585
"//litert/python/aot/vendors/example:example_backend",
8686
"@absl_py//absl/testing:absltest",
8787
],

litert/python/aot/ai_pack/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pytype_strict_library(
2424
srcs = ["export_lib.py"],
2525
visibility = ["//visibility:public"],
2626
deps = [
27+
"//litert/python/aot/core:aot_types",
2728
"//litert/python/aot/core:common",
28-
"//litert/python/aot/core:types",
2929
"//litert/python/aot/vendors:fallback_backend",
3030
"//litert/python/aot/vendors/google_tensor:target",
3131
"//litert/python/aot/vendors/mediatek:mediatek_backend",
@@ -40,7 +40,7 @@ pytype_strict_contrib_test(
4040
srcs = ["export_lib_test.py"],
4141
deps = [
4242
":export_lib",
43-
"//litert/python/aot/core:types",
43+
"//litert/python/aot/core:aot_types",
4444
"//litert/python/aot/vendors:fallback_backend",
4545
"//litert/python/aot/vendors/google_tensor:target",
4646
"@absl_py//absl/testing:absltest",

litert/python/aot/ai_pack/export_lib.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import pathlib
1919
from typing import cast
2020

21+
from litert.python.aot.core import aot_types
2122
from litert.python.aot.core import common
22-
from litert.python.aot.core import types
2323
from litert.python.aot.vendors import fallback_backend
2424
from litert.python.aot.vendors.google_tensor import target as google_tensor_target
2525
from litert.python.aot.vendors.mediatek import mediatek_backend
@@ -44,7 +44,7 @@
4444
</config:device-selector>"""
4545

4646

47-
def _is_mobile_device_backend(backend: types.Backend):
47+
def _is_mobile_device_backend(backend: aot_types.Backend):
4848
"""Returns True if the backend is a mobile device backend."""
4949
target = backend.target
5050
if backend.id() == qualcomm_backend.QualcommBackend.id():
@@ -68,7 +68,7 @@ def _is_mobile_device_backend(backend: types.Backend):
6868

6969

7070
def _export_model_files_to_ai_pack(
71-
compiled_models: types.CompilationResult,
71+
compiled_models: aot_types.CompilationResult,
7272
ai_pack_dir: pathlib.Path,
7373
ai_pack_name: str,
7474
litert_model_name: str,
@@ -131,7 +131,7 @@ def _export_model_files_to_ai_pack(
131131

132132

133133
def _export_model_files_to_mtk_ai_pack(
134-
compiled_models: types.CompilationResult,
134+
compiled_models: aot_types.CompilationResult,
135135
ai_pack_dir: pathlib.Path,
136136
ai_pack_name: str,
137137
litert_model_name: str,
@@ -164,7 +164,7 @@ def _export_model_files_to_mtk_ai_pack(
164164
model.save(model_export_path, export_only=True)
165165

166166

167-
def _build_targeting_config(compiled_backends: list[types.Backend]) -> str:
167+
def _build_targeting_config(compiled_backends: list[aot_types.Backend]) -> str:
168168
"""Builds device-targeting-config in device_targeting_configuration.xml."""
169169
device_groups = []
170170
for backend in compiled_backends:
@@ -178,7 +178,7 @@ def _build_targeting_config(compiled_backends: list[types.Backend]) -> str:
178178
return _DEVICE_TARGETING_CONFIGURATION.format(device_groups=device_groups)
179179

180180

181-
def _target_to_ai_pack_info(target: types.Target) -> str | None:
181+
def _target_to_ai_pack_info(target: aot_types.Target) -> str | None:
182182
"""Builds the device group used in device_targeting_configuration.xml."""
183183
if isinstance(target, qnn_target.Target):
184184
group_name = str(target)
@@ -252,7 +252,7 @@ def _process_google_tensor_target(
252252

253253

254254
def _write_targeting_config(
255-
compiled_models: types.CompilationResult, ai_pack_dir: pathlib.Path
255+
compiled_models: aot_types.CompilationResult, ai_pack_dir: pathlib.Path
256256
) -> None:
257257
"""Writes device_targeting_configuration.xml for the given compiled models."""
258258
compiled_backends = [x for x, _ in compiled_models.models_with_backend]
@@ -265,7 +265,7 @@ def _write_targeting_config(
265265

266266

267267
def export(
268-
compiled_models: types.CompilationResult,
268+
compiled_models: aot_types.CompilationResult,
269269
ai_pack_dir: pathlib.Path | str,
270270
ai_pack_name: str,
271271
litert_model_name: str,

litert/python/aot/ai_pack/export_lib_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@
1717
from unittest import mock
1818
from absl.testing import absltest as googletest
1919
from litert.python.aot.ai_pack import export_lib
20-
from litert.python.aot.core import types
20+
from litert.python.aot.core import aot_types
2121
from litert.python.aot.vendors import fallback_backend
2222
from litert.python.aot.vendors.google_tensor import target as google_tensor_target
2323

2424

2525
def _create_test_model():
26-
test_model = types.Model(model_bytes=b"test_model")
26+
test_model = aot_types.Model(model_bytes=b"test_model")
2727
return test_model
2828

2929

3030
def _create_mock_google_tensor_backend(
3131
soc_model: google_tensor_target.SocModel,
3232
):
33-
mock_backend = mock.Mock(spec=types.Backend)
33+
mock_backend = mock.Mock(spec=aot_types.Backend)
3434
mock_backend.target = google_tensor_target.Target(soc_model=soc_model)
3535
mock_backend.target_id = str(mock_backend.target)
3636
mock_backend.id.return_value = google_tensor_target.Target.backend_id()
3737
return mock_backend
3838

3939

4040
def _create_mock_fallback_backend():
41-
mock_backend = mock.Mock(spec=types.Backend)
41+
mock_backend = mock.Mock(spec=aot_types.Backend)
4242
mock_backend.target = fallback_backend.FallbackTarget()
4343
mock_backend.target_id = fallback_backend.FallbackBackend.id()
4444
mock_backend.id.return_value = fallback_backend.FallbackBackend.id()
@@ -48,7 +48,7 @@ def _create_mock_fallback_backend():
4848
class ExportLibTest(googletest.TestCase):
4949

5050
def test_export_with_fallback_model_succeeds(self):
51-
mock_compilation_result = types.CompilationResult(
51+
mock_compilation_result = aot_types.CompilationResult(
5252
models_with_backend=[
5353
(
5454
_create_mock_fallback_backend(),
@@ -95,7 +95,7 @@ def test_export_with_fallback_model_succeeds(self):
9595
)
9696

9797
def test_export_without_fallback_model_fails(self):
98-
mock_compilation_result = types.CompilationResult()
98+
mock_compilation_result = aot_types.CompilationResult()
9999
with self.assertRaises(AssertionError):
100100
export_lib.export(
101101
compiled_models=mock_compilation_result,
@@ -106,7 +106,7 @@ def test_export_without_fallback_model_fails(self):
106106

107107
def test_export_with_google_tensor_target_succeeds(self):
108108
output_dir = self.create_tempdir().full_path
109-
mock_compilation_result = types.CompilationResult(
109+
mock_compilation_result = aot_types.CompilationResult(
110110
models_with_backend=[
111111
(
112112
_create_mock_google_tensor_backend(

litert/python/aot/aot_compile.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
import tempfile
1919

2020
from litert.python.aot import prepare_for_npu as core
21+
from litert.python.aot.core import aot_types
2122
from litert.python.aot.core import apply_plugin
2223
from litert.python.aot.core import components
2324
from litert.python.aot.core import mlir_transforms
24-
from litert.python.aot.core import types
2525
from litert.python.aot.vendors import import_vendor
2626

2727

2828
def aot_compile(
29-
input_model: types.Model | str,
29+
input_model: aot_types.Model | str,
3030
output_dir: str | pathlib.Path | None = None,
31-
target: types.Target | list[types.Target] | None = None,
31+
target: aot_types.Target | list[aot_types.Target] | None = None,
3232
config: (
33-
types.CompilationConfig | list[types.CompilationConfig] | None
33+
aot_types.CompilationConfig | list[aot_types.CompilationConfig] | None
3434
) = None,
3535
quantizer: components.AieQuantizerT | None = None,
3636
keep_going: bool = True,
3737
subgraphs_to_compile: list[int] | None = None,
3838
**kwargs,
39-
) -> types.CompilationResult:
39+
) -> aot_types.CompilationResult:
4040
"""Prepares a TFLite model for NPU execution.
4141
4242
High level command that erforms various backend specific pre-processing steps
@@ -66,16 +66,16 @@ def aot_compile(
6666
if config is None:
6767
if target is None:
6868
target = import_vendor.AllRegisteredTarget()
69-
if isinstance(target, types.Target):
70-
config = types.CompilationConfig(target=target)
69+
if isinstance(target, aot_types.Target):
70+
config = aot_types.CompilationConfig(target=target)
7171
elif isinstance(target, list):
72-
config = [types.CompilationConfig(target=t) for t in target]
72+
config = [aot_types.CompilationConfig(target=t) for t in target]
7373
else:
7474
raise ValueError("Unsupported target type.")
7575

7676
if isinstance(input_model, str):
7777
input_path = pathlib.Path(input_model)
78-
input_model = types.Model.create_from_path(input_path)
78+
input_model = aot_types.Model.create_from_path(input_path)
7979

8080
# Resolve output paths.
8181
temp_dir = None
@@ -94,10 +94,10 @@ def aot_compile(
9494
output_dir_path = pathlib.Path(output_dir)
9595
output_dir_path.mkdir(parents=True, exist_ok=True)
9696

97-
if isinstance(config, types.CompilationConfig) or not config:
97+
if isinstance(config, aot_types.CompilationConfig) or not config:
9898
if config:
9999
# Make pytype happy.
100-
assert isinstance(config, types.CompilationConfig)
100+
assert isinstance(config, aot_types.CompilationConfig)
101101
kw_config = config.to_dict() | kwargs
102102
else:
103103
kw_config = kwargs

litert/python/aot/aot_compile_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
from absl.testing import absltest as googletest
1717
from litert.python.aot import aot_compile as aot_compile_lib
18+
from litert.python.aot.core import aot_types
1819
from litert.python.aot.core import test_common
19-
from litert.python.aot.core import types
2020
from litert.python.aot.vendors.mediatek import target as mtk_target
2121
from litert.python.aot.vendors.qualcomm import target as qnn_target
2222

@@ -31,7 +31,7 @@ def test_compile(self):
3131
for path in self.get_model_paths():
3232
results.append(
3333
aot_compile_lib.aot_compile(
34-
types.Model.create_from_path(path),
34+
aot_types.Model.create_from_path(path),
3535
output_dir=self.output_dir(),
3636
target=[sm8450_target, mt6989_target],
3737
keep_going=True,

litert/python/aot/core/BUILD

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ pytype_strict_library(
5151
)
5252

5353
pytype_strict_library(
54-
name = "types",
55-
srcs = ["types.py"],
54+
name = "aot_types",
55+
srcs = ["aot_types.py"],
5656
visibility = ["//visibility:public"],
5757
)
5858

@@ -66,9 +66,9 @@ pytype_strict_library(
6666
"//conditions:default": [],
6767
}),
6868
deps = [
69+
":aot_types",
6970
":common",
7071
":components",
71-
":types",
7272
],
7373
)
7474

@@ -81,9 +81,9 @@ pytype_strict_contrib_test(
8181
"nosan",
8282
],
8383
deps = [
84+
":aot_types",
8485
":apply_plugin",
8586
":test_common",
86-
":types",
8787
"@absl_py//absl/testing:absltest",
8888
],
8989
)
@@ -104,35 +104,35 @@ pytype_strict_library(
104104
name = "mlir_transforms",
105105
srcs = ["mlir_transforms.py"],
106106
deps = [
107+
":aot_types",
107108
":components",
108109
":tflxx_util",
109-
":types",
110110
],
111111
)
112112

113113
pytype_strict_library(
114114
name = "components",
115115
srcs = ["components.py"],
116116
visibility = ["//visibility:public"],
117-
deps = [":types"],
117+
deps = [":aot_types"],
118118
)
119119

120120
pytype_strict_library(
121121
name = "tflxx_util",
122122
srcs = ["tflxx_util.py"],
123123
deps = [
124-
":types",
124+
":aot_types",
125125
] + tflxx_deps_if_enabled(),
126126
)
127127

128128
pytype_strict_contrib_test(
129129
name = "mlir_transforms_test",
130130
srcs = ["mlir_transforms_test.py"],
131131
deps = [
132+
":aot_types",
132133
":common",
133134
":mlir_transforms",
134135
":test_common",
135-
":types",
136136
"@absl_py//absl/testing:absltest",
137137
],
138138
)

litert/python/aot/core/apply_plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import subprocess
2222
import tempfile
2323

24+
from litert.python.aot.core import aot_types
2425
from litert.python.aot.core import common
2526
from litert.python.aot.core import components
26-
from litert.python.aot.core import types
2727

2828
_BINARY = pathlib.Path("tools/apply_plugin_main")
2929

@@ -55,8 +55,8 @@ def component_name(self) -> str:
5555

5656
def __call__(
5757
self,
58-
input_model: types.Model,
59-
output_model: types.Model,
58+
input_model: aot_types.Model,
59+
output_model: aot_types.Model,
6060
soc_manufacturer: str,
6161
soc_model: str,
6262
sdk_libs_path: str | None = None,
@@ -138,9 +138,9 @@ def __call__(
138138
raise ValueError(f"{output_model.path} is not a TFLite model.")
139139

140140
partition_stats = _RE_PARTITION_STATS.findall(result.stdout)
141-
output_model.partition_stats = types.PartitionStats(
141+
output_model.partition_stats = aot_types.PartitionStats(
142142
subgraph_stats=[
143-
types.SubgraphPartitionStats(
143+
aot_types.SubgraphPartitionStats(
144144
subgraph_index=int(s[0]),
145145
num_ops_offloaded=int(s[1]),
146146
num_total_ops=int(s[2]),

0 commit comments

Comments
 (0)