compressed-tensors 0.11.1a20250923__py3-none-any.whl → 0.12.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/compressors/model_compressors/model_compressor.py +56 -0
- compressed_tensors/transform/factory/hadamard.py +1 -1
- compressed_tensors/transform/factory/matrix_multiply.py +1 -1
- compressed_tensors/transform/transform_scheme.py +7 -18
- compressed_tensors/version.py +2 -2
- {compressed_tensors-0.11.1a20250923.dist-info → compressed_tensors-0.12.0.dist-info}/METADATA +1 -1
- {compressed_tensors-0.11.1a20250923.dist-info → compressed_tensors-0.12.0.dist-info}/RECORD +10 -10
- {compressed_tensors-0.11.1a20250923.dist-info → compressed_tensors-0.12.0.dist-info}/WHEEL +0 -0
- {compressed_tensors-0.11.1a20250923.dist-info → compressed_tensors-0.12.0.dist-info}/licenses/LICENSE +0 -0
- {compressed_tensors-0.11.1a20250923.dist-info → compressed_tensors-0.12.0.dist-info}/top_level.txt +0 -0
|
@@ -52,6 +52,7 @@ from compressed_tensors.utils import (
|
|
|
52
52
|
get_offloaded_device,
|
|
53
53
|
get_safetensors_folder,
|
|
54
54
|
has_offloaded_params,
|
|
55
|
+
merge_names,
|
|
55
56
|
patch_attr,
|
|
56
57
|
register_offload_parameter,
|
|
57
58
|
update_parameter_data,
|
|
@@ -343,6 +344,61 @@ class ModelCompressor:
|
|
|
343
344
|
format, config=quantization_config
|
|
344
345
|
)
|
|
345
346
|
|
|
347
|
+
def get_unexpected_file_keys(self, model: Module) -> List[str]:
|
|
348
|
+
"""
|
|
349
|
+
Identifies extra keys introduced by the compression process in the
|
|
350
|
+
compressed state_dict that are not expected by the model graph.
|
|
351
|
+
|
|
352
|
+
During sparsity or quantization compression, additional metadata or
|
|
353
|
+
auxiliary parameters may be stored in the checkpoint, which do not
|
|
354
|
+
correspond to any parameter in the original model. These keys are
|
|
355
|
+
typically introduced to support the reconstruction of compressed weights.
|
|
356
|
+
|
|
357
|
+
For example, Sparse24Bitmask compression may introduce keys such as
|
|
358
|
+
'compressed', 'bitmask', and 'shape' in the checkpoint, which are
|
|
359
|
+
not part of the original model parameters.
|
|
360
|
+
|
|
361
|
+
:param model: The PyTorch model to check for unexpected keys.
|
|
362
|
+
:return: A list of extra keys introduced by the compression process
|
|
363
|
+
that are not expected by the model.
|
|
364
|
+
"""
|
|
365
|
+
|
|
366
|
+
unexpected_keys = set()
|
|
367
|
+
|
|
368
|
+
# Identify unexpected keys from sparsity compression
|
|
369
|
+
if (
|
|
370
|
+
self.sparsity_compressor
|
|
371
|
+
and self.sparsity_config.format != CompressionFormat.dense.value
|
|
372
|
+
):
|
|
373
|
+
sparse_targets = match_named_modules(
|
|
374
|
+
model=model,
|
|
375
|
+
targets=self.sparsity_config.targets,
|
|
376
|
+
ignore=self.sparsity_config.ignore,
|
|
377
|
+
)
|
|
378
|
+
unexpected_keys.update(
|
|
379
|
+
merge_names(target_name, param)
|
|
380
|
+
for target_name, _module in sparse_targets
|
|
381
|
+
for param in self.sparsity_compressor.compression_param_names
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
# Identify unexpected keys from quantization compression
|
|
385
|
+
if self.quantization_compressor:
|
|
386
|
+
for scheme in self.quantization_config.config_groups.values():
|
|
387
|
+
quant_targets = match_named_modules(
|
|
388
|
+
model=model,
|
|
389
|
+
targets=scheme.targets,
|
|
390
|
+
ignore=self.quantization_config.ignore,
|
|
391
|
+
)
|
|
392
|
+
for quant_compressor in self.quantization_compressor.values():
|
|
393
|
+
unexpected_keys.update(
|
|
394
|
+
merge_names(target_name, param)
|
|
395
|
+
for target_name, _module in quant_targets
|
|
396
|
+
for param in quant_compressor.compression_param_names
|
|
397
|
+
if param != "weight"
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
return list(unexpected_keys)
|
|
401
|
+
|
|
346
402
|
# ----- model memory compression/decompression pathways ----- #
|
|
347
403
|
|
|
348
404
|
def compress_model(self, model: Module):
|
|
@@ -52,7 +52,7 @@ class HadamardFactory(TransformFactory):
|
|
|
52
52
|
:param args: defines how the transform will be applied to the module
|
|
53
53
|
"""
|
|
54
54
|
assert hasattr(module, "weight")
|
|
55
|
-
size = get_transform_size(module, args.location, self.scheme.
|
|
55
|
+
size = get_transform_size(module, args.location, self.scheme.head_dim)
|
|
56
56
|
exec_device = get_execution_device(module)
|
|
57
57
|
device = get_offloaded_device(module)
|
|
58
58
|
precision = self.scheme.precision if args.is_online() else torch.float64
|
|
@@ -51,7 +51,7 @@ class RandomMatrixFactory(TransformFactory):
|
|
|
51
51
|
:param args: defines how the transform will be applied to the module
|
|
52
52
|
"""
|
|
53
53
|
assert hasattr(module, "weight")
|
|
54
|
-
size = get_transform_size(module, args.location, self.scheme.
|
|
54
|
+
size = get_transform_size(module, args.location, self.scheme.head_dim)
|
|
55
55
|
device = get_offloaded_device(module)
|
|
56
56
|
precision = self.scheme.precision if args.is_online() else torch.float64
|
|
57
57
|
|
|
@@ -17,7 +17,7 @@ from typing import List, Optional
|
|
|
17
17
|
import torch
|
|
18
18
|
from compressed_tensors.transform import TransformArgs
|
|
19
19
|
from compressed_tensors.utils import TorchDtype
|
|
20
|
-
from pydantic import BaseModel, ConfigDict, Field
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
__all__ = ["TransformScheme"]
|
|
@@ -36,8 +36,11 @@ class TransformScheme(BaseModel):
|
|
|
36
36
|
:param randomize: True if uniquely randomized transform weights should be used,
|
|
37
37
|
otherwise use identical transform weights where applicable
|
|
38
38
|
:param requires_grad: True if weights include gradients for training
|
|
39
|
-
:param
|
|
40
|
-
block being a square matrix of this size.
|
|
39
|
+
:param head_dim: If set, the transform matrix will be block diagonal with each
|
|
40
|
+
block being a square matrix of this size. The name head_dim was chosen because
|
|
41
|
+
some rotations need to be block-diagonal with block size equal to the head_dim,
|
|
42
|
+
but research has shown value in applying some rotations with smaller block size,
|
|
43
|
+
irrespective of head_dim.
|
|
41
44
|
:param precision: Precision at which this transform should be applied during online
|
|
42
45
|
rotations. Fused (offline) rotations are always performed in float64
|
|
43
46
|
"""
|
|
@@ -46,21 +49,7 @@ class TransformScheme(BaseModel):
|
|
|
46
49
|
apply: List[TransformArgs] = Field(default_factory=list)
|
|
47
50
|
randomize: bool = Field(default=False)
|
|
48
51
|
requires_grad: bool = Field(default=False)
|
|
49
|
-
|
|
50
|
-
head_dim: Optional[int] = Field(
|
|
51
|
-
default=None, deprecated="head_dim is deprecated, use block_size instead"
|
|
52
|
-
)
|
|
52
|
+
head_dim: Optional[int] = Field(default=None)
|
|
53
53
|
precision: TorchDtype = Field(default=torch.float32)
|
|
54
54
|
|
|
55
|
-
@model_validator(mode="after")
|
|
56
|
-
def validate_model_after(model: "TransformScheme") -> "TransformScheme":
|
|
57
|
-
"""
|
|
58
|
-
If head_dim is used instead of block_size, set block_size to head_dim
|
|
59
|
-
and remove head_dim
|
|
60
|
-
"""
|
|
61
|
-
if model.block_size is None and model.head_dim is not None:
|
|
62
|
-
model.block_size = model.head_dim
|
|
63
|
-
model.head_dim = None
|
|
64
|
-
return model
|
|
65
|
-
|
|
66
55
|
model_config = ConfigDict(extra="forbid")
|
compressed_tensors/version.py
CHANGED
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '0.
|
|
21
|
-
__version_tuple__ = version_tuple = (0,
|
|
20
|
+
__version__ = version = '0.12.0'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 12, 0)
|
{compressed_tensors-0.11.1a20250923.dist-info → compressed_tensors-0.12.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: compressed-tensors
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.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.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
compressed_tensors/__init__.py,sha256=SRqNYFVvxAaLa4SImhoiIBKfoOSj7EUdx0CxXjGC2PA,884
|
|
2
2
|
compressed_tensors/base.py,sha256=-gxWvDF4LCkyeDP8YlGzvBBKxo4Dk9h4NINPD61drFU,921
|
|
3
3
|
compressed_tensors/logger.py,sha256=sTm1Od1cV0aDxBm3YN-PPvsOATxY_2tBV62TQE4HiPw,4032
|
|
4
|
-
compressed_tensors/version.py,sha256
|
|
4
|
+
compressed_tensors/version.py,sha256=MzIo18wy7DMt4bO6hDNzASQ2GwerF91Xd0bFMTS3VKA,513
|
|
5
5
|
compressed_tensors/compressors/__init__.py,sha256=smSygTSfcfuujRrAXDc6uZm4L_ccV1tWZewqVnOb4lM,825
|
|
6
6
|
compressed_tensors/compressors/base.py,sha256=nvWsv4xEw1Tkxkxth6TmHplDYXfBeP22xWxOsZERyDY,7204
|
|
7
7
|
compressed_tensors/compressors/helpers.py,sha256=OK6qxX9j3bHwF9JfIYSGMgBJe2PWjlTA3byXKCJaTIQ,5431
|
|
8
8
|
compressed_tensors/compressors/model_compressors/__init__.py,sha256=5RGGPFu4YqEt_aOdFSQYFYFDjcZFJN0CsMqRtDZz3Js,666
|
|
9
|
-
compressed_tensors/compressors/model_compressors/model_compressor.py,sha256=
|
|
9
|
+
compressed_tensors/compressors/model_compressors/model_compressor.py,sha256=xoQzV660vjjqwo_kek_xHJYIeqtt2hsD-QNAlqLHDvo,36144
|
|
10
10
|
compressed_tensors/compressors/quantized_compressors/__init__.py,sha256=KvaFBL_Q84LxRGJOV035M8OBoCkAx8kOkfphswgkKWk,745
|
|
11
11
|
compressed_tensors/compressors/quantized_compressors/base.py,sha256=6GXhc2E5qFHnkcE3H2mx5CD2YtwfPXKUsvmsakzkkfA,10088
|
|
12
12
|
compressed_tensors/compressors/quantized_compressors/naive_quantized.py,sha256=0ANDcuD8aXPqTYNPY6GnX9iS6eXJw6P0TzNV_rYS2l8,5369
|
|
@@ -46,11 +46,11 @@ compressed_tensors/transform/__init__.py,sha256=v2wfl4CMfA6KbD7Hxx_MbRev63y_6QLD
|
|
|
46
46
|
compressed_tensors/transform/apply.py,sha256=YldYh3DGY09wJEKlFRSbg7-kRdCv7uFEuGkr5ZWCEXs,2984
|
|
47
47
|
compressed_tensors/transform/transform_args.py,sha256=rVgReFp7wMXcYugkfd325e2tTFh8pGV3FnYTGCEv5jY,3429
|
|
48
48
|
compressed_tensors/transform/transform_config.py,sha256=3YdtGcau3qkcapX9GMUiLuhQHFQZKFYT3eLgJGj1L6s,1204
|
|
49
|
-
compressed_tensors/transform/transform_scheme.py,sha256=
|
|
49
|
+
compressed_tensors/transform/transform_scheme.py,sha256=YR7Ri5hXWYQ8MSgMcpYg_BMyZtvXVPShz6iUf4giI8g,2475
|
|
50
50
|
compressed_tensors/transform/factory/__init__.py,sha256=fH6rjBYAxuwrTzBTlTjTgCYNyh6TCvCqajCz4Im4YrA,617
|
|
51
51
|
compressed_tensors/transform/factory/base.py,sha256=Menoz_nU64wLEPPP_FdGg_2HhdkN8mKpOCGGOkgoQIY,6532
|
|
52
|
-
compressed_tensors/transform/factory/hadamard.py,sha256=
|
|
53
|
-
compressed_tensors/transform/factory/matrix_multiply.py,sha256=
|
|
52
|
+
compressed_tensors/transform/factory/hadamard.py,sha256=uLemSQC7xuDb4k0D5INoPi-uZtRNxtN0Dj-i8ladHfE,4620
|
|
53
|
+
compressed_tensors/transform/factory/matrix_multiply.py,sha256=u-7V04EvEe9G3VEF--YwoVV-h5kmh6hXq8stY_EWmLY,4456
|
|
54
54
|
compressed_tensors/transform/factory/random_hadamard.py,sha256=ck-LF7sl7i9NW4fxLypgHgkw91lc_TpwHO8bXX-0fPU,1577
|
|
55
55
|
compressed_tensors/transform/utils/__init__.py,sha256=fH6rjBYAxuwrTzBTlTjTgCYNyh6TCvCqajCz4Im4YrA,617
|
|
56
56
|
compressed_tensors/transform/utils/hadamard.py,sha256=9JMJPtlYI2HwJ2Y2I6uyVCBhKju8yXuQ9DhK4ZpEpvY,5753
|
|
@@ -66,8 +66,8 @@ compressed_tensors/utils/permute.py,sha256=wB8LCvQxmI7xnm67S8pbHzM5CDFgG8t4D8ema
|
|
|
66
66
|
compressed_tensors/utils/safetensors_load.py,sha256=Vql34aCTDHwmTZXJHzCyBISJo7iA7EQ78LdTlMjdpZo,12023
|
|
67
67
|
compressed_tensors/utils/semi_structured_conversions.py,sha256=XKNffPum54kPASgqKzgKvyeqWPAkair2XEQXjkp7ho8,13489
|
|
68
68
|
compressed_tensors/utils/type.py,sha256=bNwoo_FWlvLuDpYAGGzZJITRg0JA_Ngk9LGPo-kvjeU,2554
|
|
69
|
-
compressed_tensors-0.
|
|
70
|
-
compressed_tensors-0.
|
|
71
|
-
compressed_tensors-0.
|
|
72
|
-
compressed_tensors-0.
|
|
73
|
-
compressed_tensors-0.
|
|
69
|
+
compressed_tensors-0.12.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
70
|
+
compressed_tensors-0.12.0.dist-info/METADATA,sha256=xkQNnAskcLKSmMJFK2xOqazsnAu1_P0pagW-p00L7Wo,7018
|
|
71
|
+
compressed_tensors-0.12.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
72
|
+
compressed_tensors-0.12.0.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
|
|
73
|
+
compressed_tensors-0.12.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{compressed_tensors-0.11.1a20250923.dist-info → compressed_tensors-0.12.0.dist-info}/top_level.txt
RENAMED
|
File without changes
|