Repository navigation
Conversation
|
@claude review |
There was a problem hiding this comment.
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
- The "Summary (human-written)" section is empty. Fill it in before merging.
torchtitan/rl/controller/controller.py:51: thetraining_batch_queuelabel is now 13 columns right of its box.torchtitan/rl/trainer/training_batch_builder.py:58: theTrainingMicrobatchdocstring table no longer lines up.torchtitan/rl/controller/controller.py:1184:# training_sample_training_batch_builder_loopnames nothing.torchtitan/rl/controller/controller.py:683and 9 other spots: prose and log messages saytraining_batch_builderorTrainingBatchBuilderwhere they mean "the training batch builder". The list is in the inline comment.
Should consider
- Naming symmetry. Your diagram shows
TrainingSampleBuilder -> TrainingSample, butTrainingBatchBuilder -> 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 ittraining_batch_queue. RenamingTrainerStepBatchtoTrainingBatchwould 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 batcherat 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.
| add group | | maybe_training_batch | put batch | ||
| v | v | ||
| Batcher (own process) training_batch_queue | ||
| TrainingBatchBuilder (own process) training_batch_queue |
There was a problem hiding this comment.
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:
| TrainingBatchBuilder (own process) training_batch_queue | |
| TrainingBatchBuilder (own process) training_batch_queue |
| batcher_task = asyncio.create_task( | ||
| self._batcher_loop(training_batch_queue=training_batch_queue), | ||
| name="batcher", | ||
| # training_sample_training_batch_builder_loop |
There was a problem hiding this comment.
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:
| # training_sample_training_batch_builder_loop | |
| # training_batch_builder_loop |
| 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. |
There was a problem hiding this comment.
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:273andactors/system.py:45:the training_batch_builder's columntraining_batch_builder.py:433:"in-process training_batch_builder."- tests:
test_shutdown.py:284,:552,test_training_batch_builder.py:538
| # 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 |
There was a problem hiding this comment.
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:
| from the training batch builder image_files, image_file_sizes the files, concatenated | |
| from the builder image_files, image_file_sizes the files, concatenated |
c709bbf to
89964b1
Compare
…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.
89964b1 to
35b30f5
Compare
|
@claude review again |
There was a problem hiding this comment.
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
- Empty "Summary (human-written)": still open.
training_batch_queuelabel in thecontroller.pydiagram: fixed. It is back at column 53.TrainingMicrobatchdocstring table: fixed (from the builder).# training_sample_training_batch_builder_loop: fixed. The grep finds nothing at HEAD.- 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
- The "Summary (human-written)" section is still empty. Fill it in before merging.
torchtitan/rl/controller/controller.py:46and:53:TrainingBatchis 3 characters shorter thanTrainerStepBatch, so both boxes' right borders are now 3 columns short. Suggestions are inline.
Details
git grep -i batcherandgit grep TrainerStepBatchboth find nothing at HEAD.TrainingBatchis only defined intorchtitan/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
TrainingBatchreplacements 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) | |
There was a problem hiding this comment.
TrainerStepBatch -> TrainingBatch is 3 characters shorter, so this row's closing | now sits 3 columns left of the box border. Pad it back:
| | 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 | |
There was a problem hiding this comment.
Same here: the shorter name leaves the training_batch_queue box's right border 3 columns short of the +---+ lines above and below it.
| | build_from_group -> add_training_samples | | size 1; holds TrainingBatch | None | | |
| | build_from_group -> add_training_samples | | size 1; holds TrainingBatch | None | |
Summary (human-written)
Why
Batcherbuilds the trainer's step batches (TrainerStepBatch) from training samples, the next stage afterTrainingSampleBuilder, 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 themtraining_batch_queue.What changed
Mechanical rename; no logic changes. Reviewers can skim all of it.
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)TrainingBatchController._batcher_loopController._training_batch_builder_looptests/rl/unit_tests/cpu/test_batcher.py,test_batcher_actor.pytest_training_batch_builder.py,test_training_batch_builder_actor.pyThe ASCII diagram at the top of
controller.pyis redrawn for the longer loop name (one call abbreviated withn = num_prompts_per_train_stepto stay within 120 columns).User-facing changes
async_loop.batcherasync_loop.training_batch_builder(all in-repo recipes updated)batcher/num_samples_dropped_oversizedtraining_batch_builder/num_samples_dropped_oversizedbatcher_pack,batcher_add_grouptraining_batch_builder_pack,training_batch_builder_add_grouprl_batcherrl_training_batch_builderbatchertraining_batch_builderNumerics
Unchanged.
rl_grpo_qwen3_0_6b_varlen_batch_invariant(score centering on) underscripts/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/meanandbit_wise/logprob_diff/meanbitwise 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 spawnsTrainingBatchBuilderActorthrough Monarch.git grep -i batcherfinds 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