Skip to content

KDA attention - #3548

Open
ksivaman wants to merge 3 commits into
NVIDIA:mainfrom
ksivaman:kda_attention
Open

ksivaman wants to merge 3 commits into
NVIDIA:mainfrom
ksivaman:kda_attention

Conversation

@ksivaman

Copy link
Copy Markdown
Member

Description

Adds support for KDA attention via the fused kernel in cudnn-frontend.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • Adds support for KDA attention via the fused kernel in cudnn-frontend.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
@greptile-apps

greptile-apps Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The implementation appears safe to merge, with non-blocking improvements needed to ensure required CI actually executes KDA tests and to preserve the new validation contracts.

Findings

  1. P2 Required Tests Can Skip
  2. P2 Validation Paths Lack Coverage

Summary

This PR adds an experimental PyTorch KimiDeltaAttention API backed by the cuDNN frontend KDA kernel.

  • Exports and documents the new attention module.
  • Supports dense and packed layouts, recurrent state, activation checkpointing, fused gate transformations, and tensor-parallel head partitioning.
  • Adds numerical forward, backward, layout, state, and gate-option tests plus an L0 test-suite invocation.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[KimiDeltaAttention.forward] --> B[Validate gates and options]
  B --> C{Checkpoint enabled?}
  C -- No --> D[_KDAKernelAdapter.forward]
  C -- Yes --> E[Reentrant checkpoint]
  E --> D
  D --> F[Convert BSHD/SBHD inputs and gates to THD]
  F --> G[cudnn.linear_attention.ops.kimi_delta_attention]
  G --> H[Restore configured output layout]
  G --> I[Optional final recurrent state]
Loading

Reviews (1) · Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..."

Comment on lines +50 to +55
_KDA_OP_AVAILABLE = _kda_op_available()
if os.getenv("NVTE_KDA_TEST_REQUIRED", "0") == "1" and not _KDA_OP_AVAILABLE:
raise RuntimeError(
"NVTE_KDA_TEST_REQUIRED=1, but the cuDNN frontend KDA op or its "
"cutedsl runtime is unavailable."
)

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.

P2 Required Tests Can Skip

If the L0 suite runs on a non-SM100/SM103/SM107 GPU that has the KDA op and CUTLASS installed, NVTE_KDA_TEST_REQUIRED=1 does not raise, but the requires_kda marker skips every KDA test. The command can therefore succeed without exercising the feature, giving false assurance that KDA was tested. Required mode should also fail when the current architecture cannot run KDA.

Comment on lines +400 to +428
if allow_neg_eigval and not use_beta_sigmoid_in_kernel:
raise ValueError(
"KimiDeltaAttention allow_neg_eigval requires "
"use_beta_sigmoid_in_kernel, which owns the sigmoid it scales."
)
if gate_domain not in {"log", "linear"}:
raise ValueError(
f"KimiDeltaAttention gate_domain must be 'log' or 'linear', got {gate_domain!r}."
)
if not safe_gate:
extra = [
name
for name, value in (
("a_log", a_log),
("dt_bias", dt_bias),
("gate_lower_bound", gate_lower_bound),
)
if value is not None
]
if extra:
raise ValueError(
f"KimiDeltaAttention {', '.join(extra)} require safe_gate, which owns "
"the transform they parameterize."
)
elif gate_domain == "linear":
raise ValueError(
"KimiDeltaAttention gate_domain='linear' cannot combine with safe_gate; "
"the safe-gate transform takes raw logits."
)

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.

P2 Validation Paths Lack Coverage

The new public validation branches have no negative tests. This leaves contracts such as rejecting allow_neg_eigval without fused sigmoid, invalid gate domains, safe-gate-only parameters without safe_gate, and safe_gate with a linear gate unprotected against regressions. Focused rejection tests would prevent future changes from passing invalid combinations to the kernel.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant