Skip to content

Roderick wu/tested four over six - #2903

Closed
Roderick-Wu wants to merge 9 commits into
mainfrom
Roderick-Wu/tested-FourOverSix
Closed

Roderick wu/tested four over six#2903
Roderick-Wu wants to merge 9 commits into
mainfrom
Roderick-Wu/tested-FourOverSix

Conversation

@Roderick-Wu

Copy link
Copy Markdown
Collaborator

Krishna Teja Chitty Venkata added 2 commits June 30, 2026 17:29
@coderabbitai

coderabbitai Bot commented Jul 8, 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

Run ID: 1e5b908e-908d-4a1f-91be-3a2fc63a85d0

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Roderick-Wu/tested-FourOverSix

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

github-actions Bot commented Jul 8, 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.

@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 the 'Four Over Six' (4/6) adaptive block scaling observer (FourOverSixObserver) for NVFP4 quantization, along with an example script demonstrating its usage on Llama 3. The feedback focuses on improving the observer's robustness and correctness: specifically, caching the computed optimized scale in get_qparams to ensure idempotency on subsequent calls, clearing this cache and resetting state when new statistics are observed or the observer is reset, and adding explicit type annotations to the _FP8ScaleData256 Pydantic subclass to prevent validation issues.

Comment on lines +78 to +81
def update_statistics_from_observed(self, observed: torch.Tensor) -> None:
self.min_vals = torch.amin(observed, dim=(0, -1))
self.max_vals = torch.amax(observed, dim=(0, -1))
self._observed_blocks = observed.detach().clone()

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 new statistics are observed, any previously cached scale becomes invalid and must be cleared. Additionally, we should implement a reset method to properly clear the cached scale and observed blocks when the observer is reset.

Suggested change
def update_statistics_from_observed(self, observed: torch.Tensor) -> None:
self.min_vals = torch.amin(observed, dim=(0, -1))
self.max_vals = torch.amax(observed, dim=(0, -1))
self._observed_blocks = observed.detach().clone()
def update_statistics_from_observed(self, observed: torch.Tensor) -> None:
self.min_vals = torch.amin(observed, dim=(0, -1))
self.max_vals = torch.amax(observed, dim=(0, -1))
self._observed_blocks = observed.detach().clone()
if hasattr(self, "_cached_scale"):
delattr(self, "_cached_scale")
def reset(self):
super().reset()
self._observed_blocks = None
if hasattr(self, "_cached_scale"):
delattr(self, "_cached_scale")

Comment on lines +118 to +124
if self._observed_blocks is not None:
scale = self._select_block_scales(
self._observed_blocks, scale_6, zero_point, global_scale
)
self._observed_blocks = None
else:
scale = scale_6

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

Currently, self._observed_blocks is set to None after the first call to get_qparams(). If get_qparams() is called again (which can happen during serialization, export, or evaluation), it will fall back to returning scale_6 (the standard NVFP4 scale) instead of the optimized 4/6 adaptive block scales.

To ensure idempotency and correctness, we should cache the computed optimized scale in self._cached_scale and return it on subsequent calls.

Suggested change
if self._observed_blocks is not None:
scale = self._select_block_scales(
self._observed_blocks, scale_6, zero_point, global_scale
)
self._observed_blocks = None
else:
scale = scale_6
if self._observed_blocks is not None:
scale = self._select_block_scales(
self._observed_blocks, scale_6, zero_point, global_scale
)
self._cached_scale = scale
self._observed_blocks = None
elif hasattr(self, "_cached_scale"):
scale = self._cached_scale
else:
scale = scale_6

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@krishnateja95
This looks to me like a real issue? But I'm not too sure about this one. Are there conditions where get_qparams() is called again?

Comment thread src/llmcompressor/observers/fouroversix.py
This reverts commit eb8966a.

put on different branch
@mergify

mergify Bot commented Jul 8, 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 force-pushed the Roderick-Wu/tested-FourOverSix branch from d04e417 to 103013c Compare July 9, 2026 15:12
@mergify mergify Bot removed the quality-failed label Jul 9, 2026
@mergify

mergify Bot commented Jul 9, 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 marked this pull request as ready for review July 9, 2026 17:03
@mergify mergify Bot added two-reviews When a PR requires two reviews and removed quality-failed labels Jul 9, 2026
@mergify

mergify Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 2 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require one maintainer review 👀 reviews
🔴 Require two reviews 👀 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

🔴 Require two reviews

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

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 commented Jul 9, 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 removed the quality-failed label Jul 9, 2026
@mergify

mergify Bot commented Jul 9, 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 removed the quality-failed label Jul 9, 2026
@mergify

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

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

Looks correct to me, @Roderick-Wu please review and ping when ready to merge

Comment thread src/llmcompressor/observers/fouroversix.py
@mergify

mergify Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

⚠️ The sha of the head commit of this PR conflicts with #2882. Mergify cannot evaluate rules on this PR. Once #2882 is merged or closed, Mergify will resume processing this PR. ⚠️

@Roderick-Wu Roderick-Wu added the ready When a PR is ready for full CI testing before merge label Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase 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.

2 participants