Skip to content

Tutorial combining DDP with Pipeline Parallelism to Train Transformer models - #1347

Merged
brianjo merged 4 commits into
pytorch:1.8-RC5-TESTfrom
pritamdamania87:ddp_pipeline_tutorial
Mar 4, 2021
Merged

brianjo merged 4 commits into
pytorch:1.8-RC5-TESTfrom
pritamdamania87:ddp_pipeline_tutorial

Conversation

@pritamdamania87

Copy link
Copy Markdown
Contributor

Summary: Tutorial which places a pipe on GPUs 0 and 1 and another Pipe
on GPUs 2 and 3. Both pipe replicas are replicated via DDP. One process
drives GPUs 0 and 1 and another drives GPUs 2 and 3.

… models.

Summary: Tutorial which places a pipe on GPUs 0 and 1 and another Pipe
on GPUs 2 and 3. Both pipe replicas are replicated via DDP. One process
drives GPUs 0 and 1 and another drives GPUs 2 and 3.
@netlify

netlify Bot commented Feb 5, 2021 •

Copy link
Copy Markdown

@mrzzd mrzzd left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks Pritam! Looks great.
Wonder if we it helps to reduce some of modeling complexity (or the comments) in this file, since the main point is about the pipelining, not other aspects. There is extensive description of say loss function or the input generation, while it could refer to other tutorials for those parts.

@pritamdamania87 pritamdamania87 left a comment

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.

Wonder if we it helps to reduce some of modeling complexity (or the comments) in this file, since the main point is about the pipelining, not other aspects. There is extensive description of say loss function or the input generation, while it could refer to other tutorials for those parts.

Agree that there is a lot of repeated stuff in this tutorial from other tutorials. But I feel it is still useful to have those sections to keep the tutorial as standalone as possible.

# Evaluate the model with the test dataset
# -------------------------------------
#
# Apply the best model to check the result with the test dataset.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we find best model across replicas? Say do an all-reduce and print only if the model has best loss.

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.

As I understand it, they should be equivalent right? With DDP they should start off with the same params and gradients are synced every iteration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see, although each of them my come to different val_loss and best_val_loss, but I see at the end it should not matter which one you choose.

Base automatically changed from master to main February 16, 2021 19:33
Base automatically changed from main to master February 16, 2021 19:37

@rohan-varma rohan-varma left a comment

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.

LGTM, thanks for adding this tutorial!

# ``PositionalEncoding`` module injects some information about the
# relative or absolute position of the tokens in the sequence. The
# positional encodings have the same dimension as the embeddings so that
# the two can be summed. Here, we use ``sine`` and ``cosine`` functions of

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.

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.

We have already mentioned the tutorial above right?

