Skip to content

Commit

Permalink
to_json_string兼容性升级 (#8608)
Browse files Browse the repository at this point in the history
* to_json_string兼容性升级

* fix lint format
  • Loading branch information
sneaxiy committed Jun 17, 2024
1 parent 0844a5b commit c134a7f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion paddlenlp/transformers/configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import copy
import inspect
import json
import os
import re
Expand Down Expand Up @@ -1109,8 +1110,14 @@ def to_json_file(self, json_file_path: Union[str, os.PathLike], use_diff: bool =
If set to `True`, only the difference between the config instance and the default `PretrainedConfig()`
is serialized to JSON file.
"""
spec = inspect.getfullargspec(self.to_json_string)
has_saving_file_arg = "saving_file" in spec.args or spec.varkw
with open(json_file_path, "w", encoding="utf-8") as writer:
writer.write(self.to_json_string(use_diff=use_diff, saving_file=saving_file))
if has_saving_file_arg:
s = self.to_json_string(use_diff=use_diff, saving_file=saving_file)
else:
s = self.to_json_string(use_diff=use_diff)
writer.write(s)

def update(self, config_dict: Dict[str, Any]):
"""
Expand Down

0 comments on commit c134a7f

Please sign in to comment.