Skip to content

Keep Stable Audio 3 RoPE angles in fp32 - #14936

Open
gokay-ai wants to merge 1 commit into
huggingface:mainfrom
gokay-ai:fix-sa3-rope-fp32
Open

gokay-ai wants to merge 1 commit into
huggingface:mainfrom
gokay-ai:fix-sa3-rope-fp32

Conversation

@gokay-ai

@gokay-ai gokay-ai commented Oct 4, 2026

Copy link
Copy Markdown

Fixes #14934

Loading StableAudio3DiTModel with torch_dtype=bf16 or fp16 casts the persistent rotary_pos_emb.inv_freq buffer, and forward was building positions in that dtype. bf16 only keeps integers exact up to 256 (fp16 up to 2048), so on longer clips neighbouring audio latents shared a rotary angle.

The outer product is now computed in fp32, and _keep_in_fp32_modules keeps rotary_pos_emb in fp32 across from_pretrained(torch_dtype=...). A later .to(bf16) can still round the buffer itself; positions no longer collapse.

test_low_precision_rope_keeps_distinct_positions covers a ~2 min sequence in fp16 and bf16.

bf16 and fp16 loads cast the persistent inv_freq buffer and built
positions in that dtype, so neighbouring latents shared a rotary angle.
Compute the outer product in fp32 and keep rotary_pos_emb in fp32 on
from_pretrained.

Signed-off-by: GokayAI <60583610+gokay-ai@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 4, 2026 06:47

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added fixes-issue size/S PR with diff < 50 LOC models tests and removed size/S PR with diff < 50 LOC labels Oct 4, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StableAudio3DiTModel: loading with torch_dtype=bf16/fp16 collapses RoPE positions (arange built in inv_freq dtype)

2 participants