1212 1. Parses command-line arguments, expecting two positional arguments:
1313 - path_params: Path to a JSON file containing parameters for the target script. This
1414 JSON must include at minimum:
15- * "path_script": String path to the target script to be executed.
16- * "kwargs_wandb_init": (Optional) A dictionary of keyword arguments for
17- wandb.init().
18- * "params_script" can be provided, which will be saved as a JSON to the output
19- directory and --path_params will be passed to the target script.
15+ * "params_wrapper": Containing the following:
16+ * "path_script": String path to the target script to be executed.
17+ * "kwargs_wandb_init": (Optional) A dictionary of keyword arguments for
18+ wandb.init().
19+ * "params_script" can be provided, which will be saved as a JSON to the output
20+ directory and --path_params will be passed to the target script.
2021 - directory_save: Directory path where output files (such as logs and saved parameters)
2122 will be stored. Will be passed to the target script as --directory_save.
2223
3738 "/path/to/save_dir". The parameter JSON file should include entries like:
3839
3940 {
40- "path_script": "/path/to/your_target_script.py",
41- "kwargs_wandb_init": {
42- "project": "face_rhythm",
43- "entity": "your_wandb_username",
44- "name": "example_run"
41+ "params_wrapper": {
42+ "path_script": "/path/to/your_target_script.py",
43+ "kwargs_wandb_init": {
44+ "project": "face_rhythm",
45+ "entity": "your_wandb_username",
46+ "name": "example_run"
47+ },
48+ "period_logger": 2,
4549 },
4650 "params_script": {
4751 "example_param": "value"
6266import time
6367import wandb
6468import psutil
69+ import functools
70+
6571
6672def stream_reader (pipe , log_label ):
6773 """
@@ -113,11 +119,15 @@ def monitor_system_metrics(interval: int = 30):
113119 import json
114120 with open (path_params , 'r' ) as f :
115121 params = json .load (f )
122+
123+ # Get sub parameters for wrapper
124+ assert 'params_wrapper' in params , "Error: 'params_wrapper' is missing in the parameters file."
125+ params_wrapper = params ['params_wrapper' ]
116126
117127 # Gather kwargs_wandb_init from the JSON file.
118- kwargs_wandb_init = params .get ('kwargs_wandb_init' , None )
128+ kwargs_wandb_init = params_wrapper .get ('kwargs_wandb_init' , None )
119129 # Gather path_script from the JSON file. Error if missing
120- path_script = params .get ('path_script' , None )
130+ path_script = params_wrapper .get ('path_script' , None )
121131 if path_script is None :
122132 print ("Error: 'path_script' is missing in the parameters file." )
123133 sys .exit (1 )
@@ -134,6 +144,9 @@ def monitor_system_metrics(interval: int = 30):
134144 json .dump (params_script , f )
135145 else :
136146 print ("Warning: 'params_script' is not provided in the parameters file. Skipping saving parameters." )
147+
148+ # Prepare call to monitor_system_metrics.
149+ monitor_system_metrics = functools .partial (monitor_system_metrics , interval = params_wrapper .get ('period_logger' , 30 ))
137150
138151 # Ensure WandB is installed.
139152 try :
0 commit comments