Fix: Seq2SeqTrainingArgs overriding to_dict for GenerationConfig json support (#22919)

* Seq2SeqTrainingArgs overriding to_dict for GenerationConfig json support

* seq2seqTrainingArgs to_dict calling super method before handling genconf
This commit is contained in:
Nathan Fradet 2023-04-21 15:53:24 +02:00 committed by GitHub
parent 64ec802e50
commit d03d8c720f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,3 +83,15 @@ class Seq2SeqTrainingArguments(TrainingArguments):
"help": "Model id, file path or url pointing to a GenerationConfig json file, to use during prediction."
},
)
def to_dict(self):
"""
Serializes this instance while replace `Enum` by their values and `GenerationConfig` by dictionaries (for JSON
serialization support). It obfuscates the token values by removing their value.
"""
# filter out fields that are defined as field(init=False)
d = super().to_dict()
for k, v in d.items():
if isinstance(v, GenerationConfig):
d[k] = v.to_dict()
return d