mct-nightly 2.0.0.20240519.436__py3-none-any.whl → 2.0.0.20240521.418__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mct-nightly
3
- Version: 2.0.0.20240519.436
3
+ Version: 2.0.0.20240521.418
4
4
  Summary: A Model Compression Toolkit for neural networks
5
5
  Home-page: UNKNOWN
6
6
  License: UNKNOWN
@@ -1,4 +1,4 @@
1
- model_compression_toolkit/__init__.py,sha256=-xNRcIW41rS3RlCyrt3JZJuXSUMGB1BG9UiBEhAtXcE,1573
1
+ model_compression_toolkit/__init__.py,sha256=hotkHO8sD6YxUKPsjLhBTyAQ5cyxVWS4Br7x_RXz5UM,1573
2
2
  model_compression_toolkit/constants.py,sha256=b63Jk_bC7VXEX3Qn9TZ3wUvrNKD8Mkz8zIuayoyF5eU,3828
3
3
  model_compression_toolkit/defaultdict.py,sha256=LSc-sbZYXENMCw3U9F4GiXuv67IKpdn0Qm7Fr11jy-4,2277
4
4
  model_compression_toolkit/logger.py,sha256=3DByV41XHRR3kLTJNbpaMmikL8icd9e1N-nkQAY9oDk,4567
@@ -31,7 +31,7 @@ model_compression_toolkit/core/common/fusion/__init__.py,sha256=Rf1RcYmelmdZmBV5
31
31
  model_compression_toolkit/core/common/fusion/layer_fusing.py,sha256=lOubqpc18TslhXZijWUJQAa1c3jIB2S-M-5HK78wJPQ,5548
32
32
  model_compression_toolkit/core/common/graph/__init__.py,sha256=Xr-Lt_qXMdrCnnOaUS_OJP_3iTTGfPCLf8_vSrQgCs0,773
33
33
  model_compression_toolkit/core/common/graph/base_graph.py,sha256=lmIw0srKiwCvz7KWqfwKTxyQHDy3s6rWMIXzFAa1UMo,38326
34
- model_compression_toolkit/core/common/graph/base_node.py,sha256=IaHrvgtUZvPshhUjS4j2lqIP22Mlny82BQZaL2iVJew,29079
34
+ model_compression_toolkit/core/common/graph/base_node.py,sha256=WGkSxjvbRLQBfFT_yrSQRnlmUpwtqkUfpVwrhLgMw5k,29338
35
35
  model_compression_toolkit/core/common/graph/edge.py,sha256=buoSEUZwilWBK3WeBKpJ-GeDaUA1SDdOHxDpxU_bGpk,3784
36
36
  model_compression_toolkit/core/common/graph/functional_node.py,sha256=71_4TrCdqR_r0mtgxmAyqI05iP5YoQQGeSmDgynuzTw,3902
37
37
  model_compression_toolkit/core/common/graph/graph_matchers.py,sha256=CrDoHYq4iPaflgJWmoJ1K4ziLrRogJvFTVWg8P0UcDU,4744
@@ -72,7 +72,7 @@ model_compression_toolkit/core/common/mixed_precision/resource_utilization_tools
72
72
  model_compression_toolkit/core/common/mixed_precision/resource_utilization_tools/resource_utilization_data.py,sha256=MhmYgsybWJ2dlCwbZjDKJB8QlDHHy--zOBs2DwJB2e0,13820
73
73
  model_compression_toolkit/core/common/mixed_precision/resource_utilization_tools/ru_aggregation_methods.py,sha256=ttc8wPa_9LZansutQ2f1ss-RTzgTv739wy3qsdLzyyk,4217
74
74
  model_compression_toolkit/core/common/mixed_precision/resource_utilization_tools/ru_functions_mapping.py,sha256=QhuqaECEGLnYC08iD6-2XXcU7NXbPzYf1sQcjYlGak8,1682
75
- model_compression_toolkit/core/common/mixed_precision/resource_utilization_tools/ru_methods.py,sha256=TUGv_4j9-WUWZceoqLdObH_61tAQnHIRyquxm09x9wI,21473
75
+ model_compression_toolkit/core/common/mixed_precision/resource_utilization_tools/ru_methods.py,sha256=WC1EHoNuo_lrzy4NRhGJ1cgmJ2IsFsbmP86mrVO3AVA,21506
76
76
  model_compression_toolkit/core/common/mixed_precision/search_methods/__init__.py,sha256=sw7LOPN1bM82o3SkMaklyH0jw-TLGK0-fl2Wq73rffI,697
