refactor(jobs): build remote config dict via cfg.to_dict()

TrainPipelineConfig.to_dict() already returns the canonical draccus
encoding, so the StringIO + draccus.dump + json.loads round-trip was
redundant. Use it directly and drop the now-unused io/draccus imports.
This commit is contained in:
Nicolas Rabault
2026-06-24 11:01:58 +02:00
parent b07a73f781
commit 1172d7b3e2
+3 -8
View File
@@ -21,7 +21,6 @@ from __future__ import annotations
import copy import copy
import datetime as dt import datetime as dt
import io
import json import json
import netrc import netrc
import os import os
@@ -32,7 +31,6 @@ import threading
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import draccus
from huggingface_hub import ( from huggingface_hub import (
HfApi, HfApi,
create_repo, create_repo,
@@ -107,12 +105,9 @@ def build_remote_config_file(cfg, repo_id: str, dest: Path, tags: list[str] | No
existing = list(remote.policy.tags or []) existing = list(remote.policy.tags or [])
remote.policy.tags = existing + [t for t in tags if t not in existing] remote.policy.tags = existing + [t for t in tags if t not in existing]
# Round-trip through draccus to get the canonical, pod-parseable layout, then # Encode to the canonical, pod-parseable dict, then drop the keys the released
# drop the keys the released trainer image doesn't know about. # trainer image doesn't know about.
buf = io.StringIO() data = remote.to_dict()
with draccus.config_type("json"):
draccus.dump(remote, buf, indent=4)
data = json.loads(buf.getvalue())
data.pop("job", None) data.pop("job", None)
if not remote.save_checkpoint_to_hub: if not remote.save_checkpoint_to_hub:
data.pop("save_checkpoint_to_hub", None) data.pop("save_checkpoint_to_hub", None)