Make `ModelOutput` serializable (#26493)
* Make `ModelOutput` serializable Original PR from diffusers : https://github.com/huggingface/diffusers/pull/5234 * Black
This commit is contained in:
parent
54e17a15dc
commit
19f0b7dd02
|
@ -416,6 +416,13 @@ class ModelOutput(OrderedDict):
|
|||
# Don't call self.__setattr__ to avoid recursion errors
|
||||
super().__setattr__(key, value)
|
||||
|
||||
def __reduce__(self):
|
||||
if not is_dataclass(self):
|
||||
return super().__reduce__()
|
||||
callable, _args, *remaining = super().__reduce__()
|
||||
args = tuple(getattr(self, field.name) for field in fields(self))
|
||||
return callable, args, *remaining
|
||||
|
||||
def to_tuple(self) -> Tuple[Any]:
|
||||
"""
|
||||
Convert self to a tuple containing all the attributes/keys that are not `None`.
|
||||
|
|
Loading…
Reference in New Issue