Skip to content

[rl] add window FIFO scheduling - #3927

Merged
acisseJZhong merged 40 commits into
mainfrom
gh/acisseJZhong/22/head
Jul 25, 2026
Merged

acisseJZhong merged 40 commits into
mainfrom
gh/acisseJZhong/22/head

Conversation

@acisseJZhong

@acisseJZhong acisseJZhong commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Motivation for window FIFO

reference: minimax paper section 6.2.4 of https://arxiv.org/pdf/2605.26494

Strict FIFO gives the strongest freshness guarantee, but it also creates head-of-line blocking: one slow rollout group at the front of the buffer can prevent newer finalized groups from being trained, even when those groups are still within the allowed offpolicy budget.

Windowed FIFO relaxes strict ordering only within a bounded look-ahead window. This lets the trainer consume ready prompt groups sooner, improving training pipeline utilization, while still preserving an explicit hard freshness bound via max_offpolicy_steps.

Changes introduced by this PR:

  • We let user provide target_offpolicy_steps and max_offpolicy_steps they can tolerate for the extra performance.
  • Derive that window_size= min(buffer_size, num_prompts_per_train_step * (max_off_policy_steps - off_policy_steps) + 1).
  • Keep the window anchored at the oldest prompt group and greedily consumes finalized groups within that window.

Todos:

  • Add a knob to enable prompt group dropping in case the first prompt group within the window wait for too long.
  • Enable trainer microbatch overlapping + dynamically adjusting the window size to include more prompt groups that we can tolerate while still honoring max_offpolicy_steps. @felipemello1

How it works

Symbols used below:

  • P: num_prompts_per_train_step
  • S: target_offpolicy_steps, the target mean offpolicy steps used for active buffer capacity
  • M: max_offpolicy_steps, the maximum consume-time offpolicy steps tolerated
  • B: active buffer size in prompt groups, B = (S + 1) * P
  • W: FIFO look-ahead window size, derives W = P * (M - S) + 1

We let user provide offpolicy_steps(S) and window_fifo_fraction(f).
From the window FIFO formula(see more in the attached graph), we know

B = (S + 1) * P
W = floor(f * B)
M = (B + W - 2) // P

image

Testing on DAPO math task

python -m torchtitan.experiments.rl.train --module dapo_math --config rl_dapo_qwen3_4b_math_8k --dump_folder outputs/rl/dapo_math_$(date +%Y%m%d-%H%M%S)

wait for train batch time on average from ~37s -> ~22s, first step wait for train batch time ~100s -> ~27s. Reward on par.
image
image

[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 16, 2026
[ghstack-poisoned]
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 16, 2026
ghstack-source-id: 4577e70
Pull-Request: #3927
@acisseJZhong acisseJZhong changed the title add window FIFO [rl] add window FIFO scheduling Jul 16, 2026
@acisseJZhong
acisseJZhong requested review from felipemello1 and tianyu-l and removed request for tianyu-l July 16, 2026 07:22
[ghstack-poisoned]
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 18, 2026
ghstack-source-id: 16b012e
Pull-Request: #3927

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

Let's do direction alignment before worrying about code. Having some examples / picture illustrations would be helpful.

[ghstack-poisoned]
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 20, 2026
ghstack-source-id: f352382
Pull-Request: #3927
[ghstack-poisoned]
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 20, 2026
ghstack-source-id: 89daf77
Pull-Request: #3927
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 20, 2026
ghstack-source-id: a0ad359
Pull-Request: #3927
acisseJZhong added a commit that referenced this pull request Jul 21, 2026
ghstack-source-id: a0ad359
Pull-Request: #3927
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 21, 2026
ghstack-source-id: c7adf73
Pull-Request: #3927
Comment thread torchtitan/experiments/rl/controller.py Resolved
Comment thread torchtitan/experiments/rl/controller.py Resolved
Comment thread torchtitan/experiments/rl/controller.py Resolved
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 23, 2026
ghstack-source-id: 1244735
Pull-Request: #3927
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 23, 2026
ghstack-source-id: ba2702f
Pull-Request: #3927
@acisseJZhong

acisseJZhong commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor Author

acisseJZhong added a commit that referenced this pull request Jul 23, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0)
(oldest at bottom):
* #3927
* __->__ #3926

Rename only, no behavior change.

## RL terminology renames
Clarify prompt-vs-microbatch / sample terminology across the RL
experiment:

* `num_groups_per_train_step` -> `num_prompts_per_train_step`
* `group_size` -> `num_samples_per_prompt`
* method `_take_groups_for_train_step` -> `_take_groups`
* Propagate to all call sites, example configs, docstrings/diagrams, and
tests.

