Skip to content

Commit 881dd46

Browse files
authored
[Bugfix] Reduce device movement while checking layer divisibility (#2385)
## Purpose ## * Improve runtime and memory usage by checking the shape of the offloaded weight, not the onloaded weight ## Changes ## * Wrap all calls to `_layer_indivisible` with the `disable_onloading` context Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
1 parent 70b610a commit 881dd46

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/llmcompressor/modifiers/quantization/group_size_validation.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
from __future__ import annotations
2626

2727
import torch
28+
from compressed_tensors.offload import disable_onloading
2829
from compressed_tensors.quantization import QuantizationScheme, QuantizationStrategy
2930
from compressed_tensors.utils import match_named_modules
3031

3132
__all__ = [
32-
"_layer_indivisible",
3333
"get_layers_indivisible_by_group_size",
3434
"validate_group_size_divisibility",
3535
]
@@ -77,16 +77,19 @@ def get_layers_indivisible_by_group_size(
7777
:return: List of (fqn, columns, group_size) for each layer that would
7878
fail at save/forward due to indivisibility.
7979
"""
80-
indivisible: list[tuple[str, int, int]] = []
81-
for name, module in match_named_modules(model, resolved_targets, ignore):
82-
scheme: QuantizationScheme | None = getattr(module, "quantization_scheme", None)
83-
if scheme is None or scheme.weights is None:
84-
continue
85-
result = _layer_indivisible(module, scheme.weights)
86-
if result is not None:
87-
columns, group_size = result
88-
indivisible.append((name, columns, group_size))
89-
return indivisible
80+
with disable_onloading():
81+
indivisible: list[tuple[str, int, int]] = []
82+
for name, module in match_named_modules(model, resolved_targets, ignore):
83+
scheme: QuantizationScheme | None = getattr(
84+
module, "quantization_scheme", None
85+
)
86+
if scheme is None or scheme.weights is None:
87+
continue
88+
result = _layer_indivisible(module, scheme.weights)
89+
if result is not None:
90+
columns, group_size = result
91+
indivisible.append((name, columns, group_size))
92+
return indivisible
9093

9194

9295
def validate_group_size_divisibility(

0 commit comments

Comments
 (0)