compressed-tensors-nightly 0.4.0.20240717__py3-none-any.whl → 0.4.0.20240719__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.
@@ -21,3 +21,4 @@ from .frozen import *
21
21
  from .initialize import *
22
22
  from .compressed import *
23
23
  from .apply import *
24
+ from .helpers import *
@@ -245,6 +245,11 @@ def wrap_module_forward_quantized(module: Module, scheme: QuantizationScheme):
245
245
 
246
246
  @wraps(forward_func_orig) # ensures docstring, names, etc are propagated
247
247
  def wrapped_forward(self, *args, **kwargs):
248
+ if not getattr(module, "quantization_enabled", True):
249
+ # quantization is disabled on forward passes, return baseline
250
+ # forward call
251
+ return forward_func_orig.__get__(module, module.__class__)(*args, **kwargs)
252
+
248
253
  input_ = args[0]
249
254
 
250
255
  if scheme.input_activations is not None:
@@ -0,0 +1,53 @@
1
+ # Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing,
10
+ # software distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ Miscelaneous helpers for the quantization lifecycle
17
+ """
18
+
19
+
20
+ from torch.nn import Module
21
+
22
+
23
+ __all__ = [
24
+ "update_layer_weight_quant_params",
25
+ "enable_quantization",
26
+ "disable_quantization",
27
+ ]
28
+
29
+
30
+ def update_layer_weight_quant_params(layer: Module):
31
+ weight = getattr(layer, "weight", None)
32
+ scale = getattr(layer, "weight_scale", None)
33
+ zero_point = getattr(layer, "weight_zero_point", None)
34
+ observer = getattr(layer, "weight_observer", None)
35
+
36
+ if weight is None or observer is None or scale is None or zero_point is None:
37
+ # scale, zp, or observer not calibratable or weight not available
38
+ return
39
+
40
+ updated_scale, updated_zero_point = observer(weight)
41
+
42
+ # update scale and zero point
43
+ device = next(layer.parameters()).device
44
+ scale.data = updated_scale.to(device)
45
+ zero_point.data = updated_zero_point.to(device)
46
+
47
+
48
+ def enable_quantization(module: Module):
49
+ module.quantization_enabled = True
50
+
51
+
52
+ def disable_quantization(module: Module):
53
+ module.quantization_enabled = False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: compressed-tensors-nightly
3
- Version: 0.4.0.20240717
3
+ Version: 0.4.0.20240719
4
4
  Summary: Library for utilization of compressed safetensors of neural network models
5
5
  Home-page: https://github.com/neuralmagic/compressed-tensors
6
6
  Author: Neuralmagic, Inc.
@@ -18,12 +18,13 @@ compressed_tensors/quantization/__init__.py,sha256=83J5bPB7PavN2TfCoW7_vEDhfYpm4
18
18
  compressed_tensors/quantization/quant_args.py,sha256=Vc_tWSTcbZZsMJlACpLq4JEPvGx87izc8VEx-mcXjoM,5621
19
19
  compressed_tensors/quantization/quant_config.py,sha256=PU3BchHm09ks6_yAderrHoIZI07zBlU9ejC87v3A-54,9568
20
20
  compressed_tensors/quantization/quant_scheme.py,sha256=IKTtMfusSe7x31t7hipBfptTbCwGd9eGMtrWC1sPM9o,5522
21
- compressed_tensors/quantization/lifecycle/__init__.py,sha256=ggRGWRqhCxCaTTDWRcgTVX3axnS2xV6rc5YvdzK7fSg,798
21
+ compressed_tensors/quantization/lifecycle/__init__.py,sha256=MXE2E7GfIfRRfhrdGy2Og3AZOz5N59B0ZGFcsD89y6c,821
22
22
  compressed_tensors/quantization/lifecycle/apply.py,sha256=fyv5ujZC0__oG1ESOTmMyMsKK7DGAxG7uQI7_sxT7Mw,13308
23
23
  compressed_tensors/quantization/lifecycle/calibration.py,sha256=mLns4jlaWmBwOW8Jtlm5bMX-JET1AiZYUBO7qa-XuxI,1776
24
24
  compressed_tensors/quantization/lifecycle/compressed.py,sha256=VreB10xPwgSLQQlTu20UCrFpRS--cA7-lx5s7nrPPrg,2247
25
- compressed_tensors/quantization/lifecycle/forward.py,sha256=iVIVt17U3ObjGVgYlmdBc-8SZQFgZbi20hvjW_NGzI4,12019
25
+ compressed_tensors/quantization/lifecycle/forward.py,sha256=yz9l93EXQtOR-DkGbrEA62rdSleNnmwZfraD0whH758,12271
26
26
  compressed_tensors/quantization/lifecycle/frozen.py,sha256=h1XYt89MouBTf3jTYLG_6OdFxIu5q2N8tPjsy6J4E6Y,1726
27
+ compressed_tensors/quantization/lifecycle/helpers.py,sha256=xDkM3yVpGVnwAdg2aUOmrlDPaOksi-bavSQ5mMeOQlk,1651
27
28
  compressed_tensors/quantization/lifecycle/initialize.py,sha256=kIEx6a7UyqAIG_ZPNBhijrDiAHnp2wR7K_GC3envz4M,4631
28
29
  compressed_tensors/quantization/observers/__init__.py,sha256=DNH31NQYrIBBcmHsMyFA6whh4pbRsLwuNa6L8AeXaGc,745
29
30
  compressed_tensors/quantization/observers/base.py,sha256=2WO7N2eyXf1r1gxVidos1bUS5o7pcrpug4gQgHIazrQ,6794
@@ -39,8 +40,8 @@ compressed_tensors/utils/helpers.py,sha256=d3yP9ViQ8R3GzMHfohxNlaokzyrRuj2PyjxWA
39
40
  compressed_tensors/utils/permutations_24.py,sha256=kx6fsfDHebx94zsSzhXGyCyuC9sVyah6BUUir_StT28,2530
40
41
  compressed_tensors/utils/safetensors_load.py,sha256=0MheXwx1jeY12PeISppiSIZHs6rmN2YddwPpFb9V67I,8527
41
42
  compressed_tensors/utils/semi_structured_conversions.py,sha256=g1EZHzdv-ko7ufPX430dp7wE33o6FWJXuSP4zZydCu0,13488
42
- compressed_tensors_nightly-0.4.0.20240717.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
43
- compressed_tensors_nightly-0.4.0.20240717.dist-info/METADATA,sha256=ixz47P7GMt_W4ajzWO00dS9PzeVBG2-Bh-GgIo8ueTU,5668
44
- compressed_tensors_nightly-0.4.0.20240717.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
45
- compressed_tensors_nightly-0.4.0.20240717.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
46
- compressed_tensors_nightly-0.4.0.20240717.dist-info/RECORD,,
43
+ compressed_tensors_nightly-0.4.0.20240719.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
+ compressed_tensors_nightly-0.4.0.20240719.dist-info/METADATA,sha256=yRgA4IrauWe129Q7qjNHH-qJGWQP52H_7bgsL9SupXc,5668
45
+ compressed_tensors_nightly-0.4.0.20240719.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
46
+ compressed_tensors_nightly-0.4.0.20240719.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
47
+ compressed_tensors_nightly-0.4.0.20240719.dist-info/RECORD,,