77
77
  model_compression_toolkit/core/common/mixed_precision/search_methods/linear_programming.py,sha256=7ceagUJVk3GgLrD8HnmXMgZTRLjEvZW_RnzDR3ahNDM,16592
78
78
  model_compression_toolkit/core/common/network_editors/__init__.py,sha256=vZmu55bYqiaOQs3AjfwWDXHmuKZcLHt-wm7uR5fPEqg,1307
@@ -126,7 +126,7 @@ model_compression_toolkit/core/common/quantization/quantizers/uniform_quantizers
126
126
  model_compression_toolkit/core/common/statistics_correction/__init__.py,sha256=sw7LOPN1bM82o3SkMaklyH0jw-TLGK0-fl2Wq73rffI,697
127
127
  model_compression_toolkit/core/common/statistics_correction/apply_bias_correction_to_graph.py,sha256=xSWVDOODgbN0k4mjJWWtpawilOsqdm4O7Uw2hbA75EA,4669
128
128
  model_compression_toolkit/core/common/statistics_correction/apply_second_moment_correction_to_graph.py,sha256=C_nwhhitTd1pCto0nHZPn3fjIMOeDD7VIciumTR3s6k,5641
129
- model_compression_toolkit/core/common/statistics_correction/compute_bias_correction_of_graph.py,sha256=0vGu7FAbuBpusaWxNbBEJHHTCAH_nigV9YeAFGAhghU,10145
129
+ model_compression_toolkit/core/common/statistics_correction/compute_bias_correction_of_graph.py,sha256=LaGhYES7HgIDf9Bi2KAG_mBzAWuum0J6AGmAFPC8wwo,10478
130
130
  model_compression_toolkit/core/common/statistics_correction/statistics_correction.py,sha256=5dzNtzDMmmLETgAU23k8Cu7q0q3z1EyS-46_Yx-aS7s,5519
131
131
  model_compression_toolkit/core/common/substitutions/__init__.py,sha256=sw7LOPN1bM82o3SkMaklyH0jw-TLGK0-fl2Wq73rffI,697
132
132
  model_compression_toolkit/core/common/substitutions/apply_substitutions.py,sha256=k-bifmakHIYZeZS-4T1QpZ1Et6AwAijMRgAKs7hmMKc,1390
@@ -136,7 +136,7 @@ model_compression_toolkit/core/common/substitutions/batchnorm_refusing.py,sha256
136
136
  model_compression_toolkit/core/common/substitutions/linear_collapsing.py,sha256=iEtzbWCDXP6EDkTZCtREQ0rpMxhQ2kM9zlcP_0KLq9I,12367
137
137
  model_compression_toolkit/core/common/substitutions/linear_collapsing_substitution.py,sha256=uoauhmncQqUBNvD-qCLIXsIbl_IzrbxSKdxiMig-5W4,2406
138
138
  model_compression_toolkit/core/common/substitutions/remove_identity.py,sha256=TKU1TIU52UIkVnl0EZvWnDhLV9nIVZ4hqi-w1i4NXMk,2637
139
- model_compression_toolkit/core/common/substitutions/residual_collapsing.py,sha256=doErjlMq-uSObYMSjA6IywSHb3Hz3QCc0HKU68ccrQ4,4767
139
+ model_compression_toolkit/core/common/substitutions/residual_collapsing.py,sha256=N82mso5j3EJQlKt9EMHjjEJ67FmdGQeCfN8U5grOFXo,4830
140
140
  model_compression_toolkit/core/common/substitutions/scale_equalization.py,sha256=p57u25qdW2pimxzGwgMXEBV4S-LzXuTVAlIM7830WfU,10966
141
141
  model_compression_toolkit/core/common/substitutions/shift_negative_activation.py,sha256=cyy4qnlD-v1Gou62oHNDsf1hWLWkYfcjVv1otFrUltY,29865
142
142
  model_compression_toolkit/core/common/substitutions/softmax_shift.py,sha256=R-0ZqhYAuZLEFWHvB2UTPm52L6gWHGdRdEnwGxKSeGI,2625
@@ -216,13 +216,13 @@ model_compression_toolkit/core/pytorch/pytorch_device_config.py,sha256=S25cuw10A
216
216
  model_compression_toolkit/core/pytorch/pytorch_implementation.py,sha256=sEtlxpWdt0rzuTN3R0bNCC_l75Xy7rIBMUWY7LuhYKI,27351
