Skip to content

Add layerwise decompression and compression to sequential pipeline - #2995

Open
kylesayrs wants to merge 2 commits into
mainfrom
layerwise-decompression-compression
Open

Add layerwise decompression and compression to sequential pipeline#2995
kylesayrs wants to merge 2 commits into
mainfrom
layerwise-decompression-compression

Conversation

@kylesayrs

Copy link
Copy Markdown
Collaborator

Summary

  • Add layerwise_decompression and layerwise_compression flags to DatasetArguments for the sequential pipeline
  • When layerwise_decompression=True, each subgraph's compressed modules are decompressed (stripping all quantization metadata), then quantization config, observers, and hooks are re-applied per-layer before calibration
  • When layerwise_compression=True, quantized modules are compressed back after calibration and error propagation to reduce peak memory
  • QuantizationModifier conditionally skips global setup (on_initialize, on_calibration_start, on_calibration_end) when layerwise mode is active, deferring to per-layer setup via start_layerwise_calibration
  • Fix freeze_module_quantization to preserve COMPRESSED status (not overwrite with FROZEN)

Companion PR

Test plan

  • Verify standard (non-layerwise) sequential pipeline is unaffected
  • Test layerwise decompression with a pre-compressed FP8 model
  • Test layerwise compression reduces peak memory vs without
  • Verify distributed (DDP) path works with layerwise flags
  • Verify freeze_module_quantization preserves COMPRESSED status

🤖 Generated with Claude Code

Enable per-layer decompress→calibrate→compress cycles in the sequential
pipeline, controlled by `layerwise_decompression` and `layerwise_compression`
DatasetArguments. This allows recalibrating pre-compressed models without
fully decompressing the entire model at once.

When layerwise_decompression is enabled, each subgraph's compressed modules
are decompressed with leave_decompressed=False (stripping all quantization
metadata), then quantization config, observers, and hooks are re-applied
scoped to just those modules before the calibration batch loop runs.

When layerwise_compression is enabled, quantized modules are compressed
back after calibration and error propagation, keeping peak memory low.

Companion PR: vllm-project/compressed-tensors#811

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e8b3d107-7c9c-48e1-b11d-dd17d3ecca6c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify

mergify Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces layerwise decompression and compression options to the sequential calibration pipeline, allowing pre-compressed models to be decompressed layer-by-layer for recalibration and compressed back afterward to reduce peak memory usage. The changes span dataset arguments, the oneshot entrypoint, quantization modifiers, and the sequential pipeline itself. The review feedback highlights two important improvements: first, adding a validation check to ensure these layerwise options are only used with the 'sequential' pipeline to prevent silent failures; second, clearing the _calibration_hooks set after removing hooks during sequential epoch ends to avoid O(N^2) accumulation of hook handles and potential memory leaks.

Comment on lines +247 to +252
session.state.layerwise_decompression = (
self.dataset_args.layerwise_decompression
)
session.state.layerwise_compression = (
self.dataset_args.layerwise_compression
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When layerwise_decompression or layerwise_compression is enabled, the sequential pipeline is strictly required. If another pipeline (such as basic or independent) is used, the global initialization and calibration steps in QuantizationModifier will be silently skipped, resulting in a model that is never actually quantized or calibrated. Adding a validation check here prevents this silent failure.

            if (
                self.dataset_args.layerwise_decompression
                or self.dataset_args.layerwise_compression
            ) and self.dataset_args.pipeline != "sequential":
                raise ValueError(
                    "Layerwise decompression and compression are only supported "
                    "with the 'sequential' pipeline."
                )

            session.state.layerwise_decompression = (
                self.dataset_args.layerwise_decompression
            )
            session.state.layerwise_compression = (
                self.dataset_args.layerwise_compression
            )

Comment on lines +121 to +125
if getattr(state, "layerwise_decompression", False):
self.remove_hooks(self._calibration_hooks)
for module in modules:
freeze_module_quantization(module)
enable_quantization(module)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The self._calibration_hooks set is not cleared after removing the hooks. Since on_sequential_epoch_end is called per-layer in the sequential pipeline, this leads to an $O(N^2)$ accumulation of hook handles across layers. Each subsequent layer will attempt to remove already-removed hooks, which is inefficient and can cause memory/reference leaks. Clearing the set after removal resolves this issue.

Suggested change
if getattr(state, "layerwise_decompression", False):
self.remove_hooks(self._calibration_hooks)
for module in modules:
freeze_module_quantization(module)
enable_quantization(module)
if getattr(state, "layerwise_decompression", False):
self.remove_hooks(self._calibration_hooks)
self._calibration_hooks.clear()
for module in modules:
freeze_module_quantization(module)
enable_quantization(module)

@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 1 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require one maintainer review 👀 reviews

🔴 Require one maintainer review

Waiting for any of

  • approved-reviews-by=HDCharles
  • approved-reviews-by=brian-dellabetta
  • approved-reviews-by=dsikka
  • approved-reviews-by=kylesayrs
  • approved-reviews-by=yiliu30
This rule is failing.

All PRs must have at least one approving review from a maintainer before merging.

  • any of:
    • approved-reviews-by=HDCharles
    • approved-reviews-by=brian-dellabetta
    • approved-reviews-by=dsikka
    • approved-reviews-by=kylesayrs
    • approved-reviews-by=yiliu30
  • #changes-requested-reviews-by = 0

Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
@mergify mergify Bot removed the quality-failed label Aug 12, 2026
@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant