MCPcopy Create free account
hub / github.com/boyiwei/alignment-attribution-code / eval_zero_shot

Function eval_zero_shot

lib/eval.py:205–254  ·  view source on GitHub ↗
(
    model_name,
    model,
    tokenizer,
    task_list=[
        "boolq",
        "rte",
        "hellaswag",
        "winogrande",
        "arc_challenge",
        "openbookqa",
    ],
    num_fewshot=0,
    use_accelerate=False,
    add_special_tokens=False,
    limit=None,
)

Source from the content-addressed store, hash-verified

203
204
205def eval_zero_shot(
206 model_name,
207 model,
208 tokenizer,
209 task_list=[
210 "boolq",
211 "rte",
212 "hellaswag",
213 "winogrande",
214 "arc_challenge",
215 "openbookqa",
216 ],
217 num_fewshot=0,
218 use_accelerate=False,
219 add_special_tokens=False,
220 limit=None,
221):
222 from lm_eval import tasks, evaluator
223
224 def pattern_match(patterns, source_list):
225 task_names = set()
226 for pattern in patterns:
227 for matching in fnmatch.filter(source_list, pattern):
228 task_names.add(matching)
229 return list(task_names)
230
231 task_names = pattern_match(task_list, tasks.ALL_TASKS)
232 model_args = f"pretrained={model_name},cache_dir=./llm_weights"
233 if use_accelerate:
234 model_args = (
235 f"pretrained={model_name},cache_dir=./llm_weights,use_accelerate=True"
236 )
237 results = evaluator.simple_evaluate(
238 model="hf-causal-experimental",
239 model_args=model_args,
240 tasks=task_names,
241 num_fewshot=num_fewshot,
242 batch_size=None,
243 device=None,
244 no_cache=True,
245 limit=limit,
246 description_dict={},
247 decontamination_ngrams_path=None,
248 check_integrity=False,
249 pretrained_model=model,
250 tokenizer=tokenizer,
251 add_special_tokens=add_special_tokens,
252 )
253
254 return results
255
256
257def eval_attack(

Callers 3

mainFunction · 0.90
mainFunction · 0.90

Calls 1

pattern_matchFunction · 0.85

Tested by

no test coverage detected