forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 30
mla: wire dynamic per-token NVFP4 scaling and cache ABI #189
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
Merged
lukealonso
merged 4 commits into
local-inference-lab:dev/gilded-gnosis
from
yatesdr:nvfp4-dynamic-token-scale
Jul 29, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ae541fc
glm52: self-describing two-level NVFP4 MLA KV records (VLLM_NVFP4_MLA…
yatesdr 72445d4
glm52: make NVFP4 MLA cache format immutable and cache-keyed
yatesdr 1435b01
glm52: register NVFP4 MLA scale environment
yatesdr b570622
glm52: preserve default offload cache namespaces
yatesdr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import hashlib | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm import envs | ||
| from vllm.model_executor.layers.mla_cache_format import ( | ||
| KV_FP8_ROPE_ENV, | ||
| NVFP4_MLA_DYNAMIC_SCALE_ENV, | ||
| NVFP4_MLA_SCALES_ENV, | ||
| Nvfp4MlaCacheFormat, | ||
| ) | ||
|
|
||
|
|
||
| def test_cache_format_envs_are_registered(): | ||
| assert NVFP4_MLA_DYNAMIC_SCALE_ENV in envs.environment_variables | ||
| assert NVFP4_MLA_SCALES_ENV in envs.environment_variables | ||
|
|
||
|
|
||
| def test_from_env_captures_one_server_static_mode(monkeypatch): | ||
| monkeypatch.setenv(NVFP4_MLA_DYNAMIC_SCALE_ENV, "1") | ||
| monkeypatch.setenv(KV_FP8_ROPE_ENV, "1") | ||
| monkeypatch.delenv(NVFP4_MLA_SCALES_ENV, raising=False) | ||
|
|
||
| cache_format = Nvfp4MlaCacheFormat.from_env() | ||
| monkeypatch.setenv(NVFP4_MLA_DYNAMIC_SCALE_ENV, "0") | ||
|
|
||
| assert cache_format.dynamic_scale | ||
| assert cache_format.fp8_rope | ||
| assert cache_format.scales_file == "" | ||
| assert ( | ||
| cache_format.record_abi("nvfp4_ds_mla") | ||
| == "nvfp4_ds_mla:fp8-rope-368:dynamic-token-v1" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "cache_format", | ||
| [ | ||
| Nvfp4MlaCacheFormat( | ||
| dynamic_scale=True, | ||
| fp8_rope=True, | ||
| scales_file="/tmp/static-scales.json", | ||
| ), | ||
| Nvfp4MlaCacheFormat( | ||
| dynamic_scale=True, | ||
| fp8_rope=False, | ||
| scales_file="", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_invalid_dynamic_combinations_fail_closed(cache_format): | ||
| with pytest.raises(ValueError): | ||
| cache_format.validate() | ||
|
|
||
|
|
||
| def test_static_scale_contents_participate_in_record_abi(tmp_path): | ||
| scales = tmp_path / "scales.json" | ||
| payload = b'{"format":"example","scales":[1.0]}' | ||
| scales.write_bytes(payload) | ||
| cache_format = Nvfp4MlaCacheFormat( | ||
| dynamic_scale=False, | ||
| fp8_rope=True, | ||
| scales_file=str(scales), | ||
| ) | ||
|
|
||
| expected_digest = hashlib.sha256(payload).hexdigest() | ||
| assert cache_format.record_abi("nvfp4_ds_mla") == ( | ||
| f"nvfp4_ds_mla:fp8-rope-368:static-calibrated-v1:{expected_digest}" | ||
| ) | ||
|
|
||
| scales.write_bytes(b'{"format":"example","scales":[2.0]}') | ||
| assert cache_format.record_abi("nvfp4_ds_mla") != ( | ||
| f"nvfp4_ds_mla:fp8-rope-368:static-calibrated-v1:{expected_digest}" | ||
| ) | ||
|
|
||
|
|
||
| def test_missing_static_scale_file_cannot_form_persistent_abi(tmp_path): | ||
| cache_format = Nvfp4MlaCacheFormat( | ||
| dynamic_scale=False, | ||
| fp8_rope=True, | ||
| scales_file=str(tmp_path / "missing.json"), | ||
| ) | ||
| with pytest.raises(ValueError, match="Cannot fingerprint"): | ||
| cache_format.record_abi("nvfp4_ds_mla") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("cache_dtype", ["bfloat16", "float16", "auto"]) | ||
| def test_non_nvfp4_cache_abi_preserves_existing_namespace(cache_dtype): | ||
| cache_format = Nvfp4MlaCacheFormat( | ||
| dynamic_scale=True, | ||
| fp8_rope=False, | ||
| scales_file="/does/not/matter", | ||
| ) | ||
| assert cache_format.record_abi(cache_dtype) == "vllm-default-v1" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("fp8_rope", [False, True]) | ||
| def test_implicit_nvfp4_cache_abi_preserves_existing_namespace(fp8_rope): | ||
| cache_format = Nvfp4MlaCacheFormat( | ||
| dynamic_scale=False, | ||
| fp8_rope=fp8_rope, | ||
| scales_file="", | ||
| ) | ||
| assert cache_format.record_abi("nvfp4_ds_mla") == "vllm-default-v1" |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.