Repository navigation
[Common] Bucket the batch size on the direct cu_seqlens fprop path - #3822
Draft
egilliam-nv wants to merge 4 commits into
Draft
egilliam-nv wants to merge 4 commits into
egilliam-nv wants to merge 4 commits into
Conversation
PR NVIDIA#3186 builds the forward graph at the exact batch size when cu_seqlens are passed directly to cuDNN, because cuDNN reads [actual_b+1] entries from the user's buffers. For packed THD training the number of documents per batch varies, so every new count misses the graph cache and rebuilds a graph. Bucket the forward graph batch size again on the direct path and launch one small kernel (pad_cu_seqlens_tails) that extends the cu_seqlens and ragged offset buffers to the bucketed size by repeating the last value, i.e. appending zero-length sequences. The kernel is only launched when the bucketed batch differs from the actual one. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Emil Gilliam <egilliam@nvidia.com> Signed-off-by: Emil Gilliam <215885072+egilliam-nv@users.noreply.github.com>
for more information, see https://pre-commit.ci
Move the pad_cu_seqlens_tails launch and its workspace sizing out of the f16 and FP8 forward launchers into pad_direct_cu_seqlens() in utils.cu. Also include <cassert> in utils.cu, which uses assert() but relied on a transitive include. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Emil Gilliam <215885072+egilliam-nv@users.noreply.github.com>
for more information, see https://pre-commit.ci
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.
Summary
#3186 passes
cu_seqlensdirectly to cuDNN SDPA fprop. Because cuDNN reads[actual_b+1]entries from the user's buffers, that PR builds the forward graph at the exact batch size instead of the bucketed one. For packed THD training the number of documents per batch varies, so every new count misses the graph cache and rebuilds a graph. This shows up as a large throughput regression in Llama-3 training (about -48% on H100 across #3186 in our bisect).Change
config_and_params.cpp).pad_cu_seqlens_tails, a small kernel that extends thecu_seqlensand ragged-offset buffers to the bucketed batch by repeating the last value (zero-length sequences), so cuDNN never reads out of bounds. It is launched only when the bucketed batch differs from the actual one, uses one launch (vs. two conversion kernels before [Common] Pass cu_seqlens and token-unit ragged offsets directly to cuDNN SDPA fprop #3186), and needs4 * (b_bucket+1) * 4bytes of extra workspace.Status (draft)
Tested on H100 (sm90), cuDNN 9.24.0, bf16, built with
NVTE_CUDA_ARCHS=90:NVTE_FUSED_ATTN_CACHE_DEBUG=1, and matches a per-document SDPA reference within bf16 noise (max abs error <= 0.0078).pytest tests/pytorch/attention/test_attention.py -k thd: 79 passed, 1532 skipped (hardware), 0 failed.TODO:
🤖 Generated with Claude Code