217
217
  model_compression_toolkit/core/pytorch/pytorch_node_prior_info.py,sha256=2LDQ7qupglHQ7o1Am7LWdfYVacfQnl-aW2N6l9det1w,3264
218
218
  model_compression_toolkit/core/pytorch/resource_utilization_data_facade.py,sha256=E6ifk1HdO60k4IRH2EFBzAYWtwUlrGqJoQ66nknpHoQ,4983
219
- model_compression_toolkit/core/pytorch/utils.py,sha256=dRPiteBg2dBNsHwZyYzXiCIAjnelSoeZZsDXlsTw5JQ,2880
219
+ model_compression_toolkit/core/pytorch/utils.py,sha256=OT_mrNEJqPgWLdtQuivKMQVjtJY49cmoIVvbRhANl1w,3004
220
220
  model_compression_toolkit/core/pytorch/back2framework/__init__.py,sha256=H_WixgN0elVWf3exgGYsi58imPoYDj5eYPeh6x4yfug,813
221
221
  model_compression_toolkit/core/pytorch/back2framework/factory_model_builder.py,sha256=DwNO8WO3JiMawKGKDhlrwCoCjMSBIw5BMbsFFF7eDS4,2279
222
222
  model_compression_toolkit/core/pytorch/back2framework/float_model_builder.py,sha256=tLrlUyYhxVKVjkad1ZAtbRra0HedB3iVfIkZ_dYnQ-4,3419
223
- model_compression_toolkit/core/pytorch/back2framework/instance_builder.py,sha256=d7U_8VKGjQjbmvcUKRKsD80woWu_0gh6LXg1NhZNTjY,1348
223
+ model_compression_toolkit/core/pytorch/back2framework/instance_builder.py,sha256=BBHBfTqeWm7L3iDyPBpk0jxvj-rBg1QWI23imkjfIl0,1467
224
224
  model_compression_toolkit/core/pytorch/back2framework/mixed_precision_model_builder.py,sha256=D7lU1r9Uq_7fdNuKk2BMF8ho5GrsY-8gyGN6yYoHaVg,15060
225
- model_compression_toolkit/core/pytorch/back2framework/pytorch_model_builder.py,sha256=11pUQUxtBM1gCxipEaXn-8A9dVI5rgRiSoFa9i_nw58,18281
225
+ model_compression_toolkit/core/pytorch/back2framework/pytorch_model_builder.py,sha256=5fPlI4BttvQB-gm0iKcWNXZMGjXlcwfXEsxxW0TilTQ,18301
226
226
  model_compression_toolkit/core/pytorch/back2framework/quantized_model_builder.py,sha256=qZNNOlNTTV4ZKPG3q5GDXkIVTPUEr8dvxAS_YiMORmg,3456
227
227
  model_compression_toolkit/core/pytorch/back2framework/quantization_wrapper/__init__.py,sha256=cco4TmeIDIh32nj9ZZXVkws4dd9F2UDrmjKzTN8G0V0,697
228
228
  model_compression_toolkit/core/pytorch/back2framework/quantization_wrapper/quantized_layer_wrapper.py,sha256=q2JDw10NKng50ee2i9faGzWZ-IydnR2aOMGSn9RoZmc,5773
@@ -261,7 +261,7 @@ model_compression_toolkit/core/pytorch/quantizer/__init__.py,sha256=Rf1RcYmelmdZ
261
261
  model_compression_toolkit/core/pytorch/quantizer/fake_quant_builder.py,sha256=D8_CEuFqKAhbUgKaRw7Jlxo0zlqgPTMu6CIIIM4LfS0,7045
262
262
  model_compression_toolkit/core/pytorch/quantizer/lut_fake_quant.py,sha256=uyeBtNokyDUikk-YkDP_mN_2DX0J5oPm3kSfdSUT2Ck,4420
263
263
  model_compression_toolkit/core/pytorch/reader/__init__.py,sha256=Rf1RcYmelmdZmBV5qOKvKWF575ofc06JFQSq83Jz99A,696
264
- model_compression_toolkit/core/pytorch/reader/graph_builders.py,sha256=8EieykOysQEMoHZQTLZv9yfkg0dkoFwRtlR3I0rlshg,12626
264
+ model_compression_toolkit/core/pytorch/reader/graph_builders.py,sha256=x5n8KHBqvutqS5l5AillA_FQfhf-2ibP813ixK3Gvy8,12627
265
265
  model_compression_toolkit/core/pytorch/reader/node_holders.py,sha256=TaolORuwBZEddWe-q0Mg79Nmswz-Sq3-9-4o8UxFQ50,1028
