Repository navigation
[rl] simple rename changes - #3926
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
There was a problem hiding this comment.
great:
"local_batch_size → microbatch_size"
"_take_groups_for_train_step → _take_groups"
Regarding group->prompt:
num_groups_per_train_step → num_prompts_per_train_step
group_size → num_samples_per_prompt
My worry is that we have many other functions and classes named "group". For example, the "_take_groups", and the RolloutGroupWorkBuffer, etc. Another concern is people not being sure if 1 prompt = 1 group or 1 rollout. For now, i am thinking we should keep "group" in the name and write prompt in the description. Wdyt?
yeah I found that too :P I am not sure if we should refactor away the I am fine leaving it for now. |
[ghstack-poisoned]
| """ | ||
|
|
||
| local_batch_size: int = 8 | ||
| microbatch_size: int = 8 |
There was a problem hiding this comment.
I think
local_batch_sizeis here to align with pretraining on gradient accumulation. When PP is enabled, PP itself also does microbatching.- We would face the same confusion in Always Pre-Split Microbatches for PP #3856 (comment)
- We should refactor so that pretraining share the same
BatchConfig.
There was a problem hiding this comment.
I see, I originally thought local_batch_size should be per gpu micro_batch_size * grad_accum_steps and global_batch_size = local_batch_size * dp_size. So here technically we are setting micro_batch_size. And we can make PP micro_batch_size the same value.
Let me try to stick with local_batch_size to align with pretrain.
[ghstack-poisoned]
@felipemello1 I changed back most places to
|
[ghstack-poisoned]
|
|
||
| @dataclass(kw_only=True, slots=True) | ||
| class TrainingConfig: | ||
| batch: BatchConfig = field(default_factory=BatchConfig) |
There was a problem hiding this comment.
Let's put this into Dataloader config. We discussed earlier about removing TrainingConfig entirely, partly motivated by the weird code here https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/rl/models/vllm_wrapper.py#L252-L264
cc @wwwjn
There was a problem hiding this comment.
We should not put global_batch_size to Dataloader.Config, as data loader should only see local_batch_size and seq_len?
Claude told me
I would not move local_batch_size and seq_len to Dataloader.Config.
They are dataloader inputs, but not dataloader-owned concepts. seq_len is also used for model sizing/flops, RoPE/attention constraints, PP/TP/CP divisibility, validation, and RL packing.
Similarly later we get rid of batch dim, I imagine we should have num_global_tokens and num_local_tokens still living under training config?
@dataclass(kw_only=True, slots=True)
class BatchConfig:
num_local_tokens: int = 16384
"""Tokens per rank per forward/backward batch."""
num_global_tokens: int = -1
"""Tokens per optimizer step across data-parallel ranks."""
max_seq_len: int = 2048
"""Maximum sequence/context length for position and attention constraints."""
Also I don't understand how https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/rl/models/vllm_wrapper.py#L252-L264 could be solved by removing TrainingConfig, looks like the reason is model.parallelize() API requires parallelism config?
There was a problem hiding this comment.
We should not put global_batch_size to Dataloader.Config, as data loader should only see local_batch_size and seq_len?
That depends on if we are going to keep the global_batch_size config. E.g. we could replace it by grad_accumulation_steps and num_pp_microbatches.
I also don't think we need BatchConfig anymore, if we don't have a batch dimension anymore. A single num_tokens field would suffice.
I agree it doesn't have to be in Dataloader, because each iteration / microbatch may use different amount of num_tokens.
Also I don't understand how https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/rl/models/vllm_wrapper.py#L252-L264 could be solved by removing TrainingConfig, looks like the reason is model.parallelize() API requires parallelism config?
That was more referring to https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/decoder.py#L205 where update_from_config would assume a training field even when generator can call this function as well. Not a big issue today, but not elegant.
There was a problem hiding this comment.
why each iteration / microbatch may use different amount of num_tokens?
for now, let me revert all the batch config changes in this PR and only keep the RL rename changes then.
There was a problem hiding this comment.
why each iteration / microbatch may use different amount of num_tokens?
i think this doesn't need to be banned, but I don't have use case right now
| global_batch_size: int = -1 | ||
| """ | ||
| Global batch size (defaults to `training.local_batch_size * data-parallel degree`) | ||
| Global batch size (defaults to `batch.local_batch_size * data-parallel degree`) |
There was a problem hiding this comment.
RL trainer doesn't have this field. What would this comment mean to users, and what if users set something?
There was a problem hiding this comment.
in RL global_batch_size is not used at all. There will be no affect if users set it. The global batch size per train step is calculated by num_prompts_per_train_step * num_samples_per_prompt.
There was a problem hiding this comment.
by the way: I think we chatted about replacing [local_batch_size, pack_seq_len] with a single param num_tokens_per_microbatch'. Do we know if we can always do local_batch_size=1 and just pack to num_tokens_per_microbatch`? Is it a problem if "num_tokens_per_microbatch" is 1 million tokens long?
There was a problem hiding this comment.
yeah I think a better way is to expose num_tokens_per_microbatch and seq_len(the max seq len for this packed [1, seq_len] tensor), instead of local_batch_size and seq_len. It's exactly what skyrl also uses

