Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PP] microbatch split config #947

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions torchtitan/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ def __init__(self):
If using looped schedules, this still specifies the number of physical ranks, not the number
of stages. Stages per rank are inferred from split points degree, and schedule.""",
)
self.parser.add_argument(
"--experimental.pipeline_parallel_batch_split_dim",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems PP has been in experimental for a while. Do you think it's time we extract pipeline_parallel into a standalone section and put all configs over there?
It doesn't have to happen in this PR.

type=int,
default=0,
help="""
The dimension to split the batch on for pipeline parallelism. Defaults to 0 (batch dimension), but can
also be set to 1 (sequence dimension).""",
)
self.parser.add_argument(
"--experimental.pipeline_parallel_split_points",
type=string_list,
Expand Down
15 changes: 9 additions & 6 deletions torchtitan/distributed/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
from typing import Callable

from torch.distributed.pipelining.microbatch import TensorChunkSpec

from torch.distributed.pipelining.schedules import (
_PipelineSchedule,
_PipelineScheduleRuntime,
Expand Down Expand Up @@ -119,17 +121,18 @@ def build_pipeline_schedule(
f"of stages ({num_total_stages}) which may result in a bubble in the pipeline."
)

# validate that the batch size is divisible by the number of microbatches otherwise we'll hang or error during training
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have several questions here:

  1. If pipeline_parallel_batch_split_dim == 0, what would happen if if job_config.training.batch_size % num_total_stages != 0?
  2. If pipeline_parallel_batch_split_dim is on the sequence dim or other dims, don't we need similar checks in the extremal cases e.g. seq_len < num_stages
  3. Btw this divisibility requirement seems not exactly the same as "batch_size >= num stages" you mentioned in the PR summary.

if job_config.training.batch_size % n_microbatches != 0:
raise ValueError(
f"Batch size {job_config.training.batch_size} must be divisible by number of microbatches {n_microbatches}. "
"Update the config arguments for either batch_size or pipeline_parallel_microbatches."
)
# determine microbatch chunking specification
if job_config.experimental.pipeline_parallel_batch_split_dim != 0:
dim = job_config.experimental.pipeline_parallel_batch_split_dim
args_chunk_spec = (TensorChunkSpec(dim),)
else:
args_chunk_spec = None

schedule = schedule_class(
stages if looped_schedule else stages[0],
n_microbatches=n_microbatches,
loss_fn=loss_fn,
args_chunk_spec=args_chunk_spec,
)
logger.info(
f"Using pipeline schedule {job_config.experimental.pipeline_parallel_schedule} "
Expand Down