Unverified Commit 96af5bf7 authored by Cyberes's avatar Cyberes Committed by GitHub
Browse files

Fix unable to save_pretrained when using pathlib (#1972)

* fix PosixPath is not JSON serializable

* use PosixPath

* forgot elif like a dummy
parent bbc2a030
...@@ -22,6 +22,7 @@ import json ...@@ -22,6 +22,7 @@ import json
import os import os
import re import re
from collections import OrderedDict from collections import OrderedDict
from pathlib import PosixPath
from typing import Any, Dict, Tuple, Union from typing import Any, Dict, Tuple, Union
import numpy as np import numpy as np
...@@ -507,6 +508,8 @@ class ConfigMixin: ...@@ -507,6 +508,8 @@ class ConfigMixin:
def to_json_saveable(value): def to_json_saveable(value):
if isinstance(value, np.ndarray): if isinstance(value, np.ndarray):
value = value.tolist() value = value.tolist()
elif isinstance(value, PosixPath):
value = str(value)
return value return value
config_dict = {k: to_json_saveable(v) for k, v in config_dict.items()} config_dict = {k: to_json_saveable(v) for k, v in config_dict.items()}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment