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

Some fastai Loss Functions Cannot be Exported due to Pickling Error #3901

Open
warner-benjamin opened this issue Apr 10, 2023 · 6 comments
Open

Comments

@warner-benjamin
Copy link
Collaborator

Some fastai loss functions, such as LabelSmoothingCrossEntropyFlat are not picklable, and thus not exportable via Learner.export. But most, including LabelSmoothingCrossEntropy and other flattened losses, appear pickle without issue.

This minimal reproduction on Python 3.10 with the Learner.export default protocol=2

try:
    pickle.dumps(LabelSmoothingCrossEntropyFlat(), protocol=2)
    print("The class is picklable")
except pickle.PicklingError as e:
    print(e)

results in TypeError: cannot pickle 'code' object for LabelSmoothingCrossEntropyFlat but no errors for LabelSmoothingCrossEntropy or CrossEntropyLossFlat.

We should probably add a test for pickling LabelSmoothingCrossEntropyFlat to catch future changes to pickle.

@nglillywhite
Copy link
Contributor

Hey @warner-benjamin, let me know if this still needs picking up, I'll put in a PR if so.

@warner-benjamin
Copy link
Collaborator Author

@nglillywhite I am unaware of this being worked on

@nglillywhite
Copy link
Contributor

Great, I'll have a look and put in a PR, thanks

@nglillywhite
Copy link
Contributor

PR 3910 adds these guards for current loss functions, I'd like to investigate why these loss functions can't be pickled with this issue but happy to open a new issue & PRs if you'd like to keep them separate.

@dharik-arsath
Copy link

Hi, I am facing a same issue on Focal Loss, unable to pickle focal loss. am I missing out something, is there any solution to this problem.

@jordiju
Copy link

jordiju commented May 11, 2024

Bump. Same issue here. Would like to export a Learner with FocalLossFlat

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

No branches or pull requests

4 participants