Skip to content

[TRTLLM-15215][fix] Kimi K3: make the FP8 weight-read master switch opt-in - #17446

Merged
brnguyen2 merged 2 commits into
NVIDIA:mainfrom
brnguyen2:k3/fp8-weight-read-default-off
Aug 10, 2026
Merged

[TRTLLM-15215][fix] Kimi K3: make the FP8 weight-read master switch opt-in#17446
brnguyen2 merged 2 commits into
NVIDIA:mainfrom
brnguyen2:k3/fp8-weight-read-default-off

Conversation

@brnguyen2

@brnguyen2 brnguyen2 commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Description

KIMI_K3_FP8_WEIGHT_READ defaulted to "1", so any Kimi K3 run on sm_100-family
hardware served the replicated MoE-MLP, KDA q/k/v/g/o and MLA projections from an FP8
copy of their weights. The FP8 read is lossy relative to BF16 and there was no opt-in:
a stock run silently traded accuracy for decode bandwidth, and the published accuracy
numbers are measured with it off.

Default the master switch to "0". The KDA and KDA-glue sub-switches only ever narrow
an already-enabled master, so they stay default-on and are inert while the master is
off; the SM100 gate is unchanged.

Resolution of the three switches moves into _resolve_fp8_weight_read_gates() so the
defaults are assertable without loading a model. Previously the expression was inline in
load_weights, which meant the only way to test it was to load a checkpoint — so in
practice it was untested, and it drifted.

Test Coverage

New tests/unittest/_torch/modeling/test_kimi_k3_fp8_weight_read_gates.py (7 tests,
CPU-only, patches the SM check): the master switch defaults off; setting it enables it
and the default-on sub-gates; each sub-gate narrows an enabled master; a sub-gate cannot
enable FP8 reads on its own; and the SM gate still wins over an explicit opt-in.

PR Checklist

  • PR title is [JIRA/NVBUG/None][type] Summary
  • Commit is signed off (DCO)
  • New tests added and passing
  • No new dependencies

Dev Engineer Review

  • Changed KIMI_K3_FP8_WEIGHT_READ from default-on to default-off.
  • Added _resolve_fp8_weight_read_gates() to centralize SM100 and environment-variable gate resolution.
  • Preserved BF16 behavior when FP8 weight reads remain disabled.
  • Kept KDA and KDA-glue sub-switches default-on, but made them narrow an enabled master switch.
  • Preserved SM100 hardware-gate precedence.
  • Updated documentation to state that FP8 weight reads are opt-in and may trade accuracy for decode bandwidth.
  • No public API changes or unintended configuration scope changes were identified.

QA Engineer Review

  • Added seven CPU-only tests in tests/unittest/_torch/modeling/test_kimi_k3_fp8_weight_read_gates.py.
  • Tests cover the default-off master switch, opt-in behavior, sub-switch narrowing, prevention of sub-switch-only activation, and SM100 hardware-gate precedence.
  • No corresponding tests/integration/test_lists/ coverage entry was identified.
  • Verdict: needs follow-up.

…pt-in

KIMI_K3_FP8_WEIGHT_READ defaulted to "1", so any Kimi K3 run on
sm_100-family hardware served the replicated MoE-MLP, KDA q/k/v/g/o and
MLA projections from an FP8 copy of their weights. The FP8 read is lossy
relative to BF16 and there was no opt-in: a stock run silently traded
accuracy for decode bandwidth, and the published accuracy numbers are
measured with it off.

Default the master switch to "0". The KDA and KDA-glue sub-switches only
ever narrow an already-enabled master, so they stay default-on and are
inert while the master is off; the SM100 gate is unchanged.

Resolution of the three switches moves into _resolve_fp8_weight_read_gates()
so the defaults are assertable without loading a model. The new test pins
them, including that a sub-switch cannot enable FP8 reads on its own and
that the SM gate still wins.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
@brnguyen2
brnguyen2 requested a review from a team as a code owner August 9, 2026 16:28
@brnguyen2
brnguyen2 requested a review from schetlur-nv August 9, 2026 16:28
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 031e2d76-62e8-4a2d-8281-05de31004dfa

