ai-edge-quantizer-nightly 0.3.0.dev20250612__py3-none-any.whl → 0.3.0.dev20250614__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.
@@ -112,6 +112,7 @@ MIN_MAX_OP_NAME_MATERIALIZE_FUNC_DICT = {
112
112
  common_quantize.materialize_squared_difference
113
113
  ),
114
114
  _TFLOpName.MAX_POOL_2D: common_quantize.materialize_max_pool_2d,
115
+ _TFLOpName.RESIZE_BILINEAR: common_quantize.materialize_resize_bilinear,
115
116
  }
116
117
  for op_name, materialize_func in MIN_MAX_OP_NAME_MATERIALIZE_FUNC_DICT.items():
117
118
  register_quantized_op(
@@ -250,6 +251,7 @@ _OCTAV_OP_NAME_MATERIALIZE_FUNC_DICT = immutabledict({
250
251
  common_quantize.materialize_squared_difference
251
252
  ),
252
253
  _TFLOpName.MAX_POOL_2D: common_quantize.materialize_max_pool_2d,
254
+ _TFLOpName.RESIZE_BILINEAR: common_quantize.materialize_resize_bilinear,
253
255
  })
254
256
 
255
257
  for op_name, materialize_func in _OCTAV_OP_NAME_MATERIALIZE_FUNC_DICT.items():
@@ -728,6 +728,23 @@ def materialize_max_pool_2d(
728
728
  )
729
729
 
730
730
 
731
+ def materialize_resize_bilinear(
732
+ get_tensor_quant_params_fn: qtyping.GetTensorQuantParamsFuncSignature,
733
+ op_info: qtyping.OpInfo,
734
+ graph_info: qtyping.GraphInfo,
735
+ tensor_name_to_qsv: dict[str, Any],
736
+ ) -> list[qtyping.TensorTransformationParams]:
737
+ """Materialize tensors in tfl.resize_bilinear."""
738
+ return common_utils.materialize_standard_op(
739
+ op_info,
740
+ graph_info,
741
+ tensor_name_to_qsv,
742
+ get_tensor_quant_params_fn,
743
+ constraint=_OpQuantConstraint.SAME_AS_INPUT_SCALE,
744
+ inputs_to_ignore=[1], # Resize size does not need to be quantized.
745
+ )
746
+
747
+
731
748
  def _get_tensor_shape_for_blockwise(
732
749
  tensor_shape: Sequence[int], quantized_dim: int, block_size: int
733
750
  ) -> list[int]:
@@ -165,7 +165,7 @@ class Calibrator:
165
165
  )
166
166
  if algorithm_name == algorithm_manager.AlgorithmName.NO_QUANTIZE:
167
167
  continue
168
- if policy.is_conditionally_unquantized(op):
168
+ if policy.is_non_quantizable_composite_op(op):
169
169
  continue
170
170
 
171
171
  # Step2.2: query algorithm_manager to get/call the related
@@ -185,7 +185,8 @@ DEFAULT_JSON_POLICY = """
185
185
  "SELECT_V2",
186
186
  "STABLEHLO_COMPOSITE",
187
187
  "PAD",
188
- "MAX_POOL_2D"
188
+ "MAX_POOL_2D",
189
+ "RESIZE_BILINEAR"
189
190
  ],
190
191
  "static_wi8_ai8": [
191
192
  "ADD",
@@ -219,7 +220,8 @@ DEFAULT_JSON_POLICY = """
219
220
  "STABLEHLO_COMPOSITE",
220
221
  "PAD",
221
222
  "SQUARED_DIFFERENCE",
222
- "MAX_POOL_2D"
223
+ "MAX_POOL_2D",
224
+ "RESIZE_BILINEAR"
223
225
  ],
224
226
  "static_wi4_ai8": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT", "EMBEDDING_LOOKUP"],
225
227
  "static_wi4_ai16": ["FULLY_CONNECTED", "CONV_2D", "INPUT", "OUTPUT", "EMBEDDING_LOOKUP"],
@@ -245,6 +247,7 @@ DEFAULT_JSON_POLICY = """
245
247
  }
246
248
  }
247
249
  """
250
+ QUANTIZABLE_COMPOSITES = ["od" + "ml.npu_call", "od" + "ml.rms_norm"]
248
251
 
249
252
 
