Skip to content

fix: wrap callable enum values with enum.member for python 3.13#583

Open
gsprochette wants to merge 1 commit intomainfrom
fix/wrap-callable-enum-values-with-enum.member-for-python-3.13
Open

fix: wrap callable enum values with enum.member for python 3.13#583
gsprochette wants to merge 1 commit intomainfrom
fix/wrap-callable-enum-values-with-enum.member-for-python-3.13

Conversation

@gsprochette
Copy link
Collaborator

Description

Problem: On Python 3.13, functools.partial used as an Enum member is treated as a method descriptor, so members like LOAD_FUNCTIONS.diffusers are no longer real enum members and accessing .name fails (e.g. during save_pruna_model).

Change: Wrap callable enum values with enum.member(...) in LOAD_FUNCTIONS, SAVE_FUNCTIONS, and the artifact enums. For Python 3.10 (no enum.member), use functools.partial aliased as member so functions are still stored as values, not methods.

Refs: PEP 663 — enum.member; CPython FutureWarning on partial in Enum for 3.11+ leading to the 3.13 behavior.

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

I ran a torchao test (including save and load using the new enum) on python 3.10 (no enum.member yet), 3.11 (enum.member introduced but partial still functional) and 3.13 (partial not functional anymore). All passed.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

Copy link
Member

@begumcig begumcig left a comment

Choose a reason for hiding this comment

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

Hi, this looks really good to me already but since this is the first time I am seeing it I have a question: I believe in TorchMetrics enum in pruna/evaluation/metrics/metric.torch.py We also have a tuple where the first item is a class wrapped in partial (e.g.
fid = (partial(FrechetInceptionDistance), fid_update, "gt_y"). Would this also be a problem and needs to change?

@gsprochette
Copy link
Collaborator Author

Hi, this looks really good to me already but since this is the first time I am seeing it I have a question: I believe in TorchMetrics enum in pruna/evaluation/metrics/metric.torch.py We also have a tuple where the first item is a class wrapped in partial (e.g. fid = (partial(FrechetInceptionDistance), fid_update, "gt_y"). Would this also be a problem and needs to change?

Probably yes, I'll double check and look for any other Enum import to make sure. Thanks for pointing it out :)

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.

2 participants