Skip to content

[rl] simple rename changes - #3926

Merged
acisseJZhong merged 16 commits into
mainfrom
gh/acisseJZhong/21/head
Jul 23, 2026
Merged

acisseJZhong merged 16 commits into
mainfrom
gh/acisseJZhong/21/head

Conversation

@acisseJZhong

@acisseJZhong acisseJZhong commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

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

[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 acisseJZhong changed the title simple rename [rl] simple rename changes Jul 16, 2026
@acisseJZhong
acisseJZhong requested review from felipemello1 and tianyu-l and removed request for tianyu-l July 16, 2026 07:22

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

"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?

@acisseJZhong

acisseJZhong commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

My worry is that we have many other functions and classes named "group"

yeah I found that too :P I am not sure if we should refactor away the group concept at some point, as I personally think group is less commonly used, and num_prompts_per_train_step or num_samples_per_prompt is more intuitive.

I am fine leaving it for now.

[ghstack-poisoned]
[ghstack-poisoned]
"""

local_batch_size: int = 8
microbatch_size: int = 8

@tianyu-l tianyu-l Jul 18, 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 think

  • local_batch_size is 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.

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 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]
[ghstack-poisoned]
@acisseJZhong acisseJZhong changed the title [rl] simple rename changes [rl] simple rename changes + refactor batch config Jul 20, 2026
@acisseJZhong

Copy link
Copy Markdown
Contributor Author

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?

@felipemello1 I changed back most places to group_size as like you mentioned, there are already a lot of group concepts, e.g. run_group_rollouts, RolloutGroupWorkBuffer etc. For user facing config level, I kept num_samplers_per_prompt as I think user might not know what is a group up front.

User-facing config keeps num_samples_per_prompt — it's self-explanatory to someone writing a config (matches GRPO's "samples per prompt" intuition).
Internal group-handling code uses group_size — since those functions already speak in "groups," run_group_rollouts(group_id=..., group_size=...) reads consistently, and arithmetic like n_groups × group_size becomes obvious.

[ghstack-poisoned]
[ghstack-poisoned]
Comment thread torchtitan/config/configs.py Outdated

@dataclass(kw_only=True, slots=True)
class TrainingConfig:
batch: BatchConfig = field(default_factory=BatchConfig)

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

@acisseJZhong acisseJZhong Jul 22, 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.

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?

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

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

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

Comment thread torchtitan/config/configs.py Outdated
Comment on lines +34 to +36
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`)

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.

RL trainer doesn't have this field. What would this comment mean to users, and what if users set something?

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.

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.

@felipemello1 felipemello1 Jul 20, 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.

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?

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.

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
image

However I saw #3938. I haven't looked much into it, but I think it's one step more advanced than simply greedy packing.

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

@felipemello1

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.

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.

@acisseJZhong

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.

@wwwjn wwwjn Jul 21, 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.

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?

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

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

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.

wondering what is #3938 doing? From the title I thought it's implementing the algorithm of how you pack into [1, num_local_tokens]

[ghstack-poisoned]
Comment thread torchtitan/train.py Outdated
Comment on lines -33 to -45
# 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}")

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 this is in base .. could you rebase?

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.

yup done

[ghstack-poisoned]
@acisseJZhong acisseJZhong changed the title [rl] simple rename changes + refactor batch config [rl] simple rename changes Jul 22, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@acisseJZhong
acisseJZhong changed the base branch from gh/acisseJZhong/21/base to main July 23, 2026 21:37
@acisseJZhong
acisseJZhong merged commit 725b995 into main Jul 23, 2026
7 of 8 checks passed
@tianyu-l
tianyu-l deleted the gh/acisseJZhong/21/head branch July 23, 2026 22:18
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Jul 24, 2026
… 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.
@wwwjn

wwwjn commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@acisseJZhong it fails the RL integration test: https://github.com/pytorch/torchtitan/actions/runs/30046908251/job/89340113587 could you help fix? Thank you!

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.

5 participants