📥 Commits

Reviewing files that changed from the base of the PR and between c4b9b87 and 9fd36f0.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/models/modeling_kimi_linear.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/models/modeling_kimi_linear.py

Walkthrough

The change centralizes Kimi FP8 weight-read gate resolution. FP8 reads now require explicit opt-in on SM100 hardware. Tests cover default, sub-gate, and non-Blackwell behavior.

Changes

FP8 weight-read gates

Layer / File(s) Summary
Centralize FP8 gate resolution
tensorrt_llm/_torch/models/modeling_kimi_linear.py
Documents FP8 reads as lossy and opt-in. Adds _resolve_fp8_weight_read_gates for SM100 and environment-variable checks.
Integrate and validate gate behavior
tensorrt_llm/_torch/models/modeling_kimi_linear.py, tests/unittest/_torch/modeling/test_kimi_k3_fp8_weight_read_gates.py
Updates load_weights to use the resolver. Adds CPU-only tests for master and subordinate gates, defaults, and non-Blackwell hardware.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: schetlur-nv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the ticket, fix type, component, and primary change to make FP8 weight reads opt-in.
Description check ✅ Passed The description clearly explains the issue, solution, test coverage, and relevant checklist items for the change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tensorrt_llm/_torch/models/modeling_kimi_linear.py (1)

2587-2587: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use kda_fp8 for the KDA conversion condition.

Line 2587 resolves kda_fp8, but line 2624 re-reads _KIMI_K3_FP8_WEIGHT_READ_KDA_ENV. Use if kda_fp8: there. This keeps load_weights() aligned with the centralized resolver and makes resolver tests represent loader behavior.

Proposed fix
-            if os.environ.get(_KIMI_K3_FP8_WEIGHT_READ_KDA_ENV, "1") != "0":
+            if kda_fp8:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/models/modeling_kimi_linear.py` at line 2587, Update
load_weights() to use the resolved kda_fp8 value from
_resolve_fp8_weight_read_gates() for the KDA conversion condition instead of
re-reading _KIMI_K3_FP8_WEIGHT_READ_KDA_ENV. Preserve the existing conversion
behavior while ensuring it follows the centralized resolver.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/models/modeling_kimi_linear.py`:
- Around line 191-193: Update the fp8_weight_read master-switch evaluation in
the surrounding model configuration logic so KIMI_K3_FP8_WEIGHT_READ enables FP8
only when its value is nonempty and not "0"; preserve the existing SM capability
check and dependent kda_fp8/kda_glue_fp8 behavior. Add a regression test
covering an empty master environment value and asserting FP8 weight reads remain
disabled.

---

Nitpick comments:
In `@tensorrt_llm/_torch/models/modeling_kimi_linear.py`:
- Line 2587: Update load_weights() to use the resolved kda_fp8 value from
_resolve_fp8_weight_read_gates() for the KDA conversion condition instead of
re-reading _KIMI_K3_FP8_WEIGHT_READ_KDA_ENV. Preserve the existing conversion
behavior while ensuring it follows the centralized resolver.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2c109ae9-54cb-4479-befb-92f9da38a911

📥 Commits

Reviewing files that changed from the base of the PR and between 1cef02e and c4b9b87.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/models/modeling_kimi_linear.py
  • tests/unittest/_torch/modeling/test_kimi_k3_fp8_weight_read_gates.py

Comment thread tensorrt_llm/_torch/models/modeling_kimi_linear.py Outdated
Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
@brnguyen2

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64865 [ run ] triggered by Bot. Commit: 9fd36f0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64865 [ run ] completed with state SUCCESS. Commit: 9fd36f0
/LLM/main/L0_MergeRequest_PR pipeline #52706 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@brnguyen2
brnguyen2 merged commit c67879c into NVIDIA:main Aug 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants