Skip to content

Commit 6d70d97

Browse files
committed
Rediect the output of run_decomposer to file.
1 parent 8027793 commit 6d70d97

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

graph_net/subgraph_decompose_and_evaluation_step.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def load_decompose_config(work_dir: str) -> Dict[str, Any]:
115115

116116

117117
def save_decompose_config(
118-
work_dir: str,
118+
workspace: str,
119119
max_subgraph_size: int,
120120
tasks_map: Dict[str, Union[int, str, list, dict]],
121121
incorrect_paths: Union[List[str], Set[str]],
@@ -135,11 +135,11 @@ def save_decompose_config(
135135
"tasks_map": tasks_map_copy,
136136
"failed_decomposition_models": list(failed_decomposition_models),
137137
}
138-
config_path = get_decompose_config_path(work_dir)
138+
config_path = get_decompose_config_path(workspace)
139139

140140
with open(config_path, "w") as f:
141141
json.dump(config, f, indent=4)
142-
print(f"[INFO] Save state to: {config_path}")
142+
print(f"\n[INFO] Save state to: {config_path}")
143143

144144

145145
def get_model_name_with_subgraph_tag(model_path):
@@ -153,6 +153,7 @@ def run_decomposer_for_single_model(
153153
model_path: str,
154154
output_dir: str,
155155
split_positions: List[int],
156+
log_path: str,
156157
) -> bool:
157158
"""Decomposes a single model."""
158159

@@ -187,26 +188,20 @@ def run_decomposer_for_single_model(
187188
"--decorator-config",
188189
decorator_config_b64,
189190
]
190-
result = subprocess.run(
191-
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
192-
)
193-
# print(result.stdout)
194-
if result.returncode != 0:
195-
print(
196-
f"[ERROR] Decomposition failed for {model_path}\n{result.stderr}",
197-
flush=True,
198-
)
199-
return False
200-
return True
191+
with open(log_path, "a") as f:
192+
result = subprocess.run(cmd, stdout=f, stderr=f, text=True)
193+
return result.returncode == 0
201194

202195

203196
def run_decomposer_for_multi_models(
204-
framework, tasks_map, decomposed_samples_dir, max_subgraph_size
197+
framework, tasks_map, decomposed_samples_dir, max_subgraph_size, log_path
205198
):
206199
failed_decomposition = []
207200

201+
print(
202+
f"[Decomposition] max_subgraph_size: {max_subgraph_size}, log_path: {log_path}"
203+
)
208204
for model_name, task_info in tasks_map.items():
209-
print(f"[Decomposition] max_subgraph_size: {max_subgraph_size}")
210205
original_path = task_info["original_path"]
211206
split_positions = calculate_split_positions_for_subgraph(
212207
task_info["subgraph_size"], max_subgraph_size
@@ -219,25 +214,29 @@ def run_decomposer_for_multi_models(
219214
), f"{rectified_model_path} does not exist."
220215

221216
success = run_decomposer_for_single_model(
222-
framework, rectified_model_path, decomposed_samples_dir, split_positions
217+
framework,
218+
rectified_model_path,
219+
decomposed_samples_dir,
220+
split_positions,
221+
log_path,
223222
)
224223
if not success:
225224
failed_decomposition.append(rectified_model_path)
226225
return tasks_map, failed_decomposition
227226

228227

229228
def run_evaluation(
230-
framework: str, test_cmd_b64: str, work_dir: str, log_path: str
229+
framework: str, test_cmd_b64: str, samples_dir: str, log_path: str
231230
) -> int:
232231
"""Executes the test command on the batch directory."""
233232

234233
test_config = convert_b64_string_to_json(test_cmd_b64)
235234
test_module_name = test_config["test_module_name"]
236235
test_module_arguments = test_config[f"{test_module_name}_arguments"]
237-
test_module_arguments["model-path"] = work_dir
236+
test_module_arguments["model-path"] = samples_dir
238237
if test_module_name in ["test_reference_device", "test_target_device"]:
239238
test_module_arguments["reference-dir"] = os.path.join(
240-
work_dir, "reference_device_outputs"
239+
samples_dir, "reference_device_outputs"
241240
)
242241

243242
cmd = [sys.executable, "-m", f"graph_net.{framework}.{test_module_name}"] + [
@@ -251,12 +250,10 @@ def run_evaluation(
251250

252251
os.makedirs(os.path.dirname(log_path), exist_ok=True)
253252
with open(log_path, "w") as f:
254-
proc = subprocess.run(cmd, stdout=f, stderr=subprocess.STDOUT, text=True)
255-
if proc.returncode != 0:
256-
with open(log_path, "r") as f:
257-
content = f.read()
258-
print(f"[ERROR] test failed for {work_dir}\n{content}", flush=True)
259-
sys.exit(proc.returncode)
253+
result = subprocess.run(cmd, stdout=f, stderr=f, text=True)
254+
assert (
255+
result.returncode == 0
256+
), f"[ERROR] test failed for {samples_dir}, please check the log."
260257

261258

262259
def reconstruct_subgraph_size(split_positions: List[int]) -> List[list]:
@@ -387,8 +384,11 @@ def execute_decomposition_phase(max_subgraph_size, tasks_map, framework, workspa
387384
os.makedirs(decomposed_samples_dir, exist_ok=True)
388385
print(f"[Decomposition] decomposed_samples_dir: {decomposed_samples_dir}")
389386

387+
log_path = os.path.join(
388+
workspace, f"log_decompose-max_subgraph_size_{max_subgraph_size}.txt"
389+
)
390390
tasks_map, failed_decomposition = run_decomposer_for_multi_models(
391-
framework, tasks_map, decomposed_samples_dir, max_subgraph_size
391+
framework, tasks_map, decomposed_samples_dir, max_subgraph_size, log_path
392392
)
393393
num_decomposed_samples = count_samples(decomposed_samples_dir)
394394
print(
@@ -477,9 +477,7 @@ def main(args):
477477
print("\n--- Phase 3: Analysis ---")
478478
next_round_models = get_incorrect_models(args.tolerance, pass_log_path)
479479
print(f"[Analysis] Found {len(next_round_models)} incorrect subgraphs.\n")
480-
481480
print_summary_and_suggestion(next_round_models, max_subgraph_size)
482-
print()
483481

484482
# --- Step 5: Save States ---
485483
save_decompose_config(

0 commit comments

Comments
 (0)