compressed-tensors 0.10.2a20250613__py3-none-any.whl → 0.10.2a20250617__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 +55 -8
- compressed_tensors/version.py +1 -1
- {compressed_tensors-0.10.2a20250613.dist-info → compressed_tensors-0.10.2a20250617.dist-info}/METADATA +1 -1
- {compressed_tensors-0.10.2a20250613.dist-info → compressed_tensors-0.10.2a20250617.dist-info}/RECORD +7 -7
- {compressed_tensors-0.10.2a20250613.dist-info → compressed_tensors-0.10.2a20250617.dist-info}/WHEEL +0 -0
- {compressed_tensors-0.10.2a20250613.dist-info → compressed_tensors-0.10.2a20250617.dist-info}/licenses/LICENSE +0 -0
- {compressed_tensors-0.10.2a20250613.dist-info → compressed_tensors-0.10.2a20250617.dist-info}/top_level.txt +0 -0
@@ -85,6 +85,7 @@ __all__ = [
|
|
85
85
|
"delete_offload_module",
|
86
86
|
"offloaded_dispatch",
|
87
87
|
"disable_offloading",
|
88
|
+
"remove_dispatch",
|
88
89
|
]
|
89
90
|
|
90
91
|
|
@@ -206,9 +207,24 @@ def register_offload_parameter(
|
|
206
207
|
has_onload = any(p.device != torch.device("meta") for p in module.parameters())
|
207
208
|
module.register_parameter(name, parameter)
|
208
209
|
|
210
|
+
# do everything AlignDevicesHook.init_hook does
|
211
|
+
# https://github.com/huggingface/accelerate/blob/main/src/accelerate/hooks.py#L281
|
209
212
|
if has_offloaded_params(module):
|
210
|
-
|
211
|
-
|
213
|
+
hook: AlignDevicesHook = module._hf_hook
|
214
|
+
assert hook.weights_map is not None
|
215
|
+
|
216
|
+
# append to original_devices
|
217
|
+
hook.original_devices[name] = parameter.device
|
218
|
+
|
219
|
+
# append to weights map
|
220
|
+
offload_to_weights_map(hook.weights_map, name, parameter.data, offload_device)
|
221
|
+
|
222
|
+
# append to tied_params_map
|
223
|
+
offloaded = hook.weights_map[name]
|
224
|
+
if hook.tied_params_map is not None:
|
225
|
+
hook.tied_params_map[offloaded.data_ptr()] = {} # (1)
|
226
|
+
|
227
|
+
# perform offloading
|
212
228
|
if not has_onload:
|
213
229
|
set_module_tensor_to_device(module, name, "meta")
|
214
230
|
|
@@ -422,7 +438,6 @@ def register_offload_module(base: torch.nn.Module, name: str, module: torch.nn.M
|
|
422
438
|
hook: AlignDevicesHook = base._hf_hook
|
423
439
|
assert hook.offload
|
424
440
|
assert hook.weights_map is not None
|
425
|
-
assert hook.tied_params_map is not None
|
426
441
|
|
427
442
|
# offloading kwargs for submodule
|
428
443
|
place_submodules = False
|
@@ -437,7 +452,8 @@ def register_offload_module(base: torch.nn.Module, name: str, module: torch.nn.M
|
|
437
452
|
module, include_buffers=offload_buffers, recurse=place_submodules
|
438
453
|
):
|
439
454
|
offloaded = param.to(offload_device)
|
440
|
-
hook.tied_params_map
|
455
|
+
if hook.tied_params_map is not None:
|
456
|
+
hook.tied_params_map[offloaded.data_ptr()] = {} # (1)
|
441
457
|
offload_to_weights_map(hook.weights_map, f"{name}.{param_name}", offloaded)
|
442
458
|
|
443
459
|
# if the parent places submodules, offload here
|
@@ -465,9 +481,6 @@ def register_offload_module(base: torch.nn.Module, name: str, module: torch.nn.M
|
|
465
481
|
|
466
482
|
base.register_module(name, module)
|
467
483
|
|
468
|
-
# (1): Since we cannot know which pointers are shared when we add parameters in an
|
469
|
-
# online way, assume that all pointers are shared. This comes at no runtime cost
|
470
|
-
|
471
484
|
|
472
485
|
def delete_offload_module(base: torch.nn.Module, name: str):
|
473
486
|
"""
|
@@ -502,6 +515,9 @@ def offloaded_dispatch(
|
|
502
515
|
if offload_device == "disk":
|
503
516
|
raise NotImplementedError("Disk offloading is not currently supported")
|
504
517
|
|
518
|
+
# remove any existing hooks
|
519
|
+
remove_dispatch(module)
|
520
|
+
|
505
521
|
# create weights map
|
506
522
|
state_dict = module.state_dict()
|
507
523
|
state_dict = {key: val.to(offload_device) for key, val in state_dict.items()}
|
@@ -523,6 +539,33 @@ def offloaded_dispatch(
|
|
523
539
|
weights_map=weights_map,
|
524
540
|
tied_params_map=tied_params_map,
|
525
541
|
)
|
542
|
+
|
543
|
+
# when saving a model, `PretrainedModel.save_pretrained` will only
|
544
|
+
# onload weights if the following requirements are met
|
545
|
+
# if (
|
546
|
+
# hasattr(self, "hf_device_map")
|
547
|
+
# and len(set(self.hf_device_map.values())) > 1
|
548
|
+
# and ("cpu" in self.hf_device_map.values()
|
549
|
+
# or "disk" in self.hf_device_map.values())
|
550
|
+
# ):
|
551
|
+
# because this function always offloads, disregard actual devices and
|
552
|
+
# always use `cpu` and `cuda:0` to guarantee this condition passes
|
553
|
+
setattr(module, "hf_device_map", {"fake_offload": "cpu", "fake_exec": "cuda:0"})
|
554
|
+
|
555
|
+
return module
|
556
|
+
|
557
|
+
|
558
|
+
def remove_dispatch(module: torch.nn.Module) -> torch.nn.Module:
|
559
|
+
"""
|
560
|
+
Remove any existing dispatches from module
|
561
|
+
|
562
|
+
:param module: module which may be dispatched with hf hooks
|
563
|
+
:return: module without dispatch
|
564
|
+
"""
|
565
|
+
remove_hook_from_module(module, recurse=True)
|
566
|
+
if hasattr(module, "hf_device_map"):
|
567
|
+
delattr(module, "hf_device_map")
|
568
|
+
|
526
569
|
return module
|
527
570
|
|
528
571
|
|
@@ -551,7 +594,7 @@ def disable_offloading():
|
|
551
594
|
# update any parameters which may have changed
|
552
595
|
for module, (hook, offload) in onloaded_modules.items():
|
553
596
|
hook.offload = offload
|
554
|
-
for name, param in module.named_parameters():
|
597
|
+
for name, param in module.named_parameters(recurse=False):
|
555
598
|
update_offload_parameter(module, name, param.data)
|
556
599
|
hook.post_forward(module, None)
|
557
600
|
|
@@ -623,3 +666,7 @@ def align_module_device(
|
|
623
666
|
|
624
667
|
else:
|
625
668
|
yield
|
669
|
+
|
670
|
+
|
671
|
+
# (1): Since we cannot know which pointers are shared when we add parameters in an
|
672
|
+
# online way, assume that all pointers are shared. This has virtually no runtime cost
|
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.2a20250617
|
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.2a20250613.dist-info → compressed_tensors-0.10.2a20250617.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=CJ_FoSTG15I7Ji3rZL8YZsmdYilY4gmfOUB4PXYVYhI,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
|
@@ -54,13 +54,13 @@ compressed_tensors/transform/utils/hadamards.safetensors,sha256=mFd1GzNodGG-ifA1
|
|
54
54
|
compressed_tensors/transform/utils/utils.py,sha256=PRPTYwPs2nnNaQMq2GEbC4QYKHFKlZwaRyPgdDhl66g,2992
|
55
55
|
compressed_tensors/utils/__init__.py,sha256=gS4gSU2pwcAbsKj-6YMaqhm25udFy6ISYaWBf-myRSM,808
|
56
56
|
compressed_tensors/utils/helpers.py,sha256=cPg-ikdeA92aIGwBONg8GmPNvcGlFhozyJVwsRiXBTA,11981
|
57
|
-
compressed_tensors/utils/offload.py,sha256=
|
57
|
+
compressed_tensors/utils/offload.py,sha256=S8dshTSWiF--C83E6mI9FuzlZAyAnD1wDK3FTa21gWE,23778
|
58
58
|
compressed_tensors/utils/permutations_24.py,sha256=kx6fsfDHebx94zsSzhXGyCyuC9sVyah6BUUir_StT28,2530
|
59
59
|
compressed_tensors/utils/permute.py,sha256=V6tJLKo3Syccj-viv4F7ZKZgJeCB-hl-dK8RKI_kBwI,2355
|
60
60
|
compressed_tensors/utils/safetensors_load.py,sha256=DMfZBuUbA6qp_BG_zIWT3ckiEE33K9ob34s-OgzReO4,12057
|
61
61
|
compressed_tensors/utils/semi_structured_conversions.py,sha256=XKNffPum54kPASgqKzgKvyeqWPAkair2XEQXjkp7ho8,13489
|
62
|
-
compressed_tensors-0.10.
|
63
|
-
compressed_tensors-0.10.
|
64
|
-
compressed_tensors-0.10.
|
65
|
-
compressed_tensors-0.10.
|
66
|
-
compressed_tensors-0.10.
|
62
|
+
compressed_tensors-0.10.2a20250617.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
63
|
+
compressed_tensors-0.10.2a20250617.dist-info/METADATA,sha256=1iFsFYyOva-la-6oLa_sP0f0iAOKxazDCnDqTjNamm4,7005
|
64
|
+
compressed_tensors-0.10.2a20250617.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
65
|
+
compressed_tensors-0.10.2a20250617.dist-info/top_level.txt,sha256=w2i-GyPs2s1UwVxvutSvN_lM22SXC2hQFBmoMcPnV7Y,19
|
66
|
+
compressed_tensors-0.10.2a20250617.dist-info/RECORD,,
|
{compressed_tensors-0.10.2a20250613.dist-info → compressed_tensors-0.10.2a20250617.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|
File without changes
|