Skip to content

[Online quantization] Add targeted online quantization configuration based on user patterns - #51285

Merged
mgoin merged 17 commits into
vllm-project:mainfrom
fxmarty-amd:per-layer-online-quantization
Sep 2, 2026
Merged

mgoin merged 17 commits into
vllm-project:mainfrom
fxmarty-amd:per-layer-online-quantization

Conversation

@fxmarty-amd

@fxmarty-amd fxmarty-amd commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Enable targeted online quantization on specific layers. This includes:

Purpose

Implements per-layer online quantization through quantization_config.targets, which follows the same spec as existing quantization_config.ignore.

This addresses the per-layer online quantization RFC.

Exact layer names, re: regex or fnmatch-style patterns allow to select different online shorthands per linear or MoE layer names patterns.

Implementation details:

  • unmatched layers remain unquantized,
  • conflicting matches with ignore raise errors,
  • fused-layer matching is shared by ignore and targets.

Additionally, an info log is added so that users are aware of what online quantization actually does, as:

INFO 08-06 16:35:33 [base_loader.py:106] Quantized 48 layers of types: block_sparse_moe.experts: 24 (from targets: re:.*block_sparse_moe\.experts, fp8_per_tensor); self_attn.o_proj: 24 (from targets: re:.*self_attn\.o_proj, fp8_per_block)

Additionally, Fused projections can now be targeted either by their fused module name (for example, re:.*self_attn\.qkv_proj) or by patterns that match every original shard (for example, re:.*self_attn\.[qkv]_proj). This was a TODO:

# TODO(future PR): also make 're:.*qkv_proj.*' work
{"ignore": ["model.layers.1.self_attn.o_proj", "re:.*[qkv]_proj"]},

Note: this behavior is now aligned for quark/compressed-tensors/online.

Note: previous ambiguous ignore regex as re:.*v_proj that did NOT resolve to qkv_proj now do. This is a "breaking" change. These kind of ambiguous patterns should probably not be used.

Left to do:

Test Plan

  • pytest tests/quantization/test_online.py -s -vvvvv (includes new tests)
  • pytest tests/quantization/test_config_utils.py -s -vvvvv (includes new tests for targets case)
  • pytest tests/quantization/test_config_utils.py -s -vvvvv (includes tests for ignore/targets parity and should_ignore_layer refactor correctness)

Test Result

Tests pass.

Disclosure

AI assistance was used to develop this PR.

Co-authored-by: Codex
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
@mergify

mergify Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Documentation preview: https://vllm--51285.org.readthedocs.build/en/51285/

@mergify mergify Bot added documentation Improvements or additions to documentation quantization labels Aug 6, 2026
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
Co-authored-by: Codex
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
Co-authored-by: Codex
Signed-off-by: Felix Marty <Felix.Marty@amd.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

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

overall looks good, haven't finished reviewing all the files

Comment thread docs/features/quantization/online.md Outdated
!!! info

- `targets` is mutually exclusive with online `linear` and `moe`: set one or the other, not both.
- A layer that matches no `targets` pattern is left unquantized.

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.

Suggested change
- A layer that matches no `targets` pattern is left unquantized.
- A layer that matches no `targets` pattern is left unchanged from its checkpoint state.

suggestion since it may be pre-quantized?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, updating, although the compatibility of this PR with pre-quantized checkpoints is not tested.

I suggest to leave online + pre-quantized checkpoint compatibility to an other PR.

Comment thread docs/features/quantization/online.md Outdated
Comment on lines +175 to +176
- A layer name may not match both `targets` and `ignore`.
- A layer may not match more than one `targets` pattern.

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.

what's the behavior when these happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

error is raised in both cases, see vllm/model_executor/layers/quantization/online/base.py -> _dispatch_target

str(quant_key),
)

return quant_key_str(self.weight)

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.

not including activation?

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.

@mgoin changes here look reasonable but would love to have another look from your team.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For context, this is to avoid duplicate strictly identical regex / ignore processing between quark/compressed-tensors/online.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please refer to the comment in the thread below #51285 (comment)

import regex as re


def check_equal_or_regex_match(layer_name: str, targets: Iterable[str]) -> bool:

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.

seems not needed anymore?

@fxmarty-amd fxmarty-amd Aug 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was still used in quark/utils.py. Removed it there as well in favor of find_matching_patterns there.

Please note the following changes:

On main:

Ignore pattern Quark should_ignore_layer behavior Compressed-tensors should_ignore_layer behavior Online should_ignore_layer behavior
"model.layers.0.self_attn.qkv_proj" Does NOT ignore Ignores Ignores
"re:.*qkv_proj.*" Does NOT ignore Does NOT ignore Does NOT ignore

On this PR:

Ignore pattern Quark should_ignore_layer behavior Compressed-tensors should_ignore_layer behavior Online should_ignore_layer behavior
"model.layers.0.self_attn.qkv_proj" Ignores Ignores Ignores
"re:.*qkv_proj.*" Ignores Ignores Ignores

This fixes a mismatching behavior in compressed-tensors, aligns the three, and simplifies the duplicate in the codebase. The layer_name not in ignore in

if proj_name in fused_mapping and layer_name not in ignore:
used to accept model.layers.0.self_attn.qkv_proj ignore pattern, but NOT "re:.*qkv_proj.*" on compressed-tensors/online side.

On Quark side on main, should_ignore_layer does NOT have this layer_name not in ignore check:

if proj_name in fused_mapping:

I believe this alignment is safe on Quark, cc @mgoin @kylesayrs please confirm on compressed-tensors side

@mergify

mergify Bot commented Aug 7, 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, @fxmarty-amd.

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 Aug 7, 2026
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
@mergify mergify Bot removed the needs-rebase label Aug 7, 2026
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
@fxmarty-amd

fxmarty-amd commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@mgoin as discussed, 2d99778 adds support for e.g. fnmatch-style ignore/target detection in online quantization only:

  • --quantization-config '{"ignore":"*mlp.experts*"}'
  • --quantization-config '{"targets":"*mlp.experts*":"mxfp4"}'

doc is updated in this regard. This does not impact Quark/compressed-tensors.

@mergify

mergify Bot commented Aug 18, 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, @fxmarty-amd.

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 Aug 18, 2026
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
@mergify mergify Bot removed the needs-rebase label Aug 19, 2026
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
@mergify

mergify Bot commented Sep 1, 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, @fxmarty-amd.

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 Sep 1, 2026
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
@mergify mergify Bot removed the needs-rebase label Sep 1, 2026
@mgoin

mgoin commented Sep 1, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #86647 for commit 82f60a7e8e89.

Signed-off-by: mgoin <mgoin64@gmail.com>
@mgoin
mgoin force-pushed the per-layer-online-quantization branch from 0f47edf to 84b57d2 Compare September 1, 2026 18:52
@mgoin

mgoin commented Sep 1, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #86679 for commit 84b57d27bae5.

Signed-off-by: mgoin <mgoin64@gmail.com>
@mgoin

mgoin commented Sep 1, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #86692 for commit de5da770def5.

@mgoin
mgoin merged commit 7894394 into vllm-project:main Sep 2, 2026
131 checks passed
mylibrar pushed a commit to tanyuqian/vllm that referenced this pull request Sep 3, 2026
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants