Skip to content

Always Pre-Split Microbatches for PP#3856

Draft
sanketpurandare wants to merge 5 commits into
gh/sanketpurandare/3/basefrom
gh/sanketpurandare/3/head
Draft

Always Pre-Split Microbatches for PP#3856
sanketpurandare wants to merge 5 commits into
gh/sanketpurandare/3/basefrom
gh/sanketpurandare/3/head

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary:

  • Have PP training and validation dataloaders emit pipeline microbatches directly.
  • Keep PP execution in the existing forward_backward_step/eval flow while passing pre-split args/kwargs/targets to torch.distributed.pipelining.
  • Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
  • Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API with the same structure-preserving pattern.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:

  • python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
  • pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
  • python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
  • NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Group dataloader-produced microbatches into pre-split args/kwargs/targets for torch.distributed.pipelining schedule.step/eval.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- SKIP=pyrefly-check pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python tests/integration_tests/run_tests.py <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8 --no-parallel
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 2, 2026
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Group dataloader-produced microbatches inline into pre-split args/kwargs/targets for torch.distributed.pipelining schedule.step/eval.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Jul 2, 2026
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Group dataloader-produced microbatches inline into pre-split args/kwargs/targets for torch.distributed.pipelining schedule.step/eval.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

ghstack-source-id: e45a042
Pull Request resolved: #3856
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Group dataloader-produced microbatches inline into pre-split args/kwargs/targets for torch.distributed.pipelining schedule.step/eval.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Jul 2, 2026
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Group dataloader-produced microbatches inline into pre-split args/kwargs/targets for torch.distributed.pipelining schedule.step/eval.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

ghstack-source-id: e45a042
Pull Request resolved: #3856
@sanketpurandare sanketpurandare changed the base branch from gh/sanketpurandare/3/base to main July 2, 2026 02:12
@sanketpurandare sanketpurandare changed the base branch from main to gh/sanketpurandare/3/base July 2, 2026 02:13
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Keep PP execution in the existing forward_backward_step/eval flow while passing pre-split args/kwargs/targets to torch.distributed.pipelining.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API with the same structure-preserving pattern.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Jul 2, 2026
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Keep PP execution in the existing forward_backward_step/eval flow while passing pre-split args/kwargs/targets to torch.distributed.pipelining.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API with the same structure-preserving pattern.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

ghstack-source-id: 51a5e12
Pull Request resolved: #3856
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Keep PP execution in the existing forward_backward_step/eval flow while passing pre-split args/kwargs/targets to torch.distributed.pipelining.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API with the same structure-preserving pattern.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Jul 2, 2026
Summary:
- Have PP training and validation dataloaders emit pipeline microbatches directly.
- Keep PP execution in the existing forward_backward_step/eval flow while passing pre-split args/kwargs/targets to torch.distributed.pipelining.
- Remove the PP+Varlen guard and switch the GPT-OSS PP integration test back to the default varlen config.
- Update copied PP train paths in TorchFT and Forge to use the pre-split schedule API with the same structure-preserving pattern.

Motivation:
TorchTitan previously built a full local batch and relied on torch.distributed.pipelining to split it. That does not work for batch-dependent non-tensor metadata such as varlen attention metadata. Owning the split at the dataloader/trainer boundary lets TorchTitan generate block masks and varlen metadata per pipeline microbatch before calling the PP schedule.

Test Plan:
- python -m py_compile torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- pre-commit run --files torchtitan/trainer.py torchtitan/components/validate.py torchtitan/models/common/decoder.py torchtitan/models/gpt_oss/config_registry.py tests/integration_tests/models.py torchtitan/experiments/torchft/trainer.py torchtitan/experiments/forge/engine.py torchtitan/experiments/forge/example_train.py
- python -m tests.integration_tests.run_tests <output_dir> --test_suite models --test_name gpt_oss_pp+fsdp+ep+sacop --ngpu 8
- NGPU=2 LOG_RANK=0,1 ./run_train.sh --dump_folder <output_dir> --module gpt_oss --config gpt_oss_debugmodel --parallelism.pipeline_parallel_degree 2 --parallelism.pipeline_parallel_schedule 1F1B --training.steps 1 --validator.enable --validator.steps 1

ghstack-source-id: 51a5e12
Pull Request resolved: #3856
@sanketpurandare sanketpurandare added the ciflow/h100.8 Trigger H100.8 CI label Jul 2, 2026
Comment thread torchtitan/trainer.py
Comment on lines 720 to 768
@@ -740,6 +767,10 @@ def forward_backward_step(
else:
loss = torch.tensor([-1.0], device=self.device)

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 move this to a method pp_forward_backward_step and this block becomes:

if parallel_dims.pp_enabled:
     return self.pp_forward_backward_step(...)

non_pp_logic

Reason: the if/else blocks now share nothing except for local alias. Before this PR, the two at least share the inputs, labels, extra_kwargs = self.post_dataloading_process(input_dict, labels). And the pp logic becomes more complicated now and justifies a method for readability.

Comment thread torchtitan/trainer.py
Comment on lines +838 to +853
if parallel_dims.pp_enabled:
assert isinstance(input_dict, list)
assert isinstance(labels, list)
for mb_input_dict in input_dict:
for k, v in mb_input_dict.items():
if isinstance(v, torch.Tensor):
mb_input_dict[k] = v.to(self.device)
labels = [mb_labels.to(self.device) for mb_labels in labels]
else:
assert isinstance(input_dict, dict)
assert isinstance(labels, torch.Tensor)
# Move tensors to GPU
for k, v in input_dict.items():
if isinstance(v, torch.Tensor):
input_dict[k] = v.to(self.device)
labels = labels.to(self.device)

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 cannot use PP with gradient accumulation after this PR, right? If so, do we error out somewhere if users try to use them together?

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.

Using pp with gradient accumulation doesn't make sense. PP is already doing gradient accumulation. So we can disable gradient accumulation for pp.

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 don't think that's true. See previous discussions in #1733

Conclusion is that we should continue to support gradient accumulation + PP.

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 main change / challenge in this PR is to properly differentiate PP microbatching vs. gradient accumulation microbatching, from UX / config perspective.

E.g. a simple way is to let user specify "local microbatch size"

  • without PP it's the local_batch_size today, which is used together with global_batch_size to determine number of grad accum steps
  • with PP, it's the local microbatch size, whose product with num PP microbatches * num grad accum steps would have to equal global_batch_size.

Comment thread torchtitan/trainer.py
loss = self.forward_backward_step(
input_dict=input_dict,
labels=labels,
labels=labels, # pyrefly: ignore [bad-argument-type]

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 do we need pyrefly ignore now? Let's try to avoid using pyrefly ignore. Let's use cast if we really cannot figure out why.

Comment thread torchtitan/trainer.py
Comment on lines +838 to +853
if parallel_dims.pp_enabled:
assert isinstance(input_dict, list)
assert isinstance(labels, list)
for mb_input_dict in input_dict:
for k, v in mb_input_dict.items():
if isinstance(v, torch.Tensor):
mb_input_dict[k] = v.to(self.device)
labels = [mb_labels.to(self.device) for mb_labels in labels]
else:
assert isinstance(input_dict, dict)
assert isinstance(labels, torch.Tensor)
# Move tensors to GPU
for k, v in input_dict.items():
if isinstance(v, torch.Tensor):
input_dict[k] = v.to(self.device)
labels = labels.to(self.device)

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 don't think that's true. See previous discussions in #1733

Conclusion is that we should continue to support gradient accumulation + PP.

Comment thread torchtitan/trainer.py
Comment on lines +798 to +803
num_microbatches = (
self.config.training.local_batch_size
// self.config.parallelism.pipeline_parallel_microbatch_size
if parallel_dims.pp_enabled
else 1
)

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 is computed twice in constructor and here

Comment thread torchtitan/trainer.py
local_valid_tokens += (labels != IGNORE_INDEX).sum()
microbatches.append((input_dict, labels))
for _ in range(self.gradient_accumulation_steps):
if parallel_dims.pp_enabled:

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 feels to me this can be improved -- two pieces of code seem almost identical

Comment thread torchtitan/trainer.py
Comment on lines +838 to +853
if parallel_dims.pp_enabled:
assert isinstance(input_dict, list)
assert isinstance(labels, list)
for mb_input_dict in input_dict:
for k, v in mb_input_dict.items():
if isinstance(v, torch.Tensor):
mb_input_dict[k] = v.to(self.device)
labels = [mb_labels.to(self.device) for mb_labels in labels]
else:
assert isinstance(input_dict, dict)
assert isinstance(labels, torch.Tensor)
# Move tensors to GPU
for k, v in input_dict.items():
if isinstance(v, torch.Tensor):
input_dict[k] = v.to(self.device)
labels = labels.to(self.device)

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 main change / challenge in this PR is to properly differentiate PP microbatching vs. gradient accumulation microbatching, from UX / config perspective.

E.g. a simple way is to let user specify "local microbatch size"

  • without PP it's the local_batch_size today, which is used together with global_batch_size to determine number of grad accum steps
  • with PP, it's the local microbatch size, whose product with num PP microbatches * num grad accum steps would have to equal global_batch_size.

@tianyu-l tianyu-l requested a review from acisseJZhong July 8, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI 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.

3 participants