Repository navigation
[TRTLLM-15215][fix] Kimi K3: make the FP8 weight-read master switch opt-in #17446
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
brnguyen2
merged 2 commits into
NVIDIA:main
from
brnguyen2:k3/fp8-weight-read-default-off
Aug 10, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
82 changes: 82 additions & 0 deletions
82
tests/unittest/_torch/modeling/test_kimi_k3_fp8_weight_read_gates.py
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,82 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
| """Pin the Kimi K3 FP8 weight-read switch defaults. | ||
|
|
||
| The FP8 weight read is lossy relative to BF16, so the master switch must stay | ||
| opt-in — a default run keeps BF16 and matches the published accuracy numbers. | ||
| These tests exist so that default cannot drift silently: it did once, and the | ||
| only symptom was accuracy measured against a configuration nobody selected. | ||
|
|
||
| CPU-only: ``is_sm_100f`` is patched so the gates can be exercised without | ||
| Blackwell hardware. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from tensorrt_llm._torch.models import modeling_kimi_linear | ||
| from tensorrt_llm._torch.models.modeling_kimi_linear import _resolve_fp8_weight_read_gates | ||
|
|
||
| ENVS = ( | ||
| "KIMI_K3_FP8_WEIGHT_READ", | ||
| "KIMI_K3_FP8_WEIGHT_READ_KDA", | ||
| "KIMI_K3_KDA_GLUE_FP8", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sm100f(monkeypatch): | ||
| """Report Blackwell so the SM gate never masks the env behavior.""" | ||
| monkeypatch.setattr(modeling_kimi_linear, "is_sm_100f", lambda: True) | ||
| for env in ENVS: | ||
| monkeypatch.delenv(env, raising=False) | ||
|
|
||
|
|
||
| def test_master_switch_defaults_off(sm100f): | ||
| """With nothing set, no FP8 weight read anywhere.""" | ||
| assert _resolve_fp8_weight_read_gates() == (False, False, False) | ||
|
|
||
|
|
||
| def test_master_switch_opt_in(sm100f, monkeypatch): | ||
| """Setting the master switch enables it and the default-on sub-gates.""" | ||
| monkeypatch.setenv("KIMI_K3_FP8_WEIGHT_READ", "1") | ||
| assert _resolve_fp8_weight_read_gates() == (True, True, True) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "env,expected", | ||
| [ | ||
| ("KIMI_K3_FP8_WEIGHT_READ_KDA", (True, False, False)), | ||
| ("KIMI_K3_KDA_GLUE_FP8", (True, True, False)), | ||
| ], | ||
| ) | ||
| def test_sub_gates_narrow_an_enabled_master(sm100f, monkeypatch, env, expected): | ||
| """Sub-gates only ever narrow; they never enable on their own.""" | ||
| monkeypatch.setenv("KIMI_K3_FP8_WEIGHT_READ", "1") | ||
| monkeypatch.setenv(env, "0") | ||
| assert _resolve_fp8_weight_read_gates() == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("env", ENVS[1:]) | ||
| def test_sub_gates_are_inert_while_master_is_off(sm100f, monkeypatch, env): | ||
| """A sub-gate set to 1 must not turn on FP8 reads by itself.""" | ||
| monkeypatch.setenv(env, "1") | ||
| assert _resolve_fp8_weight_read_gates() == (False, False, False) | ||
|
|
||
|
|
||
| def test_non_blackwell_never_reads_fp8(monkeypatch): | ||
| """The SM gate wins even with the master switch explicitly on.""" | ||
| monkeypatch.setattr(modeling_kimi_linear, "is_sm_100f", lambda: False) | ||
| monkeypatch.setenv("KIMI_K3_FP8_WEIGHT_READ", "1") | ||
| assert _resolve_fp8_weight_read_gates() == (False, False, False) |
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.