[diffusion] fix: make input/output file save paths configurable and disableable (#19580)

Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
Ruihang Li
2026-03-02 23:02:33 +08:00
committed by GitHub
parent 53de53fb53
commit 5833ea684d
9 changed files with 315 additions and 155 deletions

View File

@@ -34,6 +34,24 @@ logger = init_logger(__name__)
T = TypeVar("T")
def expand_path_fields(obj) -> None:
"""In-place expanduser on all dataclass fields whose name ends with '_path' or '_paths'."""
eu = os.path.expanduser
for f in fields(obj):
v = getattr(obj, f.name)
if f.name.endswith("_path") and isinstance(v, str):
setattr(obj, f.name, eu(v))
elif f.name.endswith("_path") and isinstance(v, list):
setattr(obj, f.name, [eu(x) if isinstance(x, str) else x for x in v])
elif f.name.endswith("_paths") and isinstance(v, dict):
setattr(
obj,
f.name,
{k: eu(p) if isinstance(p, str) else p for k, p in v.items()},
)
# TODO(will): used to convert server_args.precision to torch.dtype. Find a
# cleaner way to do this.
PRECISION_TO_TYPE = {