Skip to content

Commit

Permalink
Fix errors introduced by GPTQ UX (#2299)
Browse files Browse the repository at this point in the history
* Update GHA file to install compressed-tensors from source

* Missed commit (#2300)

* Remove src from import

* Style

* Update tests; diff updated on compressed tensors side

* De-indent recipe

* Style

* Update order of sparsification/quantization in recipe
  • Loading branch information
rahul-tuli authored May 24, 2024
1 parent c24e97f commit c672b9a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 39 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ jobs:
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
- name: "Clean sparsezoo directory"
run: rm -r sparsezoo/
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: "neuralmagic/compressed-tensors"
path: "compressed-tensors"
ref: ${{needs.test-setup.outputs.branch}}
- name: "⚙️ Install compressed-tensors dependencies"
run: pip3 install -U pip && pip3 install setuptools compressed-tensors/
- name: "Clean compressed-tensors directory"
run: rm -r compressed-tensors/
- name: "⚙️ Install dependencies"
run: pip3 install .[dev,torchvision,onnxruntime,transformers]
- name: "🔬 Running pytorch tests"
Expand Down Expand Up @@ -193,6 +203,16 @@ jobs:
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
- name: "Clean sparsezoo directory"
run: rm -r sparsezoo/
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: "neuralmagic/compressed-tensors"
path: "compressed-tensors"
ref: ${{needs.test-setup.outputs.branch}}
- name: "⚙️ Install compressed-tensors dependencies"
run: pip3 install -U pip && pip3 install setuptools compressed-tensors/
- name: "Clean compressed-tensors directory"
run: rm -r compressed-tensors/
- name: "⚙️ Install dependencies"
run: pip3 install .[dev,torchvision,onnxruntime,transformers]
- name: "🔬 Running pytorch tests"
Expand Down
10 changes: 2 additions & 8 deletions src/sparseml/modifiers/quantization/gptq/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from sparseml.core.model import ModifiableModel
from sparseml.core.state import State
from sparseml.modifiers.quantization.gptq.base import GPTQModifier
from sparseml.modifiers.quantization.gptq.utils.gptq_wrapper import GPTQWrapper
from sparseml.modifiers.utils.layer_compressor import LayerCompressor
from sparseml.modifiers.utils.pytorch_helpers import run_calibration_forward
from src.sparseml.modifiers.quantization.gptq.utils.gptq_wrapper import GPTQWrapper


__all__ = ["GPTQModifierPyTorch"]
Expand Down Expand Up @@ -117,13 +117,7 @@ def initialize_compression(

for idx, (name, layer) in enumerate(self.compressible_layers_.items()):
_LOGGER.info(f"Preparing {name} for compression")
if isinstance(self.sparsity, Dict):
layer_sparsity = self.sparsity[name]
elif isinstance(self.sparsity, List):
layer_sparsity = self.sparsity[idx]
else: # float
layer_sparsity = self.sparsity
args = self._pruning_arguments(layer_sparsity)
args = self._pruning_arguments()
comp_cls = self._compression_class()
compressor = LayerCompressor(comp_cls, self.model, layer, idx, name, args)
if not self.sequential_update:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def test_create_default_quant_modifier(self):
default_config_group_name
]
self.assertEqual(should_be_default_quant_scheme.input_activations.num_bits, 8)
assert not should_be_default_quant_scheme.input_activations.symmetric
# input activations are symmetric by default in vLLMQuantizationModifier
assert should_be_default_quant_scheme.input_activations.symmetric

self.assertEqual(should_be_default_quant_scheme.weights.num_bits, 8)
assert should_be_default_quant_scheme.weights.symmetric

Expand Down
18 changes: 2 additions & 16 deletions tests/sparseml/transformers/obcq/recipes/quant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,15 @@ test_stage:
weights:
num_bits: 8
symmetric: False
SparseGPTModifier:
sparsity: 0.0
GPTQModifier:
block_size: 128
sequential_update: False
percdamp: 0.01
mask_structure: "0:0"
targets: [
"model.layers.0",
"model.layers.1",
"model.layers.2",
"model.layers.3",
"model.layers.4",
"model.layers.5"
]
GPTQModifier:
block_size: 128
sequential_update: False
percdamp: 0.01
targets: [
"model.layers.0",
"model.layers.1",
"model.layers.2",
"model.layers.3",
"model.layers.4",
"model.layers.5"
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ test_stage:
weights:
num_bits: 8
symmetric: False
SparseGPTModifier:
sparsity: 0.5
GPTQModifier:
block_size: 128
sequential_update: False
percdamp: 0.01
mask_structure: "0:0"
targets: [
"model.layers.0",
"model.layers.1",
Expand All @@ -38,10 +36,12 @@ test_stage:
"model.layers.4",
"model.layers.5"
]
GPTQModifier:
SparseGPTModifier:
sparsity: 0.5
block_size: 128
sequential_update: False
percdamp: 0.01
mask_structure: "0:0"
targets: [
"model.layers.0",
"model.layers.1",
Expand Down
11 changes: 1 addition & 10 deletions tests/sparseml/transformers/obcq/test_sgpt_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@pytest.mark.integration
@requires_torch
class TestSGPTDefualts(unittest.TestCase):
class TestSGPTDefaults(unittest.TestCase):
def test_sgpt_defaults(self):
from sparseml.core.framework import Framework
from sparseml.core.state import State
Expand All @@ -31,18 +31,9 @@ def test_sgpt_defaults(self):
sparsegpt_modifier_only_sparsity = SparseGPTModifier(
framework=Framework.pytorch, **kwargs
)
assert not sparsegpt_modifier_only_sparsity.quantize
self.assertEqual(sparsegpt_modifier_only_sparsity.block_size, 128)
self.assertEqual(sparsegpt_modifier_only_sparsity.sparsity, 0.5)

kwargs = {"quantize": True}
sparsegpt_modifier_only_quant = SparseGPTModifier(
framework=Framework.pytorch, **kwargs
)
assert sparsegpt_modifier_only_quant.quantize
self.assertEqual(sparsegpt_modifier_only_quant.block_size, 128)
self.assertEqual(sparsegpt_modifier_only_quant.sparsity, 0.0)

# fail if we don't pass a sparsity or enable quantization
kwargs = {}
sparsegpt_invalid = SparseGPTModifier(framework=Framework.pytorch, **kwargs)
Expand Down

0 comments on commit c672b9a

Please sign in to comment.