compressed-tensors 0.4.0__py3-none-any.whl → 0.6.0__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.
- compressed_tensors/base.py +1 -0
- compressed_tensors/compressors/__init__.py +5 -1
- compressed_tensors/compressors/base.py +200 -8
- compressed_tensors/compressors/dense.py +1 -1
- compressed_tensors/compressors/marlin_24.py +11 -10
- compressed_tensors/compressors/model_compressor.py +101 -13
- compressed_tensors/compressors/naive_quantized.py +140 -0
- compressed_tensors/compressors/pack_quantized.py +128 -132
- compressed_tensors/compressors/sparse_bitmask.py +1 -1
- compressed_tensors/config/base.py +8 -1
- compressed_tensors/{compressors/utils → linear}/__init__.py +0 -6
- compressed_tensors/linear/compressed_linear.py +87 -0
- compressed_tensors/quantization/lifecycle/__init__.py +1 -0
- compressed_tensors/quantization/lifecycle/apply.py +204 -44
- compressed_tensors/quantization/lifecycle/calibration.py +22 -2
- compressed_tensors/quantization/lifecycle/compressed.py +3 -1
- compressed_tensors/quantization/lifecycle/forward.py +139 -61
- compressed_tensors/quantization/lifecycle/helpers.py +80 -0
- compressed_tensors/quantization/lifecycle/initialize.py +77 -13
- compressed_tensors/quantization/observers/__init__.py +1 -0
- compressed_tensors/quantization/observers/base.py +93 -14
- compressed_tensors/quantization/observers/helpers.py +64 -11
- compressed_tensors/quantization/observers/min_max.py +8 -0
- compressed_tensors/quantization/observers/mse.py +162 -0
- compressed_tensors/quantization/quant_args.py +139 -23
- compressed_tensors/quantization/quant_config.py +35 -2
- compressed_tensors/quantization/quant_scheme.py +112 -13
- compressed_tensors/quantization/utils/helpers.py +68 -2
- compressed_tensors/utils/__init__.py +5 -0
- compressed_tensors/utils/helpers.py +44 -2
- compressed_tensors/utils/offload.py +116 -0
- compressed_tensors/utils/permute.py +70 -0
- compressed_tensors/utils/safetensors_load.py +2 -0
- compressed_tensors/{compressors/utils → utils}/semi_structured_conversions.py +1 -0
- compressed_tensors/version.py +1 -1
- {compressed_tensors-0.4.0.dist-info → compressed_tensors-0.6.0.dist-info}/METADATA +35 -22
- compressed_tensors-0.6.0.dist-info/RECORD +52 -0
- {compressed_tensors-0.4.0.dist-info → compressed_tensors-0.6.0.dist-info}/WHEEL +1 -1
- compressed_tensors/compressors/int_quantized.py +0 -126
- compressed_tensors/compressors/utils/helpers.py +0 -43
- compressed_tensors-0.4.0.dist-info/RECORD +0 -48
- /compressed_tensors/{compressors/utils → utils}/permutations_24.py +0 -0
- {compressed_tensors-0.4.0.dist-info → compressed_tensors-0.6.0.dist-info}/LICENSE +0 -0
- {compressed_tensors-0.4.0.dist-info → compressed_tensors-0.6.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: compressed-tensors
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.6.0
|
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.
|
@@ -8,43 +8,56 @@ Author-email: support@neuralmagic.com
|
|
8
8
|
License: Apache 2.0
|
9
9
|
Description-Content-Type: text/markdown
|
10
10
|
License-File: LICENSE
|
11
|
-
Requires-Dist: torch
|
11
|
+
Requires-Dist: torch>=1.7.0
|
12
12
|
Requires-Dist: transformers
|
13
|
-
Requires-Dist: pydantic
|
13
|
+
Requires-Dist: pydantic>=2.0
|
14
|
+
Provides-Extra: accelerate
|
15
|
+
Requires-Dist: accelerate; extra == "accelerate"
|
14
16
|
Provides-Extra: dev
|
15
|
-
Requires-Dist: black
|
16
|
-
Requires-Dist: isort
|
17
|
-
Requires-Dist: wheel
|
18
|
-
Requires-Dist: flake8
|
19
|
-
Requires-Dist: pytest
|
20
|
-
Requires-Dist: nbconvert
|
17
|
+
Requires-Dist: black==22.12.0; extra == "dev"
|
18
|
+
Requires-Dist: isort==5.8.0; extra == "dev"
|
19
|
+
Requires-Dist: wheel>=0.36.2; extra == "dev"
|
20
|
+
Requires-Dist: flake8>=3.8.3; extra == "dev"
|
21
|
+
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
22
|
+
Requires-Dist: nbconvert>=7.16.3; extra == "dev"
|
21
23
|
|
22
|
-
#
|
24
|
+
# compressed-tensors
|
23
25
|
|
24
|
-
|
26
|
+
The `compressed-tensors` library extends the [safetensors](https://github.com/huggingface/safetensors) format, providing a versatile and efficient way to store and manage compressed tensor data. This library supports various quantization and sparsity schemes, making it a unified format for handling different model optimizations like GPTQ, AWQ, SmoothQuant, INT8, FP8, SparseGPT, and more.
|
25
27
|
|
26
|
-
##
|
28
|
+
## Why `compressed-tensors`?
|
27
29
|
|
28
|
-
|
30
|
+
As model compression becomes increasingly important for efficient deployment of LLMs, the landscape of quantization and compression techniques has become increasingly fragmented.
|
31
|
+
Each method often comes with its own storage format and loading procedures, making it challenging to work with multiple techniques or switch between them.
|
32
|
+
`compressed-tensors` addresses this by providing a single, extensible format that can represent a wide variety of compression schemes.
|
29
33
|
|
30
|
-
|
34
|
+
* **Unified Checkpoint Format**: Supports various compression schemes in a single, consistent format.
|
35
|
+
* **Wide Compatibility**: Works with popular quantization methods like GPTQ, SmoothQuant, and FP8. See [llm-compressor](https://github.com/vllm-project/llm-compressor)
|
36
|
+
* **Flexible Quantization Support**:
|
37
|
+
* Weight-only quantization (e.g., W4A16, W8A16, WnA16)
|
38
|
+
* Activation quantization (e.g., W8A8)
|
39
|
+
* KV cache quantization
|
40
|
+
* Non-uniform schemes (different layers can be quantized in different ways!)
|
41
|
+
* **Sparsity Support**: Handles both unstructured and semi-structured (e.g., 2:4) sparsity patterns.
|
42
|
+
* **Open-Source Integration**: Designed to work seamlessly with Hugging Face models and PyTorch.
|
31
43
|
|
32
|
-
|
33
|
-
- Quantized -> due to their low precision representation.
|
34
|
-
|
35
|
-
### Introduce an elegant interface to save/load compressed tensors
|
36
|
-
|
37
|
-
The library provides the user with the ability to compress/decompress tensors. The properties of tensors are defined by human-readable configs, allowing the users to understand the compression format at a quick glance.
|
44
|
+
This allows developers and researchers to easily experiment with composing different quantization methods, simplify model deployment pipelines, and reduce the overhead of supporting multiple compression formats in inference engines.
|
38
45
|
|
39
46
|
## Installation
|
40
47
|
|
41
|
-
###
|
48
|
+
### From [PyPI](https://pypi.org/project/compressed-tensors)
|
42
49
|
|
50
|
+
Stable release:
|
43
51
|
```bash
|
44
52
|
pip install compressed-tensors
|
45
53
|
```
|
46
54
|
|
47
|
-
|
55
|
+
Nightly release:
|
56
|
+
```bash
|
57
|
+
pip install compressed-tensors-nightly
|
58
|
+
```
|
59
|
+
|
60
|
+
### From Source
|
48
61
|
|
49
62
|
```bash
|
50
63
|
git clone https://github.com/neuralmagic/compressed-tensors
|
@@ -0,0 +1,52 @@
|
|
1
|
+
compressed_tensors/__init__.py,sha256=SV1csvHUVCd8kHXz6UDZim1HZ_fAVG3vfk-j_4Bb6hY,789
|
2
|
+
compressed_tensors/base.py,sha256=Mq4mfVQcJhNpha-BXzpOfpmFIdl01o09BJE7D2oQ_00,796
|
3
|
+
compressed_tensors/version.py,sha256=qWZbaQsbr0_5Y1qtWGstNPljw-ggMLBGZBvSKfzB9pw,1585
|
4
|
+
compressed_tensors/compressors/__init__.py,sha256=wmX4VnkUTS63xBwK5-6w8FP78bNZpcdcqvf2KOEC5E4,1133
|
5
|
+
compressed_tensors/compressors/base.py,sha256=NfVkhq6PRiq2cvAXaUXLoqC_nVYWdSrkE12c9AXYSMo,9956
|
6
|
+
compressed_tensors/compressors/dense.py,sha256=xcWECjcRY4INN6jC7vHx5wvUX3NmnKlxA9SVE1A6m2Q,1267
|
7
|
+
compressed_tensors/compressors/helpers.py,sha256=k9avlkmeYj6vkOAvl-MgcixtP7ib24SCfhzZ-RusXfw,5403
|
8
|
+
compressed_tensors/compressors/marlin_24.py,sha256=e7fGUyZbjUpA5VUMCPxqcYPGNiwoDKupHJaXWCoVKRw,9410
|
9
|
+
compressed_tensors/compressors/model_compressor.py,sha256=gI6KKtH3eeWi2540Ayx-4bg9o8qjrvxlF4Gd_sqltGA,16678
|
10
|
+
compressed_tensors/compressors/naive_quantized.py,sha256=z3h3ca5xKCN69mahutxcbzdv-OysiaxaM8P-Qum6zUQ,4823
|
11
|
+
compressed_tensors/compressors/pack_quantized.py,sha256=27RVmJ2wg2dvCoawj407HSmKT3VPGJ6ujAMHlT26WlI,7571
|
12
|
+
compressed_tensors/compressors/sparse_bitmask.py,sha256=kiDwBlFV0sJGLcIdDYxIiuF64ccgwDfqq1hWRQThYDc,8647
|
13
|
+
compressed_tensors/config/__init__.py,sha256=ZBqWn3r6ku1qfmlHHYp0mQueY0i7Pwhr9rbQk9dDlMc,704
|
14
|
+
compressed_tensors/config/base.py,sha256=BNTFKy12isY7qblwxdi_R1f00EzgrNOXLrfxqLCPT8w,1903
|
15
|
+
compressed_tensors/config/dense.py,sha256=NgSxnFCnckU9-iunxEaqiFwqgdO7YYxlWKR74jNbjks,1317
|
16
|
+
compressed_tensors/config/sparse_bitmask.py,sha256=pZUboRNZTu6NajGOQEFExoPknak5ynVAUeiiYpS1Gt8,1308
|
17
|
+
compressed_tensors/linear/__init__.py,sha256=fH6rjBYAxuwrTzBTlTjTgCYNyh6TCvCqajCz4Im4YrA,617
|
18
|
+
compressed_tensors/linear/compressed_linear.py,sha256=G0gEFfxLAUsgRcnfSV-PKz1ZBNTVokOauOoup7SE1mw,3210
|
19
|
+
compressed_tensors/quantization/__init__.py,sha256=83J5bPB7PavN2TfCoW7_vEDhfYpm4TDrqYO9vdSQ5bk,760
|
20
|
+
compressed_tensors/quantization/quant_args.py,sha256=CmyVtjJeHlqCW-7R5Z7tIw6lXUrzCX6Y9bwgmMxEudY,8069
|
21
|
+
compressed_tensors/quantization/quant_config.py,sha256=NpVu8YJ4Xw2pIQW_PGaNaml8kx1bUnxkvb0jBYWbKdE,9971
|
22
|
+
compressed_tensors/quantization/quant_scheme.py,sha256=HmR1DcFZcjuqX7KHUYI0NFXsCIzJ8sxFGH6zhYuHmEs,5870
|
23
|
+
compressed_tensors/quantization/lifecycle/__init__.py,sha256=MXE2E7GfIfRRfhrdGy2Og3AZOz5N59B0ZGFcsD89y6c,821
|
24
|
+
compressed_tensors/quantization/lifecycle/apply.py,sha256=uftWFunr_CpCZM_qWfo2O1USXKB2qSYD1pBJsO8BuCU,15285
|
25
|
+
compressed_tensors/quantization/lifecycle/calibration.py,sha256=PlS_EqCOPqJD3QKuLPXO9AOtDzXtQWvEBTynFv-FFVw,2698
|
26
|
+
compressed_tensors/quantization/lifecycle/compressed.py,sha256=Fj9n66IN0EWsOAkBHg3O0GlOQpxstqjCcs0ttzMXrJ0,2296
|
27
|
+
compressed_tensors/quantization/lifecycle/forward.py,sha256=PljD9pzATILEOiC3ZdHUTsfSbZdAa6iSIxWmvAHLG9I,13688
|
28
|
+
compressed_tensors/quantization/lifecycle/frozen.py,sha256=h1XYt89MouBTf3jTYLG_6OdFxIu5q2N8tPjsy6J4E6Y,1726
|
29
|
+
compressed_tensors/quantization/lifecycle/helpers.py,sha256=TmLY_G5VP_Fg2Ywio_dxoHRTxOKZdT7_aG5S9WtD4zI,2424
|
30
|
+
compressed_tensors/quantization/lifecycle/initialize.py,sha256=S5Kwy16Da8WUIIpa1xVKc72MijJ5C_rqM6JjanZ7MGk,7133
|
31
|
+
compressed_tensors/quantization/observers/__init__.py,sha256=4Sa7rqi5RB_S5bPO8KmncETiqDsoMBhwP37arlQym8s,764
|
32
|
+
compressed_tensors/quantization/observers/base.py,sha256=5ovQicWPYHjIxr6-EkQ4lgOX0PpI9g23iSzKpxjM1Zg,8420
|
33
|
+
compressed_tensors/quantization/observers/helpers.py,sha256=s_A23Qa_BLfOdHJCN5bm-qPWkhjjj_RIVrhSp1Y9Dtk,4211
|
34
|
+
compressed_tensors/quantization/observers/memoryless.py,sha256=jH_c6K3gxf4W3VNXQ7tbnP-J_86QTrEfjBn6Kh1C-H8,2165
|
35
|
+
compressed_tensors/quantization/observers/min_max.py,sha256=sQXqU3z-voxIDfR_9mQzwQUflZj2sASm_G8CYaXntFw,3865
|
36
|
+
compressed_tensors/quantization/observers/mse.py,sha256=Aeh-253Vbab1F8cYuBiGNn4OXWJ67wXQ_JVfl3mu2a8,6034
|
37
|
+
compressed_tensors/quantization/utils/__init__.py,sha256=VdtEmP0bvuND_IGQnyqUPc5lnFp-1_yD7StKSX4x80w,656
|
38
|
+
compressed_tensors/quantization/utils/helpers.py,sha256=pwvU613XRvMDtI5b39II5jukBl5OUCqoX0ofVRpOFRY,8633
|
39
|
+
compressed_tensors/registry/__init__.py,sha256=FwLSNYqfIrb5JD_6OK_MT4_svvKTN_nEhpgQlQvGbjI,658
|
40
|
+
compressed_tensors/registry/registry.py,sha256=fxjOjh2wklCvJhQxwofdy-zV8q7MkQ85SLG77nml2iA,11890
|
41
|
+
compressed_tensors/utils/__init__.py,sha256=gS4gSU2pwcAbsKj-6YMaqhm25udFy6ISYaWBf-myRSM,808
|
42
|
+
compressed_tensors/utils/helpers.py,sha256=bh4G8mj_YCRf8Bo2FQ9FkIIZXY8xqqPjckNnVYB0gBA,3557
|
43
|
+
compressed_tensors/utils/offload.py,sha256=d9q8LNe8HyF8tOjgjA7QGLD3HRysmNp0d8eBbdqBgIM,4089
|
44
|
+
compressed_tensors/utils/permutations_24.py,sha256=kx6fsfDHebx94zsSzhXGyCyuC9sVyah6BUUir_StT28,2530
|
45
|
+
compressed_tensors/utils/permute.py,sha256=V6tJLKo3Syccj-viv4F7ZKZgJeCB-hl-dK8RKI_kBwI,2355
|
46
|
+
compressed_tensors/utils/safetensors_load.py,sha256=m08ANVuTBxQdoa6LufDgcNJ7wCLDJolyZljB8VEybAU,8578
|
47
|
+
compressed_tensors/utils/semi_structured_conversions.py,sha256=XKNffPum54kPASgqKzgKvyeqWPAkair2XEQXjkp7ho8,13489
|
48
|
+
compressed_tensors-0.6.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
49
|
+
compressed_tensors-0.6.0.dist-info/METADATA,sha256=opV5oXtNn7EmogPQaMiv9ddOLHv-XObt_NuUSwR5Bz4,6782
|
50
|
+
compressed_tensors-0.6.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
51
|
+
compressed_tensors-0.6.0.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
|
52
|
+
compressed_tensors-0.6.0.dist-info/RECORD,,
|
@@ -1,126 +0,0 @@
|
|
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
|
-
import logging
|
16
|
-
from typing import Dict, Generator, Tuple
|
17
|
-
|
18
|
-
import torch
|
19
|
-
from compressed_tensors.compressors import Compressor
|
20
|
-
from compressed_tensors.config import CompressionFormat
|
21
|
-
from compressed_tensors.quantization import QuantizationArgs
|
22
|
-
from compressed_tensors.quantization.lifecycle.forward import dequantize, quantize
|
23
|
-
from compressed_tensors.quantization.utils import can_quantize
|
24
|
-
from compressed_tensors.utils import get_nested_weight_mappings, merge_names
|
25
|
-
from safetensors import safe_open
|
26
|
-
from torch import Tensor
|
27
|
-
from tqdm import tqdm
|
28
|
-
|
29
|
-
|
30
|
-
__all__ = ["IntQuantizationCompressor"]
|
31
|
-
|
32
|
-
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
33
|
-
|
34
|
-
|
35
|
-
@Compressor.register(name=CompressionFormat.int_quantized.value)
|
36
|
-
class IntQuantizationCompressor(Compressor):
|
37
|
-
"""
|
38
|
-
Integer compression for quantized models. Weight of each quantized layer is
|
39
|
-
converted from its original float type to the format specified by the layer's
|
40
|
-
quantization scheme.
|
41
|
-
"""
|
42
|
-
|
43
|
-
COMPRESSION_PARAM_NAMES = ["weight", "weight_scale", "weight_zero_point"]
|
44
|
-
|
45
|
-
def compress(
|
46
|
-
self,
|
47
|
-
model_state: Dict[str, Tensor],
|
48
|
-
model_quant_args: Dict[str, QuantizationArgs],
|
49
|
-
**kwargs,
|
50
|
-
) -> Dict[str, Tensor]:
|
51
|
-
"""
|
52
|
-
Compresses a dense state dict
|
53
|
-
|
54
|
-
:param model_state: state dict of uncompressed model
|
55
|
-
:param model_quant_args: quantization args for each quantized weight, needed for
|
56
|
-
quantize function to calculate bit depth
|
57
|
-
:return: compressed state dict
|
58
|
-
"""
|
59
|
-
compressed_dict = {}
|
60
|
-
weight_suffix = ".weight"
|
61
|
-
_LOGGER.debug(
|
62
|
-
f"Compressing model with {len(model_state)} parameterized layers..."
|
63
|
-
)
|
64
|
-
|
65
|
-
for name, value in tqdm(model_state.items(), desc="Compressing model"):
|
66
|
-
if name.endswith(weight_suffix):
|
67
|
-
prefix = name[: -(len(weight_suffix))]
|
68
|
-
scale = model_state.get(merge_names(prefix, "weight_scale"), None)
|
69
|
-
zp = model_state.get(merge_names(prefix, "weight_zero_point"), None)
|
70
|
-
if scale is not None and zp is not None:
|
71
|
-
# weight is quantized, compress it
|
72
|
-
quant_args = model_quant_args[prefix]
|
73
|
-
if can_quantize(value, quant_args):
|
74
|
-
# only quantize if not already quantized
|
75
|
-
value = quantize(
|
76
|
-
x=value,
|
77
|
-
scale=scale,
|
78
|
-
zero_point=zp,
|
79
|
-
args=quant_args,
|
80
|
-
dtype=torch.int8,
|
81
|
-
)
|
82
|
-
elif name.endswith("zero_point"):
|
83
|
-
if torch.all(value == 0):
|
84
|
-
# all zero_points are 0, no need to include in
|
85
|
-
# compressed state_dict
|
86
|
-
continue
|
87
|
-
compressed_dict[name] = value.to("cpu")
|
88
|
-
|
89
|
-
return compressed_dict
|
90
|
-
|
91
|
-
def decompress(
|
92
|
-
self, path_to_model_or_tensors: str, device: str = "cpu"
|
93
|
-
) -> Generator[Tuple[str, Tensor], None, None]:
|
94
|
-
"""
|
95
|
-
Reads a compressed state dict located at path_to_model_or_tensors
|
96
|
-
and returns a generator for sequentially decompressing back to a
|
97
|
-
dense state dict
|
98
|
-
|
99
|
-
:param model_path: path to compressed safetensors model (directory with
|
100
|
-
one or more safetensors files) or compressed tensors file
|
101
|
-
:param device: optional device to load intermediate weights into
|
102
|
-
:return: compressed state dict
|
103
|
-
"""
|
104
|
-
weight_mappings = get_nested_weight_mappings(
|
105
|
-
path_to_model_or_tensors, self.COMPRESSION_PARAM_NAMES
|
106
|
-
)
|
107
|
-
for weight_name in weight_mappings.keys():
|
108
|
-
weight_data = {}
|
109
|
-
for param_name, safe_path in weight_mappings[weight_name].items():
|
110
|
-
full_name = merge_names(weight_name, param_name)
|
111
|
-
with safe_open(safe_path, framework="pt", device=device) as f:
|
112
|
-
weight_data[param_name] = f.get_tensor(full_name)
|
113
|
-
|
114
|
-
if "weight_scale" in weight_data:
|
115
|
-
zero_point = weight_data.get("weight_zero_point", None)
|
116
|
-
scale = weight_data["weight_scale"]
|
117
|
-
if zero_point is None:
|
118
|
-
# zero_point assumed to be 0 if not included in state_dict
|
119
|
-
zero_point = torch.zeros_like(scale)
|
120
|
-
|
121
|
-
decompressed = dequantize(
|
122
|
-
x_q=weight_data["weight"],
|
123
|
-
scale=scale,
|
124
|
-
zero_point=zero_point,
|
125
|
-
)
|
126
|
-
yield merge_names(weight_name, "weight"), decompressed
|
@@ -1,43 +0,0 @@
|
|
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
|
-
import torch
|
16
|
-
|
17
|
-
|
18
|
-
__all__ = ["tensor_follows_mask_structure"]
|
19
|
-
|
20
|
-
|
21
|
-
def tensor_follows_mask_structure(tensor, mask: str = "2:4") -> bool:
|
22
|
-
"""
|
23
|
-
:param tensor: tensor to check
|
24
|
-
:param mask: mask structure to check for, in the format "n:m"
|
25
|
-
:return: True if the tensor follows the mask structure, False otherwise.
|
26
|
-
Note, some weights can incidentally be zero, so we check for
|
27
|
-
atleast n zeros in each chunk of size m
|
28
|
-
"""
|
29
|
-
|
30
|
-
n, m = tuple(map(int, mask.split(":")))
|
31
|
-
# Reshape the tensor into chunks of size m
|
32
|
-
tensor = tensor.view(-1, m)
|
33
|
-
|
34
|
-
# Count the number of zeros in each chunk
|
35
|
-
zero_counts = (tensor == 0).sum(dim=1)
|
36
|
-
|
37
|
-
# Check if the number of zeros in each chunk atleast n
|
38
|
-
# Greater than sign is needed as some weights can incidentally
|
39
|
-
# be zero
|
40
|
-
if not torch.all(zero_counts >= n).item():
|
41
|
-
raise ValueError()
|
42
|
-
|
43
|
-
return True
|
@@ -1,48 +0,0 @@
|
|
1
|
-
compressed_tensors/__init__.py,sha256=SV1csvHUVCd8kHXz6UDZim1HZ_fAVG3vfk-j_4Bb6hY,789
|
2
|
-
compressed_tensors/base.py,sha256=OA2TOLP1gP3LSH7gp508eqr2ZtDQ-pqRHElCp-aB0vs,755
|
3
|
-
compressed_tensors/version.py,sha256=_nj1yS4msz1OXd0H1v1m-z1JkMOuy19M9lFDTWP5xf0,1585
|
4
|
-
compressed_tensors/compressors/__init__.py,sha256=rhqPp3YXFxCJRLZs1KRNSHTIxK2rNU--sYwDI8MW47w,1061
|
5
|
-
compressed_tensors/compressors/base.py,sha256=LWEgbpgTxzmoqQ7Xhq2OQszUgWoDtFuGCiV1Y8nlBGw,2134
|
6
|
-
compressed_tensors/compressors/dense.py,sha256=G_XHbvuENyupIKlXSITOQgvPkNkcMEOLcLWQr70V9EE,1257
|
7
|
-
compressed_tensors/compressors/helpers.py,sha256=k9avlkmeYj6vkOAvl-MgcixtP7ib24SCfhzZ-RusXfw,5403
|
8
|
-
compressed_tensors/compressors/int_quantized.py,sha256=Ct2vCK0yoPm6vkIFlzDMGQ7m14xT1GyURsSwH9DP770,5242
|
9
|
-
compressed_tensors/compressors/marlin_24.py,sha256=X_BjtFB3Mn0hqiLz56UM3jGX2eNmGLnvEIPfbg7di6U,9444
|
10
|
-
compressed_tensors/compressors/model_compressor.py,sha256=h3ixQtfzt6HxSNtdnB9OVdpCucTmIo4paDoaM7XYZXE,12559
|
11
|
-
compressed_tensors/compressors/pack_quantized.py,sha256=VPiLlgJlDgARrn7YmiQoLqUfxErKBfj54epMYWRsF8k,8451
|
12
|
-
compressed_tensors/compressors/sparse_bitmask.py,sha256=H9oZSTYI1oRCzAMbd4zThUnZd1h2rfs8DmA3tPcvuNE,8637
|
13
|
-
compressed_tensors/compressors/utils/__init__.py,sha256=-mbGDZh1hd9T6u62Ht_iBIK255UmMg0f5bLkSs1f9Cc,731
|
14
|
-
compressed_tensors/compressors/utils/helpers.py,sha256=4fq7KclSIK__jemCG9pwYlgWLrQjsaAMxhIrhjdw0BQ,1506
|
15
|
-
compressed_tensors/compressors/utils/permutations_24.py,sha256=kx6fsfDHebx94zsSzhXGyCyuC9sVyah6BUUir_StT28,2530
|
16
|
-
compressed_tensors/compressors/utils/semi_structured_conversions.py,sha256=g1EZHzdv-ko7ufPX430dp7wE33o6FWJXuSP4zZydCu0,13488
|
17
|
-
compressed_tensors/config/__init__.py,sha256=ZBqWn3r6ku1qfmlHHYp0mQueY0i7Pwhr9rbQk9dDlMc,704
|
18
|
-
compressed_tensors/config/base.py,sha256=ZnpuOevCE0pXdA8OJfIJnxj-ccproH7o1EOwRY8_hUU,1482
|
19
|
-
compressed_tensors/config/dense.py,sha256=NgSxnFCnckU9-iunxEaqiFwqgdO7YYxlWKR74jNbjks,1317
|
20
|
-
compressed_tensors/config/sparse_bitmask.py,sha256=pZUboRNZTu6NajGOQEFExoPknak5ynVAUeiiYpS1Gt8,1308
|
21
|
-
compressed_tensors/quantization/__init__.py,sha256=83J5bPB7PavN2TfCoW7_vEDhfYpm4TDrqYO9vdSQ5bk,760
|
22
|
-
compressed_tensors/quantization/quant_args.py,sha256=Z9Zu20ooAwEWlliAdUw1f1zwSrheuD6vqm3YXgJ1Lws,4388
|
23
|
-
compressed_tensors/quantization/quant_config.py,sha256=hL42sXp1wAZxyrkHarw7tAMRcwSVEr0MT3wmrmL3NhE,8285
|
24
|
-
compressed_tensors/quantization/quant_scheme.py,sha256=aX4h8t8RDqrWeUqoqrYMOxc0xkWcu8Ue_CHLoG-fRjQ,3569
|
25
|
-
compressed_tensors/quantization/lifecycle/__init__.py,sha256=ggRGWRqhCxCaTTDWRcgTVX3axnS2xV6rc5YvdzK7fSg,798
|
26
|
-
compressed_tensors/quantization/lifecycle/apply.py,sha256=aZrglJ5mR3Xaxwj51-1BVVB1JGVkKQEeHxGfBaVmsHI,8881
|
27
|
-
compressed_tensors/quantization/lifecycle/calibration.py,sha256=mLns4jlaWmBwOW8Jtlm5bMX-JET1AiZYUBO7qa-XuxI,1776
|
28
|
-
compressed_tensors/quantization/lifecycle/compressed.py,sha256=VreB10xPwgSLQQlTu20UCrFpRS--cA7-lx5s7nrPPrg,2247
|
29
|
-
compressed_tensors/quantization/lifecycle/forward.py,sha256=0T817yzYqFR1wUjk2XCtOISwr4u7cdkKqAv13jjfu24,11113
|
30
|
-
compressed_tensors/quantization/lifecycle/frozen.py,sha256=h1XYt89MouBTf3jTYLG_6OdFxIu5q2N8tPjsy6J4E6Y,1726
|
31
|
-
compressed_tensors/quantization/lifecycle/initialize.py,sha256=9xgPzHejQUO_AkZcc_SH5kqFeieG-9uo0fMRYV51i7Y,4577
|
32
|
-
compressed_tensors/quantization/observers/__init__.py,sha256=DNH31NQYrIBBcmHsMyFA6whh4pbRsLwuNa6L8AeXaGc,745
|
33
|
-
compressed_tensors/quantization/observers/base.py,sha256=z_JC-CRz-PY7WlpSoyOoSQQWz5ekTEd5LbXt0iHQRes,5239
|
34
|
-
compressed_tensors/quantization/observers/helpers.py,sha256=FUyYUNd-3LbXt0-8Lwr7EPI2m-LXXBTXW1l5iOajNhA,2272
|
35
|
-
compressed_tensors/quantization/observers/memoryless.py,sha256=jH_c6K3gxf4W3VNXQ7tbnP-J_86QTrEfjBn6Kh1C-H8,2165
|
36
|
-
compressed_tensors/quantization/observers/min_max.py,sha256=UK7zCMzxv9GGn6BflBxdajV20RiWaCY2RHcvZodCP1w,3669
|
37
|
-
compressed_tensors/quantization/utils/__init__.py,sha256=VdtEmP0bvuND_IGQnyqUPc5lnFp-1_yD7StKSX4x80w,656
|
38
|
-
compressed_tensors/quantization/utils/helpers.py,sha256=NzAH18Cn_-mTAR87y6IlcQU5gC393XSjgNKC9CRkr78,6017
|
39
|
-
compressed_tensors/registry/__init__.py,sha256=FwLSNYqfIrb5JD_6OK_MT4_svvKTN_nEhpgQlQvGbjI,658
|
40
|
-
compressed_tensors/registry/registry.py,sha256=fxjOjh2wklCvJhQxwofdy-zV8q7MkQ85SLG77nml2iA,11890
|
41
|
-
compressed_tensors/utils/__init__.py,sha256=5DrYjoZbaEvSkJcC-GRSbM_RBHVF4tG9gMd3zsJnjLw,665
|
42
|
-
compressed_tensors/utils/helpers.py,sha256=5ull5yFT31M2zVxKeFvpvvlvX5f1Sk1LGuj_wrfZWCY,2267
|
43
|
-
compressed_tensors/utils/safetensors_load.py,sha256=0MheXwx1jeY12PeISppiSIZHs6rmN2YddwPpFb9V67I,8527
|
44
|
-
compressed_tensors-0.4.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
45
|
-
compressed_tensors-0.4.0.dist-info/METADATA,sha256=NtnK_A9ck3KPmh4syGcGtMBGX-_2FyFa7ntCAdf-KGo,5651
|
46
|
-
compressed_tensors-0.4.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
47
|
-
compressed_tensors-0.4.0.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
|
48
|
-
compressed_tensors-0.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|