266
266
  model_compression_toolkit/core/pytorch/reader/reader.py,sha256=GEJE0QX8XJFWbYCkbRBtzttZtmmuoACLx8gw9KyAQCE,6015
267
267
  model_compression_toolkit/core/pytorch/statistics_correction/__init__.py,sha256=Rf1RcYmelmdZmBV5qOKvKWF575ofc06JFQSq83Jz99A,696
@@ -483,8 +483,8 @@ model_compression_toolkit/trainable_infrastructure/keras/quantize_wrapper.py,sha
483
483
  model_compression_toolkit/trainable_infrastructure/keras/quantizer_utils.py,sha256=MVwXNymmFRB2NXIBx4e2mdJ1RfoHxRPYRgjb1MQP5kY,1797
484
484
  model_compression_toolkit/trainable_infrastructure/pytorch/__init__.py,sha256=huHoBUcKNB6BnY6YaUCcFvdyBtBI172ZoUD8ZYeNc6o,696
485
485
  model_compression_toolkit/trainable_infrastructure/pytorch/base_pytorch_quantizer.py,sha256=MxylaVFPgN7zBiRBy6WV610EA4scLgRJFbMucKvvNDU,2896
486
- mct_nightly-2.0.0.20240519.436.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
487
- mct_nightly-2.0.0.20240519.436.dist-info/METADATA,sha256=tKiBev23nHrH34I8xfcYLYe523x-prmdwXrf2TQq3J8,18477
488
- mct_nightly-2.0.0.20240519.436.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
489
- mct_nightly-2.0.0.20240519.436.dist-info/top_level.txt,sha256=gsYA8juk0Z-ZmQRKULkb3JLGdOdz8jW_cMRjisn9ga4,26
490
- mct_nightly-2.0.0.20240519.436.dist-info/RECORD,,
486
+ mct_nightly-2.0.0.20240521.418.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
487
+ mct_nightly-2.0.0.20240521.418.dist-info/METADATA,sha256=J-73dG_pMvZnU4is4fD4RMFUIGnr2pHz2oPayokFBVk,18477
488
+ mct_nightly-2.0.0.20240521.418.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
489
+ mct_nightly-2.0.0.20240521.418.dist-info/top_level.txt,sha256=gsYA8juk0Z-ZmQRKULkb3JLGdOdz8jW_cMRjisn9ga4,26
490
+ mct_nightly-2.0.0.20240521.418.dist-info/RECORD,,
@@ -27,4 +27,4 @@ from model_compression_toolkit import data_generation
27
27
  from model_compression_toolkit import pruning
28
28
  from model_compression_toolkit.trainable_infrastructure.keras.load_model import keras_load_quantized_model
29
29
 
30
- __version__ = "2.0.0.20240519.000436"
30
+ __version__ = "2.0.0.20240521.000418"
@@ -96,6 +96,16 @@ class BaseNode:
96
96
  """
97
97
  return self.has_activation
98
98
 
99
+ @property
100
+ def has_positional_weights(self):
101
+ """
102
+ Returns has_positional_weights attribute.
103
+
104
+ Returns: Whether the node has positional weights.
105
+
106
+ """
107
+ return any(isinstance(key, int) for key in self.weights.keys())
108
+
99
109
  def is_activation_quantization_enabled(self) -> bool:
100
110
  """
101
111
 
