[fixed] the merging output is incorrect, when parallel_num=1

This commit is contained in:
Dylancer1998 2024-04-11 09:30:32 +00:00
parent 7c34ad4fa4
commit ddf18bb444

View File

@ -90,11 +90,17 @@ def do_parallel_sampling(args, task, answer_extraction_fn, eval_fn, input_dir, o
local_pids = [global_pid for (global_pid, _, _) in procs] local_pids = [global_pid for (global_pid, _, _) in procs]
if global_n_procs == 1:
agg_preds = read_data(os.path.join(output_dir, "predictions.json"))
else:
agg_preds = [] agg_preds = []
for fname in glob(os.path.join(output_dir, "predictions.*.json")): for fname in glob(os.path.join(output_dir, "predictions.*.json")):
if any(str(pid) in fname for pid in local_pids): if any(str(pid) in fname for pid in local_pids):
agg_preds.extend(read_data(fname)) agg_preds.extend(read_data(fname))
if global_n_procs == 1:
metrics = read_data(os.path.join(output_dir, "metrics.json"))
result_msg = f"n samples = {metrics['n_samples']}"
else:
metrics = {} metrics = {}
n_samples = 0 n_samples = 0
for fname in glob(os.path.join(output_dir, "metrics.*.json")): for fname in glob(os.path.join(output_dir, "metrics.*.json")):