Skip to content

Change launch to Launcher dataclass #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
launch alias function for Launcher.run
  • Loading branch information
apoorvkh committed Jul 13, 2024
commit 165d4a04a6e16038f079a4a761900b9130fc461f
4 changes: 2 additions & 2 deletions src/torchrunx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .launcher import Launcher
from .launcher import Launcher, launch
from .slurm import slurm_hosts, slurm_workers

__all__ = ["Launcher", "slurm_hosts", "slurm_workers"]
__all__ = ["Launcher", "launch", "slurm_hosts", "slurm_workers"]
65 changes: 49 additions & 16 deletions src/torchrunx/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,24 @@ def monitor_log(log_file: Path):

@dataclass
class Launcher:
hostnames: list[str] = ["localhost"],
workers_per_host: int | list[int] = 1,
ssh_config_file: str | os.PathLike | None = None,
backend: Literal["mpi", "gloo", "nccl", "ucc", None] = None,
log_dir: os.PathLike | str = "./logs",
env_vars: list[str] = [
"PATH",
"LD_LIBRARY",
"LIBRARY_PATH",
"PYTHON*",
"CUDA*",
"TORCH*",
"PYTORCH*",
"NCCL*",
],
env_file: str | os.PathLike | None = None,
hostnames: list[str] = (["localhost"],)
workers_per_host: int | list[int] = (1,)
ssh_config_file: str | os.PathLike | None = (None,)
backend: Literal["mpi", "gloo", "nccl", "ucc", None] = (None,)
log_dir: os.PathLike | str = ("./logs",)
env_vars: list[str] = (
[
"PATH",
"LD_LIBRARY",
"LIBRARY_PATH",
"PYTHON*",
"CUDA*",
"TORCH*",
"PYTORCH*",
"NCCL*",
],
)
env_file: str | os.PathLike | None = (None,)

def run(
self,
Expand Down Expand Up @@ -261,3 +263,34 @@ def run(

return_values: dict[int, Any] = dict(ChainMap(*[s.return_values for s in agent_statuses]))
return return_values


def launch(
func: Callable,
func_kwargs: dict[str, Any],
hostnames: list[str] = ["localhost"],
workers_per_host: int | list[int] = 1,
ssh_config_file: str | os.PathLike | None = None,
backend: Literal["mpi", "gloo", "nccl", "ucc", None] = None,
log_dir: os.PathLike | str = "./logs",
env_vars: list[str] = [
"PATH",
"LD_LIBRARY",
"LIBRARY_PATH",
"PYTHON*",
"CUDA*",
"TORCH*",
"PYTORCH*",
"NCCL*",
],
env_file: str | os.PathLike | None = None,
):
return Launcher(
hostnames=hostnames,
workers_per_host=workers_per_host,
ssh_config_file=ssh_config_file,
backend=backend,
log_dir=log_dir,
env_vars=env_vars,
env_file=env_file,
).run(func=func, func_kwargs=func_kwargs)
Loading