Skip to content

Default pad_to_multiple_of to "auto": pad to a multiple of 128 on Neuron - #7724

Merged
qgallouedec merged 4 commits into
mainfrom
pad-to-multiple-of-auto
Oct 14, 2026
Merged

qgallouedec merged 4 commits into
mainfrom
pad-to-multiple-of-auto

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Part of #7658.

Neuron compiles once per input shape, so without pad_to_multiple_of every new sequence length stalls training for about a minute. This PR makes "auto" the default pad_to_multiple_of in SFT, DPO, KTO, Reward, GRPO, RLOO and Distillation: 128 on Neuron, None elsewhere, so nothing changes on GPU. An explicit value is kept as is.

  • Trainium2, Qwen3-0.6B SFT, 20 steps: 130 s with the default, 260 s with pad_to_multiple_of=None.

Why not a warning

We already know the right value, and warnings get missed (agents launching runs never read them).

Why not 128 everywhere

It only helps SDPA on Hopper (cuDNN builds a graph for each new sequence length), and less as the model grows. Elsewhere, and with flash attention on every GPU, it costs 2-6%.

pad128_vs_none
Data

SFT on trl-lib/Capybara, max_length=4096, 100 steps, steady-state samples/s, torch 2.13 unless noted. Change with pad_to_multiple_of=128 vs None:

GPU model, batch SDPA FA2 FA3
H100 Qwen3-1.7B, 1 +57.1% -9.7% -6.4%
H100 Qwen3-1.7B, 4 +31.5% -3.6% -3.3%
H100 Qwen3-1.7B, 8 +16.7% -2.7% -2.8%
H100 Qwen3-1.7B, 16 +4.6% -3.5% -3.3%
H100 Qwen3-4B, 1 +39.2% -8.7% -8.3%
H100 Qwen3-4B, 2 +26.2% -3.0% -2.5%
H100 Qwen3-4B, 4 +15.4% -2.7% -3.1%
H200 Qwen3-1.7B, 4 +26.5% -1.7%
H200 Qwen3-4B, 2 +22.3% -4.6%
H200 Qwen3-8B, 2 +9.8% -4.3%
H200 Qwen3-8B, 4 +2.7% -5.3%
H200 (torch 2.14) Qwen3-1.7B, 4 +22.7% -2.8%
H200 (torch 2.14) Qwen3-4B, 2 +21.9% -5.9%
A100 Qwen3-1.7B, 4 -0.5% -1.7%
A100 Qwen3-4B, 2 -3.2% -6.1%
L40S Qwen3-1.7B, 4 -3.8% -2.9%
RTX PRO 6000 Qwen3-1.7B, 4 -2.7% -1.8%
RTX PRO 6000 Qwen3-4B, 2 -3.0% -2.9%

Full H100 sweep (192 runs). Peak allocated memory doesn't depend on the pad; the fragmentation OOMs at batch 8 go away with expandable_segments, not with padding:

padmult_sweep

cc @michaelbenayoun


Note

Medium Risk
Cross-cutting default change on all major trainer configs affects batch padding and sequence lengths on Neuron (intended); off Neuron "auto" still resolves to no padding, but anyone depending on the old implicit default should confirm explicit overrides.

Overview
pad_to_multiple_of now defaults to "auto" (instead of None) on SFT, DPO, KTO, Reward, GRPO, RLOO, and Distillation configs. The field type accepts int | str | None, and __post_init__ normalizes CLI strings ("128", "none"/"null") and resolves "auto" to 128 when device.type == "neuron", otherwise None—so GPU training behavior stays unpadded unless overridden.

Docs/help text for pad_to_multiple_of are updated accordingly. tests/test_cli_utils.py adds parametrized coverage that TrlParser parses --pad_to_multiple_of correctly across those config classes (including "auto" → None off Neuron).

Reviewed by Cursor Bugbot for commit 93c6e25. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T16:20:24.021777Z 4ecf90b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ecf90b4e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread trl/trainer/sft_config.py Resolved
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 4ecf90b. Configure here.

Comment thread trl/trainer/sft_config.py Resolved
@qgallouedec
qgallouedec merged commit b54122a into main Oct 14, 2026
10 checks passed
@qgallouedec
qgallouedec deleted the pad-to-multiple-of-auto branch October 14, 2026 20:18
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