f'Both target_delimiter "{self.config.target_delimiter}" and target choice: "{choice}" do not have whitespace, ignore if the language you are evaluating on does not require/use whitespace'
# returns task_hierarchy tracking which groups contain which subtasks,
# and a list of TaskOutput classes for each non-group subtask
returntask_hierarchy,[xforxinoutputsifx.task]
defprint_writeout(task)->None:
forinstintask.instances:
# print the prompt for the first few documents
ifinst.doc_id<1:
eval_logger.info(
f"Task: {task}; document {inst.doc_id}; context prompt (starting on next line):\
\n{inst.args[0]}\n(end of prompt on previous line)\ntarget string or answer choice index (starting on next line):\n{task.doc_to_target(inst.doc)}\n(end of target on previous line)"
# optionally: take in an already-initialized transformers.PreTrainedModel
ifnotisinstance(pretrained,str):
eval_logger.warning(
"`pretrained` model kwarg is not of type `str`. Many other model arguments may be ignored. Please do not launch via accelerate or use `parallelize=True` if passing an existing model this way."
)
assertnotparallelize,"`parallelize=True` is not compatible with passing pre-initialized model to `pretrained`"
# or any other option that preloads model onto device
try:
self.model.to(self.device)
exceptValueError:
eval_logger.debug(
"Failed to place model onto specified device. This may be because the model is quantized via `bitsandbytes` or `device_map` is provided. If the desired GPU is being used, this message is safe to ignore."
# multigpu data-parallel support when launched with accelerate
ifgpus>1:
ifparallelize:
ifaccelerator.num_processes>1:
raiseRuntimeError(
"Attempted to use both a HF Accelerate `device_map` and to launch via `accelerate launch`. If this is the case, please either remove `parallelize=True` from --model_args or launch outside of the Accelerate launcher."
)
else:
pass
elifaccelerator.num_processes==1:
# if we aren't launching via accelerate, ditch
self._rank=0
self._world_size=1
else:
ifgpus>accelerator.num_processes:
eval_logger.warning(
"WARNING: The number of total system GPUs does not match the number of spawned processes. "
"If you would like to use data parallelism, please launch the script "
"with 'accelerate launch *script*'. "
f"Current run will proceed with {accelerator.num_processes} devices."
)
assert(
accelerator.distributed_type
in[
DistributedType.FSDP,
DistributedType.MULTI_GPU,
]
),"Unsupported distributed type provided. Only DDP and FSDP are supported."