Skip to content

[rl] Fix model-specific attention scaling in vLLM - #5347

Merged
tianyu-l merged 2 commits into
pytorch:mainfrom
haydn-jones:fix/attention-softmax-scale
Oct 17, 2026
Merged

tianyu-l merged 2 commits into
pytorch:mainfrom
haydn-jones:fix/attention-softmax-scale

Conversation

@haydn-jones

Copy link
Copy Markdown
Contributor

The vLLM attention replacement does not include model specific softmax scales which makes GPT-OSS and DeepSeek lose their YaRN-adjusted scaling.

I just exposed the scale as a property on the attention config and threaded it through to vLLM. Not sure if this is how you’d want it done.

KL mismatch went from 0.055 before to 0.0006 with GPT-OSS-20b. I didn't test deepseek.

@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Oct 13, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 13, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/rl
  • ciflow/fake-pg

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@felipemello1

Copy link
Copy Markdown
Contributor

thanks for the pr @haydn-jones! We will review it.

If you are using GPT-OSS, there a few things you have to be aware:

  1. freeze bias/router: [rl] RL model defaults in every run: fp32 lm_head, frozen MoE expert bias and router gate #5271
  2. For perf, take a look at this stack: [gpt_oss][perf] Add expert biases with a gather and a one-hot GEMM backward #5192
  3. Ask your agent to sanity check if the attn kernels you are using for your hardware are fast. There may be a large difference between cudnn, flag attn, flash-infer for fwd+bwd/prefill/decode

Sorry that those are not merged yet. We have been mostly focused on qwen 35B MoE. This model is more optimized and tested if you are interested.

Feel free to shoot an email if you want to chat at some point and share more about the work you are doing / features you are looking for [email protected]

@wwwjn wwwjn self-assigned this Oct 13, 2026

@wwwjn wwwjn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch, please address nit comments. And maybe add a note

rope: RoPE.Config

@property
def softmax_scale(self) -> float:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So if we don't set vllm parameter scale=attention_cfg.softmax_scale,, vllm will use the default property scale that we set here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, the explicit scale=attention_cfg.softmax_scale forwarding is necessary, otherwise the wrapper uses head_dim**-0.5.

@@ -85,6 +85,7 @@ def _replace_vllm_layer_configs(model_config):
num_kv_heads=num_kv_heads,
head_dim=head_dim,
value_head_dim=value_head_dim,
scale=attention_cfg.softmax_scale,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would this line raise error if a model doesn't have softmax_scale property?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's set to return None by default so models without their own override inherit it.

class Attention(Module):
inner_attention: InnerAttention
@dataclass(kw_only=True, slots=True)
class Config(Module.Config):
n_heads: int
inner_attention: InnerAttention.Config
@property
def softmax_scale(self) -> float | None:
"""None selects the attention backend's default scale."""
return None

@haydn-jones
haydn-jones force-pushed the fix/attention-softmax-scale branch from 1807b70 to b4beb43 Compare October 17, 2026 01:48
@tianyu-l
tianyu-l requested a review from wwwjn October 17, 2026 03:43
@tianyu-l
tianyu-l merged commit 8a3f5bc into pytorch:main Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants