Skip to content

Do warmup in cudagraph pool - #96433

Closed
eellison wants to merge 13 commits into
gh/eellison/393/basefrom
gh/eellison/393/head
Closed

eellison wants to merge 13 commits into
gh/eellison/393/basefrom
gh/eellison/393/head

Conversation

@eellison

@eellison eellison commented Mar 9, 2023 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

The main change here is to do warmup within a cudagraph pool. If you imagine we are part of the way through training, all of the memory would be allocated to the CUDAGraph pool, and if we were to try to run a model again in the eager pool we would OOM. Moreover, for many models you need to reclaim the activations in the backward as you run it, otherwise you have a steep memory penalty, so keeping the inputs alive as you do warmup is not an option.

The new flow is:

  • Warmup and return outputs
  • Record and run graph
  • Replay Graph.

There are a few smaller changes that are in this PR.

  • Have a separate TapeContainerManager per device. This follows the same per device logic of the Caching Allocator. Also limits CUDAGraphs in the multi device scenario. TBH, i'm not sure how this would work even for the other more naive implementation.
  • Simplifies pool preservation by having the TapeContainer store a graph.
  • Also fixed one bug where we were keeping an output that was an alias of a parameter as a path_live_weakref, which would then get freed when we needed to record a new generation and it was still live.

cc @soumith @voznesenskym @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @desertfire

Differential Revision: D43999885

@pytorch-bot

pytorch-bot Bot commented Mar 9, 2023 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/96433

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit d028a38:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
eellison added a commit that referenced this pull request Mar 9, 2023
ghstack-source-id: c4da398
Pull Request resolved: #96433
@eellison eellison changed the title [WIP] Do warmup in cudagraph pool Do warmup in cudagraph pool Mar 9, 2023
@eellison
eellison requested a review from ezyang March 9, 2023 23:17
cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
@eellison
eellison removed the request for review from ezyang March 11, 2023 01:29

This is working but probably needs a bit of clean up before review.

cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
eellison added a commit that referenced this pull request Mar 11, 2023
ghstack-source-id: 25cb2a0
Pull Request resolved: #96433
@davidberard98

Copy link
Copy Markdown
Contributor

@davidberard98 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.


This is working but probably needs a bit of clean up before review.

cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

Differential Revision: [D43999885](https://our.internmc.facebook.com/intern/diff/D43999885)

[ghstack-poisoned]

This is working but probably needs a bit of clean up before review.

cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

Differential Revision: [D43999885](https://our.internmc.facebook.com/intern/diff/D43999885)

[ghstack-poisoned]
eellison added a commit that referenced this pull request Mar 13, 2023
ghstack-source-id: 9278965
Pull Request resolved: #96433

This is working but probably needs a bit of clean up before review.

cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

Differential Revision: [D43999885](https://our.internmc.facebook.com/intern/diff/D43999885)

[ghstack-poisoned]
@eellison eellison added the topic: not user facing topic category label Mar 14, 2023
@eellison
eellison requested a review from ezyang March 14, 2023 17:23

The main change here is to do warmup within a cudagraph pool. If you imagine we are part of the way through training, all of the memory would be allocated to the CUDAGraph pool, and if we were to try to run a model again in the eager pool we would OOM. Moreover, for many models you need to reclaim the activations in the backward as you run it, otherwise you have a steep memory penalty, so keeping the inputs alive as you do warmup is not an option. 

The new flow is:
- Warmup and return outputs
- Record and run graph
- Replay Graph. 

There are a few smaller changes that are in this PR.
- Have a separate TapeContainerManager per device. This follows the same per device logic of the Caching Allocator. Also limits CUDAGraphs in the multi device scenario. TBH, i'm not sure how this would work even for the other more naive implementation. 
- Simplifies pool preservation by having the TapeContainer store a graph. 
- Also fixed one bug where we were keeping an output that was an alias of a parameter as a path_live_weakref, which would then get freed when we needed to record a new generation and it was still live.





cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

Differential Revision: [D43999885](https://our.internmc.facebook.com/intern/diff/D43999885)

[ghstack-poisoned]
eellison added a commit that referenced this pull request Mar 14, 2023
ghstack-source-id: 8731e1c
Pull Request resolved: #96433
@eellison eellison mentioned this pull request Mar 14, 2023

The main change here is to do warmup within a cudagraph pool. If you imagine we are part of the way through training, all of the memory would be allocated to the CUDAGraph pool, and if we were to try to run a model again in the eager pool we would OOM. Moreover, for many models you need to reclaim the activations in the backward as you run it, otherwise you have a steep memory penalty, so keeping the inputs alive as you do warmup is not an option. 

The new flow is:
- Warmup and return outputs
- Record and run graph
- Replay Graph. 

There are a few smaller changes that are in this PR.
- Have a separate TapeContainerManager per device. This follows the same per device logic of the Caching Allocator. Also limits CUDAGraphs in the multi device scenario. TBH, i'm not sure how this would work even for the other more naive implementation. 
- Simplifies pool preservation by having the TapeContainer store a graph. 
- Also fixed one bug where we were keeping an output that was an alias of a parameter as a path_live_weakref, which would then get freed when we needed to record a new generation and it was still live.





cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

Differential Revision: [D43999885](https://our.internmc.facebook.com/intern/diff/D43999885)

[ghstack-poisoned]

The main change here is to do warmup within a cudagraph pool. If you imagine we are part of the way through training, all of the memory would be allocated to the CUDAGraph pool, and if we were to try to run a model again in the eager pool we would OOM. Moreover, for many models you need to reclaim the activations in the backward as you run it, otherwise you have a steep memory penalty, so keeping the inputs alive as you do warmup is not an option. 

The new flow is:
- Warmup and return outputs
- Record and run graph
- Replay Graph. 

There are a few smaller changes that are in this PR.
- Have a separate TapeContainerManager per device. This follows the same per device logic of the Caching Allocator. Also limits CUDAGraphs in the multi device scenario. TBH, i'm not sure how this would work even for the other more naive implementation. 
- Simplifies pool preservation by having the TapeContainer store a graph. 
- Also fixed one bug where we were keeping an output that was an alias of a parameter as a path_live_weakref, which would then get freed when we needed to record a new generation and it was still live.





cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

Differential Revision: [D43999885](https://our.internmc.facebook.com/intern/diff/D43999885)

[ghstack-poisoned]
@eellison

Copy link
Copy Markdown
Contributor Author

Squashed into #89146

@eellison eellison closed this Mar 15, 2023
eellison added a commit that referenced this pull request Mar 16, 2023
ghstack-source-id: c2aa27e
Pull Request resolved: #89146

Use Storages for Cudagraph liveness

ghstack-source-id: c2aa27e
Pull Request resolved: #96154

Do warmup in cudagraph pool

ghstack-source-id: c2aa27e
Pull Request resolved: #96433

Comments for cuda graph trees

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: c2aa27e
Pull Request resolved: #96932
@facebook-github-bot
facebook-github-bot deleted the gh/eellison/393/head branch June 8, 2023 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants