ai-edge-quantizer-nightly 0.1.0.dev20250325__py3-none-any.whl → 0.1.0.dev20250326__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.
@@ -306,7 +306,7 @@ class ParamsGenerator:
306
306
 
307
307
  buffers_to_duplicate = []
308
308
  for tensors in self.buffer_to_tensors.values():
309
- if len(tensors) <= 1:
309
+ if not tensors:
310
310
  continue
311
311
 
312
312
  first_tensor = tensors[0]
@@ -314,7 +314,7 @@ class ParamsGenerator:
314
314
  if first_tensor_params is None:
315
315
  continue
316
316
 
317
- for tensor in tensors[1:]:
317
+ for tensor in tensors: # Also checking against itself.
318
318
  tensor_params = get_result(tensor)
319
319
  if tensor_params is None:
320
320
  continue
@@ -190,22 +190,15 @@ def parse_fc_bmm_conv_tensors(
190
190
  # flatbuffer_model has Any type since tensorflow.lite.tools.flatbuffer_utils
191
191
  # is not type annotated.
192
192
  def buffer_to_tensors(flatbuffer_model: Any) -> dict[int, list[Any]]:
193
- """Get the buffer to tensor map for a tflite model.
194
-
195
- Args:
196
- flatbuffer_model: the flatbuffer_model.
197
-
198
- Returns:
199
- buffer_to_tensor_map: key as buffer index, value as list of tensors share
200
- the buffer
201
- """
193
+ """Returns a map from buffer id to tensors that use it."""
202
194
  buffer_to_tensor_map = {}
203
195
  for subgraph in flatbuffer_model.subgraphs:
204
196
  for op in subgraph.operators:
205
197
  for tensor in parse_op_tensors(op, subgraph.tensors):
206
198
  if tensor.buffer not in buffer_to_tensor_map:
207
199
  buffer_to_tensor_map[tensor.buffer] = []
208
- buffer_to_tensor_map[tensor.buffer].append(tensor)
200
+ if tensor not in buffer_to_tensor_map[tensor.buffer]:
201
+ buffer_to_tensor_map[tensor.buffer].append(tensor)
209
202
  return buffer_to_tensor_map
210
203
 
211
204
 
@@ -105,6 +105,26 @@ class FlatbufferUtilsTest(googletest.TestCase):
105
105
  conv2d_filter_tensor = tensors[0]
106
106
  self.assertEqual(tuple(conv2d_filter_tensor.shape), (8, 3, 3, 1))
107
107
 
108
+ def test_buffer_to_tensors_has_unique_values(self):
109
+ test_model_path = os.path.join(
110
+ TEST_DATA_PREFIX_PATH,
111
+ "constant_tensor_and_buffer_only_sharing_weight_fcs.tflite",
112
+ )
113
+ test_model = tfl_flatbuffer_utils.read_model(test_model_path)
114
+ buffer_to_tensor_map = tfl_flatbuffer_utils.buffer_to_tensors(test_model)
115
+ self.assertLen(buffer_to_tensor_map, 7)
116
+ # The following buffer is shared by two tensors, each shared by two FC ops.
117
+ # This is where before we had multiple enrties for the same tensor.
118
+ self.assertLen(buffer_to_tensor_map[2], 2)
119
+ got_tensor_names = [
120
+ tfl_flatbuffer_utils.get_tensor_name(tensor)
121
+ for tensor in buffer_to_tensor_map[2]
122
+ ]
123
+ self.assertEqual(
124
+ got_tensor_names,
125
+ ["arith.constant", "arith.constant1"],
126
+ )
127
+
108
128
  def test_get_tensor_name(self):
109
129
  subgraph0 = self._test_model.subgraphs[0]
110
130
  subgraph_tensors = subgraph0.tensors
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ai-edge-quantizer-nightly
3
- Version: 0.1.0.dev20250325
3
+ Version: 0.1.0.dev20250326
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
@@ -10,7 +10,7 @@ ai_edge_quantizer/model_modifier.py,sha256=SPt9X-xBzRvcd4xIS24zLHt3aUS2QwsNDqweF
10
10
  ai_edge_quantizer/model_modifier_test.py,sha256=cJd04SLOG-fQZZNZPcisoBLx3cLtWEwGqUBbLb-pif4,4751
11
11
  ai_edge_quantizer/model_validator.py,sha256=fRNz0jO54cthPTibsCuViUXUuFRHl_fbvEiCukIVy20,13030
12
12
  ai_edge_quantizer/model_validator_test.py,sha256=EeqOP_mrZsnZ3rug756s0ryDDqd2KgIDld5Lm_gDuWY,13020
13
- ai_edge_quantizer/params_generator.py,sha256=jOCK2UuEsnnbqtbmLxUBpjmhsXZXjZZto2vdsPifliU,16039
13
+ ai_edge_quantizer/params_generator.py,sha256=f-KhJMFdRv2oHxfM8tAANPOtfBMw8vD7Vjv0rYQbnF4,16062
14
14
  ai_edge_quantizer/params_generator_test.py,sha256=zmDS6jG5zKhHL_hzJw2wlMTx1LLcNCK6S5WlwogWF-A,41122
15
15
  ai_edge_quantizer/qtyping.py,sha256=UBZ3HgO8IDLY6VJmO05rGtFv_idMD3Os3WWsnriA0NA,15235
16
16
  ai_edge_quantizer/quantizer.py,sha256=g3DMqFMrMpt9jQttCE0WcdNbMtk0JZnmN5MmCHrNdyM,13202
@@ -58,14 +58,14 @@ ai_edge_quantizer/utils/__init__.py,sha256=lpq1g2ayg3lCPLy79t2VicYcnGKw64FfYIj1V
58
58
  ai_edge_quantizer/utils/calibration_utils.py,sha256=1Fj9MIO6aLZIRgyd4axvZN4S_O64nB_-Miu1WP664js,2536
59
59
  ai_edge_quantizer/utils/calibration_utils_test.py,sha256=Z-AcdTieesWFKyKBb08ZXm4Mgu6cvJ4bg2-MJ7hLD10,2856
60
60
  ai_edge_quantizer/utils/test_utils.py,sha256=HwZCIpO9fJRAhuN6t6voXKOYQtcioFtt_tpkAlDsAYk,6205
61
- ai_edge_quantizer/utils/tfl_flatbuffer_utils.py,sha256=51GRkwj7PK0XvAqohdv6mAepOWRk1AnW2y-9ne6LzWo,10628
62
- ai_edge_quantizer/utils/tfl_flatbuffer_utils_test.py,sha256=AbyDxoM62k4ojD8gPdkWo--xe5hlX3t0kobQSA80kuk,7740
61
+ ai_edge_quantizer/utils/tfl_flatbuffer_utils.py,sha256=irrGbbOt14PLFcS4538II0dB4Q7YJMgGvpBERVHevXM,10535
62
+ ai_edge_quantizer/utils/tfl_flatbuffer_utils_test.py,sha256=K1SbK8q92qYVtiVj0I0GtugsPTkpIpEKv9zakvFV_Sc,8555
63
63
  ai_edge_quantizer/utils/tfl_interpreter_utils.py,sha256=x2xA2CFPpe_2trcV8v5xGaBETvVCfwAcJuq6yieGJ0Y,12687
64
64
  ai_edge_quantizer/utils/tfl_interpreter_utils_test.py,sha256=Op3JxtOqlrjzmYF18jnnstL1k9xiY9kKJ8S2vklKGkc,11327
65
65
  ai_edge_quantizer/utils/validation_utils.py,sha256=oYw33Sg547AqtGw-choPUJmp9SAKkV46J_ddqSsum2Q,3950
66
66
  ai_edge_quantizer/utils/validation_utils_test.py,sha256=V_qNDikPD4OPB-siOLQCWNVWTAu87h2IgNYt7teFd-o,2934
67
- ai_edge_quantizer_nightly-0.1.0.dev20250325.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
68
- ai_edge_quantizer_nightly-0.1.0.dev20250325.dist-info/METADATA,sha256=RKkQCy7ObIveJ5SFfo_GghHWtCcbTts72QS4ZXyGTG4,1527
69
- ai_edge_quantizer_nightly-0.1.0.dev20250325.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
70
- ai_edge_quantizer_nightly-0.1.0.dev20250325.dist-info/top_level.txt,sha256=8QTfPnFXNVUhScFLaa-NWZMFWMn72M50DVPubpwWB1g,18
71
- ai_edge_quantizer_nightly-0.1.0.dev20250325.dist-info/RECORD,,
67
+ ai_edge_quantizer_nightly-0.1.0.dev20250326.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
68
+ ai_edge_quantizer_nightly-0.1.0.dev20250326.dist-info/METADATA,sha256=TMD_HBIneEi6YXf7SoDynPrENpiv_L4D_b_VHL9z_-c,1527
69
+ ai_edge_quantizer_nightly-0.1.0.dev20250326.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
70
+ ai_edge_quantizer_nightly-0.1.0.dev20250326.dist-info/top_level.txt,sha256=8QTfPnFXNVUhScFLaa-NWZMFWMn72M50DVPubpwWB1g,18
71
+ ai_edge_quantizer_nightly-0.1.0.dev20250326.dist-info/RECORD,,