Skip to content

[rl] Rename Batcher to TrainingBatchBuilder, TrainerStepBatch to TrainingBatch - #6423

Open
tianyu-l wants to merge 1 commit into
sampler-replayfrom
training-batch-builder
Open

tianyu-l wants to merge 1 commit into
sampler-replayfrom
training-batch-builder

Conversation

@tianyu-l

@tianyu-l tianyu-l commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Why

Batcher builds the trainer's step batches (TrainerStepBatch) from training samples, the next stage after TrainingSampleBuilder, which builds those samples from rollouts. Neither name says that the two stages are a pair, or that a builder's product is named after it. The new names pair each builder with what it builds; the controller already calls the queue between them training_batch_queue.

before: rollouts -> TrainingSampleBuilder -> TrainingSample -> Batcher              -> TrainerStepBatch -> trainer
after:  rollouts -> TrainingSampleBuilder -> TrainingSample -> TrainingBatchBuilder -> TrainingBatch    -> trainer

What changed

Mechanical rename; no logic changes. Reviewers can skim all of it.

Before After
Batcher (rl/trainer/batcher.py) TrainingBatchBuilder (rl/trainer/training_batch_builder.py)
BatcherActor (rl/actors/monarch/batcher.py) TrainingBatchBuilderActor (rl/actors/monarch/training_batch_builder.py)
TrainerStepBatch (one optimizer step's microbatches) TrainingBatch
Controller._batcher_loop Controller._training_batch_builder_loop
tests/rl/unit_tests/cpu/test_batcher.py, test_batcher_actor.py test_training_batch_builder.py, test_training_batch_builder_actor.py
comments and docs: "the batcher" "the training batch builder"

The ASCII diagram at the top of controller.py is redrawn for the longer loop name (one call abbreviated with n = num_prompts_per_train_step to stay within 120 columns).

User-facing changes

Before After
config async_loop.batcher async_loop.training_batch_builder (all in-repo recipes updated)
metric batcher/num_samples_dropped_oversized training_batch_builder/num_samples_dropped_oversized
trace spans batcher_pack, batcher_add_group training_batch_builder_pack, training_batch_builder_add_group
structured-log source rl_batcher rl_training_batch_builder
Monarch actor / asyncio task name batcher training_batch_builder

Numerics

Unchanged. rl_grpo_qwen3_0_6b_varlen_batch_invariant (score centering on) under scripts/rl/loss_compare.py's deterministic configuration with trainer TP 2 + vLLM TP 2 (4 GB300s), 10 steps: loss/mean, trainer/grad_norm/mean, score_centering/coefficient_l1/mean and bit_wise/logprob_diff/mean bitwise equal to #6406 every step, and the same set of TensorBoard tags (no sample was dropped, so the renamed metric is not logged in either run).

Testing

  • pytest tests/rl/unit_tests/cpu: 840 passed, 7 skipped (aarch64 GB300 host); the renamed actor test spawns TrainingBatchBuilderActor through Monarch.
  • git grep -i batcher finds nothing outside test assets. The +112 net lines are µfmt re-wrapping lines that the longer names pushed past the limit.

Known issues / follow-ups

@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Nov 27, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 27, 2026
@tianyu-l
tianyu-l added this pull request to stack #6396 November 27, 2026 23:39
@tianyu-l

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions
github-actions Bot requested a review from pzhan9 November 27, 2026 23:39
@claude

claude Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 2m 0s —— View job


Approve -- the rename is complete; only small leftovers from find-and-replace need fixing before merge. See the review.

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

Verdict: Approve -- please address the items below before merging. The rename is complete and changes no logic. What's left is leftovers from find-and-replace in comments, log messages and two ASCII tables.

What this PR does. Renames Batcher to TrainingBatchBuilder and updates its Monarch actor, its controller loop, its config field, its metric key, its trace spans, its structured-log source, and every in-repo caller, recipe, test and doc. Lines are added only where ufmt re-wrapped the longer names.

Example.

# before
config.async_loop.batcher.rdma_min_tensor_bytes = None
self.batcher = await actor_system.spawn_batcher(async_loop.batcher, ...)
# after
config.async_loop.training_batch_builder.rdma_min_tensor_bytes = None
self.training_batch_builder = await actor_system.spawn_training_batch_builder(
    async_loop.training_batch_builder, ...
)

Must fix

  1. The "Summary (human-written)" section is empty. Fill it in before merging.
  2. torchtitan/rl/controller/controller.py:51: the training_batch_queue label is now 13 columns right of its box.
  3. torchtitan/rl/trainer/training_batch_builder.py:58: the TrainingMicrobatch docstring table no longer lines up.
  4. torchtitan/rl/controller/controller.py:1184: # training_sample_training_batch_builder_loop names nothing.
  5. torchtitan/rl/controller/controller.py:683 and 9 other spots: prose and log messages say training_batch_builder or TrainingBatchBuilder where they mean "the training batch builder". The list is in the inline comment.

Should consider

  • Naming symmetry. Your diagram shows TrainingSampleBuilder -> TrainingSample, but TrainingBatchBuilder -> TrainerStepBatch. The builder and the type it produces still have different names, which is the mismatch this PR is fixing for "batcher". The controller already calls it training_batch_queue. Renaming TrainerStepBatch to TrainingBatch would finish the pairing, as a follow-up PR or in this one.
Details
  • Gate: a pure rename. torchtitan promises no BC, so renaming the config field, metric key (batcher/num_samples_dropped_oversized), trace spans and log source is fine, and the description lists all of them.
  • Running git grep -i batcher at HEAD finds nothing, so no stale callers, recipes or log-scraping scripts are left.
  • Every removed line that doesn't contain "batcher" is ufmt re-wrapping or the redrawn work-buffer table, so there is no logic change.
  • In the TLDR line, the second ^ (column 48) still points into _training_batch_builder_loop.

A maintainer still needs to review.

Comment thread torchtitan/rl/controller/controller.py Outdated
add group | | maybe_training_batch | put batch
v | v
Batcher (own process) training_batch_queue
TrainingBatchBuilder (own process) training_batch_queue

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.

The longer label pushed training_batch_queue 13 columns to the right, so it no longer sits above its box (the +--- on the next line starts at column 53). The rest of the diagram was redrawn, but this line wasn't. Remove 13 spaces to put it back:

Suggested change
TrainingBatchBuilder (own process) training_batch_queue
TrainingBatchBuilder (own process) training_batch_queue

Comment thread torchtitan/rl/controller/controller.py Outdated
batcher_task = asyncio.create_task(
self._batcher_loop(training_batch_queue=training_batch_queue),
name="batcher",
# training_sample_training_batch_builder_loop

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.

Find-and-replace turned training_sample_batcher_loop into training_sample_training_batch_builder_loop, which names nothing. The sibling labels use the loop name (# trainer_loop), so:

Suggested change
# training_sample_training_batch_builder_loop
# training_batch_builder_loop

Comment thread torchtitan/rl/controller/controller.py Outdated
self.generator_router: InterGeneratorRouter | None = None
# The batcher's single-actor handle.
self.batcher: Any | None = None
# The training_batch_builder's single-actor handle.

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.

In several prose spots, "batcher" became the identifier training_batch_builder or the class name TrainingBatchBuilder where the PR otherwise uses "the training batch builder". Some of these are log messages users read:

  • controller.py:683 (here)
  • controller.py:1427: "Buffer drained; training_batch_builder loop stopping"
  • controller.py:1507: "TrainingBatchBuilder closed and drained; stopping training"
  • work_buffer.py:171: """TrainingBatchBuilder loop: ...
  • trainer.py:273 and actors/system.py:45: the training_batch_builder's column
  • training_batch_builder.py:433: "in-process training_batch_builder."
  • tests: test_shutdown.py:284, :552, test_training_batch_builder.py:538
Suggested change
# The training_batch_builder's single-actor handle.
# The training batch builder's single-actor handle.

(`TrainingBatchBuilder._pack_image_inputs`, whose example draws the dedup):

from the batcher image_files, image_file_sizes the files, concatenated
from the training batch builder image_files, image_file_sizes the files, concatenated

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.

The longer label shifts this row's key and description columns 15 characters right, so they no longer line up with the grid_thw / image_vision_bank_indices_T / mrope_positions rows below. A 16-character label keeps the table intact:

Suggested change
from the training batch builder image_files, image_file_sizes the files, concatenated
from the builder image_files, image_file_sizes the files, concatenated

@tianyu-l
tianyu-l force-pushed the training-batch-builder branch from c709bbf to 89964b1 Compare November 27, 2026 23:52
…ningBatch

The RL batcher builds the trainer's step batches from training samples, as
TrainingSampleBuilder builds the samples from rollouts; the new names say so and pair
builder with product (TrainingSampleBuilder -> TrainingSample, TrainingBatchBuilder ->
TrainingBatch). Mechanical: the classes, the Monarch actor (TrainingBatchBuilderActor),
their modules (trainer/training_batch_builder.py, actors/monarch/training_batch_builder.py),
the config field (async_loop.training_batch_builder), the metric key
(training_batch_builder/num_samples_dropped_oversized), the trace spans, the structured
log source, the actor name, and the tests.
@tianyu-l tianyu-l changed the title [rl] Rename Batcher to TrainingBatchBuilder [rl] Rename Batcher to TrainingBatchBuilder, TrainerStepBatch to TrainingBatch Nov 28, 2026
@tianyu-l
tianyu-l force-pushed the training-batch-builder branch from 89964b1 to 35b30f5 Compare November 28, 2026 04:14
@tianyu-l

Copy link
Copy Markdown
Contributor Author

@claude review again

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 1m 29s —— View job


Approve -- the earlier leftovers are fixed. Two diagram borders are now 3 columns short and the human-written summary is still empty; see the review.

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

Verdict: Approve -- please address the items below before merging. Every leftover from the last review is fixed, and the TrainerStepBatch -> TrainingBatch rename is complete. That rename left two new misaligned box borders, and the human-written summary is still empty.

What changed since the last review. The commit was amended to also rename TrainerStepBatch to TrainingBatch, which was the should-consider item from that review. The builder and its product now pair the same way TrainingSampleBuilder -> TrainingSample does.

Earlier must-fix items

  1. Empty "Summary (human-written)": still open.
  2. training_batch_queue label in the controller.py diagram: fixed. It is back at column 53.
  3. TrainingMicrobatch docstring table: fixed (from the builder).
  4. # training_sample_training_batch_builder_loop: fixed. The grep finds nothing at HEAD.
  5. Prose and log messages that used the identifier in place of "the training batch builder": fixed. The grep finds none of the listed strings at HEAD.

Must fix

  1. The "Summary (human-written)" section is still empty. Fill it in before merging.
  2. torchtitan/rl/controller/controller.py:46 and :53: TrainingBatch is 3 characters shorter than TrainerStepBatch, so both boxes' right borders are now 3 columns short. Suggestions are inline.
Details
  • git grep -i batcher and git grep TrainerStepBatch both find nothing at HEAD.
  • TrainingBatch is only defined in torchtitan/rl/trainer/training_batch_builder.py:230, so it doesn't collide with a pretraining type. Its docstring ("Packed microbatches for one optimizer step") matches the repo's batch-vs-microbatch terminology.
  • I checked the other TrainingBatch replacements for column alignment. The two boxes above are the only ones affected.

A maintainer still needs to review.

| batch, trainable = training_batch_builder.add_group.call_one(group) |
| if no trainable samples: group_buffer.release_active_groups(1, "untrainable_group") |
| training_batch_queue.put(TrainerStepBatch) |
| training_batch_queue.put(TrainingBatch) |

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.

TrainerStepBatch -> TrainingBatch is 3 characters shorter, so this row's closing | now sits 3 columns left of the box border. Pad it back:

Suggested change
| training_batch_queue.put(TrainingBatch) |
| training_batch_queue.put(TrainingBatch) |

TrainingBatchBuilder (own process) training_batch_queue
+-------------------------------------------------+ +----------------------------------------------+
| build_from_group -> add_training_samples | | size 1; holds TrainerStepBatch | None |
| build_from_group -> add_training_samples | | size 1; holds TrainingBatch | None |

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.

Same here: the shorter name leaves the training_batch_queue box's right border 3 columns short of the +---+ lines above and below it.

Suggested change
| build_from_group -> add_training_samples | | size 1; holds TrainingBatch | None |
| build_from_group -> add_training_samples | | size 1; holds TrainingBatch | None |

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl 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.

1 participant