Skip to content

Pt2Pipeline input_transform just before model.compile #2141

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

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 11 additions & 3 deletions torchrec/distributed/train_pipeline/train_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import torch
from torch.autograd.profiler import record_function
from torchrec.distributed.comm_ops import set_use_sync_collectives
from torchrec.distributed.dist_data import KJTAllToAllTensorsAwaitable
from torchrec.distributed.model_parallel import ShardedModule
from torchrec.distributed.train_pipeline.utils import (
Expand Down Expand Up @@ -208,17 +209,24 @@ def __init__(
self._cur_batch: Optional[In] = None

def progress(self, dataloader_iter: Iterator[In]) -> Out:
if self._iter == 0:
# Turn on sync collectives for PT2 pipeline.
# To have similar logic between compiled/graph_break ranks.
set_use_sync_collectives(True)

cc = self._compile_configs

with record_function("## load_batch ##"):
cur_batch = next(dataloader_iter)

if self._input_transformer:
cur_batch = self._input_transformer(cur_batch)

with record_function("## copy_batch_to_gpu ##"):
self._cur_batch = _to_device(cur_batch, self._device, non_blocking=False)

# Input transformer here is used also for pt2 hints to compiler, that should happen on exact object passed to model.compile.
# Do not move it before _to_device
if self._input_transformer:
self._cur_batch = self._input_transformer(self._cur_batch)

if self._model.training:
with record_function("## zero_grad ##"):
self._optimizer.zero_grad()
Expand Down
Loading