ai-edge-quantizer-nightly 0.5.0.dev20251215__py3-none-any.whl → 0.5.0.dev20251217__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.
@@ -133,6 +133,7 @@ MIN_MAX_OP_NAME_MATERIALIZE_FUNC_DICT = {
133
133
  _TFLOpName.NOT_EQUAL: common_quantize.materialize_not_equal,
134
134
  _TFLOpName.MIRROR_PAD: common_quantize.materialize_mirror_pad,
135
135
  _TFLOpName.SPACE_TO_DEPTH: common_quantize.materialize_space_to_depth,
136
+ _TFLOpName.RELU: common_quantize.materialize_relu,
136
137
  }
137
138
  for op_name, materialize_func in MIN_MAX_OP_NAME_MATERIALIZE_FUNC_DICT.items():
138
139
  register_quantized_op(
@@ -288,6 +289,7 @@ _OCTAV_OP_NAME_MATERIALIZE_FUNC_DICT = immutabledict({
288
289
  _TFLOpName.NOT_EQUAL: common_quantize.materialize_not_equal,
289
290
  _TFLOpName.MIRROR_PAD: common_quantize.materialize_mirror_pad,
290
291
  _TFLOpName.SPACE_TO_DEPTH: common_quantize.materialize_space_to_depth,
292
+ _TFLOpName.RELU: common_quantize.materialize_relu,
291
293
  })
292
294
 
293
295
  for op_name, materialize_func in _OCTAV_OP_NAME_MATERIALIZE_FUNC_DICT.items():
@@ -1070,6 +1070,21 @@ def materialize_not_equal(
1070
1070
  )
1071
1071
 
1072
1072
 
1073
+ def materialize_relu(
1074
+ get_tensor_quant_params_fn: qtyping.GetTensorQuantParamsFuncSignature,
1075
+ op_info: qtyping.OpInfo,
1076
+ graph_info: qtyping.GraphInfo,
1077
+ tensor_name_to_qsv: dict[str, Any],
1078
+ ) -> list[qtyping.TensorTransformationParams]:
1079
+ """Materialize tensors in tfl.relu."""
1080
+ return common_utils.materialize_standard_op(
1081
+ op_info,
1082
+ graph_info,
1083
+ tensor_name_to_qsv,
1084
+ get_tensor_quant_params_fn,
1085
+ )
1086
+
1087
+
1073
1088
  def _get_tensor_shape_for_blockwise(
1074
1089
  tensor_shape: Sequence[int], quantized_dim: int, block_size: int
1075
1090
  ) -> list[int]:
@@ -198,7 +198,8 @@ DEFAULT_JSON_POLICY = """
198
198
  "REDUCE_MIN",
199
199
  "EQUAL",
200
200
  "NOT_EQUAL",
201
- "MIRROR_PAD"
201
+ "MIRROR_PAD",
202
+ "RELU"
202
203
  ],
203
204
  "static_wi8_ai8": [
204
205
  "ADD",
@@ -248,7 +249,8 @@ DEFAULT_JSON_POLICY = """
248
249
  "EQUAL",
249
250
  "NOT_EQUAL",
250
251
  "MIRROR_PAD",
251
- "SPACE_TO_DEPTH"
252
+ "SPACE_TO_DEPTH",
253
+ "RELU"
252
254
  ],
253
255
  "static_wi4_ai8": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT"],
254
256
  "static_wi4_ai16": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT"],
@@ -82,6 +82,7 @@ class TFLOperationName(str, enum.Enum):
82
82
  NOT_EQUAL = 'NOT_EQUAL'
83
83
  MIRROR_PAD = 'MIRROR_PAD'
84
84
  SPACE_TO_DEPTH = 'SPACE_TO_DEPTH'
85
+ RELU = 'RELU'
85
86
 
86
87
 
87
88
  class QuantizeMode(enum.Enum):
@@ -108,6 +108,11 @@ class RecipeManager:
108
108
  configuration will be used.
109
109
  algorithm_key: Algorithm key to be applied.
