Skip to content

Pad to a multiple of 128 by default with SDPA on H100 and B200 GPUs - #8554

Open
albertvillanova wants to merge 3 commits into
mainfrom
pad-auto-cudnn-sdpa
Open

albertvillanova wants to merge 3 commits into
mainfrom
pad-auto-cudnn-sdpa

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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 == 64 on 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 to None otherwise, 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_implementation reaches model_init_kwargs only 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

  • Leave 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.
  • Resolve it in the seven trainers from the model's attention implementation (identical blocks).
  • Add the require_cudnn_sdpa and require_no_cudnn_sdpa test markers, skip the CLI "auto" case on these GPUs, and add a test of the new default to each trainer.

This PR depends on:


Note

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" to None on 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", otherwise None (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.

@bot-ci-comment

Copy link
Copy Markdown

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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread trl/trainer/sft_config.py Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread trl/trainer/sft_trainer.py Resolved
@qgallouedec

Copy link
Copy Markdown
Member

LGTM. It should be indeed good on Blackwell too, but #7724 and #8439 only measured H100/H200, so numbers on a B200 or B300 would confirm it: SDPA with and without the padding, throughput and host memory, e.g. with the #7724 setup. Once we have numbers, we could confidently merge

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants