Skip to content

Commit 96af5bf

Browse files
authored
Fix unable to save_pretrained when using pathlib (huggingface#1972)
* fix PosixPath is not JSON serializable * use PosixPath * forgot elif like a dummy
1 parent bbc2a03 commit 96af5bf

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/diffusers/configuration_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import os
2323
import re
2424
from collections import OrderedDict
25+
from pathlib import PosixPath
2526
from typing import Any, Dict, Tuple, Union
2627

2728
import numpy as np
@@ -507,6 +508,8 @@ def to_json_string(self) -> str:
507508
def to_json_saveable(value):
508509
if isinstance(value, np.ndarray):
509510
value = value.tolist()
511+
elif isinstance(value, PosixPath):
512+
value = str(value)
510513
return value
511514

512515
config_dict = {k: to_json_saveable(v) for k, v in config_dict.items()}

0 commit comments

Comments
 (0)