# Need to use 'checkpoint=never' since as of PyTorch 1.8, Pipe checkpointing
# doesn't work with DDP.
from torch.distributed.pipeline.sync import Pipe
model = Pipe(

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.

Not really related to the tutorial, but as a follow up, might be useful to see the performance win we get by using Pipeline parallel here. I'm assuming this would work if the user just did a reqular nn.Sequential not wrapped with Pipe and manually handled the split across multiple devices, but it would be a lot less performant.

# Evaluate the model with the test dataset
# -------------------------------------
#
# Apply the best model to check the result with the test dataset.

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.

As I understand it, they should be equivalent right? With DDP they should start off with the same params and gradients are synced every iteration.

@mrzzd mrzzd left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me, thanks!

# Evaluate the model with the test dataset
# -------------------------------------
#
# Apply the best model to check the result with the test dataset.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see, although each of them my come to different val_loss and best_val_loss, but I see at the end it should not matter which one you choose.

@brianjo
brianjo removed the request for review from jlin27 February 22, 2021 21:51
@jspisak jspisak added the 1.8 PRs for upcoming release label Mar 4, 2021
@brianjo
brianjo changed the base branch from master to 1.8-RC5-TEST March 4, 2021 17:03
@brianjo
brianjo merged commit 49362b1 into pytorch:1.8-RC5-TEST Mar 4, 2021
brianjo added a commit that referenced this pull request Mar 4, 2021
* Update build.sh

* Update audio tutorial for release pytorch 1.8 / torchaudio 0.8 (#1379)

* [wip] replace audio tutorial

* Update

* Update

* Update

* fixup

* Update requirements.txt

* update

* Update

Co-authored-by: Brian Johnson <[email protected]>

* [1.8 release] Switch to the new datasets in torchtext 0.9.0 release - text classification tutorial (#1352)

* switch to the new dataset API

* checkpoint

* checkpoint

* checkpoint

* update docs

* checkpoint

* switch to legacy vocab

* update to follow the master API

* checkpoint

* checkpoint

* address reviewer's comments

Co-authored-by: Guanheng Zhang <[email protected]>
Co-authored-by: Brian Johnson <[email protected]>

* [1.8 release] Switch to LM dataset in torchtext 0.9.0 release (#1349)

* switch to raw text dataset in torchtext 0.9.0 release

* follow the new API in torchtext master

Co-authored-by: Guanheng Zhang <[email protected]>
Co-authored-by: Brian Johnson <[email protected]>

* [WIP][FX] CPU Performance Profiling with FX (#1319)

Co-authored-by: Brian Johnson <[email protected]>

* [FX] Added fuser tutorial (#1356)

* Added fuser tutorial

* updated index.rst

* fixed conclusion

* responded to some comments

* responded to comments

* respond

Co-authored-by: Brian Johnson <[email protected]>

* Update numeric_suite_tutorial.py

* Tutorial combining DDP with Pipeline Parallelism to Train Transformer models (#1347)

* Tutorial combining DDP with Pipeline Parallelism to Train Transformer models.

Summary: Tutorial which places a pipe on GPUs 0 and 1 and another Pipe
on GPUs 2 and 3. Both pipe replicas are replicated via DDP. One process
drives GPUs 0 and 1 and another drives GPUs 2 and 3.

* Polish out some of the docs.

* Add thumbnail and address some comments.

Co-authored-by: pritam <[email protected]>

* More updates to numeric_suite

* Even more updates

* Update numeric_suite_tutorial.py

Hopefully that's the last one

* Update numeric_suite_tutorial.py

Last one

* Update build.sh

Co-authored-by: moto <[email protected]>
Co-authored-by: Guanheng George Zhang <[email protected]>
Co-authored-by: Guanheng Zhang <[email protected]>
Co-authored-by: James Reed <[email protected]>
Co-authored-by: Horace He <[email protected]>
Co-authored-by: Pritam Damania <[email protected]>
Co-authored-by: pritam <[email protected]>
Co-authored-by: Nikita Shulga <[email protected]>
@pritamdamania87
pritamdamania87 deleted the ddp_pipeline_tutorial branch March 16, 2021 23:37
rodrigo-techera pushed a commit to Experience-Monks/tutorials that referenced this pull request Nov 29, 2021
* Update build.sh

* Update audio tutorial for release pytorch 1.8 / torchaudio 0.8 (pytorch#1379)

* [wip] replace audio tutorial

* Update

* Update

* Update

* fixup

* Update requirements.txt

* update

* Update

Co-authored-by: Brian Johnson <[email protected]>

* [1.8 release] Switch to the new datasets in torchtext 0.9.0 release - text classification tutorial (pytorch#1352)

* switch to the new dataset API

* checkpoint

* checkpoint

* checkpoint

* update docs

* checkpoint

* switch to legacy vocab

* update to follow the master API

* checkpoint

* checkpoint

* address reviewer's comments

Co-authored-by: Guanheng Zhang <[email protected]>
Co-authored-by: Brian Johnson <[email protected]>

* [1.8 release] Switch to LM dataset in torchtext 0.9.0 release (pytorch#1349)

* switch to raw text dataset in torchtext 0.9.0 release

* follow the new API in torchtext master

Co-authored-by: Guanheng Zhang <[email protected]>
Co-authored-by: Brian Johnson <[email protected]>

* [WIP][FX] CPU Performance Profiling with FX (pytorch#1319)

Co-authored-by: Brian Johnson <[email protected]>

* [FX] Added fuser tutorial (pytorch#1356)

* Added fuser tutorial

* updated index.rst

* fixed conclusion

* responded to some comments

* responded to comments

* respond

Co-authored-by: Brian Johnson <[email protected]>

* Update numeric_suite_tutorial.py

* Tutorial combining DDP with Pipeline Parallelism to Train Transformer models (pytorch#1347)

* Tutorial combining DDP with Pipeline Parallelism to Train Transformer models.

Summary: Tutorial which places a pipe on GPUs 0 and 1 and another Pipe
on GPUs 2 and 3. Both pipe replicas are replicated via DDP. One process
drives GPUs 0 and 1 and another drives GPUs 2 and 3.

* Polish out some of the docs.

* Add thumbnail and address some comments.

Co-authored-by: pritam <[email protected]>

* More updates to numeric_suite

* Even more updates

* Update numeric_suite_tutorial.py

Hopefully that's the last one

* Update numeric_suite_tutorial.py

Last one

* Update build.sh

Co-authored-by: moto <[email protected]>
Co-authored-by: Guanheng George Zhang <[email protected]>
Co-authored-by: Guanheng Zhang <[email protected]>
Co-authored-by: James Reed <[email protected]>
Co-authored-by: Horace He <[email protected]>
Co-authored-by: Pritam Damania <[email protected]>
Co-authored-by: pritam <[email protected]>
Co-authored-by: Nikita Shulga <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.8 PRs for upcoming release cla signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants