Skip to content

Enable Gradient Checkpointing for UNet2DModel (New)#7201

Merged
yiyixuxu merged 14 commits intohuggingface:mainfrom
dg845:unet-2d-model-grad-checkpointing3
Dec 20, 2024
Merged

Enable Gradient Checkpointing for UNet2DModel (New)#7201
yiyixuxu merged 14 commits intohuggingface:mainfrom
dg845:unet-2d-model-grad-checkpointing3

Conversation

@dg845
Copy link
Collaborator

@dg845 dg845 commented Mar 4, 2024

What does this PR do?

This PR supports gradient checkpointing for UNet2DModel.

Successor to PR #6718.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@sayakpaul
@yiyixuxu

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Clean!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 3, 2024

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Apr 3, 2024
@yiyixuxu yiyixuxu added close-to-merge and removed stale Issues that haven't received updates labels Dec 3, 2024
@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Dec 3, 2024

sorry @dg845
don't know how I missed this PR! would you be able to resolve the conflicts and we'll merge once CI is green?

sayakpaul and others added 7 commits December 14, 2024 17:42
* Fixing the global_step key not found

* Apply suggestions from code review

---------

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
…point check and remove references to deprecated scale/lora_scale
… UNet2DConditionModel gradient checkpointing tests
@dg845
Copy link
Collaborator Author

dg845 commented Dec 15, 2024

@yiyixuxu resolved the merge conflicts and updated the code to match the way gradient checkpointing is currently done in UNet2DConditionModel. The tests are passing locally for me. (Also, messed up the git history a little bit, whoops😅).

@dg845 dg845 requested a review from sayakpaul December 15, 2024 03:03
Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@yiyixuxu yiyixuxu requested a review from hlky December 18, 2024 08:00
@yiyixuxu
Copy link
Collaborator

@hlky can you take a look here and help merge in?

Copy link
Contributor

@hlky hlky left a comment

Choose a reason for hiding this comment

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

Thanks! I've left a general comment and I'll look into the test failures, should be good to merge after CI turns green.

Comment on lines +245 to +247
def _set_gradient_checkpointing(self, module, value=False):
if hasattr(module, "gradient_checkpointing"):
module.gradient_checkpointing = value
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice we use hasattr(module, "gradient_checkpointing") in around half the cases of _set_gradient_checkpointing and module names in the other half, no need to change it for now but we could look at making it uniform at some point.

Copy link
Contributor

@hlky hlky left a comment

Choose a reason for hiding this comment

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

Thanks @dg845!

)

def test_effective_gradient_checkpointing(self):
super().test_effective_gradient_checkpointing(skip={"time_proj.weight"})
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @sayakpaul time_proj.weight has no grad, other parameters are ok

@yiyixuxu yiyixuxu merged commit 648d968 into huggingface:main Dec 20, 2024
11 of 12 checks passed
Foundsheep pushed a commit to Foundsheep/diffusers that referenced this pull request Dec 23, 2024
* Port UNet2DModel gradient checkpointing code from huggingface#6718.


---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: Vincent Neemie <92559302+VincentNeemie@users.noreply.github.com>
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
Co-authored-by: hlky <hlky@hlky.ac>
sayakpaul added a commit that referenced this pull request Dec 23, 2024
* Port UNet2DModel gradient checkpointing code from #6718.


---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: Vincent Neemie <92559302+VincentNeemie@users.noreply.github.com>
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
Co-authored-by: hlky <hlky@hlky.ac>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants