Repository navigation
[Online quantization] Add targeted online quantization configuration based on user patterns - #51285
Conversation
Co-authored-by: Codex Signed-off-by: Felix Marty <Felix.Marty@amd.com>
|
Documentation preview: https://vllm--51285.org.readthedocs.build/en/51285/ |
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>
BowenBao
left a comment
There was a problem hiding this comment.
overall looks good, haven't finished reviewing all the files
| !!! 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. |
There was a problem hiding this comment.
| - 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?
There was a problem hiding this comment.
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.
| - A layer name may not match both `targets` and `ignore`. | ||
| - A layer may not match more than one `targets` pattern. |
There was a problem hiding this comment.
what's the behavior when these happen?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
@mgoin changes here look reasonable but would love to have another look from your team.
There was a problem hiding this comment.
For context, this is to avoid duplicate strictly identical regex / ignore processing between quark/compressed-tensors/online.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
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:
I believe this alignment is safe on Quark, cc @mgoin @kylesayrs please confirm on compressed-tensors side
|
This pull request has merge conflicts that must be resolved before it can be |
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
|
@mgoin as discussed, 2d99778 adds support for e.g. fnmatch-style ignore/target detection in online quantization only:
doc is updated in this regard. This does not impact Quark/compressed-tensors. |
|
This pull request has merge conflicts that must be resolved before it can be |
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
|
This pull request has merge conflicts that must be resolved before it can be |
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
|
/ci run |
|
✅ Triggered Buildkite CI #86647 for commit |
Signed-off-by: mgoin <mgoin64@gmail.com>
0f47edf to
84b57d2
Compare
|
/ci run |
|
✅ Triggered Buildkite CI #86679 for commit |
Signed-off-by: mgoin <mgoin64@gmail.com>
|
/ci run |
|
✅ Triggered Buildkite CI #86692 for commit |
…based on user patterns (vllm-project#51285)
…based on user patterns (vllm-project#51285)
Motivation
Enable targeted online quantization on specific layers. This includes:
vllm/vllm/model_executor/layers/attention/mla_attention.py
Line 547 in dc9f845
linear+ignoreexcluding everything else, but e.g. FSE is not possible at the moment--quantization-config '{"linear":"fp8_per_channel","ignore":["lm_head","re:.*embed_tokens.*","re:.*mlp\\.gate$","re:.*expert.*","re:.*kv_b_proj.*"]}'to achieve thistargetsfeature (e.g. in [Quark] Online-requant unquantized layers via quantization_config ove… #49313))Purpose
Implements per-layer online quantization through
quantization_config.targets, which follows the same spec as existingquantization_config.ignore.This addresses the per-layer online quantization RFC.
Exact layer names,
re:regex orfnmatch-style patterns allow to select different online shorthands per linear or MoE layer names patterns.Implementation details:
ignoreraise errors,ignoreandtargets.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:vllm/tests/quantization/test_online.py
Lines 64 to 65 in 81be2e0
Note: this behavior is now aligned for quark/compressed-tensors/online.
Note: previous ambiguous ignore regex as
re:.*v_projthat did NOT resolve toqkv_projnow 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 forignore/targetsparity andshould_ignore_layerrefactor correctness)Test Result
Tests pass.
Disclosure
AI assistance was used to develop this PR.