-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathtrain.py
More file actions
50 lines (43 loc) · 1.73 KB
/
Copy pathtrain.py
File metadata and controls
50 lines (43 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import mlflow
import click
print("MLflow Version:", mlflow.__version__)
print("MLflow Tracking URI:", mlflow.get_tracking_uri())
_TAB = " "
def _mk_tab(level):
return "".join([ _TAB for j in range(level) ])
def _train(base_name, max_levels, max_children, level=0, child_idx=0):
if level >= max_levels:
return
tab = _mk_tab(level)
tab2 = tab + _TAB
name = f"L_{level}"
print(f"{tab}Level={level} Child={child_idx}")
print(f"{tab2}name: {name} max_levels: {max_levels}")
with mlflow.start_run(run_name=name, nested=(level > 0)) as run:
print(f"{tab2}run_id: {run.info.run_id}")
print(f"{tab2}experiment_id: {run.info.experiment_id}")
mlflow.log_param("max_levels", max_levels)
mlflow.log_param("max_children", max_children)
mlflow.log_param("alpha", str(child_idx+0.1))
mlflow.log_metric("auroch", 0.123)
mlflow.set_tag("algo", name)
with open("info.txt", "w", encoding="utf-8") as f:
f.write(name)
mlflow.log_artifact("info.txt")
for j in range(max_children):
_train(base_name, max_levels, max_children, level+1, j)
@click.command()
@click.option("--experiment", help="Experiment name.", type=str, required=False)
@click.option("--max-levels", help="Number of nested levels.", type=int, default=1)
@click.option("--max-children", help="Number of runs per level.", type=int, default=1)
def main(experiment, max_levels, max_children):
"""
Create a nested run with specified number of levels.
"""
print("Options:")
for k,v in locals().items(): print(f" {k}: {v}")
if experiment:
mlflow.set_experiment(experiment)
_train("nst",max_levels, max_children)
if __name__ == "__main__":
main()