@@ -285,7 +285,7 @@ def _bops_utilization(mp_cfg: List[int],
285
285
  # Go over all nodes that should be taken into consideration when computing the BOPS utilization.
286
286
  bops = []
287
287
  for n in graph.get_topo_sorted_nodes():
288
- if n.has_kernel_weight_to_quantize(fw_info):
288
+ if n.has_kernel_weight_to_quantize(fw_info) and not n.has_positional_weights:
289
289
  # If node doesn't have weights then its MAC count is 0, and we shouldn't consider it in the BOPS count.
290
290
  incoming_edges = graph.incoming_edges(n, sort_by_attr=EDGE_SINK_INDEX)
291
291
  if len(incoming_edges) != 1:
@@ -49,11 +49,16 @@ def compute_bias_correction_of_graph(graph: Graph,
49
49
  if fw_info.is_kernel_op(n.type):
50
50
  kernel_attr = fw_info.get_kernel_op_attributes(n.type)[0]
51
51
  if n.is_weights_quantization_enabled(kernel_attr):
52
- _compute_bias_correction_per_candidate_qc(n,
53
- kernel_attr,
54
- fw_info,
55
- graph.get_in_stats_collector(n),
56
- fw_impl=fw_impl)
52
+ # Bias correction is not applied to layers with constant inputs.
53
+ if n.has_positional_weights:
54
+ for candidate_qc in n.candidates_quantization_cfg:
55
+ candidate_qc.weights_quantization_cfg.weights_bias_correction = False
56
+ else:
57
+ _compute_bias_correction_per_candidate_qc(n,
58
+ kernel_attr,
59
+ fw_info,
60
+ graph.get_in_stats_collector(n),
61
+ fw_impl=fw_impl)
57
62
  return graph
58
63
 
59
64
 
@@ -67,7 +67,8 @@ class ResidualCollapsing(common.BaseSubstitution):
67
67
  return graph
68
68
 
69
69
  # Check if convolution and residual satisfy the collapsing conditions, otherwise skip substitution
70
- if len(graph.get_next_nodes(first_node)) > 1 or len(graph.get_prev_nodes(second_node)) != 2:
70
+ if (len(graph.get_next_nodes(first_node)) > 1 or len(graph.get_prev_nodes(first_node)) < 1 or
71
+ len(graph.get_prev_nodes(second_node)) != 2):
71
72
  return graph
72
73
 
73
74
  # Check if Add is residual connection, otherwise skip substitution
@@ -33,7 +33,8 @@ def node_builder(n: BaseNode) -> Module:
33
33
 
34
34
  framework_attr = copy.copy(n.framework_attr)
35
35
  node_instance = n.type(**framework_attr)
36
- node_instance.load_state_dict({k: torch.tensor(v) for k, v in n.weights.items()}, strict=False)
36
+ # Positional weights act as inputs to the PyTorch layer, rather than serving as its weights.
37
+ node_instance.load_state_dict({k: torch.tensor(v) for k, v in n.weights.items() if isinstance(k, str)}, strict=False)
37
38
  set_model(node_instance)
38
39
  return node_instance
39
40
 
@@ -71,7 +71,7 @@ def _build_input_tensors_list(node: BaseNode,
71
71
  input_tensors = node.insert_positional_weights_to_input_list(input_tensors)
72
72
  # convert inputs from positional weights (numpy arrays) to tensors. Must handle each element in the
73
73
  # list separately, because in FX the tensors are FX objects and fail to_torch_tensor
74
- input_tensors = [to_torch_tensor(t) if isinstance(t, np.ndarray) else t
74
+ input_tensors = [to_torch_tensor(t, numpy_type=t.dtype) if isinstance(t, np.ndarray) else t
75
75
  for t in input_tensors]
76
76
  return input_tensors
77
77
 
@@ -138,6 +138,7 @@ def nodes_builder(model: GraphModule,
138
138
  if input_node in consts_dict:
139
139
  used_consts.add(input_node)
140
140
  weights.update({i: consts_dict[input_node]})
141
+
141
142
  tensor_meta = input_node.meta
142
143
  if tensor_meta[TYPE] == torch.Tensor:
143
144
  input_shape += [list(tensor_meta[TENSOR_META].shape)]
@@ -38,11 +38,13 @@ def set_model(model: torch.nn.Module, train_mode: bool = False):
38
38
  model.to(device)
39
39
 
40
40
 
41
- def to_torch_tensor(tensor):
41
+ def to_torch_tensor(tensor,
42
+ numpy_type=np.float32):
42
43
  """
43
44
  Convert a Numpy array to a Torch tensor.
44
45
  Args:
45
46
  tensor: Numpy array.
47
+ numpy_type: The desired data type for the tensor. Default is np.float32.
46
48
 
47
49
  Returns:
48
50
  Torch tensor converted from the input Numpy array.
@@ -55,9 +57,9 @@ def to_torch_tensor(tensor):
55
57
  elif isinstance(tensor, tuple):
56
58
  return (to_torch_tensor(t) for t in tensor)
57
59
  elif isinstance(tensor, np.ndarray):
58
- return torch.from_numpy(tensor.astype(np.float32)).to(working_device)
60
+ return torch.from_numpy(tensor.astype(numpy_type)).to(working_device)
59
61
  elif isinstance(tensor, (int, float)):
60
- return torch.from_numpy(np.array(tensor).astype(np.float32)).to(working_device)
62
+ return torch.from_numpy(np.array(tensor).astype(numpy_type)).to(working_device)
61
63
  else:
62
64
  Logger.critical(f'Unsupported type for conversion to Torch.tensor: {type(tensor)}.')
63
65