| import os |
| import sys |
| import argparse |
| import subprocess |
| from tqdm import tqdm |
|
|
| |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) |
| from eval.evaluation import simple_verify,majority_verify |
|
|
| def main(): |
| parser = argparse.ArgumentParser(description="Sequence self-critique pipeline from previous solution in Majority.") |
| parser.add_argument('--model_name', type=str, required=True) |
| parser.add_argument('--max_completion_tokens', type=int, default=2048) |
| parser.add_argument('--dataset', type=str, required=True) |
| parser.add_argument('--method', type=str, default="Sequence") |
| parser.add_argument('--input_path', type=str, required=True) |
| |
| parser.add_argument('--tensor_parallel_size', type=int, default=2) |
| parser.add_argument('--budget', type=int, default=8) |
| |
| args = parser.parse_args() |
|
|
| |
| if not os.path.exists(args.input_path): |
| raise FileNotFoundError(f"Input file {args.input_path} not found") |
| |
| |
| result_dir = os.path.join( |
| '/home/tianqiu/tts_schedule/batch_infer/results', |
| args.dataset, args.model_name.replace('/', '_'), args.method |
| ) |
| batch_dir = os.path.join(result_dir, "batch_data") |
| output_dir = os.path.join(result_dir, "output_data") |
| os.makedirs(result_dir, exist_ok=True) |
| os.makedirs(output_dir, exist_ok=True) |
| os.makedirs(batch_dir, exist_ok=True) |
| current_input_path = args.input_path |
| |
| for i in range(args.budget): |
| |
| batch_dir_i = os.path.join(batch_dir, f"batch_{i}") |
| os.makedirs(batch_dir_i, exist_ok=True) |
| prepare_cmd = [ |
| 'python', |
| '/home/tianqiu/tts_schedule/batch_infer/src/sequence_data_prepare.py', |
| '--model_name', args.model_name, |
| '--max_completion_tokens', str(args.max_completion_tokens), |
| '--output_dir', batch_dir_i, |
| '--input_path', current_input_path, |
| '--budget', str(1) |
| ] |
| print(f"[Pipeline] Running sequence data prepare: {' '.join(prepare_cmd)}") |
| subprocess.run(prepare_cmd, check=True) |
| |
| |
| batch_jsonl = os.path.join(batch_dir_i, f"batch_0.jsonl") |
| if not os.path.exists(batch_jsonl): |
| raise FileNotFoundError(f"Batch file {batch_jsonl} not found") |
| vllm_cmd = [ |
| 'python', '-m', 'vllm.entrypoints.openai.run_batch', |
| '-i', batch_jsonl, |
| '-o', os.path.join(batch_dir_i, f'output_0.jsonl'), |
| '--model', args.model_name, |
| '--tensor-parallel-size', str(args.tensor_parallel_size) |
| ] |
| print(f"[Pipeline] Running batch inference: {' '.join(vllm_cmd)}") |
| env = os.environ.copy() |
| subprocess.run(vllm_cmd, check=True,env=env) |
|
|
| |
| merge_cmd = [ |
| 'python', '/home/tianqiu/tts_schedule/batch_infer/src/output_extract.py', |
| '--input_dir', batch_dir_i, |
| '--extra_re', |
| '--dataset', args.dataset |
| ] |
| print(f"[Pipeline] Running output merge: {' '.join(merge_cmd)}") |
| subprocess.run(merge_cmd, check=True) |
| current_input_path = os.path.join(batch_dir_i, f'parallel_merged_output.jsonl') |
| |
| acc_path = os.path.join(batch_dir_i, f'acc.jsonl') |
| majority_verify(current_input_path,acc_path) |
|
|
| print(f"[Pipeline] All results saved in: {result_dir}") |
| |
| |
| |
| if __name__ == "__main__": |
| main() |
|
|