(
configs: str,
commands: str,
env_vars: str,
exp_key: str,
exp_name: str,
args=None,
)
| 74 | |
| 75 | |
| 76 | def make_run_script( |
| 77 | configs: str, |
| 78 | commands: str, |
| 79 | env_vars: str, |
| 80 | exp_key: str, |
| 81 | exp_name: str, |
| 82 | args=None, |
| 83 | ) -> Path: |
| 84 | script = "#!/bin/bash\n\n\n" |
| 85 | |
| 86 | if env_vars: |
| 87 | for ev in env_vars.split(","): |
| 88 | ev = ev.strip() |
| 89 | script += f"export {ev}\n" |
| 90 | |
| 91 | script += f"export WANDB_RUN_ID={exp_key}\n" |
| 92 | script += f"export APP_EXPERIMENT_NAME={exp_name}\n" |
| 93 | script += f"export WANDB_TAGS=launched_by_{exp_key}\n" |
| 94 | |
| 95 | if use_torch_distributed(args): |
| 96 | script += LOAD_GPU_COUNTS_TO_VAR |
| 97 | |
| 98 | script += maybe_set_master_ip_and_address(args) |
| 99 | |
| 100 | script = add_python_paths(script) |
| 101 | |
| 102 | configs_str = configs |
| 103 | script += "\n\n" |
| 104 | for c in commands.split(","): |
| 105 | script += command_to_bash_str(c, configs_str, prefix="", args=args) |
| 106 | |
| 107 | script += maybe_add_post_script(args) |
| 108 | |
| 109 | script += 'echo "Experiment finished!"\n' |
| 110 | |
| 111 | tmp_dir = Path(tempfile.gettempdir()) / next(tempfile._get_candidate_names()) |
| 112 | tmp_dir.mkdir(parents=True, exist_ok=True) |
| 113 | script_path = tmp_dir / "run.sh" |
| 114 | with open(script_path, "w") as f: |
| 115 | f.write(script) |
| 116 | |
| 117 | # subprocess.check_call(shlex.split(f"vim {script_path}")) |
| 118 | |
| 119 | return script_path |
| 120 | |
| 121 | |
| 122 | def add_python_paths(script): |
no test coverage detected