ai-edge-quantizer-nightly 0.4.0.dev20251008__py3-none-any.whl → 0.4.0.dev20251010__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.
- ai_edge_quantizer/default_policy.py +2 -4
- ai_edge_quantizer/quantizer.py +25 -2
- ai_edge_quantizer/quantizer_test.py +15 -0
- {ai_edge_quantizer_nightly-0.4.0.dev20251008.dist-info → ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info}/METADATA +1 -1
- {ai_edge_quantizer_nightly-0.4.0.dev20251008.dist-info → ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info}/RECORD +8 -8
- {ai_edge_quantizer_nightly-0.4.0.dev20251008.dist-info → ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info}/LICENSE +0 -0
- {ai_edge_quantizer_nightly-0.4.0.dev20251008.dist-info → ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info}/WHEEL +0 -0
- {ai_edge_quantizer_nightly-0.4.0.dev20251008.dist-info → ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info}/top_level.txt +0 -0
|
@@ -178,7 +178,6 @@ DEFAULT_JSON_POLICY = """
|
|
|
178
178
|
"INPUT",
|
|
179
179
|
"OUTPUT",
|
|
180
180
|
"SLICE",
|
|
181
|
-
"EMBEDDING_LOOKUP",
|
|
182
181
|
"SUM",
|
|
183
182
|
"SELECT",
|
|
184
183
|
"SELECT_V2",
|
|
@@ -226,7 +225,6 @@ DEFAULT_JSON_POLICY = """
|
|
|
226
225
|
"INPUT",
|
|
227
226
|
"OUTPUT",
|
|
228
227
|
"SLICE",
|
|
229
|
-
"EMBEDDING_LOOKUP",
|
|
230
228
|
"SUM",
|
|
231
229
|
"SELECT",
|
|
232
230
|
"SELECT_V2",
|
|
@@ -252,8 +250,8 @@ DEFAULT_JSON_POLICY = """
|
|
|
252
250
|
"NOT_EQUAL",
|
|
253
251
|
"MIRROR_PAD"
|
|
254
252
|
],
|
|
255
|
-
"static_wi4_ai8": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT"
|
|
256
|
-
"static_wi4_ai16": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT"
|
|
253
|
+
"static_wi4_ai8": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT"],
|
|
254
|
+
"static_wi4_ai16": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT"],
|
|
257
255
|
"dynamic_wi8_afp32": [
|
|
258
256
|
"BATCH_MATMUL",
|
|
259
257
|
"CONV_2D",
|
ai_edge_quantizer/quantizer.py
CHANGED
|
@@ -126,12 +126,16 @@ class Quantizer:
|
|
|
126
126
|
float_model: TFLite model file path or bytearray.
|
|
127
127
|
quantization_recipe: Quantization recipe .json filepath or in loaded json
|
|
128
128
|
format.
|
|
129
|
+
previous_quantized_model: Optional previously quantized TFLite model file
|
|
130
|
+
path or bytearray. This is useful for validating a quantized model
|
|
131
|
+
without quantizing it again.
|
|
129
132
|
"""
|
|
130
133
|
|
|
131
134
|
def __init__(
|
|
132
135
|
self,
|
|
133
136
|
float_model: Union[str, bytearray],
|
|
134
137
|
quantization_recipe: Optional[Union[str, _QuantRecipe]] = None,
|
|
138
|
+
previous_quantized_model: Optional[Union[str, bytearray]] = None,
|
|
135
139
|
):
|
|
136
140
|
"""Initializes the quantizer.
|
|
137
141
|
|
|
@@ -139,6 +143,9 @@ class Quantizer:
|
|
|
139
143
|
float_model: Path to the float tflite model.
|
|
140
144
|
quantization_recipe: Quantization recipe in .json filepath or loaded json
|
|
141
145
|
format.
|
|
146
|
+
previous_quantized_model: Path to an optional previously quantized tflite
|
|
147
|
+
model. This is useful for validating a quantized model without
|
|
148
|
+
quantizing it again.
|
|
142
149
|
"""
|
|
143
150
|
# Use `float model` as bytes for memory efficiency.
|
|
144
151
|
self.float_model: bytes = (
|
|
@@ -146,6 +153,14 @@ class Quantizer:
|
|
|
146
153
|
if isinstance(float_model, str)
|
|
147
154
|
else float_model
|
|
148
155
|
)
|
|
156
|
+
if previous_quantized_model is not None:
|
|
157
|
+
self.previous_quantized_model: bytes = (
|
|
158
|
+
tfl_flatbuffer_utils.get_model_content(previous_quantized_model)
|
|
159
|
+
if isinstance(previous_quantized_model, str)
|
|
160
|
+
else previous_quantized_model
|
|
161
|
+
)
|
|
162
|
+
else:
|
|
163
|
+
self.previous_quantized_model = None
|
|
149
164
|
|
|
150
165
|
self._recipe_manager: recipe_manager.RecipeManager = (
|
|
151
166
|
recipe_manager.RecipeManager()
|
|
@@ -153,6 +168,7 @@ class Quantizer:
|
|
|
153
168
|
if quantization_recipe is not None:
|
|
154
169
|
self.load_quantization_recipe(quantization_recipe)
|
|
155
170
|
self._result: QuantizationResult = QuantizationResult([{}], None)
|
|
171
|
+
self._quantize_called = False
|
|
156
172
|
|
|
157
173
|
def load_quantization_recipe(self, recipe: Union[str, _QuantRecipe]) -> None:
|
|
158
174
|
"""Loads a quantization recipe.
|
|
@@ -399,7 +415,7 @@ class Quantizer:
|
|
|
399
415
|
Raises:
|
|
400
416
|
RuntimeError: If quantization recipe is empty.
|
|
401
417
|
"""
|
|
402
|
-
|
|
418
|
+
self._quantize_called = True
|
|
403
419
|
if calibration_result is not None:
|
|
404
420
|
self._ensure_model_qsv_sufficient(calibration_result)
|
|
405
421
|
|
|
@@ -445,9 +461,16 @@ class Quantizer:
|
|
|
445
461
|
test_data = tfl_interpreter_utils.create_random_normal_input_data(
|
|
446
462
|
self.float_model, num_samples=1
|
|
447
463
|
)
|
|
464
|
+
if self._quantize_called:
|
|
465
|
+
quantized_model = self._result.quantized_model
|
|
466
|
+
else:
|
|
467
|
+
quantized_model = self.previous_quantized_model
|
|
468
|
+
|
|
469
|
+
if quantized_model is None:
|
|
470
|
+
raise ValueError('No quantized model available to validate.')
|
|
448
471
|
return model_validator.compare_model(
|
|
449
472
|
self.float_model,
|
|
450
|
-
|
|
473
|
+
quantized_model,
|
|
451
474
|
test_data,
|
|
452
475
|
error_metrics,
|
|
453
476
|
validation_utils.get_validation_func(error_metrics),
|
|
@@ -337,6 +337,21 @@ class QuantizerTest(parameterized.TestCase):
|
|
|
337
337
|
'sequential/dense_1/MatMul', validation_result.intermediate_tensors
|
|
338
338
|
)
|
|
339
339
|
|
|
340
|
+
def test_validate_with_quantized_model_arg_succeeds(self):
|
|
341
|
+
self._quantizer.quantize()
|
|
342
|
+
quantized_model = self._quantizer._result.quantized_model
|
|
343
|
+
self.assertIsNotNone(quantized_model)
|
|
344
|
+
|
|
345
|
+
new_quantizer = quantizer.Quantizer(
|
|
346
|
+
self._test_model_path, previous_quantized_model=quantized_model
|
|
347
|
+
)
|
|
348
|
+
validation_result = new_quantizer.validate()
|
|
349
|
+
validation_result = validation_result.get_signature_comparison_result()
|
|
350
|
+
self.assertIsNotNone(validation_result)
|
|
351
|
+
self.assertIn(
|
|
352
|
+
'sequential/dense_1/MatMul', validation_result.intermediate_tensors
|
|
353
|
+
)
|
|
354
|
+
|
|
340
355
|
def test_load_custom_policies_succeeds(self):
|
|
341
356
|
|
|
342
357
|
test_op_config = qtyping.OpQuantizationConfig(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ai-edge-quantizer-nightly
|
|
3
|
-
Version: 0.4.0.
|
|
3
|
+
Version: 0.4.0.dev20251010
|
|
4
4
|
Summary: A quantizer for advanced developers to quantize converted AI Edge models.
|
|
5
5
|
Home-page: https://github.com/google-ai-edge/ai-edge-quantizer
|
|
6
6
|
Keywords: On-Device ML,AI,Google,TFLite,Quantization,LLMs,GenAI
|
|
@@ -5,7 +5,7 @@ ai_edge_quantizer/algorithm_manager_api_test.py,sha256=w6bSONvXkX6bzXAGc0-7b6gND
|
|
|
5
5
|
ai_edge_quantizer/calibrator.py,sha256=Sms7_AIHPH9G5xFaz5Ef3a5gPhxuIWQI8d2LUM8C96I,12071
|
|
6
6
|
ai_edge_quantizer/calibrator_test.py,sha256=ZLzIMWB2FSFU4TOatDioYuwp_kLh8iSCefZ5_Q9FU7s,11900
|
|
7
7
|
ai_edge_quantizer/conftest.py,sha256=SxCz-5LlRD_lQm4hQc4c6IGG7DS8d7IyEWY9gnscPN0,794
|
|
8
|
-
ai_edge_quantizer/default_policy.py,sha256=
|
|
8
|
+
ai_edge_quantizer/default_policy.py,sha256=DpQUe0ETpRtx2qWwvrj9pFAhfyEwES1mVTTak8kyPzM,11678
|
|
9
9
|
ai_edge_quantizer/model_modifier.py,sha256=U70JByv6CItP8tg4bdyMfX-R3UlwylAGSviZkF_FSAM,10468
|
|
10
10
|
ai_edge_quantizer/model_modifier_test.py,sha256=CV4pgMEQkBJr_qbYR720TO8HBCutbEYLHptDHgdQMUE,7274
|
|
11
11
|
ai_edge_quantizer/model_validator.py,sha256=Hj0_5o-Oa3dSlJ3ryVjRhvsyelHNyek1GrtG9buMczg,13153
|
|
@@ -13,8 +13,8 @@ ai_edge_quantizer/model_validator_test.py,sha256=EeqOP_mrZsnZ3rug756s0ryDDqd2KgI
|
|
|
13
13
|
ai_edge_quantizer/params_generator.py,sha256=0w-sDGk84sVNkXoduon1wDqq30sGOHVgBVbdg44QVF4,20153
|
|
14
14
|
ai_edge_quantizer/params_generator_test.py,sha256=RDYoRZDJfEZRtjlTAU2kZ_4t3JHOqEHxfJX9V4ETAhg,40597
|
|
15
15
|
ai_edge_quantizer/qtyping.py,sha256=rp2jdmCuSsP6Ay8rD7NxDCpbFkRNkbYP29Uwe0xBfnA,17196
|
|
16
|
-
ai_edge_quantizer/quantizer.py,sha256=
|
|
17
|
-
ai_edge_quantizer/quantizer_test.py,sha256=
|
|
16
|
+
ai_edge_quantizer/quantizer.py,sha256=teYeONdIS31IAY6ubLujCRi1t6lYAd0LkC8dRPxQdbw,18919
|
|
17
|
+
ai_edge_quantizer/quantizer_test.py,sha256=9BVwt7oyM8IsSC7jN73nI0O-4MikBkymm_FigJnSeCM,27117
|
|
18
18
|
ai_edge_quantizer/recipe.py,sha256=MEkfQ2Sg3KAE9LAORHWcbjYNPg06EUbwc1d-VspQA2U,6461
|
|
19
19
|
ai_edge_quantizer/recipe_manager.py,sha256=6l2uq8KL23KLu9OQDmPGkxrFiwHrdDB9xnn-ni8WdEM,15036
|
|
20
20
|
ai_edge_quantizer/recipe_manager_test.py,sha256=qjgGUF-wggXnSXqZ5khmqrDMIQI5CShk52IVWTahq6s,36817
|
|
@@ -74,8 +74,8 @@ ai_edge_quantizer/utils/tfl_interpreter_utils.py,sha256=EoVjI_hplX_Rml3hfRsGmQOi
|
|
|
74
74
|
ai_edge_quantizer/utils/tfl_interpreter_utils_test.py,sha256=6fjkM-rycZ95L4yfvlr0TN6RlrhfPzxNUYrZaYO_F0A,12013
|
|
75
75
|
ai_edge_quantizer/utils/validation_utils.py,sha256=0sOdH4pzk_Pwh1r8O47iaECRng1Xn0ABn9GVc8UPNcY,4994
|
|
76
76
|
ai_edge_quantizer/utils/validation_utils_test.py,sha256=1sblJWHLTYTbn1Qi9rwnrREOSXRy5KwHAWSwgI1e_aU,3697
|
|
77
|
-
ai_edge_quantizer_nightly-0.4.0.
|
|
78
|
-
ai_edge_quantizer_nightly-0.4.0.
|
|
79
|
-
ai_edge_quantizer_nightly-0.4.0.
|
|
80
|
-
ai_edge_quantizer_nightly-0.4.0.
|
|
81
|
-
ai_edge_quantizer_nightly-0.4.0.
|
|
77
|
+
ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
78
|
+
ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info/METADATA,sha256=n_gZ1KzZVjtGwWh9EEnE7lCZ8Qt1AzkUjDbGcmFvs-I,1508
|
|
79
|
+
ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
80
|
+
ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info/top_level.txt,sha256=8QTfPnFXNVUhScFLaa-NWZMFWMn72M50DVPubpwWB1g,18
|
|
81
|
+
ai_edge_quantizer_nightly-0.4.0.dev20251010.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|