(
model:MetaModel,
infer_file: str,
overwrite: bool = False,
num_samples_per_task: int = 10,
format_tabs: bool = True
)
| 123 | return [filter_code(fix_indents(completion)) for completion in batch_completions] |
| 124 | |
| 125 | def run_infer( |
| 126 | model:MetaModel, |
| 127 | infer_file: str, |
| 128 | overwrite: bool = False, |
| 129 | num_samples_per_task: int = 10, |
| 130 | format_tabs: bool = True |
| 131 | ): |
| 132 | |
| 133 | if not overwrite and os.path.exists(infer_file): |
| 134 | print(f"{infer_file} existed, skip!") |
| 135 | return |
| 136 | |
| 137 | problems = read_problems() |
| 138 | samples = [] |
| 139 | pbar = tqdm(total=len(problems) * num_samples_per_task) |
| 140 | |
| 141 | for task_id in problems: |
| 142 | if format_tabs: |
| 143 | prompt = problems[task_id]["prompt"].replace(" ", "\t") |
| 144 | else: |
| 145 | prompt = problems[task_id]["prompt"] |
| 146 | |
| 147 | batch_completions = generate_batch_completion( |
| 148 | model, prompt, num_samples_per_task |
| 149 | ) |
| 150 | |
| 151 | for sample in batch_completions: |
| 152 | result = dict( |
| 153 | task_id=task_id, |
| 154 | completion=sample, |
| 155 | ) |
| 156 | |
| 157 | samples += [result] |
| 158 | |
| 159 | pbar.update(num_samples_per_task) |
| 160 | |
| 161 | torch.distributed.barrier() |
| 162 | if torch.distributed.get_rank() == 0: |
| 163 | |
| 164 | with jsonlines.open(infer_file, mode='w') as writer: |
| 165 | for x in samples: |
| 166 | writer.write(x) |
| 167 | |
| 168 | def main(args): |
| 169 |
no test coverage detected