Skip to content

[Distributed] Support forward backward overlap schdule for VPP #71995

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

Merged
merged 3 commits into from
Apr 9, 2025
Merged
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
1 change: 1 addition & 0 deletions paddle/fluid/framework/distributed_strategy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ message PpConfig {
optional bool enable_offload_queue = 11 [ default = false ];
optional bool enable_dynamic_shape = 12 [ default = false ];
optional bool use_dualpipev = 13 [ default = false ];
optional bool forward_backward_overlap_scheduler = 14 [ default = false ];
}

message DygraphShardingConfig {
Expand Down
8 changes: 2 additions & 6 deletions python/paddle/distributed/fleet/meta_parallel/dualpipev.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def _forward_compute(self, phase: int, micro_datasets=None) -> None:
inputs = self._get_forward_inputs(micro_datasets, phase, acc_id)

if self.overlapped_forward_backward:
schedule_chunk = self._layers.forward(
inputs, chunk_id=phase, overlap_schedule_mode=True
)
schedule_chunk = self._layers.get_schedule_chunk(chunk_id=phase)
outputs = schedule_chunk.forward(inputs)
else:
schedule_chunk = None
Expand Down Expand Up @@ -296,9 +294,7 @@ def _forward_backward_compute(
)

# forward & backward
forward_chunk = self._layers.forward(
None, chunk_id=forward_phase, overlap_schedule_mode=True
)
forward_chunk = self._layers.get_schedule_chunk(chunk_id=forward_phase)
backward_chunk = self.schedule_chunks[backward_phase][backward_acc_id]
forward_outputs, forward_loss, backward_input_grads = (
self._layers.overlapped_forward_backward(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ def execute_func(*x):

return execute_func

def forward(self, input, chunk_id=None, overlap_schedule_mode=False):
def update_run_function(self, chunk_id):
if chunk_id is not None:
assert isinstance(chunk_id, int), "chunk_id should be an int"
assert (
Expand All @@ -1035,9 +1035,15 @@ def forward(self, input, chunk_id=None, overlap_schedule_mode=False):
# But for interleave, self.run_function will keep updating to the target functions at every run.
self.run_function = model_chunk.get_run_function()

if overlap_schedule_mode:
assert self._recompute_interval == 0
return self.build_schedule_nodes(0, len(self.run_function))
def get_schedule_chunk(self, chunk_id):
self.update_run_function(chunk_id)

assert self._recompute_interval == 0
return self.build_schedule_nodes(0, len(self.run_function))

def forward(self, input, chunk_id=None):
self.update_run_function(chunk_id)

if self._recompute_interval == 0:
input = self.forward_function(0, len(self.run_function))(input)
else:
Expand Down
Loading