Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions paddlenlp/transformers/model_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from typing import Optional, Tuple
from collections import OrderedDict
from dataclasses import fields, dataclass
from typing import Any, List, Tuple, Optional
from typing import Any, Tuple, Optional
from paddle.nn.layer.transformer import _convert_attention_mask, MultiHeadAttention
from paddle.distributed.fleet.utils import recompute

Expand Down Expand Up @@ -357,7 +357,16 @@ def to_tuple(self) -> Tuple[Any]:
"""
Convert self to a tuple containing all the attributes/keys that are not `None`.
"""
return tuple(self[k] for k in self.keys())
# try to fix: https://github.com/PaddlePaddle/PaddleNLP/issues/3355
# when trying to get the keys of `OrderedDict`, `keys` method return empty values.
# TODO(wj-Mcat): this bug should be fixed in Paddle framework
tuples = ()
for field in fields(self):
if getattr(self, field.name, None) is None:
continue
tuples = tuples + (getattr(self, field.name), )

return tuples


@dataclass
Expand Down