Skip to content

MSE Observer Enhancement - #2950

Merged
kylesayrs merged 8 commits into
mainfrom
Roderick-Wu/big-grid
Aug 19, 2026
Merged

MSE Observer Enhancement#2950
kylesayrs merged 8 commits into
mainfrom
Roderick-Wu/big-grid

Conversation

@Roderick-Wu

@Roderick-Wu Roderick-Wu commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Improve the use of mse observer for NVFP4.
-- Grid search expansion factor added as observer kwargs -- there are settings that enable a search that is equivalent to a superset of fouroversix. By expanding the grid search range, we cover fouroversix as well as potentially better ranges.
-- Adds new nvfp4 observer with good defaults, which also disables rounding during grid search.

fouroversix (https://arxiv.org/abs/2512.02010) chooses between two quantization ranges: the full absmax or absmax*1.5. The reasoning is that in fp4 the largest values jump from 4 --> 6 which is a significatn gap compared to previous increments. By using absmax*1.5, we are limiting the largest values in a block to be quantized to 4. This uses fewer values and therefore loses granularity but in exchange ensures that rounding error for large values will be smaller. This is better for some blocks.

We can go beyond this and start the grid search at a higher max -- beyond the maximum observed value -- and gradually shrink the scale. This includes searching over the two points used in fouroversix, as well as any scale range between them.

Config Llama-8B Qwen3-8B Qwen3-14B Qwen3-32B Llama-70B MoE-30B Avg Delta
minmax (nvfp4 default) +0.333 +0.284 +0.138 +0.099 +0.201 +0.208 +0.211
fouroversix +0.230 +0.098 +0.128 +0.183 +0.261 +0.300 +0.200
1x + 1.5x, no fp8 rounding +0.223 +0.168 +0.124 +0.159 +0.256 +0.363 +0.216
1x + 1.5x, global-scale prior determined locally (1x) +0.233 +0.255 +0.086 +0.167 +0.353 +0.323 +0.236
default mse observer +0.299 +0.270 +0.137 +0.135 +0.193 +0.250 +0.214
Expanded search with default settings +0.242 +0.028 +0.093 +0.171 +0.149 +0.149 +0.139

We also include this expand kwarg for the imatrix observer. Using the same default mse params, we find that it performs slightly worse but within reasonable error. Tuning imatrix parameters with the expanded search can be done later. Both of them outperform gptq. Both imatrix and gptq use ultrachat dataset.

Config Llama-8B Qwen3-8B Qwen3-14B Qwen3-32B Llama-70B MoE-30B Avg Delta
mse-expanded (same as above) +0.242 +0.028 +0.093 +0.171 +0.149 +0.149 +0.139
imatrix-expanded +0.242 +0.056 +0.138 +0.135 +0.264 +0.120 +0.159
gptq-nvfp4 +0.238 +0.176 +0.158 +0.123 +0.340 +0.096 +0.189

Justification

Starting at very high range and shrinking down, empirically observe all blocks follow this distribution:
image
Register new observer "nvfp4_mse" with defaults

        self.expand = observer_kwargs.get("expand", 1.8)
        self.maxshrink = observer_kwargs.get("maxshrink", 1 - 0.8 / 1.8) # From 1.8x to 0.8x
        self.grid = observer_kwargs.get("grid", 200.0)
        self.patience = observer_kwargs.get("patience", 1000) # Get the whole range

Fouroversix does set the global scale beforehand. The mse observer performs grid search without a global scale. We consider using a global-scale prior guess calculated from observed absmax values. When we include good guesses for the global scale ahead of time we can also improve over fouroversix.

Config Llama-8B Qwen3-8B Qwen3-14B Qwen3-32B Llama-70B MoE-30B Avg Delta
expanded + global-scale determined at start (1.8x) + fused statistics +0.257 +0.017 +0.132 +0.185 +0.139 +0.222 +0.159
expanded (1.5x) + global-scale determined at start (1.5x) + no fusion +0.239 +0.090 +0.165 +0.167 +0.389 +0.194 +0.207
expanded (1.8x) + global-scale prior (1.25x, gs recalculated at end) + no fusion +0.142 +0.302 +0.043 +0.051 +0.186 - +0.145
expanded (1.8x) + global-scale prior (1.75x, gs recalculated at end) + no fusion +0.170 +0.284 +0.123 +0.045 +0.171 - +0.159

These are improvements over fouroversix and existing mse implementation. However, still worse than just dropping global scale from grid search and disabling roudning.

Code for tests + compression and eval scripts:
#3042

@coderabbitai

coderabbitai Bot commented Jul 22, 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: 905e86bd-9c6b-4728-9c99-055474534aa2

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
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: enhancements to the MSE observer for expanded grid search and NVFP4 quantization.
Description check ✅ Passed The description directly explains the expanded MSE grid search, NVFP4 observer behavior, global-scale handling, and evaluation results.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Roderick-Wu/big-grid

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.

@github-actions

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.

@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 a new 'Four Over Six' (4/6) adaptive block scaling observer for NVFP4 quantization, adds a corresponding example script, and updates the MSE quantization search logic to support range expansion and custom global scale maximums. The reviewer feedback identifies several key improvements: ensuring idempotency in the new observer's parameter retrieval via caching, fixing a range-scaling bug when expanding positive minimum values, removing a leftover debugging statement, and caching dynamically created scale data classes to avoid overhead and compilation issues under torch.compile.

Comment thread src/llmcompressor/observers/fouroversix.py Outdated
Comment thread src/llmcompressor/observers/fouroversix.py Outdated
Comment thread src/llmcompressor/observers/mse_quant.py Outdated
Comment thread src/llmcompressor/modifiers/quantization/calibration.py
Comment thread src/llmcompressor/observers/mse_quant.py Outdated
Comment thread src/llmcompressor/observers/base.py Outdated
@coderabbitai coderabbitai Bot added enhancement New feature or request fp8 For any issue / PR related to FP8 support two-reviews When a PR requires two reviews labels Jul 22, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/llmcompressor/modifiers/quantization/calibration.py (1)

147-147: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the commented-out debugger.

#import pdb; pdb.set_trace() is dead debug code in production source and is easy to re-enable accidentally. Remove it before merge.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/llmcompressor/modifiers/quantization/calibration.py` at line 147, Remove
the commented-out debugger line from the calibration module, including the
“import pdb; pdb.set_trace()” statement. Do not replace it with other debugging
code.
src/llmcompressor/observers/mse_quant.py (1)

29-30: 📐 Maintainability & Code Quality | 🔵 Trivial

Document the expand/maxshrink coupling and add a docstring entry for global_scale_max.

With default maxshrink=0.20, grid=100.0, the shrink factor p only sweeps [0.8, 1.0]. If a caller sets expand=2.0 without also increasing maxshrink, the search never gets close to the true observed range (would need p≈0.5). This coupling isn't documented, and global_scale_max (new parameter) has no docstring entry unlike expand.

Also applies to: 50-53

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/llmcompressor/observers/mse_quant.py` around lines 29 - 30, Update the
parameter documentation for expand, maxshrink, and global_scale_max in the
relevant observer API. Document that increasing expand requires a corresponding
increase to maxshrink so the shrink-factor search can reach the observed range
(for example, expand=2.0 needs p near 0.5 rather than the default lower bound of
0.8). Add global_scale_max’s purpose and behavior alongside the existing expand
entry.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/quantization_w4a4_fp4/llama3_fouroversix_example.py`:
- Around line 88-90: Update the quantization configuration around the observer
argument to use an observer name registered by the repository or
compressed_tensors, preserving the MSE scale-selection behavior where supported;
alternatively, add the required registration before this configuration is
constructed.

In `@src/llmcompressor/observers/base.py`:
- Around line 107-114: Update the global-scale setup in the observer method
containing gs_max so gparam_kwargs["scale_data"] uses an _CustomFP8ScaleData
instance initialized with gs_max as the configured maximum and its negation as
the minimum. Preserve the existing conditional behavior when global_scale_max is
absent.
- Around line 30-35: Remove the undefined class-level max and min assignments
from _CustomFP8ScaleData, allowing callers to provide these bounds explicitly
during instantiation as done by mse_quant.py. Keep the remaining FloatArgs
configuration unchanged and ensure importing the module no longer evaluates an
undefined gs_max reference.

---

Nitpick comments:
In `@src/llmcompressor/modifiers/quantization/calibration.py`:
- Line 147: Remove the commented-out debugger line from the calibration module,
including the “import pdb; pdb.set_trace()” statement. Do not replace it with
other debugging code.

In `@src/llmcompressor/observers/mse_quant.py`:
- Around line 29-30: Update the parameter documentation for expand, maxshrink,
and global_scale_max in the relevant observer API. Document that increasing
expand requires a corresponding increase to maxshrink so the shrink-factor
search can reach the observed range (for example, expand=2.0 needs p near 0.5
rather than the default lower bound of 0.8). Add global_scale_max’s purpose and
behavior alongside the existing expand entry.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c3310b93-36f7-4e0f-ba69-26a5558b8e76

📥 Commits

Reviewing files that changed from the base of the PR and between 655b83d and 482210b.

📒 Files selected for processing (13)
  • docs/scripts/zensical_gen_files.py
  • examples/multimodal_vision/gemma4_example.py
  • examples/quantization_w4a4_fp4/llama3_fouroversix_example.py
  • examples/quantization_w8a8_fp8/qwen3_reranker_example.py
  • examples/quantization_w8a8_int8/benchmark_smoothquant_ddp.py
  • src/llmcompressor/modifiers/quantization/calibration.py
  • src/llmcompressor/observers/__init__.py
  • src/llmcompressor/observers/base.py
  • src/llmcompressor/observers/mse.py
  • src/llmcompressor/observers/mse_quant.py
  • tests/llmcompressor/modifiers/autoround/test_base.py
  • tests/llmcompressor/modifiers/quantization/test_sequential_observation.py
  • tests/llmcompressor/transformers/compression/test_compression_ddp.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • vllm-project/compressed-tensors (manual)

Comment thread examples/quantization_w4a4_fp4/llama3_fouroversix_example.py Outdated
Comment thread src/llmcompressor/observers/base.py Outdated
Comment thread src/llmcompressor/observers/base.py Outdated
@coderabbitai coderabbitai Bot removed the two-reviews When a PR requires two reviews label Jul 22, 2026
@mergify

mergify Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @Roderick-Wu.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Jul 22, 2026
@Roderick-Wu
Roderick-Wu force-pushed the Roderick-Wu/big-grid branch from ea69b1d to 7fd9a08 Compare July 23, 2026 15:54
@Roderick-Wu
Roderick-Wu deleted the Roderick-Wu/big-grid branch July 23, 2026 15:59
@Roderick-Wu
Roderick-Wu restored the Roderick-Wu/big-grid branch July 23, 2026 15:59
@Roderick-Wu Roderick-Wu reopened this Jul 23, 2026
@mergify

mergify Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @Roderick-Wu.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify

mergify Bot commented Jul 23, 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

@Roderick-Wu Roderick-Wu changed the title Roderick wu/big grid MSE Observer Enhancement Jul 23, 2026
@Roderick-Wu
Roderick-Wu marked this pull request as ready for review July 24, 2026 13:13
@Roderick-Wu Roderick-Wu added the ready When a PR is ready for full CI testing before merge label Jul 24, 2026
@mergify mergify Bot added the two-reviews When a PR requires two reviews label Jul 24, 2026
@mergify

mergify Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 Require one maintainer review

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

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

🟢 Require two reviews

PRs labelled "two-reviews" must have at least two approving reviews before merging.

  • #approved-reviews-by >= 2
  • #changes-requested-reviews-by = 0

@mergify mergify Bot removed the quality-failed label Jul 24, 2026

@brian-dellabetta brian-dellabetta left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good to me pending @HDCharles 's thoughts, since I know you've been working closely on the 4over6 stuff with him. usage of observer kwargs seems like the right place to plug this in

Comment thread src/llmcompressor/observers/mse_quant.py Outdated
@mergify

mergify Bot commented Jul 24, 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

@mergify

mergify Bot commented Aug 17, 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

- Add `expand` parameter to MSE grid search (default 1.0, no behavior change)
- Add `nvfp4_expanded_mse` observer with tuned defaults for NVFP4 range expansion
- Add `expand` and `nvfp4_expanded_imatrix_mse` observer to imatrix
- Skip scale_dtype rounding during grid search for NVFP4 observers
- Add llama3 NVFP4 expanded MSE example

Signed-off-by: Roderick Wu <roderick@neuralmagic.com>
@Roderick-Wu
Roderick-Wu force-pushed the Roderick-Wu/big-grid branch from a3c3885 to 10a566d Compare August 17, 2026 20:04
@mergify mergify Bot removed the quality-failed label Aug 17, 2026
@mergify

mergify Bot commented Aug 17, 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

Comment thread src/llmcompressor/observers/imatrix.py Outdated
Comment thread src/llmcompressor/observers/mse.py Outdated
Signed-off-by: Roderick-Wu <roderickwu2003@gmail.com>
@mergify mergify Bot removed the quality-failed label Aug 17, 2026
@mergify

mergify Bot commented Aug 17, 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

Signed-off-by: Roderick-Wu <roderickwu2003@gmail.com>
@mergify mergify Bot removed the quality-failed label Aug 18, 2026
Comment thread src/llmcompressor/observers/imatrix.py Outdated

@HDCharles HDCharles left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

good, the imatrix thing is an experiment so we add functionality (expand) but not the UX helper, once that's removed this will be ready to land

Roderick Wu and others added 2 commits August 18, 2026 16:06
Signed-off-by: Roderick Wu <Roderick-Wu@h100-03.nemg-001.lab.rdu2.dc.redhat.com>
…e_example.py

Co-authored-by: Kyle Sayers <kylesayrs@gmail.com>
Signed-off-by: Roderick Wu <roderickwu2003@gmail.com>
@mergify

mergify Bot commented Aug 18, 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

Signed-off-by: Roderick Wu <Roderick-Wu@h100-03.nemg-001.lab.rdu2.dc.redhat.com>
@mergify mergify Bot removed the quality-failed label Aug 18, 2026
@kylesayrs
kylesayrs enabled auto-merge (squash) August 19, 2026 18:50
@kylesayrs
kylesayrs merged commit bef2998 into main Aug 19, 2026
8 checks passed
@kylesayrs
kylesayrs deleted the Roderick-Wu/big-grid branch August 19, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fp8 For any issue / PR related to FP8 support ready When a PR is ready for full CI testing before merge two-reviews When a PR requires two reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants