deepspeedai / deepspeedai/DeepSpeed

[BUG] PipelineEngine does not store losses on last stage in pipeline buffers

Open
#3,900 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug training
Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

In the PipelineEngine class, the _exec_forward_pass function will store the loss (for the last pipeline stage) in a single variable self.loss for all micro-batches:
https://github.com/microsoft/DeepSpeed/blob/d24629f4fdaaa92df068de24f926d341f129112c/deepspeed/runtime/pipe/engine.py#L657-L663

This seems to be because the PipelineEngine assumes that self.loss will be differentiated immediately before any other forward passes are executed (as in 1F1B).
https://github.com/microsoft/DeepSpeed/blob/d24629f4fdaaa92df068de24f926d341f129112c/deepspeed/runtime/pipe/engine.py#L688-L691

This is problematic for implementing other pipeline schedules that do not behave this way (such as GPipe). One way to fix this would be to store the losses in the pipeline buffers and call backward on the correct loss (indexed by buffer_id).
https://github.com/microsoft/DeepSpeed/blob/d24629f4fdaaa92df068de24f926d341f129112c/deepspeed/runtime/pipe/engine.py#L150-L156

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in deepspeed/runtime/pipe/engine.py at _exec_forward_pass, the backward path, and the pipeline buffer setup around the referenced lines. Trace how buffer_id maps to micro-batches and verify that each loss is retained and the matching loss is differentiated; done means schedules that delay backward, such as GPipe, no longer overwrite or use the wrong loss.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.