---------

Co-authored-by: JessicaZhong <[email protected]>

@felipemello1 felipemello1 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.

Great PR! Its funny how the changes in the buffer are so simple after such a long discussion.

IMO, we still have some work to do on documentation. It took us several days to align, and it will be hard for new users to digest whats going on. I think that we need to take it easy on the jargon, and make very clear WHY we are doing it.

Also, some comments on variables names.

Sorry for blocking it. Thanks for getting the PR to the finish line!

Comment on lines +97 to +102
if not 1 <= window_size <= max_active_rollout_groups:
raise ValueError(
"window_size must be between 1 and max_active_rollout_groups, got "
f"window_size={window_size}, "
f"max_active_rollout_groups={max_active_rollout_groups}"
)

@felipemello1 felipemello1 Jul 23, 2026 •

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.

i havent read the rest of the code, but this is a bit confusing, since before it says that the fraction is what its set...

"The controller defaults
to strict FIFO (window_size=1) unless windowed_fifo_fraction is set."

I guess some other function calculates and passes it? Should we rename it to _window_size, so its clear that its not directly defined by the user?

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.

window_size is a derived property in AsyncLoopConfig class, and we pass into the buffer. The buffer stores this as _window_size.

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.

should we pass it as _window_size directly, so its evident that the user doesnt need to define it?

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.

Personally I feel it's fine? I rarely see people pass in private variables as a function argument? also users don't need to construct the work buffer themselves. Similarly, the max_active_rollout_groups is also derived.

from codex:
No. A leading underscore on a parameter implies a private or ignored argument, not a derived value.

The current separation is clear:

  • User configures window_fraction.
  • AsyncLoopConfig.window_size derives the size.
  • RolloutGroupWorkBuffer receives window_size.
  • The buffer stores it internally as _window_size.

Comment thread torchtitan/experiments/rl/controller.py Resolved
Comment thread torchtitan/experiments/rl/controller.py Resolved
Comment on lines +208 to +217
if (
self.windowed_fifo_fraction is not None
and self.windowed_fifo_fraction * self.max_active_rollout_groups < 1
):
warnings.warn(
f"windowed_fifo_fraction={self.windowed_fifo_fraction} is too small for "
f"active_buffer_size={self.max_active_rollout_groups}; forcing "
"window_size=1 (strict FIFO)",
stacklevel=2,
)

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.

we can delete it. We can just enforce later that window_size = max(1, window_size). LEts save some lines of code.

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.

edit: you already do it on line 240. Lets delete it.

@acisseJZhong acisseJZhong Jul 24, 2026 •

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.

I thought it would be useful for letting user know that the window_fifo_fraction they set are "useless" and they are still doing strict FIFO? wdyt

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.

hmmm, thats a good idea, but we would have to change this code. As it is today, windowed FIFO is only really useful if window > groups_pet_step.

what if we always logged the calculated window + extra off_policy?

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 actually if you look at the proof of max offpolicy bounds in the readme, we longer hold the assumption that window size > P. The formula should hold regardless.

For logging, I agree we need to add more informative loggings, after we do more experiments. I feel some of the logging names are confusing to me. We can do some cleanup as a follow up PR?

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.

for logging, what i mean here is a simple "logger.info("Window size ...., max_off_policy ...")

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.

added this one line logging.

