[Kimi K3] allow KDA using inline Attention Gym reference eager implementation to support non-SM100/103 devices - #4374
[Kimi K3] allow KDA using inline Attention Gym reference eager implementation to support non-SM100/103 devices#4374QIU023 wants to merge 1 commit into
Conversation
…mplementation KDAKernel hardcoded impl="fused" and raised on any CUDA capability outside SM100/SM103, so the model folder that entered torchtitan as a run-anywhere eager reference now runs only on datacenter Blackwell, and the KDA tests skip everywhere else. Attention Gym ships a reference implementation behind the same chunk_kda/bound_gate API. KDAKernel.Config gains impl (auto/fused/reference, default auto): auto resolves to fused on SM100/SM103 -- numerics and behavior there unchanged -- and to the reference implementation elsewhere, with an info log. Explicit fused on unsupported hardware still raises. The KDA test gates drop the capability check so the recurrent-reference and varlen parity oracles run on any CUDA device.
|
Hi maintainers @shuhuayu @tianyu-l @liangel-02, I noticed the #4351 PR has shifted the KDA to use attention gym added KDAKernel and only used "fused" kernel that is only runnable on SM100/103 devices (B200/B300 GPUs or above), would like to add allowed fallback on non-SM100/103 users to be able to run titan Kimi K3. There will not be any behavior changes on SM100/103 devices since the This also added back the titan K3 CI/CD test coverage back and unblocked all downstream K3 parallelism PR merging. Please let me know if there is any concern on this, thank you very much! PS. In the published K3 CP PR #4313, the KCP (KDA Context Parallelism) part has to be shifted to add reference/fuse KCP implementation (referring fla KCP) in Attention Gym or torchtitan, I am happy to take the eager reference part if you are okay with that, please keep me posted on the plan, thank you very much! |
Summary
Before this change
KDAKernelhardcodesimpl="fused"(PR-4351) and raises on any CUDA capability outside SM100/SM103, so Kimi K3, which entered as an eager reference model (PR-4025), runs only on datacenter Blackwell and its KDA tests skip everywhere else.After it,
KDAKernel.Confighasimplwith valuesauto,fusedandreference, defaultauto:autoresolves tofusedon SM100/SM103, so numerics and behavior there are unchanged, and to Attention Gym's reference implementation elsewhere (samechunk_kda/bound_gateAPI), with an info log. Explicitfusedon unsupported hardware still raises. The two KDA test gates drop the capability check, so the recurrent-reference and varlen parity oracles run on any CUDA device.Results
Everything below is on an RTX 5060 Ti (SM120, CUDA capability 12.0), where
autoresolves toreference(the log printsKDA: CUDA capability (12, 0) has no fused kernel; using Attention Gym's reference implementation); on SM100/SM103 the resolved path isfusedand nothing changes.pre-commit run --all-filesis clean.The two upstream oracles that skipped off SM100 now run and pass:
tests/unit_tests/test_kda_attention.py::TestKDA::test_varlen_matches_independent_documents(packed sequences against the documents run one at a time, forward and gradient) andtests/unit_tests/gpu/test_kimi_k3.py::TestKimiK3::test_attention_gym_kda_kernel_matches_recurrent_reference(kernel against the FP32 sequential recurrence).To reproduce the training rows, from the torchtitan checkout root on this branch. Every cell loads the same seed checkpoint; run each cell twice and read the second run (a cold compile cache moves step 1):
kimi_k3_debugmodelthrough the reference path, seed 42,--debug.deterministic, one seed checkpoint loaded by both cells; the dp2 row is the usual dp-degree shift of the debug flavor (the two cells see different tokens per step), not a kernel difference:Changed files