-
Notifications
You must be signed in to change notification settings - Fork 62
Enable load MXFP4/MXFP8 + FP8 KV #1095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yiliu30
wants to merge
21
commits into
main
Choose a base branch
from
load-kv-ext
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
493c384
add fp8 kv
yiliu30 c0aff35
calib for kv/attn
yiliu30 aea1c1c
add ut
yiliu30 e5473c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 831e770
revert
yiliu30 b0dede0
Merge branch 'fp8-kv-attn-fix' of https://github.com/intel/auto-round…
yiliu30 97e61b2
update config
yiliu30 72e6c85
Merge branch 'main' into fp8-kv-attn-fix
yiliu30 4b850bf
update
yiliu30 66ffe1d
add ut
yiliu30 a4b94ab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa56ddd
merge main
yiliu30 25b12ab
fix mxfp4 linear
yiliu30 c3784f3
enable compile for fp8 kv
yiliu30 955cacd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d0e048f
add kv
yiliu30 e641fc1
fix
yiliu30 ef8e2bc
Merge branch 'load-kv-ext' of https://github.com/intel/auto-round int…
yiliu30 1fe26d9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f64e353
Merge branch 'main' into load-kv-ext
yiliu30 2782f00
Merge branch 'main' into load-kv-ext
yiliu30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright (c) 2025 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| from typing import TYPE_CHECKING, Any, Literal, Optional, cast | ||
|
|
||
| import torch | ||
| from vllm.logger import init_logger | ||
| from vllm.model_executor.layers.quantization.kv_cache import BaseKVCacheMethod | ||
|
|
||
| logger = init_logger(__name__) | ||
|
|
||
|
|
||
| class AutoRoundKVCacheMethod(BaseKVCacheMethod): | ||
| """ | ||
| Supports loading kv-cache scaling factors from compressed-tensors | ||
| checkpoints. | ||
| """ | ||
|
|
||
| def __init__(self, quant_config): | ||
| self.validate_kv_cache_scheme(quant_config) | ||
| super().__init__(quant_config) | ||
|
|
||
| @staticmethod | ||
| def validate_kv_cache_scheme(quant_config): | ||
| # FIXME: parse from quant_config | ||
| return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Copyright (c) 2025 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import pytest | ||
| import torch | ||
| from vllm.platforms import current_platform | ||
|
|
||
|
|
||
| def cuda_capability_at_least(major, minor): | ||
| device_capability = torch.cuda.get_device_capability() | ||
| return device_capability[0] >= major or (device_capability[0] == major and device_capability[1] >= minor) | ||
|
|
||
|
|
||
| MODELS = ["/home/yiliu7/workspace/auto-round/examples/Qwen2.5-0.5B-Instruct-ar-MXFP4-fp8"] | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def set_vllm_ar_env(monkeypatch): | ||
| monkeypatch.setenv("VLLM_AR_MXFP4_MODULAR_MOE", "1") | ||
| monkeypatch.setenv("VLLM_MXFP4_PRE_UNPACK_TO_FP8", "1") | ||
| monkeypatch.setenv("VLLM_MXFP4_PRE_UNPACK_WEIGHTS", "0") | ||
| monkeypatch.setenv("VLLM_ENABLE_STATIC_MOE", "0") | ||
| monkeypatch.setenv("VLLM_USE_DEEP_GEMM", "0") | ||
| monkeypatch.setenv("VLLM_ENABLE_AR_EXT", "1") | ||
| monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "0") | ||
| monkeypatch.setenv("VLLM_FLASHINFER_DISABLE_Q_QUANTIZATION", "1") | ||
| monkeypatch.setenv("VLLM_ATTENTION_BACKEND", "FLASHINFER") | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not current_platform.is_cuda(), | ||
| reason="only supports CUDA backend.", | ||
| ) | ||
| @pytest.mark.skipif( | ||
| not cuda_capability_at_least(10, 0), reason="FP8 KV cache only supported on CUDA with compute capability >= 10.0" | ||
| ) | ||
| @pytest.mark.parametrize("model", MODELS) | ||
| def test_auto_fp8_kv(vllm_runner, model): | ||
| with vllm_runner( | ||
| model, | ||
| # enforce_eager=True, | ||
| kv_cache_dtype="fp8", | ||
| gpu_memory_utilization=0.1, | ||
| ) as llm: | ||
| output = llm.generate_greedy(["The capital of France is"], max_tokens=8) | ||
| assert ( | ||
| llm.llm.llm_engine.engine_core.engine_core.model_executor.driver_worker.worker.model_runner.kv_cache_dtype | ||
| == torch.uint8 | ||
| ), f"Expected kv_cache_dtype to be torch.uint8, but got {llm.llm.llm_engine.engine_core.engine_core.model_executor.driver_worker.worker.model_runner.kv_cache_dtype}" | ||
| assert output | ||
| print(f"output is: {output[0][1]}") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mengniwang95 @xin3he ,please be aware of the usage of FP8 kv.