Repository navigation
Pad to a multiple of 128 by default with SDPA on H100 and B200 GPUs - #8554
Open
albertvillanova wants to merge 3 commits into
Open
albertvillanova wants to merge 3 commits into
albertvillanova wants to merge 3 commits into
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 52ba558. Configure here.
Member
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.

This PR makes
pad_to_multiple_of="auto"pad to a multiple of 128 with SDPA attention on NVIDIA GPUs of compute capability 9.x and 10.x (H100, H200, B200, B300), as it already does on Neuron, in SFT, DPO, KTO, Reward, GRPO, RLOO and Distillation.Tracking issue:
Motivation
On these GPUs, PyTorch runs SDPA with cuDNN, which keeps a graph in host memory for every new sequence length and never frees it (pytorch/pytorch#202607). With the script of #8439 on an H100 (torch 2.14.1), host memory ends at 3.54 GB with today's default and at 2.13 GB with this PR, flat from step 100. Padding to 128 also keeps clear of the cuDNN NaN at
seq_len % 128 == 64on torch < 2.15 (pytorch/pytorch#196678), and #7724 measured +3% to +57% throughput with SDPA on H100/H200.Solution
The configs still resolve
"auto"in__post_init__, except on CUDA (not ROCm) GPUs of compute capability 9.x/10.x, where the trainers resolve it once the model is loaded: to 128 if the model uses SDPA, and toNoneotherwise, e.g. with FA2/FA3, which #7724 measured 2 to 6% slower when padded. Resolving it from the loaded model also covers the CLI, where--attn_implementationreachesmodel_init_kwargsonly after the config is built, and models passed as objects. Generation with transformers still hits the cache; the docs cover that case (#8440).On an H100, the test files of the seven trainers pass with this PR and #8553 (without #8553, the vision-language tests of SFT, DPO and KTO hit #8551).
Changes
pad_to_multiple_of="auto"for the trainer to resolve on compute capability 9.x/10.x in the seven configs, and update their docstrings and help texts.require_cudnn_sdpaandrequire_no_cudnn_sdpatest markers, skip the CLI"auto"case on these GPUs, and add a test of the new default to each trainer.This PR depends on:
pad_to_multiple_ofwith vision-language models in SFT, DPO and KTO #8553Note
Medium Risk
Changes default padding for all seven trainers on H100/B200 when using SDPA, which affects batch shapes, memory, and throughput; scope is broad but behavior is gated on GPU capability and attention backend.
Overview
Extends
pad_to_multiple_of="auto"so it pads sequences to a multiple of 128 on NVIDIA compute capability 9.x/10.x GPUs when the loaded model uses SDPA—same motivation as on Neuron: bound cuDNN’s per-sequence-length graph cache (#8439).Configs (SFT, DPO, KTO, Reward, GRPO, RLOO, Distillation) no longer collapse
"auto"toNoneon those CUDA GPUs in__post_init__; docstrings and CLI help describe the new behavior. Trainers resolve"auto"after the model is loaded: 128 if_attn_implementation == "sdpa", otherwiseNone(e.g. eager or FlashAttention).Tests add
require_cudnn_sdpa/require_no_cudnn_sdpa, gate the CLI"auto"expectation on non–cuDNN-SDPA hardware, and add parametrized trainer tests for SDPA vs eager.Reviewed by Cursor Bugbot for commit 58bf9ec. Bugbot is set up for automated code reviews on this repo. Configure here.