fix: wrap callable enum values with enum.member for python 3.13#583
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 :) |
|
This PR has been inactive for 10 days and is now marked as stale. |
4f94b9b to
5a3beb0
Compare
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
TIP This summary will be updated as you push new changes. Give us feedback
|
Hello @begumcig , I reviewed the enum in TorchMetrics and it turns out that it doesn't suffer from the same problem: the member itself is not the partial but a tuple whose first element is the partial. |
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