File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 2020from typing import Optional , Tuple
2121from collections import OrderedDict
2222from dataclasses import fields , dataclass
23- from typing import Any , List , Tuple , Optional
23+ from typing import Any , Tuple , Optional
2424from paddle .nn .layer .transformer import _convert_attention_mask , MultiHeadAttention
2525from paddle .distributed .fleet .utils import recompute
2626
@@ -357,7 +357,16 @@ def to_tuple(self) -> Tuple[Any]:
357357 """
358358 Convert self to a tuple containing all the attributes/keys that are not `None`.
359359 """
360- return tuple (self [k ] for k in self .keys ())
360+ # try to fix: https://github.com/PaddlePaddle/PaddleNLP/issues/3355
361+ # when trying to get the keys of `OrderedDict`, `keys` method return empty values.
362+ # TODO(wj-Mcat): this bug should be fixed in Paddle framework
363+ tuples = ()
364+ for field in fields (self ):
365+ if getattr (self , field .name , None ) is None :
366+ continue
367+ tuples = tuples + (getattr (self , field .name ), )
368+
369+ return tuples
361370
362371
363372@dataclass
You can’t perform that action at this time.
0 commit comments