Repository navigation
[rl] batch invariant mode under same parallelism - #2683
Merged
Merged
Conversation
Contributor
Author
|
Need to rebase onto #2649 and clean up the varlen patch in trainer side in this PR |
wwwjn
force-pushed
the
rl-batch-invariant
branch
from
March 26, 2026 22:15
254d3da to
c69a7ac
Compare
wwwjn
commented
Mar 26, 2026
wwwjn
marked this pull request as ready for review
March 27, 2026 16:10
wwwjn
requested review from
Lucaskabela,
acisseJZhong,
daniellepintz,
felipemello1 and
joecummings
March 27, 2026 16:12
Lucaskabela
reviewed
Mar 27, 2026
Lucaskabela
left a comment
Contributor
There was a problem hiding this comment.
Can we rebase on #2649 to see what these changes look like post rebase?
wwwjn
force-pushed
the
rl-batch-invariant
branch
from
March 30, 2026 20:03
55d4280 to
ee39957
Compare
tianyu-l
requested changes
Mar 30, 2026
wwwjn
force-pushed
the
rl-batch-invariant
branch
from
March 31, 2026 23:30
35eb9ea to
f52e7f2
Compare
tianyu-l
reviewed
Apr 1, 2026
tianyu-l
reviewed
Apr 1, 2026
tianyu-l
reviewed
Apr 1, 2026
tianyu-l
reviewed
Apr 1, 2026
wwwjn
commented
Apr 1, 2026
wwwjn
commented
Apr 1, 2026
tianyu-l
reviewed
Apr 1, 2026
tianyu-l
reviewed
Apr 1, 2026
wwwjn
force-pushed
the
rl-batch-invariant
branch
from
April 6, 2026 18:58
80e97da to
0cc91e2
Compare
TXacs
pushed a commit
to McmillanTAC/torchtitan
that referenced
this pull request
Apr 13, 2026
## What changed
- Currently only support both trainer and generator using bfloat16.
(working on consolidating the details of dtype conversion, but currently
FA3 kernel only support bf16/f16)
- Tested with compile("eager") and cudagraph("piecewise"), the bitwise
identity are still preserved.
## Test
TP=2 on both trainer and generator:
- Verified after enabling batch-invariant mode, run-to-run deterministic
is also so enabled as prerequisite .
```
[actor=<root>] Eval: Accuracy=20% (4/20) Format=20% (4/20)
[actor=<root>] ================================================================================
[actor=<root>] Starting RL training for 10 steps
[actor=<root>] ================================================================================
[actor=<root>] Weight sync: push=0.198s, total=0.827s
[actor=<root>] Step 0 | Loss: -0.0041 | Reward: -0.100 | Correct: 18/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 52.1s
[actor=<root>] Weight sync: push=0.203s, total=0.400s
[actor=<root>] Step 1 | Loss: -0.0047 | Reward: -0.350 | Correct: 13/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.8s
[actor=<root>] Weight sync: push=0.197s, total=0.384s
[actor=<root>] Step 2 | Loss: -0.0067 | Reward: -0.300 | Correct: 14/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.6s
[actor=<root>] Weight sync: push=0.196s, total=0.414s
[actor=<root>] Step 3 | Loss: -0.0064 | Reward: -0.100 | Correct: 18/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.3s
[actor=<root>] Weight sync: push=0.204s, total=0.413s
[actor=<root>] Step 4 | Loss: -0.0084 | Reward: -0.400 | Correct: 12/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.7s
[actor=<root>] Weight sync: push=0.211s, total=0.413s
[actor=<root>] Step 5 | Loss: -0.0120 | Reward: +0.300 | Correct: 26/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.1s
[actor=<root>] Weight sync: push=0.186s, total=0.385s
[actor=<root>] Step 6 | Loss: -0.0051 | Reward: -0.350 | Correct: 13/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.6s
[actor=<root>] Weight sync: push=0.223s, total=0.426s
[actor=<root>] Step 7 | Loss: -0.0058 | Reward: -0.600 | Correct: 8/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.9s
[actor=<root>] Weight sync: push=0.206s, total=0.408s
[actor=<root>] Step 8 | Loss: -0.0075 | Reward: -0.250 | Correct: 15/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.5s
[actor=<root>] Weight sync: push=0.200s, total=0.402s
[actor=<root>] Step 9 | Loss: -0.0124 | Reward: +0.100 | Correct: 22/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.8s
[actor=<root>] RL Training complete
[actor=<root>] Evaluating post-training performance...
[actor=<root>] Eval: Accuracy=35% (7/20) Format=50% (10/20)
[actor=<root>] ================================================================================
[actor=<root>] Pre-training: Accuracy=20% (4/20) Format=20% (4/20)
[actor=<root>] Post-training: Accuracy=35% (7/20) Format=50% (10/20)
[actor=<root>] ================================================================================
```
## Config for bit-wise identity:
- RLTrainer.debug is set from config_registry. When
`batch_invariant_mode=True`, we check `deterministic` must be true, and
dtype on both trainer and generator needs to be `bfloat16` in
`__post__init`
- PolicyTrainer.debug is set by RLTrainer.debug
- PolicyTrainer model's inner_attn (VarlenAttention) has a
`batch_invariant` flag, this flag is set by PolicyTrainer
- Generator.debug is set by RLTrainer.debug
- Generator model's inner_attn (VLLMAttentionWrapper) enables
`batch_invariant` mode by checking `is_batch_invariant_mode_enabled()`
global variable.
## Attention Part
Attention changes (for both VarlenAttention in core torchtitan, and
VLLMAttentionWrapper in RL):
- If the hardware is Hopper, always use FA3 attention. If not, use FA2
for Blackwell hardware.
- If we are using FA3 attention, then batch-invariant is enabled by
setting `num_split=1`
- If we are using FA2 attention, batch-invariant is automatically
supported.
jemitche1
pushed a commit
to jemitche1/torchtitan
that referenced
this pull request
Apr 14, 2026
## What changed
- Currently only support both trainer and generator using bfloat16.
(working on consolidating the details of dtype conversion, but currently
FA3 kernel only support bf16/f16)
- Tested with compile("eager") and cudagraph("piecewise"), the bitwise
identity are still preserved.
## Test
TP=2 on both trainer and generator:
- Verified after enabling batch-invariant mode, run-to-run deterministic
is also so enabled as prerequisite .
```
[actor=<root>] Eval: Accuracy=20% (4/20) Format=20% (4/20)
[actor=<root>] ================================================================================
[actor=<root>] Starting RL training for 10 steps
[actor=<root>] ================================================================================
[actor=<root>] Weight sync: push=0.198s, total=0.827s
[actor=<root>] Step 0 | Loss: -0.0041 | Reward: -0.100 | Correct: 18/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 52.1s
[actor=<root>] Weight sync: push=0.203s, total=0.400s
[actor=<root>] Step 1 | Loss: -0.0047 | Reward: -0.350 | Correct: 13/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.8s
[actor=<root>] Weight sync: push=0.197s, total=0.384s
[actor=<root>] Step 2 | Loss: -0.0067 | Reward: -0.300 | Correct: 14/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.6s
[actor=<root>] Weight sync: push=0.196s, total=0.414s
[actor=<root>] Step 3 | Loss: -0.0064 | Reward: -0.100 | Correct: 18/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.3s
[actor=<root>] Weight sync: push=0.204s, total=0.413s
[actor=<root>] Step 4 | Loss: -0.0084 | Reward: -0.400 | Correct: 12/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.7s
[actor=<root>] Weight sync: push=0.211s, total=0.413s
[actor=<root>] Step 5 | Loss: -0.0120 | Reward: +0.300 | Correct: 26/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.1s
[actor=<root>] Weight sync: push=0.186s, total=0.385s
[actor=<root>] Step 6 | Loss: -0.0051 | Reward: -0.350 | Correct: 13/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.6s
[actor=<root>] Weight sync: push=0.223s, total=0.426s
[actor=<root>] Step 7 | Loss: -0.0058 | Reward: -0.600 | Correct: 8/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.9s
[actor=<root>] Weight sync: push=0.206s, total=0.408s
[actor=<root>] Step 8 | Loss: -0.0075 | Reward: -0.250 | Correct: 15/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.5s
[actor=<root>] Weight sync: push=0.200s, total=0.402s
[actor=<root>] Step 9 | Loss: -0.0124 | Reward: +0.100 | Correct: 22/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.8s
[actor=<root>] RL Training complete
[actor=<root>] Evaluating post-training performance...
[actor=<root>] Eval: Accuracy=35% (7/20) Format=50% (10/20)
[actor=<root>] ================================================================================
[actor=<root>] Pre-training: Accuracy=20% (4/20) Format=20% (4/20)
[actor=<root>] Post-training: Accuracy=35% (7/20) Format=50% (10/20)
[actor=<root>] ================================================================================
```
## Config for bit-wise identity:
- RLTrainer.debug is set from config_registry. When
`batch_invariant_mode=True`, we check `deterministic` must be true, and
dtype on both trainer and generator needs to be `bfloat16` in
`__post__init`
- PolicyTrainer.debug is set by RLTrainer.debug
- PolicyTrainer model's inner_attn (VarlenAttention) has a
`batch_invariant` flag, this flag is set by PolicyTrainer
- Generator.debug is set by RLTrainer.debug
- Generator model's inner_attn (VLLMAttentionWrapper) enables
`batch_invariant` mode by checking `is_batch_invariant_mode_enabled()`
global variable.
## Attention Part
Attention changes (for both VarlenAttention in core torchtitan, and
VLLMAttentionWrapper in RL):
- If the hardware is Hopper, always use FA3 attention. If not, use FA2
for Blackwell hardware.
- If we are using FA3 attention, then batch-invariant is enabled by
setting `num_split=1`
- If we are using FA2 attention, batch-invariant is automatically
supported.
ACharacterInASimulation
pushed a commit
to ACharacterInASimulation/torchtitan
that referenced
this pull request
Apr 21, 2026
## What changed
- Currently only support both trainer and generator using bfloat16.
(working on consolidating the details of dtype conversion, but currently
FA3 kernel only support bf16/f16)
- Tested with compile("eager") and cudagraph("piecewise"), the bitwise
identity are still preserved.
## Test
TP=2 on both trainer and generator:
- Verified after enabling batch-invariant mode, run-to-run deterministic
is also so enabled as prerequisite .
```
[actor=<root>] Eval: Accuracy=20% (4/20) Format=20% (4/20)
[actor=<root>] ================================================================================
[actor=<root>] Starting RL training for 10 steps
[actor=<root>] ================================================================================
[actor=<root>] Weight sync: push=0.198s, total=0.827s
[actor=<root>] Step 0 | Loss: -0.0041 | Reward: -0.100 | Correct: 18/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 52.1s
[actor=<root>] Weight sync: push=0.203s, total=0.400s
[actor=<root>] Step 1 | Loss: -0.0047 | Reward: -0.350 | Correct: 13/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.8s
[actor=<root>] Weight sync: push=0.197s, total=0.384s
[actor=<root>] Step 2 | Loss: -0.0067 | Reward: -0.300 | Correct: 14/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.6s
[actor=<root>] Weight sync: push=0.196s, total=0.414s
[actor=<root>] Step 3 | Loss: -0.0064 | Reward: -0.100 | Correct: 18/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.3s
[actor=<root>] Weight sync: push=0.204s, total=0.413s
[actor=<root>] Step 4 | Loss: -0.0084 | Reward: -0.400 | Correct: 12/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 46.7s
[actor=<root>] Weight sync: push=0.211s, total=0.413s
[actor=<root>] Step 5 | Loss: -0.0120 | Reward: +0.300 | Correct: 26/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.1s
[actor=<root>] Weight sync: push=0.186s, total=0.385s
[actor=<root>] Step 6 | Loss: -0.0051 | Reward: -0.350 | Correct: 13/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.6s
[actor=<root>] Weight sync: push=0.223s, total=0.426s
[actor=<root>] Step 7 | Loss: -0.0058 | Reward: -0.600 | Correct: 8/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.9s
[actor=<root>] Weight sync: push=0.206s, total=0.408s
[actor=<root>] Step 8 | Loss: -0.0075 | Reward: -0.250 | Correct: 15/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 44.5s
[actor=<root>] Weight sync: push=0.200s, total=0.402s
[actor=<root>] Step 9 | Loss: -0.0124 | Reward: +0.100 | Correct: 22/40 | Avg tokens: 100 | Logprob diff: mean=0.0000e+00, max=0.0000e+00 | Time: 47.8s
[actor=<root>] RL Training complete
[actor=<root>] Evaluating post-training performance...
[actor=<root>] Eval: Accuracy=35% (7/20) Format=50% (10/20)
[actor=<root>] ================================================================================
[actor=<root>] Pre-training: Accuracy=20% (4/20) Format=20% (4/20)
[actor=<root>] Post-training: Accuracy=35% (7/20) Format=50% (10/20)
[actor=<root>] ================================================================================
```
## Config for bit-wise identity:
- RLTrainer.debug is set from config_registry. When
`batch_invariant_mode=True`, we check `deterministic` must be true, and
dtype on both trainer and generator needs to be `bfloat16` in
`__post__init`
- PolicyTrainer.debug is set by RLTrainer.debug
- PolicyTrainer model's inner_attn (VarlenAttention) has a
`batch_invariant` flag, this flag is set by PolicyTrainer
- Generator.debug is set by RLTrainer.debug
- Generator model's inner_attn (VLLMAttentionWrapper) enables
`batch_invariant` mode by checking `is_batch_invariant_mode_enabled()`
global variable.
## Attention Part
Attention changes (for both VarlenAttention in core torchtitan, and
VLLMAttentionWrapper in RL):
- If the hardware is Hopper, always use FA3 attention. If not, use FA2
for Blackwell hardware.
- If we are using FA3 attention, then batch-invariant is enabled by
setting `num_split=1`
- If we are using FA2 attention, batch-invariant is automatically
supported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Test
TP=2 on both trainer and generator:
Config for bit-wise identity:
batch_invariant_mode=True, we checkdeterministicmust be true, and dtype on both trainer and generator needs to bebfloat16in__post__initbatch_invariantflag, this flag is set by PolicyTrainerbatch_invariantmode by checkingis_batch_invariant_mode_enabled()global variable.Attention Part
Attention changes (for both VarlenAttention in core torchtitan, and VLLMAttentionWrapper in RL):
num_split=1