Comment thread torchtitan/experiments/rl/controller.py Resolved
[ghstack-poisoned]
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 24, 2026
ghstack-source-id: cd8bd12
Pull-Request: #3927
acisseJZhong added a commit that referenced this pull request Jul 24, 2026
ghstack-source-id: cd8bd12
Pull-Request: #3927
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 24, 2026
ghstack-source-id: 4853525
Pull-Request: #3927
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 24, 2026
ghstack-source-id: 1afea2e
Pull-Request: #3927
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 24, 2026
ghstack-source-id: 3be661d
Pull-Request: #3927
this target, up to `max_offpolicy_steps`. See
``torchtitan/experiments/rl/docs/windowed_fifo.md`` for details."""

window_fraction: float | None = 0.3

@tianyu-l tianyu-l Jul 24, 2026 •

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.

window_fraction is ambiguous. Do you mean windowed_fifo_window_fraction or WindowedFifoConfig.window_fraction?

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.

originally we had

window_size
window_fifo_fraction

from @felipemello1 who thinks we should unify the naming of these two.

so options could be:
lookahead_window_size
lookahead_buffer_fraction

or

window_fifo_size
window_fifo_buffer_fraction

I feel both options doesn't sounds right.

I am okay with what we had before. But to address Felipe's concern, I changed to window_size and window_fraction.

Let me know what you guys prefer.

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.

lets go with window_fifo_buffer_fraction. Its the most literal thing. It contains the algorithm name "windowed fifo", and says what its a "fraction" of.

@tianyu-l tianyu-l Jul 25, 2026 •

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.

  • it's "windowed fifo", not "window fifo"
  • what is "buffer" referring to? We are not even calling the WorkBuffer "buffer"

If you are OK, let's go with the simplest window_fraction? I have a feeling that we'll deprecate this field any way, hopefully soon.

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.

If you are OK, let's go with the simplest window_fraction? I have a feeling that we'll deprecate this field any way, hopefully soon.

IMO, as a new reader, its not intuitive what either "window" or "fraction" are referring to. But, if both of you think its better, then its fine.

Comment on lines +25 to +33
- `S`: target offpolicy steps (`target_offpolicy_steps`)
- `f`: fraction of the active buffer visible to the scheduler (`window_fraction`), which defaults to `0.3` following the MiniMax paper

Given `P` prompt groups per train step, the controller derives:

```text
B = (S + 1) * P
W = max(1, floor(f * B))
```

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.

can we spell all variables? i dont think that we gain much by using B, S, W, f, B, P. It makes it harder for the reader.

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.

for example, "Let S = 1, P = 3, and f = 0.5, which gives B = 6 and W = 3. Groups 0, 1, 3, 4, and 5 finish quickly, but group 2 is slow:"

this could be read naturally, as plain english, but because of the letters, users have to go back and read what each letter means.

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.

the symbol is introduced for easier derivation of the math proof below. For the example illustration, I expanded using natural language.


Given a window size `W`, we can calculate the worst-case extra offpoliciness it introduces. Consider a slow target group `g` that was admitted at the back of a full active buffer:

1. The trainer consumes all `B - 1` older groups ahead of `g`.

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.

Suggested change
1. The trainer consumes all `B - 1` older groups ahead of `g`.
1. The trainer consumes all `B - 1` older groups before `g`.


Given a window size `W`, we can calculate the worst-case extra offpoliciness it introduces. Consider a slow target group `g` that was admitted at the back of a full active buffer:

1. The trainer consumes all `B - 1` older groups ahead of `g`.

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.

why B-1? before you were using B for buffer size "B = (S + 1) * P", but now it seems to be batch size? we should also avoid the word batch, since we use "num_prompt_per_step"

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.

B always mean buffer size. updated in the notation section.

Given a window size `W`, we can calculate the worst-case extra offpoliciness it introduces. Consider a slow target group `g` that was admitted at the back of a full active buffer:

1. The trainer consumes all `B - 1` older groups ahead of `g`.
2. Because `B - 1 = S * P + (P - 1)`, this completes `S` train steps and leaves the next batch one group short.

@felipemello1 felipemello1 Jul 24, 2026 •

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.

this formula is not obvious. Do we need it? I think that we could even delete 1,2,3 here and the doc would be fine.

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.

why B - 1 = S * P + (P - 1) is not obvious? B = (S + 1) * P

1. The trainer consumes all `B - 1` older groups ahead of `g`.
2. Because `B - 1 = S * P + (P - 1)`, this completes `S` train steps and leaves the next batch one group short.
3. Group `g`, which would complete that batch, stalls.
4. The trainer consumes all `W - 1` younger groups that may bypass `g` before the anchored window blocks again.

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.

Suggested change
4. The trainer consumes all `W - 1` younger groups that may bypass `g` before the anchored window blocks again.
4. The trainer consumes all `W - 1` younger groups ahead of `g`within the window.

Comment on lines +208 to +217
if (
self.windowed_fifo_fraction is not None
and self.windowed_fifo_fraction * self.max_active_rollout_groups < 1
):
warnings.warn(
f"windowed_fifo_fraction={self.windowed_fifo_fraction} is too small for "
f"active_buffer_size={self.max_active_rollout_groups}; forcing "
"window_size=1 (strict FIFO)",
stacklevel=2,
)

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.

for logging, what i mean here is a simple "logger.info("Window size ...., max_off_policy ...")

Comment on lines +230 to +239
Symbols:
``P``: prompts per train step (``num_prompts_per_train_step``).
``S``: target steady-state offpolicy steps (``target_offpolicy_steps``).
``f``: fraction of the active buffer visible to windowed FIFO
(``window_fraction``).
``B``: active buffer size in prompt groups, ``B = (S + 1) * P``.

Returns:
The FIFO look-ahead window size, ``max(1, floor(f * B))``. A value
of 1 is strict FIFO.

@felipemello1 felipemello1 Jul 24, 2026 •

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.

i still dont see why we need all the symbols. Window size is just buffer_size * window_fraction.

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 helps below? to understand max_offpolicy_steps

Comment on lines +252 to +254
For active buffer size ``B``, window size ``W``, and prompts per
train step ``P``, the bound is ``(B + W - 2) // P``.

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.

Suggested change
For active buffer size ``B``, window size ``W``, and prompts per
train step ``P``, the bound is ``(B + W - 2) // P``.

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.

why deleting? I think it provides a nice illustration/explanation.

Comment on lines +75 to +95
```text
consumed_before = B - 1
consumed_after = W - 1
total_consumed = consumed_before + consumed_after = B + W - 2
```

Each train step consumes `P` groups, so the maximum age of `g` at consumption is:

```text
max_offpolicy_steps = (B + W - 2) // P
```

Substituting `B = (S + 1) * P` gives:

```text
max_offpolicy_steps
= floor(((S + 1) * P + W - 2) / P)
= floor(S + (P + W - 2) / P)
= S + floor(((W - 1) + (P - 1)) / P)
= S + ceil((W - 1) / P)
```

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.

Its funny that this works, but it is also wrong.

you are doing total_consumed = consumed_before + consumed_after = B + W - 2

Its not B. Its P. The worst case scenario is NOT when the last prompt of the buffer stalls.
The owrst case scenario is when the last prompt of a batch P stalls.

It should be:

P+W-2

Then the formula is:

max_offpolicy_steps = target_off_polocy + extra_off_policy
= S + (P + W - 2) // P

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.

(P+W-2)//P is extra off policy and (B + W - 2) // P is max off policy steps. I don't think it's wrong, and they don't conflict.

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.

S + (P + W - 2) // P = S + 1 + (W - 1) // P = S + 1 + floor((W - 1) / P)

but @acisseJZhong has S + ceil((W - 1) / P)

without reading the proof, one of them is wrong

@felipemello1 felipemello1 Jul 25, 2026 •

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.

@tianyu-l your 2nd step is wrong. You are doing -1 instead of -2.

S + 1 + (W - 2) // P = 1 + floor((W - 2) / P) == ceil((W - 1) / P)

Example: W=4, P=3:
1 + floor(2/3) = 1
ceil(3/3) = 1

But still, the concept is a bit unnatural IMO as presented.

The worst case is when i have, for example P=8
then i consume the 7 before me
i stall on the 8th, and then consume the window ahead of me.

So the formula is:
extra_policy_steps = (consumed_before + consumed_ahead) // P
max_off_policy = target_off_policy + extra_policy_steps

but the way currently presented, it says:
the worst case is when i consume the entire buffer
stall on the last example
then consume the window ahead.

max_off_policy = B-1 + W-1

Now i see why she called it max_off_policy, instead of extra_policy_steps, but it feels unnatural to me to frame it this way. It only works because B is a multiple of P.

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.

wdym by it only works because B is a multiple of P? I think max_offpolicy_steps = (B + W - 2) // P = S + ceil((W - 1) / P) holds without any constraints. This is the whole point of what the last section of the readme is trying to prove?

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.

Its not B. Its P. The worst case scenario is NOT when the last prompt of the buffer stalls.
The owrst case scenario is when the last prompt of a batch P stalls.

I don't agree with this.
image
see this example, worst case is that all the eight groups generated by policy 0 are in the buffer and group 7 stalls.

@felipemello1 felipemello1 Jul 25, 2026 •

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.

wdym by it only works because B is a multiple of P? I think max_offpolicy_steps = (B + W - 2) // P = S + ceil((W - 1) / P) holds without any constraints.

We define B = (S + 1)P, so B must be a multiple of P.

For arbitrary B = qP + r:

floor((B + W - 2) / P)
= q + floor((r + W - 2) / P)

The remainder r determines how many bypasses complete the partial batch.

To the limit: Imagine the buffer is infinite, and we just drop samples when they get too old.
The logic is not about the size of buffer.

The logic, as I see it, is about:

  • We consume P-1, just shy of a new train step
  • Then we consume the window ahead.

In other words: Pth_example_policy_version + How many extra train steps will happen ahead of the Pth example


I will leave it up to you and we can revisit when we follow up with the work where we drop old samples and expand the buffer to oversample.

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.

The logic, as I see it, is about:

We consume P-1, just shy of a new train step
Then we consume the window ahead.

I agree with this, but this(P+W-2) is how many extra off policy steps. B+W-2 is how many max off policy steps. They don't conflict.

I don't agree with the statement that the math works because of B is a multiple of P(although B is multiple of P in reality), if that's what you are trying to say?

Anyways, I believe we should be on the same page now?

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.

follow up with the work where we drop old samples

I didn't think too much but i feel like if we drop old samples, or if enable trainer microabtch overlap, then max offpolicy steps won't be nicely derived as a formula of B and W. It will vary depends on the actual runtime behavior. Therefore the code will become very different.

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.

@felipemello1

your 2nd step is wrong. You are doing -1 instead of -2.

sorry my derivation was wrong.

Each train step consumes `P` groups, so the maximum age of `g` at consumption is:

```text
max_offpolicy_steps = (B + W - 2) // P

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.

Suggested change
max_offpolicy_steps = (B + W - 2) // P
extra_offpolicy_steps = (B + W - 2) // P

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.

we used max_offpolicy_steps for all the rest of places.

# LICENSE file in the root directory of this source tree.

"""Run-ahead buffer of RolloutGroupWork shared between the data-input, rollout, and batcher loops.
"""Active work buffer shared between the data-input, rollout, and batcher loops.

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.

Suggested change
"""Active work buffer shared between the data-input, rollout, and batcher loops.
"""Buffer of `RolloutGroupWork` shared between the data-input, rollout, and batcher loops.

I want to avoid adding "active" -- its confusing. I added this nomenclature, but now that i read it, its not obvious what active means


## Strict FIFO

The simplest scheduling policy is strict FIFO: always consume the oldest prompt group before any younger group. With `P` prompt groups per train step and a target of `S` offpolicy steps, the active buffer holds `B = (S + 1) * P` groups. Strict FIFO keeps every group within the target bound because at most `B - 1` older groups can be consumed first.

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.

Suggested change
The simplest scheduling policy is strict FIFO: always consume the oldest prompt group before any younger group. With `P` prompt groups per train step and a target of `S` offpolicy steps, the active buffer holds `B = (S + 1) * P` groups. Strict FIFO keeps every group within the target bound because at most `B - 1` older groups can be consumed first.
The simplest scheduling policy is strict FIFO: always consume the oldest prompt group before any younger group. With `P` prompt groups per train step and a target of `S` offpolicy steps, the buffer holds `B = (S + 1) * P` groups. Strict FIFO keeps every group within the target bound because at most `B - 1` older groups can be consumed first.

The user configures:

- `S`: target offpolicy steps (`target_offpolicy_steps`)
- `f`: fraction of the active buffer visible to the scheduler (`window_fraction`), which defaults to `0.3` following the MiniMax paper

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.

Suggested change
- `f`: fraction of the active buffer visible to the scheduler (`window_fraction`), which defaults to `0.3` following the MiniMax paper
- `f`: fraction of the buffer visible to the scheduler (`window_fraction`), which defaults to `0.3` following the MiniMax paper

## Reference configurations

Both configurations run 150 optimizer steps on one eight-GPU node. One TP=2 trainer uses two GPUs, and six independent TP=1 generators use the remaining GPUs. Each optimizer step consumes 8 prompt groups with 16 completions per group. `max_offpolicy_steps=4` bounds policy lag.
Both configurations run 150 optimizer steps on one eight-GPU node. One TP=2 trainer uses two GPUs, and six independent TP=1 generators use the remaining GPUs. Each optimizer step consumes 8 prompt groups with 16 completions per group. `target_offpolicy_steps=4` sizes the active buffer.

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.

Suggested change
Both configurations run 150 optimizer steps on one eight-GPU node. One TP=2 trainer uses two GPUs, and six independent TP=1 generators use the remaining GPUs. Each optimizer step consumes 8 prompt groups with 16 completions per group. `target_offpolicy_steps=4` sizes the active buffer.
Both configurations run 150 optimizer steps on one eight-GPU node. One TP=2 trainer uses two GPUs, and six independent TP=1 generators use the remaining GPUs. Each optimizer step consumes 8 prompt groups with 16 completions per group. `target_offpolicy_steps=4` sizes the `RolloutGroupWorkBuffer`.

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 25, 2026
ghstack-source-id: d89f260
Pull-Request: #3927
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Jul 25, 2026
ghstack-source-id: bbfae1e
Pull-Request: #3927
@acisseJZhong
acisseJZhong changed the base branch from gh/acisseJZhong/22/base to main July 25, 2026 04:47
@acisseJZhong
acisseJZhong merged commit fd27765 into main Jul 25, 2026
18 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu 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