Skip to content

[https://nvbugs/7125691][fix] Restore the Kimi K3 KDA reference helpers used by test_kda_prefill.py - #22685

Merged
erictsai-nv merged 1 commit into
NVIDIA:mainfrom
erictsai-nv:fix/7125691-restore-kda-reference-helpers
Nov 23, 2026
Merged

erictsai-nv merged 1 commit into
NVIDIA:mainfrom
erictsai-nv:fix/7125691-restore-kda-reference-helpers

Conversation

@erictsai-nv

@erictsai-nv erictsai-nv commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

#22247 removed kimi_k3_inputs and recurrent_reference from ops/ssm/_kda_reference.py. test_kda_prefill.py (added by #21996) still calls both, so its five cases fail with AttributeError on GR100 post-merge. This PR restores the two helpers.

Test Coverage

unittest/_torch/modeling_v2/models/kimi_k3_vl/ops/ssm/test_kda_prefill.py passes on B300 (5 cases).

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

Dev Engineer Review

  • Restores kimi_k3_inputs and recurrent_reference in the test-only reference module _kda_reference.py. Both were removed by #22247, but test_kda_prefill.py still calls them.
  • The change touches test helpers only. No production code changes.
  • The helper math was not independently verified. Review the gated delta-rule update and the per-key decay against the reference implementation.

QA Engineer Review

  • Test files changed: tests/unittest/_torch/modeling_v2/models/kimi_k3_vl/ops/ssm/_kda_reference.py (modified, +51/-1). It is a helper module, not a test file.
  • Test functions, test IDs, or waivers changed: none.
  • Covered by test_kda_prefill.py (5 cases). The author reports these pass on B300. GR100 results and CI results: not available.
  • Test-db or QA list membership: not available.
  • Coverage verdict: needs follow-up. Confirm the 5 cases pass on GR100 and in CI.

Per-File QA Perspective

  • _kda_reference.py (test-code helper): adds an fp64 token-by-token KDA prefill reference and its input generator. Verify test_kda_prefill.py runs all 5 cases on GR100. Test-list membership: not available.

…rs used by test_kda_prefill.py

Signed-off-by: Eric Tsai <ertsai@nvidia.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds input-generation and recurrent-reference helpers to the Kimi K3 KDA test module. The helpers create CUDA tensors and compute token-by-token outputs and final state in fp64.

Changes

KDA prefill test support

Layer / File(s) Summary
Input generation and recurrent reference
tests/unittest/_torch/modeling_v2/models/kimi_k3_vl/ops/ssm/_kda_reference.py
kimi_k3_inputs generates CUDA tensors for the prefill inputs. recurrent_reference computes per-key decay and applies the beta-weighted delta-rule update for each token, then returns the outputs and final state.

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

Change: Other · Severity of issue fixed: Low

Possibly related PRs

Suggested reviewers: vsabavat, brnguyen2, moraxu

Merge Risk: Minimal · up to a4756

This restores the test helpers that test_kda_prefill.py needs, and it changes no production code. No merge-blocking risk was identified.

Security architecture risk: Minimal · up to a4756

The change restores test-only input generation and a numerical reference. The inspected changes introduce no material risk to production access controls, state ownership, or failure containment.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the NVBugs ID and [fix] type, and states that the Kimi K3 KDA reference helpers used by test_kda_prefill.py are restored. This matches the changeset, which adds kimi_k3_inputs and recu…
Description check Passed The description states the problem and the fix. It explains that #22247 removed kimi_k3_inputs and recurrent_reference, and that test_kda_prefill.py (added by #21996) still calls both, causing five At…
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.
Full details: Title check

Explanation

The title names the NVBugs ID and [fix] type, and states that the Kimi K3 KDA reference helpers used by test_kda_prefill.py are restored. This matches the changeset, which adds kimi_k3_inputs and recurrent_reference to _kda_reference.py. The title is specific and follows the repository template.

Full details: Description check

Explanation

The description states the problem and the fix. It explains that #22247 removed kimi_k3_inputs and recurrent_reference, and that test_kda_prefill.py (added by #21996) still calls both, causing five AttributeError failures on GR100 after merge. It also lists test coverage (5 cases passing on B300) and includes the PR checklist. It does not follow the template's structure exactly: the Description section is brief, and the checklist is marked as checked without showing the ticket format or label status. The description is still mostly complete and clear.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6533070 and a47561b.

Files selected for processing: 1

  • tests/unittest/_torch/modeling_v2/models/kimi_k3_vl/ops/ssm/_kda_reference.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@erictsai-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --extra-stage "GR100-PyTorch-Post-Merge-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86339 [ run ] triggered by Bot. Commit: a47561b Link to invocation

@trtllm-agent-review trtllm-agent-review left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. It restores the kimi_k3_inputs and recurrent_reference helpers that #22247 removed from _kda_reference.py, so the five test_kda_prefill.py cases stop failing with AttributeError on GR100.

Reviewed at commit a47561bad6 (1 file, +51/−1).

Approve: no Blocker found. 2 suggestions below are nice to have.

Nice to have (2): 1 inline, 1 below
  • (N5: Code tidiness) batch_rows in the restored kimi_k3_inputs is never passed by any caller (the only call is test_kda_prefill.py:53), so it brings back an unused input path. (_kda_reference.py:20)

  • [Nice to have] (R3: Repository rules) AGENTS.md asks every change to follow CODING_GUIDELINES.md ("Read and follow CODING_GUIDELINES.md for ALL code changes"), and the restored helpers miss two of its Static Typing rules:

    • _kda_reference.py:48 def recurrent_reference(q, k, v, g, beta, state, A_log, dt_bias): and _kda_reference.py:24 def unit(t): have no annotations. Static Typing 4: "Always annotate functions. Make the return type None if the function does not return anything". Without them the type checker infers Any for the eight tensor inputs and for the (o, state) result that test_kda_prefill.py:138 unpacks.
    • _kda_reference.py:20 returns -> Dict, imported at _kda_reference.py:10. Static Typing 6: "Prefer using the built-in types list, dict, and tuple to the legacy typing.List, typing.Dict, and typing.Tuple."

    Suggested fix (and drop from typing import Dict):

    def kimi_k3_inputs(...) -> dict[str, torch.Tensor]:
        ...
        def unit(t: torch.Tensor) -> torch.Tensor:
            ...
    
    def recurrent_reference(
        q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, g: torch.Tensor, beta: torch.Tensor,
        state: torch.Tensor, A_log: torch.Tensor, dt_bias: torch.Tensor,
    ) -> tuple[torch.Tensor, torch.Tensor]:
What this review checked
  • Apart from two docstrings, the restored kimi_k3_inputs and recurrent_reference are byte-identical to the version before #22247. On CPU, recurrent_reference matches KdaPrefill.reference (k3r_kda_prefill.py:176-200) within the 1e-2 output and 1e-6 state tolerances of test_reference_is_the_family_recurrence.
  • At the base, kr.kimi_k3_inputs (test_kda_prefill.py:53) and kr.recurrent_reference (:138) are the only unresolved helper-module references under tests/unittest/_torch/modeling_v2. At this head all 3,221 resolve, so #22247 left no other test calling a helper it deleted.
  • test_kda_prefill.py is listed on the GR100 post-merge stage (l0_gr100.yml:155), and its skip gate (kda_prefill.ARCHS = SM103, SM107) admits GR100. No waive or other open PR covers the test or nvbug 7125691.
  • Not covered: A GPU run: the test needs SM103 or SM107, so the reference comparison ran on CPU.
  • Not covered: The author's B300 run (not inspected); pre-merge CI does not run test_kda_prefill.py, which is listed only for GR100 post-merge.
  • Not covered: ruff and pyrefly (not installed here); lint relies on the passing Pre-commit Check.

Automated review by trtllm-agent-review. If a point is wrong, reply in its thread. After you push fixes or reply, the bot re-checks the Blockers within a few hours.

@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86339 [ run ] completed with state SUCCESS. Commit: a47561b
/LLM/main/L0_MergeRequest_PR pipeline #71538 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@erictsai-nv

Copy link
Copy Markdown
Collaborator Author

/bot skip --comment "tests passed"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86624 [ skip ] triggered by Bot. Commit: a47561b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86624 [ skip ] completed with state SUCCESS. Commit: a47561b
Skipping testing for commit a47561b

Link to invocation

@erictsai-nv
erictsai-nv merged commit 0f88f9f into NVIDIA:main Nov 23, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants