-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Make BaseOutput dataclasses picklable
#5234
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
Conversation
BaseOutput dataclasses picklable
| # Don't call self.__setattr__ to avoid recursion errors | ||
| super().__setattr__(key, value) | ||
|
|
||
| def __reduce__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works! In Python, the __reduce__ function is more or less exclusively reserved for pickle no? So there should be no other side-effects that could be trigger here?
patrickvonplaten
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for me! I don't think Transformer's model output class has this reduce feature either (see here: https://github.com/huggingface/transformers/blob/391177441b133645c02181b57370ab12f71b88c4/src/transformers/utils/generic.py#L288) but I don't see a reason why we should not add it
|
cc @LysandreJik for visibility in case it's needed for Transformers |
Good catch, I wasn't aware that transformers were also using this dataclass OrderedDict class. |
Original PR from diffusers : huggingface/diffusers#5234
|
Just opened a draft PR in transformers : huggingface/transformers#26493 |
* Make BaseOutput dataclasses picklable * make style * Test * Empty commit * Simpler and safer
* Make `ModelOutput` serializable Original PR from diffusers : huggingface/diffusers#5234 * Black
* Make BaseOutput dataclasses picklable * make style * Test * Empty commit * Simpler and safer
* Make BaseOutput dataclasses picklable * make style * Test * Empty commit * Simpler and safer
Unpickling pipeline outputs currently produces an error (because the output is both a
@dataclassand anOrderedDict)This PR fixes this by setting a custom
__reduce__method on theBaseOutputclass