ai-edge-quantizer-nightly 0.3.0.dev20250610__py3-none-any.whl → 0.3.0.dev20250612__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/algorithm_manager.py +2 -0
- ai_edge_quantizer/algorithms/uniform_quantize/common_quantize.py +16 -0
- ai_edge_quantizer/algorithms/uniform_quantize/uniform_quantize_tensor.py +9 -5
- ai_edge_quantizer/algorithms/uniform_quantize/uniform_quantize_tensor_test.py +6 -2
- ai_edge_quantizer/default_policy.py +3 -2
- ai_edge_quantizer/qtyping.py +1 -0
- ai_edge_quantizer/utils/tfl_flatbuffer_utils.py +1 -0
- {ai_edge_quantizer_nightly-0.3.0.dev20250610.dist-info → ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info}/METADATA +1 -1
- {ai_edge_quantizer_nightly-0.3.0.dev20250610.dist-info → ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info}/RECORD +12 -12
- {ai_edge_quantizer_nightly-0.3.0.dev20250610.dist-info → ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info}/LICENSE +0 -0
- {ai_edge_quantizer_nightly-0.3.0.dev20250610.dist-info → ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info}/WHEEL +0 -0
- {ai_edge_quantizer_nightly-0.3.0.dev20250610.dist-info → ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info}/top_level.txt +0 -0
@@ -111,6 +111,7 @@ MIN_MAX_OP_NAME_MATERIALIZE_FUNC_DICT = {
|
|
111
111
|
_TFLOpName.SQUARED_DIFFERENCE: (
|
112
112
|
common_quantize.materialize_squared_difference
|
113
113
|
),
|
114
|
+
_TFLOpName.MAX_POOL_2D: common_quantize.materialize_max_pool_2d,
|
114
115
|
}
|
115
116
|
for op_name, materialize_func in MIN_MAX_OP_NAME_MATERIALIZE_FUNC_DICT.items():
|
116
117
|
register_quantized_op(
|
@@ -248,6 +249,7 @@ _OCTAV_OP_NAME_MATERIALIZE_FUNC_DICT = immutabledict({
|
|
248
249
|
_TFLOpName.SQUARED_DIFFERENCE: (
|
249
250
|
common_quantize.materialize_squared_difference
|
250
251
|
),
|
252
|
+
_TFLOpName.MAX_POOL_2D: common_quantize.materialize_max_pool_2d,
|
251
253
|
})
|
252
254
|
|
253
255
|
for op_name, materialize_func in _OCTAV_OP_NAME_MATERIALIZE_FUNC_DICT.items():
|
@@ -712,6 +712,22 @@ def materialize_squared_difference(
|
|
712
712
|
)
|
713
713
|
|
714
714
|
|
715
|
+
def materialize_max_pool_2d(
|
716
|
+
get_tensor_quant_params_fn: qtyping.GetTensorQuantParamsFuncSignature,
|
717
|
+
op_info: qtyping.OpInfo,
|
718
|
+
graph_info: qtyping.GraphInfo,
|
719
|
+
tensor_name_to_qsv: dict[str, Any],
|
720
|
+
) -> list[qtyping.TensorTransformationParams]:
|
721
|
+
"""Materialize tensors in tfl.max_pool_2d."""
|
722
|
+
return common_utils.materialize_standard_op(
|
723
|
+
op_info,
|
724
|
+
graph_info,
|
725
|
+
tensor_name_to_qsv,
|
726
|
+
get_tensor_quant_params_fn,
|
727
|
+
constraint=_OpQuantConstraint.SAME_AS_INPUT_SCALE,
|
728
|
+
)
|
729
|
+
|
730
|
+
|
715
731
|
def _get_tensor_shape_for_blockwise(
|
716
732
|
tensor_shape: Sequence[int], quantized_dim: int, block_size: int
|
717
733
|
) -> list[int]:
|
@@ -435,7 +435,8 @@ def _is_valid_quantization_params(
|
|
435
435
|
"""Checks if the quantization parameters are valid.
|
436
436
|
|
437
437
|
A valid quantization params requires:
|
438
|
-
1. scale and zero point have the same shape
|
438
|
+
1. scale and zero point either have the same shape or the zero point is a
|
439
|
+
scalar.
|
439
440
|
2. scale and zero point have the same rank as the tensor content (avoid
|
440
441
|
ambiguous broadcasting).
|
441
442
|
|
@@ -446,17 +447,20 @@ def _is_valid_quantization_params(
|
|
446
447
|
Returns:
|
447
448
|
True if the quantization parameters are valid.
|
448
449
|
"""
|
449
|
-
if
|
450
|
+
if (
|
451
|
+
quantization_params.scale.shape != quantization_params.zero_point.shape
|
452
|
+
and quantization_params.zero_point.size != 1
|
453
|
+
):
|
450
454
|
raise ValueError(
|
451
|
-
"scale and zero_point must have the same shape
|
452
|
-
f" {quantization_params.scale.shape} and"
|
455
|
+
"scale and zero_point must have the same shape or zero_point must have"
|
456
|
+
f" only one element. Got {quantization_params.scale.shape} and"
|
453
457
|
f" {quantization_params.zero_point.shape}"
|
454
458
|
)
|
455
459
|
|
456
460
|
tensor_rank = tensor_data.ndim
|
457
461
|
scale_rank = quantization_params.scale.ndim
|
458
462
|
zero_point_rank = quantization_params.zero_point.ndim
|
459
|
-
if
|
463
|
+
if tensor_rank != scale_rank or (tensor_rank != zero_point_rank):
|
460
464
|
raise ValueError(
|
461
465
|
f"Ranks of scales ({scale_rank}) and zps"
|
462
466
|
f" ({zero_point_rank}) must be the same as the tensor rank"
|
@@ -160,7 +160,9 @@ class TensorUtilsTest(parameterized.TestCase):
|
|
160
160
|
def test_uniform_quantize_wrong_shape(self):
|
161
161
|
tensor = [-3.0, 1.3, 2.4, 16.0]
|
162
162
|
|
163
|
-
error_message =
|
163
|
+
error_message = (
|
164
|
+
"Ranks of scales (3) and zps (2) must be the same as the tensor rank"
|
165
|
+
)
|
164
166
|
with self.assertRaisesWithPredicateMatch(
|
165
167
|
ValueError, lambda err: error_message in str(err)
|
166
168
|
):
|
@@ -233,7 +235,9 @@ class TensorUtilsTest(parameterized.TestCase):
|
|
233
235
|
def test_uniform_dequantize_wrong_shape(self):
|
234
236
|
tensor = [-3.0, 1.3, 2.4, 16.0]
|
235
237
|
|
236
|
-
error_message =
|
238
|
+
error_message = (
|
239
|
+
"Ranks of scales (3) and zps (2) must be the same as the tensor rank"
|
240
|
+
)
|
237
241
|
with self.assertRaisesWithPredicateMatch(
|
238
242
|
ValueError, lambda err: error_message in str(err)
|
239
243
|
):
|
@@ -185,7 +185,7 @@ DEFAULT_JSON_POLICY = """
|
|
185
185
|
"SELECT_V2",
|
186
186
|
"STABLEHLO_COMPOSITE",
|
187
187
|
"PAD",
|
188
|
-
"
|
188
|
+
"MAX_POOL_2D"
|
189
189
|
],
|
190
190
|
"static_wi8_ai8": [
|
191
191
|
"ADD",
|
@@ -218,7 +218,8 @@ DEFAULT_JSON_POLICY = """
|
|
218
218
|
"SELECT_V2",
|
219
219
|
"STABLEHLO_COMPOSITE",
|
220
220
|
"PAD",
|
221
|
-
"SQUARED_DIFFERENCE"
|
221
|
+
"SQUARED_DIFFERENCE",
|
222
|
+
"MAX_POOL_2D"
|
222
223
|
],
|
223
224
|
"static_wi4_ai8": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT", "EMBEDDING_LOOKUP"],
|
224
225
|
"static_wi4_ai16": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT", "EMBEDDING_LOOKUP"],
|
ai_edge_quantizer/qtyping.py
CHANGED
@@ -58,6 +58,7 @@ TFL_OP_NAME_TO_CODE = immutabledict.immutabledict({
|
|
58
58
|
),
|
59
59
|
_TFLOpName.PAD: schema.BuiltinOperator.PAD,
|
60
60
|
_TFLOpName.SQUARED_DIFFERENCE: schema.BuiltinOperator.SQUARED_DIFFERENCE,
|
61
|
+
_TFLOpName.MAX_POOL_2D: schema.BuiltinOperator.MAX_POOL_2D,
|
61
62
|
})
|
62
63
|
|
63
64
|
TFL_OP_CODE_TO_NAME = immutabledict.immutabledict(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ai-edge-quantizer-nightly
|
3
|
-
Version: 0.3.0.
|
3
|
+
Version: 0.3.0.dev20250612
|
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
|
@@ -1,18 +1,18 @@
|
|
1
1
|
ai_edge_quantizer/__init__.py,sha256=4pFSkukSwahYyzwqia0yPRyz8TnFQfGRthVJhYpMWas,793
|
2
|
-
ai_edge_quantizer/algorithm_manager.py,sha256=
|
2
|
+
ai_edge_quantizer/algorithm_manager.py,sha256=lfCazb2b0Q4L3of0cTWkF5lMr3AD6LWW1ekmFoEGB_4,12062
|
3
3
|
ai_edge_quantizer/algorithm_manager_api.py,sha256=u903TG0s1uIDhJqfeJne3CFl8A93phZrwgV2-hwdcXU,9247
|
4
4
|
ai_edge_quantizer/algorithm_manager_api_test.py,sha256=w6bSONvXkX6bzXAGc0-7b6gNDt9oz9ieq97KP8Sg_JU,7666
|
5
5
|
ai_edge_quantizer/calibrator.py,sha256=-_jX_KkfIepkQAwxxDrZjvPO1JsoSjHXVy1DPc1iFjM,12068
|
6
6
|
ai_edge_quantizer/calibrator_test.py,sha256=C_oWOaRugPKYX74jF-eRFH-k6nGOdA8I9_uPiocaOuE,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=nKtghUjTQ8QS9CgLRwQb3iB2eZOyQv0FqyISlcgzSH4,11195
|
9
9
|
ai_edge_quantizer/model_modifier.py,sha256=teGa8I6kGvn6TQY6Xv53YFIc_pQEhNvM9Zb4bvhezyw,7110
|
10
10
|
ai_edge_quantizer/model_modifier_test.py,sha256=cJd04SLOG-fQZZNZPcisoBLx3cLtWEwGqUBbLb-pif4,4751
|
11
11
|
ai_edge_quantizer/model_validator.py,sha256=Hj0_5o-Oa3dSlJ3ryVjRhvsyelHNyek1GrtG9buMczg,13153
|
12
12
|
ai_edge_quantizer/model_validator_test.py,sha256=EeqOP_mrZsnZ3rug756s0ryDDqd2KgIDld5Lm_gDuWY,13020
|
13
13
|
ai_edge_quantizer/params_generator.py,sha256=j1BV2cGFLlQmUY6aoW5uglYqf77b9ytN8oZ1gh6o0mM,20096
|
14
14
|
ai_edge_quantizer/params_generator_test.py,sha256=RDYoRZDJfEZRtjlTAU2kZ_4t3JHOqEHxfJX9V4ETAhg,40597
|
15
|
-
ai_edge_quantizer/qtyping.py,sha256=
|
15
|
+
ai_edge_quantizer/qtyping.py,sha256=0Dwz6LHQG8LhZMhVAo_h6ieZ_gcfkJl2yJcsGf17YYs,16527
|
16
16
|
ai_edge_quantizer/quantizer.py,sha256=g3DMqFMrMpt9jQttCE0WcdNbMtk0JZnmN5MmCHrNdyM,13202
|
17
17
|
ai_edge_quantizer/quantizer_test.py,sha256=K_HBA56JkFI3HL8VLWCqGEfC0ISh5ldMKoNyBdGRAJg,20368
|
18
18
|
ai_edge_quantizer/recipe.py,sha256=FR0uJceumZrnle2VRSOQZ1uXup4S1cTYKRH-N53mWRo,2919
|
@@ -28,7 +28,7 @@ ai_edge_quantizer/algorithms/nonlinear_quantize/__init__.py,sha256=lpq1g2ayg3lCP
|
|
28
28
|
ai_edge_quantizer/algorithms/nonlinear_quantize/float_casting.py,sha256=Bs9CK7wZAw6jNaZ8xEtbwO2vM34VYXNZSMVWvxJo9nw,9297
|
29
29
|
ai_edge_quantizer/algorithms/nonlinear_quantize/float_casting_test.py,sha256=EqIHGEZ1LgUrTN7zf880RuAzEv3Qy7kgh5ivObJGHSo,22646
|
30
30
|
ai_edge_quantizer/algorithms/uniform_quantize/__init__.py,sha256=lpq1g2ayg3lCPLy79t2VicYcnGKw64FfYIj1V7J-4m8,676
|
31
|
-
ai_edge_quantizer/algorithms/uniform_quantize/common_quantize.py,sha256=
|
31
|
+
ai_edge_quantizer/algorithms/uniform_quantize/common_quantize.py,sha256=ofDoiZhOKjF7Tm-v0a4xsLSvytjfvMALXLDcuwcKNK0,29634
|
32
32
|
ai_edge_quantizer/algorithms/uniform_quantize/common_quantize_test.py,sha256=GGf_n3wIeg3GB_eGsmyNJ0fTcxgpeMMbugTMRONK6TQ,3553
|
33
33
|
ai_edge_quantizer/algorithms/uniform_quantize/dequantized_weight_recovery.py,sha256=BDdn_uBZakfHyzdMJPKadsOqxqyC-s6W2ZzFH99L4fE,8652
|
34
34
|
ai_edge_quantizer/algorithms/uniform_quantize/dequantized_weight_recovery_test.py,sha256=sT5eX5TLZEHTtPfnSkCPDlS0sQxlTFWbCsbvOuj--yY,8889
|
@@ -38,8 +38,8 @@ ai_edge_quantizer/algorithms/uniform_quantize/naive_min_max_quantize.py,sha256=8
|
|
38
38
|
ai_edge_quantizer/algorithms/uniform_quantize/naive_min_max_quantize_test.py,sha256=zoF_EHjYqsKkuev8wfuutIITEmp_maa70IpJI_Df3ck,7431
|
39
39
|
ai_edge_quantizer/algorithms/uniform_quantize/octav.py,sha256=Umxh4kJyeHddZf-Wd4aXE5MTI1XWFa5KRuM17uYU714,6922
|
40
40
|
ai_edge_quantizer/algorithms/uniform_quantize/octav_test.py,sha256=sha1d99Xk87bI87tgz0g5LeDC-EeE4WMfM5rRC98-m4,9140
|
41
|
-
ai_edge_quantizer/algorithms/uniform_quantize/uniform_quantize_tensor.py,sha256=
|
42
|
-
ai_edge_quantizer/algorithms/uniform_quantize/uniform_quantize_tensor_test.py,sha256=
|
41
|
+
ai_edge_quantizer/algorithms/uniform_quantize/uniform_quantize_tensor.py,sha256=3zq2AO_PRYKHuNvHzwg0pVDZT7kcpaMgXx6OEyEl6co,16103
|
42
|
+
ai_edge_quantizer/algorithms/uniform_quantize/uniform_quantize_tensor_test.py,sha256=JlX3fLHiknGH1osu6gwWEGUizLrEsE6d8iRpzDODmXo,12510
|
43
43
|
ai_edge_quantizer/algorithms/utils/__init__.py,sha256=lpq1g2ayg3lCPLy79t2VicYcnGKw64FfYIj1V7J-4m8,676
|
44
44
|
ai_edge_quantizer/algorithms/utils/common_utils.py,sha256=UoZxeAQmZk3b3hK51KFwq6XfdbeduXVjdYIxAxlAzB8,34982
|
45
45
|
ai_edge_quantizer/algorithms/utils/common_utils_test.py,sha256=zqapGEfYhjQWe9cNGPLmdbwtEUUYQRhlO_kNe0cXX6E,18104
|
@@ -64,14 +64,14 @@ ai_edge_quantizer/utils/__init__.py,sha256=lpq1g2ayg3lCPLy79t2VicYcnGKw64FfYIj1V
|
|
64
64
|
ai_edge_quantizer/utils/calibration_utils.py,sha256=1Fj9MIO6aLZIRgyd4axvZN4S_O64nB_-Miu1WP664js,2536
|
65
65
|
ai_edge_quantizer/utils/calibration_utils_test.py,sha256=Z-AcdTieesWFKyKBb08ZXm4Mgu6cvJ4bg2-MJ7hLD10,2856
|
66
66
|
ai_edge_quantizer/utils/test_utils.py,sha256=Y2pdMvn1k4gmqDo3noJfzx3fJcDHX_1hcsP6oiIz65Y,8240
|
67
|
-
ai_edge_quantizer/utils/tfl_flatbuffer_utils.py,sha256=
|
67
|
+
ai_edge_quantizer/utils/tfl_flatbuffer_utils.py,sha256=Yy1u53FzRBFx-fr1TqoycWMZwAlAl0b2IB4MmGV1xJA,10758
|
68
68
|
ai_edge_quantizer/utils/tfl_flatbuffer_utils_test.py,sha256=K1SbK8q92qYVtiVj0I0GtugsPTkpIpEKv9zakvFV_Sc,8555
|
69
69
|
ai_edge_quantizer/utils/tfl_interpreter_utils.py,sha256=EtOv6cpKM_F0uv2bWuSXylYmTeXT6zUc182pw4sdYSI,13889
|
70
70
|
ai_edge_quantizer/utils/tfl_interpreter_utils_test.py,sha256=6fjkM-rycZ95L4yfvlr0TN6RlrhfPzxNUYrZaYO_F0A,12013
|
71
71
|
ai_edge_quantizer/utils/validation_utils.py,sha256=oYw33Sg547AqtGw-choPUJmp9SAKkV46J_ddqSsum2Q,3950
|
72
72
|
ai_edge_quantizer/utils/validation_utils_test.py,sha256=V_qNDikPD4OPB-siOLQCWNVWTAu87h2IgNYt7teFd-o,2934
|
73
|
-
ai_edge_quantizer_nightly-0.3.0.
|
74
|
-
ai_edge_quantizer_nightly-0.3.0.
|
75
|
-
ai_edge_quantizer_nightly-0.3.0.
|
76
|
-
ai_edge_quantizer_nightly-0.3.0.
|
77
|
-
ai_edge_quantizer_nightly-0.3.0.
|
73
|
+
ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
74
|
+
ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info/METADATA,sha256=C0e46WStdRDjUO05juSVs83Bu_Tm27ZBa9XZoLRmAZo,1528
|
75
|
+
ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
76
|
+
ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info/top_level.txt,sha256=8QTfPnFXNVUhScFLaa-NWZMFWMn72M50DVPubpwWB1g,18
|
77
|
+
ai_edge_quantizer_nightly-0.3.0.dev20250612.dist-info/RECORD,,
|
File without changes
|
File without changes
|