Skip to content

[Llama] Add scaled RoPE support for Llama 3 and 4 - #1839

Merged
tianyu-l merged 2 commits into
pytorch:mainfrom
shuhuayu:modeldev
Oct 9, 2025
Merged

tianyu-l merged 2 commits into
pytorch:mainfrom
shuhuayu:modeldev

Conversation

@shuhuayu

@shuhuayu shuhuayu commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor

Llama 3.1 models use scaled RoPE by default, and Llama 4 17B x 16E uses scaled RoPE while 17B x 128E does not.

  1. Verified forward parity between Titan Llama 3.1 8B and HuggingFace Llama 3.1 8B. The KL divergence of outputs from the same sample inputs is small.
    llama 3 8b forward parity small

    For comparison, before adding scaled RoPE support, the forward parity check on the Llama 3.1 8B model incurred a slightly larger KL divergence on sample inputs.
    llama 3 8b forward parity without scaled rope

  2. Verified training of Llama 3.1 8B with tensor parallel degree = 4.
    llama 3-1 8b training tp=4

  3. Verified training of Llama 4 debug model with scaled RoPE.
    llama 4 debug model training

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 8, 2025

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

Thanks! Looks good in general. I left some comments.

Verified forward parity between Titan Llama 3.1 8B and HuggingFace Llama 3.1 8B. The KL divergence of outputs from the same sample inputs is small.

Would be good to show before vs. after. IIRC previously the difference is already very small.

Comment thread torchtitan/models/llama3/model/model.py Resolved

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

Looks very good. Had one more nit comment.

Comment thread torchtitan/models/llama3/model/model.py Resolved
@tianyu-l
tianyu-l merged commit 5bbda42 into pytorch:main Oct 9, 2025
githubsgi pushed a commit to githubsgi/torchtitan that referenced this pull request Oct 13, 2025
Llama 3.1 models use scaled RoPE by default, and Llama 4 17B x 16E uses
scaled RoPE while 17B x 128E does not.

1. Verified forward parity between Titan Llama 3.1 8B and HuggingFace
Llama 3.1 8B. The KL divergence of outputs from the same sample inputs
is small.
![llama 3 8b forward parity
small](https://github.com/user-attachments/assets/891df89b-006f-4ed0-a68a-36e939d2169b)

For comparison, before adding scaled RoPE support, the forward parity
check on the Llama 3.1 8B model incurred a slightly larger KL divergence
on sample inputs.
![llama 3 8b forward parity without scaled
rope](https://github.com/user-attachments/assets/9a68357a-34d4-497f-977f-27cc548d8f62)

2. Verified training of Llama 3.1 8B with tensor parallel degree = 4.
![llama 3-1 8b training
tp=4](https://github.com/user-attachments/assets/a8b1ab10-0da0-4d02-afbb-a775716beaa3)

3. Verified training of Llama 4 debug model with scaled RoPE.
![llama 4 debug model
training](https://github.com/user-attachments/assets/1fbf8939-31a5-475f-987c-d5bcf6d2376b)
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
Llama 3.1 models use scaled RoPE by default, and Llama 4 17B x 16E uses
scaled RoPE while 17B x 128E does not.

1. Verified forward parity between Titan Llama 3.1 8B and HuggingFace
Llama 3.1 8B. The KL divergence of outputs from the same sample inputs
is small.
![llama 3 8b forward parity
small](https://github.com/user-attachments/assets/891df89b-006f-4ed0-a68a-36e939d2169b)

For comparison, before adding scaled RoPE support, the forward parity
check on the Llama 3.1 8B model incurred a slightly larger KL divergence
on sample inputs.
![llama 3 8b forward parity without scaled
rope](https://github.com/user-attachments/assets/9a68357a-34d4-497f-977f-27cc548d8f62)

2. Verified training of Llama 3.1 8B with tensor parallel degree = 4.
![llama 3-1 8b training
tp=4](https://github.com/user-attachments/assets/a8b1ab10-0da0-4d02-afbb-a775716beaa3)

3. Verified training of Llama 4 debug model with scaled RoPE.
![llama 4 debug model
training](https://github.com/user-attachments/assets/1fbf8939-31a5-475f-987c-d5bcf6d2376b)
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
Llama 3.1 models use scaled RoPE by default, and Llama 4 17B x 16E uses
scaled RoPE while 17B x 128E does not.

1. Verified forward parity between Titan Llama 3.1 8B and HuggingFace
Llama 3.1 8B. The KL divergence of outputs from the same sample inputs
is small.
![llama 3 8b forward parity
small](https://github.com/user-attachments/assets/891df89b-006f-4ed0-a68a-36e939d2169b)

For comparison, before adding scaled RoPE support, the forward parity
check on the Llama 3.1 8B model incurred a slightly larger KL divergence
on sample inputs.
![llama 3 8b forward parity without scaled
rope](https://github.com/user-attachments/assets/9a68357a-34d4-497f-977f-27cc548d8f62)

2. Verified training of Llama 3.1 8B with tensor parallel degree = 4.
![llama 3-1 8b training
tp=4](https://github.com/user-attachments/assets/a8b1ab10-0da0-4d02-afbb-a775716beaa3)

3. Verified training of Llama 4 debug model with scaled RoPE.
![llama 4 debug model
training](https://github.com/user-attachments/assets/1fbf8939-31a5-475f-987c-d5bcf6d2376b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants