MCPcopy Create free account
hub / github.com/Alpha-VLLM/LLaMA2-Accessory / run_infer

Function run_infer

light-eval/src/eval_humaneval.py:125–166  ·  view source on GitHub ↗
(
    model:MetaModel,
    infer_file: str, 
    overwrite: bool = False, 
    num_samples_per_task: int = 10, 
    format_tabs: bool = True 
)

Source from the content-addressed store, hash-verified

123 return [filter_code(fix_indents(completion)) for completion in batch_completions]
124
125def 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
168def main(args):
169

Callers 1

mainFunction · 0.70

Calls 3

printFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected