Skip to content

Added softmax_scale in attentions#2828

Open
Sirorezka wants to merge 9 commits into
PrimeIntellect-ai:mainfrom
Sirorezka:feat_attn_scalling
Open

Added softmax_scale in attentions#2828
Sirorezka wants to merge 9 commits into
PrimeIntellect-ai:mainfrom
Sirorezka:feat_attn_scalling

Conversation

@Sirorezka

@Sirorezka Sirorezka commented Jun 16, 2026

Copy link
Copy Markdown
  1. Added softmax_scale in attentions (+ring, ulysses)
  2. Refactored Attention function to split Q,K,V calculations and core attention call.
  3. Added possibility to use flash attentions for cases when batch>1 (non cp)
  4. Added tests on flash attention layer

This fix is required to later merge DeepSeek_V3 (#2681)


Note

High Risk
Touches the core transformer attention and distributed ring/Ulysses paths; wrong scaling or kernel routing would silently change training numerics across models.

Overview
Adds configurable attention scaling (AttentionConfig.scaling / softmax_scale) and threads it through flash varlen, padded flash, SDPA (scale=), ring FA3/FA4, and Ulysses so non-default scales (e.g. upcoming DeepSeek V3) stay consistent across kernels and CP patches.

Refactors flash/SDPA into FlashAttentionCore / SDPAAttentionCore (kernel + _attention_core) with FlashAttention / SDPAAttention owning Q/K/V projections—same hook point for ring/Ulysses _compute_attention overrides on model-specific classes.

Behavior change: when cu_seqlens is absent, flash now uses standard flash_attn_func on [bs, sl, nh, dim] (batch > 1 without CP); varlen remains bs == 1 only. Sliding window is driven via window_size_left on config/core.

Adds CUDA unit tests comparing FA2/3/4, ring varlen, Ulysses varlen, and sliding-window cores against SDPA (default and custom scale).

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

… attention with Q,K,V layers. Added tests for attentions.
Comment thread src/prime_rl/trainer/models/layers/attn.py
Comment thread src/prime_rl/trainer/models/layers/ring_attn.py
Comment thread src/prime_rl/trainer/models/layers/attn.py
Comment thread src/prime_rl/trainer/models/layers/attn.py Outdated

@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 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 3429290. Configure here.

Comment thread src/prime_rl/trainer/models/layers/ulysses_attn.py Outdated
@Sirorezka

Copy link
Copy Markdown
Author

I appreciate you're very busy, but I would be exceedingly grateful for your feedback on this pull request whenever you get a chance. Thank you! @samsja @mikasenghaas @S1ro1.

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.

1 participant