fix: wrap callable enum values with enum.member for python 3.13#583
fix: wrap callable enum values with enum.member for python 3.13#583gsprochette wants to merge 1 commit intomainfrom
Conversation
begumcig
left a comment
There was a problem hiding this comment.
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 :) |
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
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
Additional Notes