Skip to content

Commit cc9c1d0

Browse files
committed
mutable default dataclass values
1 parent 765e802 commit cc9c1d0

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/torchrunx/launcher.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import time
1313
from collections import ChainMap
14-
from dataclasses import dataclass
14+
from dataclasses import dataclass, field
1515
from functools import partial
1616
from multiprocessing import Process
1717
from pathlib import Path
@@ -78,21 +78,23 @@ def monitor_log(log_file: Path):
7878

7979
@dataclass
8080
class Launcher:
81-
hostnames: list[str] = ["localhost"]
81+
hostnames: list[str] = field(default_factory=lambda: ["localhost"])
8282
workers_per_host: int | list[int] = 1
8383
ssh_config_file: str | os.PathLike | None = None
8484
backend: Literal["mpi", "gloo", "nccl", "ucc", None] = None
8585
log_dir: os.PathLike | str = "./logs"
86-
env_vars: list[str] = [
87-
"PATH",
88-
"LD_LIBRARY",
89-
"LIBRARY_PATH",
90-
"PYTHON*",
91-
"CUDA*",
92-
"TORCH*",
93-
"PYTORCH*",
94-
"NCCL*",
95-
]
86+
env_vars: list[str] = field(
87+
default_factory=lambda: [
88+
"PATH",
89+
"LD_LIBRARY",
90+
"LIBRARY_PATH",
91+
"PYTHON*",
92+
"CUDA*",
93+
"TORCH*",
94+
"PYTORCH*",
95+
"NCCL*",
96+
]
97+
)
9698
env_file: str | os.PathLike | None = None
9799

98100
def run(

0 commit comments

Comments
 (0)