diff --git a/src/transformers/training_args_seq2seq.py b/src/transformers/training_args_seq2seq.py index 19e1ff1b2d2..ccacbbb3702 100644 --- a/src/transformers/training_args_seq2seq.py +++ b/src/transformers/training_args_seq2seq.py @@ -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