Skip to content
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

Fix deprecation warning for torch.utils._pytree._register_pytree_node in PyTorch 2.2 #7008

Merged

Conversation

zyinghua
Copy link
Contributor

What does this PR do?

Fixes issue #7000. The latest PyTorch version (2.2) introduced a deprecation warning for torch.utils._pytree._register_pytree_node as used in src/diffusers/utils/outputs.py, suggesting the use of torch.utils._pytree.register_pytree_node (without the leading underscore). This PR updates the usage to align with the PyTorch recommendation, while also ensuring backward compatibility with older versions of PyTorch.

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.

@yiyixuxu

@yiyixuxu yiyixuxu requested a review from sayakpaul February 18, 2024 07:55
torch.utils._pytree._dict_flatten,
lambda values, context: cls(**torch.utils._pytree._dict_unflatten(values, context)),
)
if version.parse(get_torch_version()) < version.parse("2.2"):
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use something like

if device_map is not None and not is_torch_version(">=", "1.9.0"):

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @sayakpaul ! I have addressed this, please lmk if it's alright, cheers!

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.

LGTM with one comment. Once that's addressed, I think we can merge.

@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.

@zyinghua zyinghua force-pushed the fix-pytree-pytorch-2.2-deprecation branch from 0c1d25c to 38e7954 Compare February 18, 2024 10:21
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.

Cool!

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.

3 participants