Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for hpu devices #281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bigcode_eval/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def parallel_generations(
# The input_length / start_length set to 0 for now will be adjusted later
# Check if the task has a custom check_fn method for the stopping criteria
if task.stop_words and tokenizer.eos_token:
task.stop_words.append(tokenizer.eos_token)
# if padding token is same as eos it cannot be a delimiter as hpu output is padded
if not (accelerator.device.type == "hpu" and tokenizer.eos_token == tokenizer.pad_token):
task.stop_words.append(tokenizer.eos_token)
if hasattr(task, "check_fn"):
stopping_criteria.append(
EndOfFunctionCriteria(0, task.stop_words, tokenizer, task.check_fn)
Expand Down
23 changes: 22 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ def get_gpus_max_memory(max_memory, num_gpus):
return max_memory


def use_hpu():
import importlib
if importlib.util.find_spec("habana_frameworks") is not None:
import habana_frameworks.torch.hpu as hthpu
if hthpu.is_available():
return True
return False

def main():
args = parse_args()
transformers.logging.set_verbosity_error()
Expand All @@ -239,10 +247,19 @@ def main():
else:
task_names = pattern_match(args.tasks.split(","), ALL_TASKS)

accelerator = Accelerator()
if use_hpu():
from optimum.habana.accelerate import GaudiAccelerator
accelerator = GaudiAccelerator()
else:
accelerator = Accelerator()

if accelerator.is_main_process:
print(f"Selected Tasks: {task_names}")

if accelerator.device.type == "hpu":
from optimum.habana.transformers.modeling_utils import adapt_transformers_to_gaudi
adapt_transformers_to_gaudi()

results = {}
if args.load_generations_path:
# here we don't generate code but only evaluate previously computed generations
Expand Down Expand Up @@ -310,6 +327,10 @@ def main():
f"Non valid modeltype {args.modeltype}, choose from: causal, seq2seq"
)

if accelerator.device.type == "hpu":
from habana_frameworks.torch.hpu import wrap_in_hpu_graph
model = wrap_in_hpu_graph(model)

if args.peft_model:
from peft import PeftModel # dynamic import to avoid dependency on peft

Expand Down