compressed-tensors 0.10.2a20250611__py3-none-any.whl → 0.10.2a20250612__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/utils/offload.py +49 -48
- compressed_tensors/version.py +1 -1
- {compressed_tensors-0.10.2a20250611.dist-info → compressed_tensors-0.10.2a20250612.dist-info}/METADATA +1 -1
- {compressed_tensors-0.10.2a20250611.dist-info → compressed_tensors-0.10.2a20250612.dist-info}/RECORD +7 -7
- {compressed_tensors-0.10.2a20250611.dist-info → compressed_tensors-0.10.2a20250612.dist-info}/WHEEL +0 -0
- {compressed_tensors-0.10.2a20250611.dist-info → compressed_tensors-0.10.2a20250612.dist-info}/licenses/LICENSE +0 -0
- {compressed_tensors-0.10.2a20250611.dist-info → compressed_tensors-0.10.2a20250612.dist-info}/top_level.txt +0 -0
@@ -14,27 +14,29 @@
|
|
14
14
|
"""
|
15
15
|
Utilities associated with offloading functionality provided by `accelerate`.
|
16
16
|
|
17
|
-
|
|
18
|
-
| Operation
|
19
|
-
|
|
20
|
-
| Add
|
21
|
-
| Check
|
22
|
-
| Onload
|
23
|
-
| Update
|
24
|
-
| Delete
|
25
|
-
|
|
17
|
+
| ------------------------------------------------------------------------------------------------------ | # noqa: E501
|
18
|
+
| Operation | Without offloading support | With offloading support | # noqa: E501
|
19
|
+
| ---------- | -------------------------------------- | ------------------------------------------------ | # noqa: E501
|
20
|
+
| Add | module.register_parameter(name, param) | register_offload_parameter(module, name, param) | # noqa: E501
|
21
|
+
| Check | N/A | has_offloaded_params(module) | # noqa: E501
|
22
|
+
| Onload | N/A | with align_module_device(module) | # noqa: E501
|
23
|
+
| Update | module.name.data.copy_(new_data) | update_offload_parameter(module, name, new_data) | # noqa: E501
|
24
|
+
| Delete | del module.name | delete_offload_parameter(module, name) | # noqa: E501
|
25
|
+
| Add Module | module.register_module(name, child) | register_offload_module(name, child) | # noqa: E501
|
26
|
+
| Del Module | del module.name | delete_offload_module(module, name) | # noqa: E501
|
27
|
+
| ------------------------------------------------------------------------------------------------------ | # noqa: E501
|
26
28
|
"""
|
27
29
|
|
28
30
|
import contextlib
|
29
31
|
import warnings
|
30
32
|
from functools import wraps
|
31
|
-
from
|
33
|
+
from operator import attrgetter
|
34
|
+
from typing import Any, Callable, Dict, Iterable, Literal, Optional, Union
|
32
35
|
|
33
36
|
import torch
|
34
37
|
|
35
38
|
|
36
39
|
try:
|
37
|
-
from accelerate import dispatch_model
|
38
40
|
from accelerate.hooks import (
|
39
41
|
AlignDevicesHook,
|
40
42
|
add_hook_to_module,
|
@@ -45,10 +47,12 @@ try:
|
|
45
47
|
from accelerate.utils import (
|
46
48
|
OffloadedWeightsLoader,
|
47
49
|
PrefixedDataset,
|
50
|
+
find_tied_parameters,
|
48
51
|
set_module_tensor_to_device,
|
49
52
|
)
|
50
53
|
|
51
54
|
_has_accelerate = True
|
55
|
+
|
52
56
|
except ImportError:
|
53
57
|
_has_accelerate = False
|
54
58
|
AlignDevicesHook = None
|
@@ -58,8 +62,8 @@ except ImportError:
|
|
58
62
|
PrefixedDataset = None
|
59
63
|
set_module_tensor_to_device = None
|
60
64
|
named_module_tensors = None
|
61
|
-
dispatch_model = None
|
62
65
|
attach_align_device_hook = None
|
66
|
+
find_tied_parameters = None
|
63
67
|
|
64
68
|
|
65
69
|
__all__ = [
|
@@ -78,14 +82,13 @@ __all__ = [
|
|
78
82
|
"align_module_device",
|
79
83
|
"register_offload_module",
|
80
84
|
"delete_offload_module",
|
81
|
-
"
|
85
|
+
"offloaded_dispatch",
|
82
86
|
]
|
83
87
|
|
84
88
|
|
85
89
|
def check_accelerate(fallback: Any):
|
86
90
|
def decorator(func: Callable[[Any], Any]):
|
87
91
|
if not _has_accelerate:
|
88
|
-
|
89
92
|
if fallback == "error":
|
90
93
|
|
91
94
|
@wraps(func)
|
@@ -479,46 +482,44 @@ def delete_offload_module(base: torch.nn.Module, name: str):
|
|
479
482
|
|
480
483
|
|
481
484
|
@check_accelerate(fallback="error")
|
482
|
-
def
|
483
|
-
module: torch.nn.Module,
|
485
|
+
def offloaded_dispatch(
|
486
|
+
module: torch.nn.Module,
|
487
|
+
execution_device: torch.device,
|
488
|
+
offload_device: Union[torch.device, Literal["disk"]] = torch.device("cpu"),
|
484
489
|
) -> torch.nn.Module:
|
485
490
|
"""
|
486
|
-
|
491
|
+
Unlike `dispatch_model`, this function forces a module (and its submodules) to
|
492
|
+
offload all parameters and replace them with meta tensors, utiliizing the
|
493
|
+
`AlignDevicesHook` to control onloading and offloading.
|
487
494
|
|
488
495
|
:param module: module containing parameters to offload
|
489
|
-
:param execution_device:
|
490
|
-
:
|
496
|
+
:param execution_device: device that modules will onload and execute on
|
497
|
+
:param offload_device: device that module parameters will offload to
|
498
|
+
:return: module with offloading device hooks
|
491
499
|
"""
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
name.append(submodule_name)
|
514
|
-
collect_device_map(name, submodule)
|
515
|
-
name.pop()
|
516
|
-
|
517
|
-
collect_device_map([], module)
|
518
|
-
|
519
|
-
return dispatch_model(
|
520
|
-
module, device_map, main_device=execution_device, force_hooks=True
|
500
|
+
if offload_device == "disk":
|
501
|
+
raise NotImplementedError("Disk offloading is not currently supported")
|
502
|
+
|
503
|
+
# create weights map
|
504
|
+
weights_map = OffloadedWeightsLoader(state_dict=module.state_dict(), device="cpu")
|
505
|
+
|
506
|
+
# create tied params map
|
507
|
+
tied_params = find_tied_parameters(module)
|
508
|
+
tied_params_map = {}
|
509
|
+
for group in tied_params:
|
510
|
+
for param_name in group:
|
511
|
+
data_ptr = attrgetter(param_name)(module).data_ptr()
|
512
|
+
tied_params_map[data_ptr] = {}
|
513
|
+
|
514
|
+
# recursively attaches hooks to all submodules
|
515
|
+
attach_align_device_hook(
|
516
|
+
module,
|
517
|
+
execution_device=execution_device,
|
518
|
+
offload=True,
|
519
|
+
weights_map=weights_map,
|
520
|
+
tied_params_map=tied_params_map,
|
521
521
|
)
|
522
|
+
return module
|
522
523
|
|
523
524
|
|
524
525
|
""" Upstreamed Functions """
|
compressed_tensors/version.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: compressed-tensors
|
3
|
-
Version: 0.10.
|
3
|
+
Version: 0.10.2a20250612
|
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.
|
{compressed_tensors-0.10.2a20250611.dist-info → compressed_tensors-0.10.2a20250612.dist-info}/RECORD
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
compressed_tensors/__init__.py,sha256=UtKmifNeBCSE2TZSAfduVNNzHY-3V7bLjZ7n7RuXLOE,812
|
2
2
|
compressed_tensors/base.py,sha256=73HYH7HY7O2roC89yG_piPFnZwrBfn_i7HmKl90SKc0,875
|
3
|
-
compressed_tensors/version.py,sha256=
|
3
|
+
compressed_tensors/version.py,sha256=F2izwCTRKbiv1mAW6qD3TbJD5cXQrz4zRmew4qZ4Ud0,523
|
4
4
|
compressed_tensors/compressors/__init__.py,sha256=smSygTSfcfuujRrAXDc6uZm4L_ccV1tWZewqVnOb4lM,825
|
5
5
|
compressed_tensors/compressors/base.py,sha256=nvWsv4xEw1Tkxkxth6TmHplDYXfBeP22xWxOsZERyDY,7204
|
6
6
|
compressed_tensors/compressors/helpers.py,sha256=OK6qxX9j3bHwF9JfIYSGMgBJe2PWjlTA3byXKCJaTIQ,5431
|
@@ -53,13 +53,13 @@ compressed_tensors/transform/utils/hadamard.py,sha256=SmPZmnHtc5N36gJA5EbM1T65uf
|
|
53
53
|
compressed_tensors/transform/utils/utils.py,sha256=PRPTYwPs2nnNaQMq2GEbC4QYKHFKlZwaRyPgdDhl66g,2992
|
54
54
|
compressed_tensors/utils/__init__.py,sha256=gS4gSU2pwcAbsKj-6YMaqhm25udFy6ISYaWBf-myRSM,808
|
55
55
|
compressed_tensors/utils/helpers.py,sha256=cPg-ikdeA92aIGwBONg8GmPNvcGlFhozyJVwsRiXBTA,11981
|
56
|
-
compressed_tensors/utils/offload.py,sha256=
|
56
|
+
compressed_tensors/utils/offload.py,sha256=myV7iC75gA8A3BGgwR3uoeaJkIC9oigKp9CcqsHsVJc,20686
|
57
57
|
compressed_tensors/utils/permutations_24.py,sha256=kx6fsfDHebx94zsSzhXGyCyuC9sVyah6BUUir_StT28,2530
|
58
58
|
compressed_tensors/utils/permute.py,sha256=V6tJLKo3Syccj-viv4F7ZKZgJeCB-hl-dK8RKI_kBwI,2355
|
59
59
|
compressed_tensors/utils/safetensors_load.py,sha256=DMfZBuUbA6qp_BG_zIWT3ckiEE33K9ob34s-OgzReO4,12057
|
60
60
|
compressed_tensors/utils/semi_structured_conversions.py,sha256=XKNffPum54kPASgqKzgKvyeqWPAkair2XEQXjkp7ho8,13489
|
61
|
-
compressed_tensors-0.10.
|
62
|
-
compressed_tensors-0.10.
|
63
|
-
compressed_tensors-0.10.
|
64
|
-
compressed_tensors-0.10.
|
65
|
-
compressed_tensors-0.10.
|
61
|
+
compressed_tensors-0.10.2a20250612.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
62
|
+
compressed_tensors-0.10.2a20250612.dist-info/METADATA,sha256=541wdYU5905X69fwti-7pubCIzjsENQnbOxpJt4X2qQ,7005
|
63
|
+
compressed_tensors-0.10.2a20250612.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
64
|
+
compressed_tensors-0.10.2a20250612.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
|
65
|
+
compressed_tensors-0.10.2a20250612.dist-info/RECORD,,
|
{compressed_tensors-0.10.2a20250611.dist-info → compressed_tensors-0.10.2a20250612.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|
File without changes
|