ai-edge-litert-nightly 2.2.0.dev20260102__cp312-cp312-manylinux_2_27_x86_64.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.
Files changed (78) hide show
  1. ai_edge_litert/__init__.py +1 -0
  2. ai_edge_litert/_pywrap_analyzer_wrapper.so +0 -0
  3. ai_edge_litert/_pywrap_litert_compiled_model_wrapper.so +0 -0
  4. ai_edge_litert/_pywrap_litert_interpreter_wrapper.so +0 -0
  5. ai_edge_litert/_pywrap_litert_tensor_buffer_wrapper.so +0 -0
  6. ai_edge_litert/_pywrap_modify_model_interface.so +0 -0
  7. ai_edge_litert/_pywrap_string_util.so +0 -0
  8. ai_edge_litert/_pywrap_tensorflow_lite_calibration_wrapper.so +0 -0
  9. ai_edge_litert/_pywrap_tensorflow_lite_metrics_wrapper.so +0 -0
  10. ai_edge_litert/any_pb2.py +37 -0
  11. ai_edge_litert/aot/__init__.py +0 -0
  12. ai_edge_litert/aot/ai_pack/__init__.py +0 -0
  13. ai_edge_litert/aot/ai_pack/export_lib.py +300 -0
  14. ai_edge_litert/aot/aot_compile.py +153 -0
  15. ai_edge_litert/aot/core/__init__.py +0 -0
  16. ai_edge_litert/aot/core/apply_plugin.py +148 -0
  17. ai_edge_litert/aot/core/common.py +97 -0
  18. ai_edge_litert/aot/core/components.py +93 -0
  19. ai_edge_litert/aot/core/mlir_transforms.py +36 -0
  20. ai_edge_litert/aot/core/tflxx_util.py +30 -0
  21. ai_edge_litert/aot/core/types.py +374 -0
  22. ai_edge_litert/aot/prepare_for_npu.py +152 -0
  23. ai_edge_litert/aot/vendors/__init__.py +22 -0
  24. ai_edge_litert/aot/vendors/example/__init__.py +0 -0
  25. ai_edge_litert/aot/vendors/example/example_backend.py +157 -0
  26. ai_edge_litert/aot/vendors/fallback_backend.py +128 -0
  27. ai_edge_litert/aot/vendors/google_tensor/__init__.py +0 -0
  28. ai_edge_litert/aot/vendors/google_tensor/google_tensor_backend.py +168 -0
  29. ai_edge_litert/aot/vendors/google_tensor/target.py +84 -0
  30. ai_edge_litert/aot/vendors/import_vendor.py +132 -0
  31. ai_edge_litert/aot/vendors/mediatek/__init__.py +0 -0
  32. ai_edge_litert/aot/vendors/mediatek/mediatek_backend.py +196 -0
  33. ai_edge_litert/aot/vendors/mediatek/target.py +94 -0
  34. ai_edge_litert/aot/vendors/qualcomm/__init__.py +0 -0
  35. ai_edge_litert/aot/vendors/qualcomm/qualcomm_backend.py +161 -0
  36. ai_edge_litert/aot/vendors/qualcomm/target.py +75 -0
  37. ai_edge_litert/api_pb2.py +43 -0
  38. ai_edge_litert/compiled_model.py +250 -0
  39. ai_edge_litert/descriptor_pb2.py +3361 -0
  40. ai_edge_litert/duration_pb2.py +37 -0
  41. ai_edge_litert/empty_pb2.py +37 -0
  42. ai_edge_litert/field_mask_pb2.py +37 -0
  43. ai_edge_litert/format_converter_wrapper_pybind11.so +0 -0
  44. ai_edge_litert/hardware_accelerator.py +22 -0
  45. ai_edge_litert/internal/__init__.py +0 -0
  46. ai_edge_litert/internal/litertlm_builder.py +584 -0
  47. ai_edge_litert/internal/litertlm_core.py +58 -0
  48. ai_edge_litert/internal/litertlm_header_schema_py_generated.py +1596 -0
  49. ai_edge_litert/internal/llm_metadata_pb2.py +45 -0
  50. ai_edge_litert/internal/llm_model_type_pb2.py +51 -0
  51. ai_edge_litert/internal/sampler_params_pb2.py +39 -0
  52. ai_edge_litert/internal/token_pb2.py +38 -0
  53. ai_edge_litert/interpreter.py +1039 -0
  54. ai_edge_litert/libLiteRt.so +0 -0
  55. ai_edge_litert/libpywrap_litert_common.so +0 -0
  56. ai_edge_litert/metrics_interface.py +48 -0
  57. ai_edge_litert/metrics_portable.py +70 -0
  58. ai_edge_litert/model_runtime_info_pb2.py +66 -0
  59. ai_edge_litert/plugin_pb2.py +46 -0
  60. ai_edge_litert/profiling_info_pb2.py +47 -0
  61. ai_edge_litert/pywrap_genai_ops.so +0 -0
  62. ai_edge_litert/schema_py_generated.py +19640 -0
  63. ai_edge_litert/source_context_pb2.py +37 -0
  64. ai_edge_litert/struct_pb2.py +47 -0
  65. ai_edge_litert/tensor_buffer.py +167 -0
  66. ai_edge_litert/timestamp_pb2.py +37 -0
  67. ai_edge_litert/tools/__init__.py +0 -0
  68. ai_edge_litert/tools/apply_plugin_main +0 -0
  69. ai_edge_litert/tools/flatbuffer_utils.py +534 -0
  70. ai_edge_litert/type_pb2.py +53 -0
  71. ai_edge_litert/vendors/google_tensor/compiler/libLiteRtCompilerPlugin_google_tensor.so +0 -0
  72. ai_edge_litert/vendors/mediatek/compiler/libLiteRtCompilerPlugin_MediaTek.so +0 -0
  73. ai_edge_litert/vendors/qualcomm/compiler/libLiteRtCompilerPlugin_Qualcomm.so +0 -0
  74. ai_edge_litert/wrappers_pb2.py +53 -0
  75. ai_edge_litert_nightly-2.2.0.dev20260102.dist-info/METADATA +52 -0
  76. ai_edge_litert_nightly-2.2.0.dev20260102.dist-info/RECORD +78 -0
  77. ai_edge_litert_nightly-2.2.0.dev20260102.dist-info/WHEEL +5 -0
  78. ai_edge_litert_nightly-2.2.0.dev20260102.dist-info/top_level.txt +1 -0
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/source_context.proto
5
+ # Protobuf Python Version: 6.31.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 6,
15
+ 31,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/source_context.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$google/protobuf/source_context.proto\x12\x0fgoogle.protobuf\"\"\n\rSourceContext\x12\x11\n\tfile_name\x18\x01 \x01(\tB\x8a\x01\n\x13\x63om.google.protobufB\x12SourceContextProtoP\x01Z6google.golang.org/protobuf/types/known/sourcecontextpb\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.source_context_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\022SourceContextProtoP\001Z6google.golang.org/protobuf/types/known/sourcecontextpb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
35
+ _globals['_SOURCECONTEXT']._serialized_start=57
36
+ _globals['_SOURCECONTEXT']._serialized_end=91
37
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,47 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/struct.proto
5
+ # Protobuf Python Version: 6.31.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 6,
15
+ 31,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/struct.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1cgoogle/protobuf/struct.proto\x12\x0fgoogle.protobuf\"\x84\x01\n\x06Struct\x12\x33\n\x06\x66ields\x18\x01 \x03(\x0b\x32#.google.protobuf.Struct.FieldsEntry\x1a\x45\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12%\n\x05value\x18\x02 \x01(\x0b\x32\x16.google.protobuf.Value:\x02\x38\x01\"\xea\x01\n\x05Value\x12\x30\n\nnull_value\x18\x01 \x01(\x0e\x32\x1a.google.protobuf.NullValueH\x00\x12\x16\n\x0cnumber_value\x18\x02 \x01(\x01H\x00\x12\x16\n\x0cstring_value\x18\x03 \x01(\tH\x00\x12\x14\n\nbool_value\x18\x04 \x01(\x08H\x00\x12/\n\x0cstruct_value\x18\x05 \x01(\x0b\x32\x17.google.protobuf.StructH\x00\x12\x30\n\nlist_value\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x00\x42\x06\n\x04kind\"3\n\tListValue\x12&\n\x06values\x18\x01 \x03(\x0b\x32\x16.google.protobuf.Value*\x1b\n\tNullValue\x12\x0e\n\nNULL_VALUE\x10\x00\x42\x7f\n\x13\x63om.google.protobufB\x0bStructProtoP\x01Z/google.golang.org/protobuf/types/known/structpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.struct_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\013StructProtoP\001Z/google.golang.org/protobuf/types/known/structpb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
35
+ _globals['_STRUCT_FIELDSENTRY']._loaded_options = None
36
+ _globals['_STRUCT_FIELDSENTRY']._serialized_options = b'8\001'
37
+ _globals['_NULLVALUE']._serialized_start=474
38
+ _globals['_NULLVALUE']._serialized_end=501
39
+ _globals['_STRUCT']._serialized_start=50
40
+ _globals['_STRUCT']._serialized_end=182
41
+ _globals['_STRUCT_FIELDSENTRY']._serialized_start=113
42
+ _globals['_STRUCT_FIELDSENTRY']._serialized_end=182
43
+ _globals['_VALUE']._serialized_start=185
44
+ _globals['_VALUE']._serialized_end=419
45
+ _globals['_LISTVALUE']._serialized_start=421
46
+ _globals['_LISTVALUE']._serialized_end=472
47
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,167 @@
1
+ # Copyright 2025 Google LLC.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Python wrapper for LiteRT tensor buffer."""
16
+
17
+ import os
18
+ import numpy as np
19
+
20
+ # pylint: disable=g-import-not-at-top
21
+ if not os.path.splitext(__file__)[0].endswith(
22
+ os.path.join("ai_edge_litert", "tensor_buffer")
23
+ ):
24
+ # This file is part of litert package.
25
+ from ai_edge_litert.litert_wrapper.tensor_buffer_wrapper import _pywrap_litert_tensor_buffer_wrapper as _tb
26
+ else:
27
+ # This file is part of ai_edge_litert package.
28
+ from ai_edge_litert import _pywrap_litert_tensor_buffer_wrapper as _tb
29
+ # pylint: enable=g-import-not-at-top
30
+
31
+
32
+ class TensorBuffer:
33
+ """Python wrapper for LiteRtTensorBuffer.
34
+
35
+ This class provides a high-level interface to the underlying C++
36
+ LiteRtTensorBuffer
37
+ implementation, allowing for creation, reading, writing, and management of
38
+ tensor
39
+ buffers in Python.
40
+ """
41
+
42
+ def __init__(self, capsule):
43
+ """Initializes a TensorBuffer with the provided PyCapsule.
44
+
45
+ Args:
46
+ capsule: A PyCapsule containing a pointer to a LiteRtTensorBuffer.
47
+ """
48
+ self._capsule = capsule
49
+
50
+ @staticmethod
51
+ def _dtype_to_str(np_dtype):
52
+ """Converts a numpy dtype to a string representation.
53
+
54
+ Args:
55
+ np_dtype: A numpy dtype (e.g., np.float32, np.int8).
56
+
57
+ Returns:
58
+ String representation of the data type (e.g., "float32", "int8").
59
+
60
+ Raises:
61
+ ValueError: If the dtype is not supported.
62
+ """
63
+ if np_dtype == np.float32:
64
+ return "float32"
65
+ elif np_dtype == np.int32:
66
+ return "int32"
67
+ elif np_dtype == np.int8:
68
+ return "int8"
69
+ else:
70
+ raise ValueError(f"Unsupported dtype: {np_dtype}")
71
+
72
+ @classmethod
73
+ def create_from_host_memory(cls, data_array):
74
+ """Creates a new TensorBuffer referencing existing host memory.
75
+
76
+ Args:
77
+ data_array: A NumPy array (e.g., np.array([[1.0, 2.0, 3.0, 4.0]],
78
+ dtype=np.float32)). The dtype of the array is used.
79
+
80
+ Returns:
81
+ A new TensorBuffer instance.
82
+
83
+ Raises:
84
+ ValueError: If the input is not a NumPy array or has an unsupported dtype.
85
+ """
86
+ if not isinstance(data_array, np.ndarray):
87
+ raise ValueError("data_array must be a NumPy array")
88
+
89
+ dtype_str = cls._dtype_to_str(data_array.dtype)
90
+ num_elements = data_array.size
91
+
92
+ cap = _tb.CreateTensorBufferFromHostMemory(
93
+ data_array, dtype_str, num_elements
94
+ )
95
+ return cls(cap)
96
+
97
+ def write(self, data_array):
98
+ """Writes data to this tensor buffer.
99
+
100
+ Args:
101
+ data_array: A NumPy array (e.g., np.array([[1.0, 2.0, 3.0, 4.0]],
102
+ dtype=np.float32)). The dtype of the array is used.
103
+
104
+ Example:
105
+ # Using NumPy array
106
+ test_input = np.array([[1.0, 2.0, 3.0, 4.0]], dtype=np.float32)
107
+ tensor_buffer.write(test_input)
108
+
109
+ Raises:
110
+ ValueError: If the input is not a NumPy array or has an unsupported dtype.
111
+ """
112
+ if not isinstance(data_array, np.ndarray):
113
+ raise ValueError("data_array must be a NumPy array")
114
+
115
+ dtype_str = self._dtype_to_str(data_array.dtype)
116
+ _tb.WriteTensor(self._capsule, data_array.flatten().tolist(), dtype_str)
117
+
118
+ def read(self, num_elements: int, output_dtype):
119
+ """Reads data from this tensor buffer.
120
+
121
+ Args:
122
+ num_elements: Number of elements to read.
123
+ output_dtype: NumPy dtype for the output (e.g., np.float32, np.int8).
124
+
125
+ Returns:
126
+ A NumPy array containing the tensor data.
127
+
128
+ Example:
129
+ # Get output as NumPy array
130
+ output_array = tensor_buffer.read(4, np.float32).reshape((1, 4))
131
+
132
+ Raises:
133
+ ValueError: If output_dtype is not a NumPy dtype or is not supported.
134
+ """
135
+ if not isinstance(output_dtype, type) or not hasattr(
136
+ np, output_dtype.__name__
137
+ ):
138
+ raise ValueError(f"output_dtype must be a NumPy dtype (e.g., np.float32)")
139
+
140
+ dtype_str = self._dtype_to_str(output_dtype)
141
+ data_list = _tb.ReadTensor(self._capsule, num_elements, dtype_str)
142
+ return np.array(data_list, dtype=output_dtype)
143
+
144
+ def destroy(self):
145
+ """Explicitly releases resources associated with this tensor buffer.
146
+
147
+ After calling this method, the tensor buffer is no longer valid for use.
148
+ """
149
+ _tb.DestroyTensorBuffer(self._capsule)
150
+ self._capsule = None
151
+
152
+ @property
153
+ def capsule(self):
154
+ """Returns the underlying PyCapsule for direct C++ interoperability.
155
+
156
+ When the capsule is used with compiled_model methods, the ownership remains
157
+ with this TensorBuffer instance. This avoids double-free when both objects
158
+ try to destroy the same underlying tensor buffer.
159
+
160
+ Returns:
161
+ The PyCapsule containing the pointer to the LiteRtTensorBuffer, with
162
+ ownership remaining with this TensorBuffer instance.
163
+ """
164
+ # Once destroyed, shouldn't try to access the capsule again.
165
+ if self._capsule is None:
166
+ raise ValueError("TensorBuffer has been destroyed")
167
+ return self._capsule
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: google/protobuf/timestamp.proto
5
+ # Protobuf Python Version: 6.31.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 6,
15
+ 31,
16
+ 1,
17
+ '',
18
+ 'google/protobuf/timestamp.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1fgoogle/protobuf/timestamp.proto\x12\x0fgoogle.protobuf\"+\n\tTimestamp\x12\x0f\n\x07seconds\x18\x01 \x01(\x03\x12\r\n\x05nanos\x18\x02 \x01(\x05\x42\x85\x01\n\x13\x63om.google.protobufB\x0eTimestampProtoP\x01Z2google.golang.org/protobuf/types/known/timestamppb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.timestamp_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\016TimestampProtoP\001Z2google.golang.org/protobuf/types/known/timestamppb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
35
+ _globals['_TIMESTAMP']._serialized_start=52
36
+ _globals['_TIMESTAMP']._serialized_end=95
37
+ # @@protoc_insertion_point(module_scope)
File without changes
Binary file