Skip to content

Commit 6d38dce

Browse files
committed
Updated to version 0.9.5
* Now --config in slaunch and py-srun can take multiple values and be stacked. * Fixed the order of stacking of slurm_params and profile params.
1 parent 9245b6d commit 6d38dce

4 files changed

Lines changed: 64 additions & 29 deletions

File tree

bin/py-srun

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import subprocess
66
import argparse
77

88
from submititnow.umiacs.handlers import profile_handlers
9+
from rich import print as rich_print
910

1011
parser = argparse.ArgumentParser()
11-
parser.add_argument("config", type=str)
12-
parser.add_argument("shell", nargs="+", default="zsh")
13-
args = parser.parse_args()
12+
parser.add_argument("--config", default=[], action="append")
13+
parser.add_argument("--job-name", default="dev")
14+
parser.add_argument("shell", nargs="+", default=["bash"])
1415

1516

1617
def removeprefix(var: str, prefix: str):
@@ -30,17 +31,41 @@ def load_config(config_filename: str):
3031
}
3132

3233

33-
cmd_args = load_config(args.config)
34+
def parse_arguments():
35+
"""Returns command args for SRUN and the downstream command to execute on the execution node."""
36+
args, downstream_args = parser.parse_known_args()
3437

38+
# Create args dict from downstream args
39+
cli_args = {}
40+
for arg in downstream_args:
41+
if arg.startswith("--"):
42+
key, value = arg[2:].split("=")
43+
cli_args[key] = value
3544

36-
# Make Bash command
37-
cmd = "srun"
38-
for key, value in cmd_args.items():
39-
cmd += f" --{key}={value}"
40-
cmd += " --job-name=llms"
41-
shell_cmd = " ".join(args.shell)
42-
cmd += f" --pty {shell_cmd}"
45+
# Populate arguments from config files
46+
config_args = {}
47+
for config_filename in args.config:
48+
config_args = {**config_args, **load_config(config_filename)}
4349

44-
print(cmd)
50+
# Merge arguments from config files and cli
51+
cmd_args = {**config_args, **cli_args, "job-name": args.job_name}
4552

46-
subprocess.run(cmd, shell=True)
53+
return cmd_args, " ".join(args.shell)
54+
55+
56+
def make_shell_command(cmd_args: dict, downstream_cmd: str):
57+
"""Returns the full SRUN command to execute on the shell."""
58+
shell_cmd = "srun"
59+
for key, value in cmd_args.items():
60+
shell_cmd += f" --{key}={value}"
61+
shell_cmd += f" --pty {downstream_cmd}"
62+
return shell_cmd
63+
64+
65+
if __name__ == "__main__":
66+
cmd_args, downstream_cmd = parse_arguments()
67+
cmd = make_shell_command(cmd_args, downstream_cmd)
68+
69+
rich_print(f"[bold]{cmd}")
70+
71+
subprocess.run(cmd, shell=True)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setuptools.setup(
99
name="submititnow",
10-
version="0.9.4.1",
10+
version="0.9.5",
1111
author="Maharshi Gor",
1212
author_email="maharshigor@gmail.com",
1313
description="A package to make submitit easier to use",

submititnow/options.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def add_slurm_arguments(parser: argparse.ArgumentParser):
3636
slurm_group = parser.add_argument_group("SLURM parameters")
3737
slurm_group.add_argument(
3838
"--config",
39-
default=None,
39+
default=[],
40+
action="append",
4041
help="SubmititNow config file for SLURM.",
4142
dest="slurm_config",
4243
)
@@ -134,11 +135,16 @@ def load_slurm_config(config_filename: str) -> Dict[str, Any]:
134135

135136
def get_slurm_params(args: argparse.Namespace) -> Dict[str, Any]:
136137
# Grabs all SLURM arguments from the parser that are explicitly set to a value
137-
slurm_args = {
138+
slurm_cli_args = {
138139
k: v for k, v in vars(args).items() if k.startswith("slurm_") and v is not None
139140
}
140-
if slurm_args.get("slurm_config") is not None:
141-
config_filename = slurm_args.pop("slurm_config")
142-
default_args = load_slurm_config(config_filename)
143-
slurm_args = {**default_args, **slurm_args}
144-
return slurm_args
141+
slurm_config_args = {}
142+
143+
config_filenames = slurm_cli_args.pop("slurm_config")
144+
for config_filename in config_filenames:
145+
slurm_config_args = {
146+
**slurm_config_args,
147+
**load_slurm_config(config_filename),
148+
}
149+
slurm_cli_args = {**slurm_config_args, **slurm_cli_args}
150+
return slurm_cli_args

submititnow/umiacs/handlers.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,50 @@
33

44
def clip_profile_handler(slurm_params: Dict[str, Any]):
55
return {
6-
**slurm_params,
76
"slurm_account": "clip",
87
"slurm_partition": "clip",
8+
**slurm_params,
99
}
1010

1111

1212
def scavenger_profile_handler(slurm_params: Dict[str, Any]):
1313
return {
14-
**slurm_params,
1514
"slurm_account": "scavenger",
1615
"slurm_partition": "scavenger",
1716
"slurm_qos": "scavenger",
17+
**slurm_params,
1818
}
1919

20+
2021
def cml_zhou_profile_handler(slurm_params: Dict[str, Any]):
2122
return {
22-
**slurm_params,
2323
"slurm_account": "cml-zhou",
2424
"slurm_partition": "cml-dpart",
25+
**slurm_params,
2526
}
26-
27+
28+
2729
def cml_profile_handler(slurm_params: Dict[str, Any]):
2830
return {
29-
**slurm_params,
3031
"slurm_account": "cml",
3132
"slurm_partition": "cml-dpart",
33+
**slurm_params,
3234
}
3335

36+
3437
def cml_scavenger_profile_handler(slurm_params: Dict[str, Any]):
3538
return {
36-
**slurm_params,
3739
"slurm_account": "cml-scavenger",
3840
"slurm_partition": "cml-scavenger",
3941
"slurm_qos": "cml-scavenger",
42+
**slurm_params,
4043
}
41-
44+
45+
4246
profile_handlers = {
4347
"clip": clip_profile_handler,
4448
"scavenger": scavenger_profile_handler,
4549
"cml": cml_profile_handler,
4650
"cml-zhou": cml_zhou_profile_handler,
4751
"cml-scavenger": cml_scavenger_profile_handler,
48-
}
52+
}

0 commit comments

Comments
 (0)