Repository navigation
feat(deepseek-v4): cudnn_flashmla sparse attention backend (FlashMLA forward, cuDNN backward) - #4078
Merged
Merged
Conversation
…d table Add a backend argument to prime_rl::dsv4_sparse_attn and its backward, dispatched through FORWARD_BACKENDS / BACKWARD_BACKENDS, with tilelang as the only entry. DeepseekV4Attention reads dsa_backend from the model config and rejects backends DSv4 does not implement. Kernel tests are parametrized over DSV4_BACKENDS. No behavior change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
FlashMLA's sparse prefill runs the forward and the cuDNN frontend's SM90 DSA backward runs the backward, behind model.dsa_backend = "cudnn_flashmla". Slot widths round up to FlashMLA's 128-slot tile. The public LSE stays TileLang's (base 2, sink included), converted from FlashMLA's natural-log, sink-excluded one. The backward receives the sink-inclusive natural-log LSE with no attn_sink, so the sink gradient stays in torch, and its delta comes from TileLang's fused preprocess kernel. The backend runs on SM90 only. The cuDNN backward still compiles one main kernel per slot width. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… width The cuDNN frontend keys its SM90 DSA backward main kernel on the slot width, so each new HCA width compiled a new kernel (about 2.5 s) mid-training. The kernel only uses max_topk to clamp topk_length, so `cudnn_dsa_compile` builds it with max_topk at a clamp derived from the config (the next power of two at or above the widest slot axis, 16384 for DeepSeek-V4-Flash) and keys it on that clamp, in an in-memory cache. Calls without topk_length (GLM) keep the frontend's behavior. Each compile of the preprocess, main and postprocess kernels is logged at INFO with its duration. The widest slot axis reaches the ops as `max_slots`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
compile_counts.py counts the cuDNN and TileLang kernels the sparse attention ops compile in one process over corpus items, wide slot widths, or two clamps. launch.sh runs the end-to-end arms serially on one held node from frozen worktrees with fresh caches, and compare.py reports speed, parity, and per-rank, per-step compile counts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ward op The forward op already asserts it; the backward op is public too and would otherwise fail with a TypeError deep in the slot-width rounding. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…d logs/latest Ranks sharing a Triton cache on NFS raced on its files and crashed the first smoke run, and torchrun logs live under logs/latest. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ults Kernel-level compile counts, the six-arm end-to-end comparison, and rank 0 kernel breakdowns from job 3935 on 2026-10-13. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
They stay reachable at ef2ab83. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ontext A/Bs Adds 128k- and 1M-token configs (16k and 128k tokens per GPU at cp 8) and CONFIG / RUN_TAG knobs in launch.sh. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Job 4008 on 2026-10-13: 16k tokens per GPU, and the 1M-sequence attempt that runs out of memory in the shared FP8 indexer. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ckend Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Admit compute capabilities (10, 0) and (10, 3) for cudnn_flashmla. On Blackwell the backward calls the cuDNN SM100 DSA kernel with the same sink-inclusive natural-log LSE as SM90, a -inf attn_sink and a caller workspace, and keeps dsink in torch. cudnn_dsa_compile gains an SM100 path that builds the generic_m64 main kernel with max_topk at the power-of-two clamp of max_slots and keys it on the clamp, so one compile serves every slot width. It applies only to calls with topk_length, refuses widths that are not a multiple of 64, and leaves the tuned H128 two-CTA kernels and GLM's calls on stock behavior. The SM90 path is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
GLM-5's cudnn_flashmla backward on SM100/SM103 called flash_attn_bwd_sm100 without a workspace, which the frontend requires, so every Blackwell backward raised ValueError. Allocate it from flash_attn_bwd_sm100_workspace_size. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…d B300 handoff The harness, H200 results and B300 handoff stay reachable at a4e159cee. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…opk clamp Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… prevents Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…as patches Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
samsja
previously approved these changes
Oct 14, 2026
samsja
marked this pull request as ready for review
October 14, 2026 01:20
samsja
marked this pull request as draft
October 14, 2026 01:20
…hmla backend The shared dsa_backend default stays tilelang, as for GLM-5.3, whose example configs opt in the same way. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
garrett361
marked this pull request as ready for review
October 14, 2026 16:25
samsja
approved these changes
Oct 14, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a
cudnn_flashmlaoption tomodel.dsa_backendfor DeepSeek V4 that runs the same FlashMLA sparse prefill forward vLLM uses for DeepSeek V4 prefill, so the trainer and inference compute attention with the same kernel. The backward is the cuDNN frontend's DSA kernel; it runs on SM90, SM100 and SM103, andtilelangstays the default.cudnn_dsa_patchstops cuDNNrecompiling its backward for each new width. GLM-5's backward uses one fixed width and is unaffected.
6a1cae560), both DSv4 test files pass again, and a 3-step end-to-end run (cp 8,ep 8) compiles 3 cuDNN kernels per rank in step 1 and matches the earlier losses, step time and peak memory.
cudnn_flashmlabackward, which omitted cuDNN's required workspace and always raised.tilelangstays the shareddsa_backenddefault andconfigs/advanced/deepseek-v4-flash/sft.tomlopts in tocudnn_flashmla, following perf(dsa): cuDNN + FlashMLA kernels for GLM-5 sparse attention (model.dsa_backend) #3829, which did the same for the GLM-5.3 configs. FlashMLA only ships an x86_64 wheelin an optional extra, so a
cudnn_flashmladefault would break aarch64 and installs without the extra. We can flipthe default instead if reviewers prefer.
DeepSeek-V4-Flash first 6 layers, real weights, cp 8, ep 8, one 8xH200 node. Sparse attention GPU time per step, rank 0 profiler trace at 8k tokens/GPU:
Sparse attention is under 5% of the step here, so the end-to-end gain is smaller. Median steady-state step time:
Peak memory is equal, and each rank compiles 3 cuDNN kernels, all in step 1. Baseline
main; results and config at524ec668e.🤖 Generated with Claude Code