Repository navigation
[#20586][fix] DeepSeek-V4.1 vision: skip cuDNN SDPA on SM107 with cuDNN < 9.25 - #20587
Draft
lucifer1004 wants to merge 1 commit into
Draft
lucifer1004 wants to merge 1 commit into
lucifer1004 wants to merge 1 commit into
Conversation
…th cuDNN < 9.25 PyTorch prefers cuDNN SDPA on SM 10.x and does not fall back when plan building fails. cuDNN < 9.25 cannot build any SDPA forward plan on SM 10.7, so the vision tower fails during KV-cache profiling. Exclude only the cuDNN backend around the vision SDPA call in that configuration. Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
This branch has not been deployed
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.
Description
Fixes #20586.
The DeepSeek-V4.1 vision tower calls
F.scaled_dot_product_attention. PyTorch (CUDA >= 13 builds) prefers cuDNN SDPA on SM 10.x. On SM 10.7 with cuDNN < 9.25 (e.g. torch 2.14.0+cu132 with its bundled cuDNN 9.24), cuDNN cannot build any forward plan, and PyTorch raises instead of falling back. This fails server startup in KV-cache profiling, which encodes a dummy image._vision_sdpa_context(device)(new): on a CUDA device with compute capability 10.7 and cuDNN < 9.25 (_excludes_cudnn_sdpa, cached per device), the vision SDPA call runs undersdpa_kernelwith only the FLASH / EFFICIENT / MATH backends that the caller has enabled; cuDNN is the only backend removed, and in practice FLASH is selected. Every other configuration (CPU, SM100/SM103, cuDNN >= 9.25) gets anullcontextand is unchanged. The scope is kept narrow because cuDNN is the fastest backend wherever it works (on Vera Rubin with cuDNN 9.27 the tower is 26–33% faster than with FLASH).Vision tower forward on one Vera Rubin GPU (compute capability 10.7; full 32-layer tower + aligner, real weights, BF16; 5329 / 8192 patches): cuDNN 9.24 fails; FLASH 30.8 / 53.0 ms; EFFICIENT 44.6 / 86.3 ms; MATH 260 / 567 ms; cuDNN 9.27 22.8 / 35.5 ms. Against an FP32 reference, every BF16 backend has a relative L2 error of 3.5–3.8% at the aligner output, so the backend choice is within BF16 noise.
Test Coverage
tests/unittest/_torch/modeling/test_deepseek_v41_multimodal.py(CPU-only,unittest/_torch/modelinginl0_cpu):test_vision_sdpa_skips_cudnn_only_on_sm107_with_old_cudnn(capability and cuDNN version mocked: only (10, 7) with cuDNN 9.24 removes cuDNN; 9.25, (10, 0), (10, 3) and CPU leave the SDPA flags unchanged; flags are restored on exit) andtest_vision_sdpa_keeps_backends_the_caller_disabled(a backend disabled by the caller stays disabled).tests/unittest/_torch/modeling/test_deepseek_v41_vision_sm107.py(new, GPU, skipped unless compute capability 10.7; added tol0_gr100.yml): one full-width vision block on a 32x32 grid with the default SDPA dispatch, compared with the MATH backend.test_deepseek_v41_multimodal.py(4) pass with and without the fix; the full tower with thedeepseek-ai/DeepSeek-V4.1-Flashweights runs with the fix, and its output is bitwise identical to forcing FLASH. Re-run on this commit (80828b1): the SM 10.7 GPU test fails without the fix and passes with it;test_deepseek_v41_multimodal.pypasses 10/10 with the fix; the CPU gate cases (-k vision_sdpa) pass 6/6. End to end,trtllm-serve(TP4/EP4, vision encoder enabled) starts, passes our image test cases, and keeps text accuracy (GSM8K 98–99/100 vs 98 with the encoder disabled).>= (10, 0), no filtering by the caller's flags) makes at least one of them fail.py_compileand pre-commit on the changed files: clean.PR Checklist