250
253
  def _unroll_json_config(
@@ -322,10 +325,10 @@ def _unroll_json_config(
322
325
 
323
326
 
324
327
  # TODO: b/401024954 - Have a better way to specify recipes based on op options.
325
- def is_conditionally_unquantized(
328
+ def is_non_quantizable_composite_op(
326
329
  op: Union[schema.Operator, schema.OperatorT],
327
330
  ) -> bool:
328
- """Checks if the operator is conditionally unquantized.
331
+ """Checks if the operator is a non-quantizable composite op.
329
332
 
330
333
  We may want to quantize an op only when its has certain options.
331
334
  Policies/recipes
@@ -340,10 +343,9 @@ def is_conditionally_unquantized(
340
343
  if opts := flatbuffer_utils.get_options_as(
341
344
  op, schema.StableHLOCompositeOptionsT
342
345
  ):
343
- name: bytes = opts.name
344
- # Non npu_call composites may have a kernel and as such will not be
345
- # quantized.
346
- return ("od" + "ml.npu_call") not in name.decode("utf-8")
346
+ name = opts.name.decode("utf-8")
347
+ if name not in QUANTIZABLE_COMPOSITES:
348
+ return True
347
349
 
348
350
  return False
349
351
 
@@ -109,7 +109,7 @@ class ParamsGenerator:
109
109
  algorithm_name, op_quant_config = (
110
110
  model_recipe_manager.get_quantization_configs(op_key, op_scope)
111
111
  )
112
- if policy.is_conditionally_unquantized(op):
112
+ if policy.is_non_quantizable_composite_op(op):
113
113
  algorithm_name = algorithm_manager.AlgorithmName.NO_QUANTIZE
114
114
 
115
115
  if algorithm_name == algorithm_manager.AlgorithmName.NO_QUANTIZE:
@@ -65,6 +65,7 @@ class TFLOperationName(str, enum.Enum):
65
65
  PAD = 'PAD'
66
66
  SQUARED_DIFFERENCE = 'SQUARED_DIFFERENCE'
67
67
  MAX_POOL_2D = 'MAX_POOL_2D'
68
+ RESIZE_BILINEAR = 'RESIZE_BILINEAR'
68
69
 
69
70
 
70
71
  class QuantizeMode(enum.Enum):
@@ -59,6 +59,7 @@ TFL_OP_NAME_TO_CODE = immutabledict.immutabledict({
59
59
  _TFLOpName.PAD: schema.BuiltinOperator.PAD,
60
60
  _TFLOpName.SQUARED_DIFFERENCE: schema.BuiltinOperator.SQUARED_DIFFERENCE,
61
61
  _TFLOpName.MAX_POOL_2D: schema.BuiltinOperator.MAX_POOL_2D,
62
+ _TFLOpName.RESIZE_BILINEAR: schema.BuiltinOperator.RESIZE_BILINEAR,
62
63
  })
63
64
 
64
65
  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.dev20250612
3
+ Version: 0.3.0.dev20250614
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=lfCazb2b0Q4L3of0cTWkF5lMr3AD6LWW1ekmFoEGB_4,12062
2
+ ai_edge_quantizer/algorithm_manager.py,sha256=rMTM89YDPkmLKlUQV_Rjr7B2KpcvldAHzfpgUqaOqdU,12216
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
- ai_edge_quantizer/calibrator.py,sha256=-_jX_KkfIepkQAwxxDrZjvPO1JsoSjHXVy1DPc1iFjM,12068
5
+ ai_edge_quantizer/calibrator.py,sha256=Sms7_AIHPH9G5xFaz5Ef3a5gPhxuIWQI8d2LUM8C96I,12071
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=nKtghUjTQ8QS9CgLRwQb3iB2eZOyQv0FqyISlcgzSH4,11195
8
+ ai_edge_quantizer/default_policy.py,sha256=zghBh9dTB-ouPFumV-0siBSnEbp0WxF6tGOsn3TLirg,11242
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
- ai_edge_quantizer/params_generator.py,sha256=j1BV2cGFLlQmUY6aoW5uglYqf77b9ytN8oZ1gh6o0mM,20096
13
+ ai_edge_quantizer/params_generator.py,sha256=gC7G6Ne4Fumc8RSmIAbx96ZBhszZlHqBKSmE9p6RPTo,20099
14
14
  ai_edge_quantizer/params_generator_test.py,sha256=RDYoRZDJfEZRtjlTAU2kZ_4t3JHOqEHxfJX9V4ETAhg,40597
15
- ai_edge_quantizer/qtyping.py,sha256=0Dwz6LHQG8LhZMhVAo_h6ieZ_gcfkJl2yJcsGf17YYs,16527
15
+ ai_edge_quantizer/qtyping.py,sha256=kX1AoD-YlHYbDI1RfGVXIbPn-CYT7HUF2x77-hPtKBM,16565
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=ofDoiZhOKjF7Tm-v0a4xsLSvytjfvMALXLDcuwcKNK0,29634
31
+ ai_edge_quantizer/algorithms/uniform_quantize/common_quantize.py,sha256=rImKK2ax7LrRx6XurSdvRTk0h6WtFGtQn9sYNJcn-uw,30222
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
@@ -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=Yy1u53FzRBFx-fr1TqoycWMZwAlAl0b2IB4MmGV1xJA,10758
67
+ ai_edge_quantizer/utils/tfl_flatbuffer_utils.py,sha256=pZv8FMWyjBSLN5MGJ2K_dZ6oqkJGbp9RI4CfnlPuPII,10830
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.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,,
73
+ ai_edge_quantizer_nightly-0.3.0.dev20250614.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
74
+ ai_edge_quantizer_nightly-0.3.0.dev20250614.dist-info/METADATA,sha256=5ZPSscczc1tLmVN4sCf-xtX2qvmabAWOAkIjZVCb_7U,1528
75
+ ai_edge_quantizer_nightly-0.3.0.dev20250614.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
76
+ ai_edge_quantizer_nightly-0.3.0.dev20250614.dist-info/top_level.txt,sha256=8QTfPnFXNVUhScFLaa-NWZMFWMn72M50DVPubpwWB1g,18
77
+ ai_edge_quantizer_nightly-0.3.0.dev20250614.dist-info/RECORD,,