However I saw #3938. I haven't looked much into it, but I think it's one step more advanced than simply greedy packing.
There was a problem hiding this comment.
by the way: I think we chatted about replacing [local_batch_size, pack_seq_len] with a single param num_tokens_per_microbatch'. Do we know if we can always do local_batch_size=1 and just pack to num_tokens_per_microbatch`? Is it a problem if "num_tokens_per_microbatch" is 1 million tokens long?
In the past, we need local_batch_size because PP would further do microbatching on top of it. Now with Sanket's change, I don't know if there are other reasons, other than
- we need a way to enforce longest sequences in the row doesn't surpass model max_seq_len limit. Today this is enforced by a restriction on the row's seq length (consisting packed sequences)
Is it a problem if "num_tokens_per_microbatch" is 1 million tokens long?
I also realized that our CP today always all-gather KV on the sequence dim, so making this dim long may not be most efficient. On the other hand, if local_batch_size > 1 is possible, then one probably shouldn't use CP.
There was a problem hiding this comment.
in RL global_batch_size is not used at all. There will be no affect if users set it. The global batch size per train step is calculated by num_prompts_per_train_step * num_samples_per_prompt.
I know this. My worry is that users don't know and would be confused.
There was a problem hiding this comment.
by the way: I think we chatted about replacing [local_batch_size, pack_seq_len] with a single param
num_tokens_per_microbatch'. Do we know if we can always do local_batch_size=1 and just pack tonum_tokens_per_microbatch`? Is it a problem if "num_tokens_per_microbatch" is 1 million tokens long?
@felipemello1 @acisseJZhong Do you mean we should let RL batcher goal on num_tokens_per_microbatch, instead of num_prompts_per_train_step? eg, when the batcher accumulated enough tokens, yield a batch with size [<no_matter_how_many_rows_packed>, seq_length]
No matter what is the goal of the batcher (the goal decided when to yield) , the generated train sample still need to have size [xxx, seq_len] , and seq_length need to be shorter than the model.seq_len?
#3938 is orthogonal to whatever the batcher goals on.
There was a problem hiding this comment.
no I think we still let user decide num_prompts_per_train_step and num_samples_per_prompt.
The difference is that now instead of saying local_batch_size and seq_len, we only expose num_local_tokens, each train batch will become [1, num_local_tokens](or [num_local_tokens, ] if we discard batch dim). This should strictly save us paddings compared to each batch being `[local_batch_size, seq_len].
There was a problem hiding this comment.
wondering what is #3938 doing? From the title I thought it's implementing the algorithm of how you pack into [1, num_local_tokens]
| # Give each run its own dump folder so it never resumes from / collides with a | ||
| # previous run's checkpoints. Skip when --dump_folder is set explicitly (then | ||
| # the user's exact path is honored, e.g. to resume a specific run). | ||
| dump_folder_overridden = any( | ||
| a == "--dump_folder" or a.startswith("--dump_folder=") for a in sys.argv[1:] | ||
| ) | ||
| if not dump_folder_overridden: | ||
| run_name = config_manager.config_name or "run" | ||
| timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") | ||
| # pyrefly: ignore [missing-attribute] | ||
| config.dump_folder = os.path.join(config.dump_folder, f"{run_name}-{timestamp}") | ||
| # pyrefly: ignore [missing-attribute] | ||
| logger.info(f"Dumping run artifacts to: {config.dump_folder}") |
There was a problem hiding this comment.
why this is in base .. could you rebase?
[ghstack-poisoned]
[ghstack-poisoned]
… kwargs into ezpz overlay pytorch#3926 renamed AsyncLoopConfig.num_groups_per_train_step -> num_prompts_per_train_step and group_size -> num_samples_per_prompt. Replayed the rename into the reason_agpt and alphabet_sort_agpt overlays (only the kwargs passed to AsyncLoopConfig; helper param names unchanged). AST-verified both overlays now pass exactly the merged AsyncLoopConfig fields. Without this the next GRPO run would TypeError.
|
@acisseJZhong it fails the RL integration test: https://github.com/pytorch/torchtitan/actions/runs/30046908251/job/89340113587 could you help fix? Thank you! |
Stack from ghstack (oldest at bottom):
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_stepgroup_size->num_samples_per_prompt_take_groups_for_train_step->_take_groups