compressed-tensors 0.11.1a20250929__py3-none-any.whl → 0.12.1__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 +49 -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.1a20250929.dist-info → compressed_tensors-0.12.1.dist-info}/METADATA +1 -1
- {compressed_tensors-0.11.1a20250929.dist-info → compressed_tensors-0.12.1.dist-info}/RECORD +10 -10
- {compressed_tensors-0.11.1a20250929.dist-info → compressed_tensors-0.12.1.dist-info}/WHEEL +0 -0
- {compressed_tensors-0.11.1a20250929.dist-info → compressed_tensors-0.12.1.dist-info}/licenses/LICENSE +0 -0
- {compressed_tensors-0.11.1a20250929.dist-info → compressed_tensors-0.12.1.dist-info}/top_level.txt +0 -0
|
@@ -344,6 +344,55 @@ class ModelCompressor:
|
|
|
344
344
|
format, config=quantization_config
|
|
345
345
|
)
|
|
346
346
|
|
|
347
|
+
def get_missing_module_keys(self, model: Module) -> List[str]:
|
|
348
|
+
"""
|
|
349
|
+
Identifies the expected missing weight keys in the compressed state_dict.
|
|
350
|
+
|
|
351
|
+
When a model undergoes sparsity or quantization compression, certain
|
|
352
|
+
weight tensors may be absent from the checkpoint by virtue of compression.
|
|
353
|
+
This function determines which weight keys are missing based on the
|
|
354
|
+
applied compression techniques.
|
|
355
|
+
|
|
356
|
+
:param model: The PyTorch model to check for missing keys.
|
|
357
|
+
:return: A list of missing keys expected in the compressed state_dict.
|
|
358
|
+
"""
|
|
359
|
+
missing_keys = set()
|
|
360
|
+
|
|
361
|
+
# Determine missing keys due to sparsity compression
|
|
362
|
+
if (
|
|
363
|
+
self.sparsity_compressor
|
|
364
|
+
and self.sparsity_config.format != CompressionFormat.dense.value
|
|
365
|
+
):
|
|
366
|
+
sparse_targets = match_named_modules(
|
|
367
|
+
model=model,
|
|
368
|
+
targets=self.sparsity_config.targets,
|
|
369
|
+
ignore=self.sparsity_config.ignore,
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
missing_keys.update(
|
|
373
|
+
merge_names(target_name, "weight")
|
|
374
|
+
for target_name, _module in sparse_targets
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
# Determine missing keys due to pack quantization
|
|
378
|
+
if (
|
|
379
|
+
self.quantization_compressor
|
|
380
|
+
and self.quantization_config.format
|
|
381
|
+
== CompressionFormat.pack_quantized.value
|
|
382
|
+
):
|
|
383
|
+
for scheme in self.quantization_config.config_groups.values():
|
|
384
|
+
quant_targets = match_named_modules(
|
|
385
|
+
model=model,
|
|
386
|
+
targets=scheme.targets,
|
|
387
|
+
ignore=self.quantization_config.ignore,
|
|
388
|
+
)
|
|
389
|
+
missing_keys.update(
|
|
390
|
+
merge_names(target_name, "weight")
|
|
391
|
+
for target_name, _module in quant_targets
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
return list(missing_keys)
|
|
395
|
+
|
|
347
396
|
def get_unexpected_file_keys(self, model: Module) -> List[str]:
|
|
348
397
|
"""
|
|
349
398
|
Identifies extra keys introduced by the compression process in the
|
|
@@ -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.1'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 12, 1)
|
{compressed_tensors-0.11.1a20250929.dist-info → compressed_tensors-0.12.1.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.1
|
|
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=DzB47l1iPNTY8yuA60VuZvneNqNdRBd1svEjKxC37o4,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=zPe3T0hyHuvIzSXHBWHPiqJ3sQcdVY3tgwF1aBeG7oo,38044
|
|
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.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
70
|
+
compressed_tensors-0.12.1.dist-info/METADATA,sha256=rGHOzy2FZFRUNCuiBKb99tnWtlks5mAIBrR76QltFkM,7018
|
|
71
|
+
compressed_tensors-0.12.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
72
|
+
compressed_tensors-0.12.1.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
|
|
73
|
+
compressed_tensors-0.12.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{compressed_tensors-0.11.1a20250929.dist-info → compressed_tensors-0.12.1.dist-info}/top_level.txt
RENAMED
|
File without changes
|