110
110
  """
111
+ try:
112
+ algorithm_manager.AlgorithmName(algorithm_key)
113
+ except ValueError as e:
114
+ raise ValueError(f'Unsupported algorithm key: {algorithm_key}.') from e
115
+
111
116
  if op_config is None:
112
117
  op_config = _OpQuantizationConfig()
113
118
 
@@ -241,19 +241,6 @@ class ConfiguratorTest(parameterized.TestCase, googletest.TestCase):
241
241
  compute_precision=_ComputePrecision.INTEGER, # DRQ.
242
242
  ),
243
243
  )
244
- # Add unregistered algorithm
245
- with self.assertRaisesWithPredicateMatch(
246
- ValueError, lambda err: error_message in str(err)
247
- ):
248
- self._recipe_manager.add_quantization_config(
249
- regex='.*/Dense/.*',
250
- operation_name=_TFLOpName.FULLY_CONNECTED,
251
- algorithm_key='AWQ',
252
- op_config=qtyping.OpQuantizationConfig(
253
- weight_tensor_config=_TensorQuantConfig(num_bits=8),
254
- compute_precision=_ComputePrecision.INTEGER, # DRQ.
255
- ),
256
- )
257
244
 
258
245
  def test_add_unsupported_num_bits_raise_error(self):
259
246
  test_op_name = _TFLOpName.FULLY_CONNECTED
@@ -293,6 +280,31 @@ class ConfiguratorTest(parameterized.TestCase, googletest.TestCase):
293
280
  # DRQ check.
294
281
  self.assertEqual(op_config.compute_precision, _ComputePrecision.INTEGER)
295
282
 
283
+ def test_add_unsupported_algorithm_key_raise_error(self):
284
+ error_message = 'Unsupported algorithm key'
285
+ with self.assertRaisesWithPredicateMatch(
286
+ ValueError, lambda err: error_message in str(err)
287
+ ):
288
+ self._recipe_manager.add_quantization_config(
289
+ regex='.*/Dense/.*',
290
+ operation_name=_TFLOpName.FULLY_CONNECTED,
291
+ algorithm_key='decomposed_hadamard',
292
+ op_config=qtyping.OpQuantizationConfig(
293
+ weight_tensor_config=_TensorQuantConfig(num_bits=8),
294
+ ),
295
+ )
296
+ with self.assertRaisesWithPredicateMatch(
297
+ ValueError, lambda err: error_message in str(err)
298
+ ):
299
+ self._recipe_manager.add_quantization_config(
300
+ regex='.*/Dense/.*',
301
+ operation_name=_TFLOpName.ALL_SUPPORTED,
302
+ algorithm_key='decomposed_hadamard',
303
+ op_config=qtyping.OpQuantizationConfig(
304
+ weight_tensor_config=_TensorQuantConfig(num_bits=8),
305
+ ),
306
+ )
307
+
296
308
  def test_add_dynamic_config(self):
297
309
  self._recipe_manager.add_dynamic_config(
298
310
  regex='.*/Dense/.*',
@@ -38,7 +38,7 @@ class ConstrainedOpsUtilsTest(parameterized.TestCase):
38
38
  dict(
39
39
  testcase_name="no_constrain",
40
40
  constraint=_OpQuantConstraint.NO_CONSTRAIN,
41
- expected_num_ops=24,
41
+ expected_num_ops=25,
42
42
  ),
43
43
  )
44
44
  def test_get_constrained_op_list(self, constraint, expected_num_ops):
@@ -76,6 +76,7 @@ TFL_OP_NAME_TO_CODE = immutabledict.immutabledict({
76
76
  _TFLOpName.NOT_EQUAL: schema.BuiltinOperator.NOT_EQUAL,
77
77
  _TFLOpName.MIRROR_PAD: schema.BuiltinOperator.MIRROR_PAD,
78
78
  _TFLOpName.SPACE_TO_DEPTH: schema.BuiltinOperator.SPACE_TO_DEPTH,
79
+ _TFLOpName.RELU: schema.BuiltinOperator.RELU,
79
80
  })
80
81
 
81
82
  TFL_OP_CODE_TO_NAME = immutabledict.immutabledict(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ai-edge-quantizer-nightly
3
- Version: 0.5.0.dev20251215
3
+ Version: 0.5.0.dev20251217
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,23 +1,23 @@
1
1
  ai_edge_quantizer/__init__.py,sha256=4pFSkukSwahYyzwqia0yPRyz8TnFQfGRthVJhYpMWas,793
2
- ai_edge_quantizer/algorithm_manager.py,sha256=0jSNITKl0Ge1XeYKueOUj9brlS4B5ZcdcVQ1kZS3JKg,16518
2
+ ai_edge_quantizer/algorithm_manager.py,sha256=GuFls-3z23dk6wKxRDvmg2WI0uvAzCwbDDC3q5OXeVs,16628
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=nkHUmxdWy16Vw3EOD3B_7EkGiX8V-XJRXXFynweGfG8,9744
6
6
  ai_edge_quantizer/calibrator_test.py,sha256=c2ZCjl7PQYU9KtAovpDO9JX8sClgaLGO0P7oqoL6rP0,8830
7
7
  ai_edge_quantizer/conftest.py,sha256=SxCz-5LlRD_lQm4hQc4c6IGG7DS8d7IyEWY9gnscPN0,794
8
- ai_edge_quantizer/default_policy.py,sha256=YcwwtVzoWUhjYgMtJ7b9f647740lURKteDOeJvwe17o,11384
8
+ ai_edge_quantizer/default_policy.py,sha256=0ISIrS1ofzDv_ekC6p-1TUw4OIKVF8iKmiAILf2F7VU,11412
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=HCXl8lu8wRmLn6wUaEm3I7xDOul3s7VC6XzbKjGfkuU,13945
12
12
  ai_edge_quantizer/model_validator_test.py,sha256=EeqOP_mrZsnZ3rug756s0ryDDqd2KgIDld5Lm_gDuWY,13020
13
13
  ai_edge_quantizer/params_generator.py,sha256=-tbXB6crutiFhmLFEMe_-sxGylsvgd_cRZQ2fB67bNE,20436
14
14
  ai_edge_quantizer/params_generator_test.py,sha256=gJlq_qCPC0dWkbkyCpQiqAsmCYoWYxtxM2xYMEkrr3g,40436
15
- ai_edge_quantizer/qtyping.py,sha256=y9KretGzUGztyLdmto2XV6U0cxrSrfLWP1UOVcwR4dY,18011
15
+ ai_edge_quantizer/qtyping.py,sha256=0AVvoCN0TPzbkSsE8bp3vb-b4hctZZ-q098cjnp46c8,18027
16
16
  ai_edge_quantizer/quantizer.py,sha256=_XRzj1UTXoPa0AeE1Ygz6XAelst2p2fGLqrhYB5MOCg,19150
17
17
  ai_edge_quantizer/quantizer_test.py,sha256=6gcOLsZO-XW9VoKmcf_9CalG-_2lSUAe_fcmH2zHcoU,30167
18
18
  ai_edge_quantizer/recipe.py,sha256=MEkfQ2Sg3KAE9LAORHWcbjYNPg06EUbwc1d-VspQA2U,6461
19
- ai_edge_quantizer/recipe_manager.py,sha256=6l2uq8KL23KLu9OQDmPGkxrFiwHrdDB9xnn-ni8WdEM,15036
20
- ai_edge_quantizer/recipe_manager_test.py,sha256=gYK3haUJ8-AISQvTI6tD-E-drJXQPSXPqBZdgpc5QTo,36595
19
+ ai_edge_quantizer/recipe_manager.py,sha256=OcnrY8Qj_kjDIXx71RX1MHw5qND89N-DKuMRajfGMEg,15205
20
+ ai_edge_quantizer/recipe_manager_test.py,sha256=pLEnLX8zwfZu9LcZoU0a8QpxNr8IFwbGdxp-hlYEwU4,37050
21
21
  ai_edge_quantizer/recipe_test.py,sha256=QisyaTol8JRZFcGOGyee7QRCvqj5VbF4guKWdIoMUOE,6213
22
22
  ai_edge_quantizer/transformation_instruction_generator.py,sha256=YmjtOFqc4ajGzvHEWTyIUIom0I0uJtxt4Uc9nxzmw2A,31852
23
23
  ai_edge_quantizer/transformation_instruction_generator_test.py,sha256=KW5-WoTTo9IqLEVnWxVC8ut8eWLi_91xfKgGqVQ9QDk,54635
@@ -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=s4JudZaYZlL5PwdfjKV-HcbaVSzVcXXueNFdBxZDv9I,41033
31
+ ai_edge_quantizer/algorithms/uniform_quantize/common_quantize.py,sha256=XZ79vEVqUF7CGLC2M4PEbGFbdPKeMFmOpkyjdX2MCso,41468
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=VjBDxGxjITHJc7xJABqBbZt6_qhobtZAl2gnVQrYJgc,8652
34
34
  ai_edge_quantizer/algorithms/uniform_quantize/dequantized_weight_recovery_test.py,sha256=sT5eX5TLZEHTtPfnSkCPDlS0sQxlTFWbCsbvOuj--yY,8889
@@ -66,16 +66,16 @@ ai_edge_quantizer/utils/__init__.py,sha256=lpq1g2ayg3lCPLy79t2VicYcnGKw64FfYIj1V
66
66
  ai_edge_quantizer/utils/calibration_utils.py,sha256=iMf_bSCf-O86MzDt5D9hLKqbTydqLwirluaC6BJ9yHo,11553
67
67
  ai_edge_quantizer/utils/calibration_utils_test.py,sha256=4BlksXl7b4yptL8xPR67hmJCnjhN9V10a2PunzfHrUE,9372
68
68
  ai_edge_quantizer/utils/constrained_ops_utils.py,sha256=z0sm1R9anRRVgdgI23XQKwDRcdARdpTo_6UBDB_lHXE,4502
69
- ai_edge_quantizer/utils/constrained_ops_utils_test.py,sha256=i_uERo-KvMj0dvUSuI67kdOBHvRQETg8-qnejs_MgTE,1756
69
+ ai_edge_quantizer/utils/constrained_ops_utils_test.py,sha256=O0ull_vJeFlYG9Yl6L0IIJlx0Kn882xc4yl1uqA4-bo,1756
70
70
  ai_edge_quantizer/utils/test_utils.py,sha256=a4Nk-wbeB09dFjTDZiA0K67d26j5DD0UDH_GIVmVG_4,8685
71
- ai_edge_quantizer/utils/tfl_flatbuffer_utils.py,sha256=42OWzQsRTXq3XQYmoxlz177_dw2fJfq7mDSJaU--ArQ,12076
71
+ ai_edge_quantizer/utils/tfl_flatbuffer_utils.py,sha256=39KvguSg3qQMwHVybKLqXvFclAA-N1nbe0yrcT9wiDU,12126
72
72
  ai_edge_quantizer/utils/tfl_flatbuffer_utils_test.py,sha256=K1SbK8q92qYVtiVj0I0GtugsPTkpIpEKv9zakvFV_Sc,8555
73
73
  ai_edge_quantizer/utils/tfl_interpreter_utils.py,sha256=zgXVSIoNU-M2V1Wcq06M0MPoA-dCXXEZd1Y9vvors_c,15100
74
74
  ai_edge_quantizer/utils/tfl_interpreter_utils_test.py,sha256=EPOXbmXqbt3tAewo3BQQjh2mjuxrrFit5tkF0wUVYHU,12471
75
75
  ai_edge_quantizer/utils/validation_utils.py,sha256=Mr0D6X-pTDLODFAnCX3IlqdV1OL02tlq0ZjHbqx8nzg,7439
76
76
  ai_edge_quantizer/utils/validation_utils_test.py,sha256=T8K5mCWeMcihND2KS_dHvCJUU9lEdG2sD95EgPkaX3w,5584
77
- ai_edge_quantizer_nightly-0.5.0.dev20251215.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
78
- ai_edge_quantizer_nightly-0.5.0.dev20251215.dist-info/METADATA,sha256=oDPUvwvP5bUUvUny3rIbTkZ7B367LDbvLuPJA3jP18Y,1707
79
- ai_edge_quantizer_nightly-0.5.0.dev20251215.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
80
- ai_edge_quantizer_nightly-0.5.0.dev20251215.dist-info/top_level.txt,sha256=8QTfPnFXNVUhScFLaa-NWZMFWMn72M50DVPubpwWB1g,18
81
- ai_edge_quantizer_nightly-0.5.0.dev20251215.dist-info/RECORD,,
77
+ ai_edge_quantizer_nightly-0.5.0.dev20251217.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
78
+ ai_edge_quantizer_nightly-0.5.0.dev20251217.dist-info/METADATA,sha256=Csj8SZfxE68KEVk3Wgjwsl3WoYfrLlEnVU_JeKjdHf4,1707
79
+ ai_edge_quantizer_nightly-0.5.0.dev20251217.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
80
+ ai_edge_quantizer_nightly-0.5.0.dev20251217.dist-info/top_level.txt,sha256=8QTfPnFXNVUhScFLaa-NWZMFWMn72M50DVPubpwWB1g,18
81
+ ai_edge_quantizer_nightly-0.5.0.dev20251217.dist-info/RECORD,,