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 XPU support for IPEXModel.from_pretrained #704

Merged
merged 4 commits into from
May 15, 2024

Conversation

faaany
Copy link
Contributor

@faaany faaany commented May 11, 2024

What does this PR do?

This PR adds XPU support for loading a Torchscript model using IPEXModel.from_pretrained. Below is a test example:

import torch 
from transformers import AutoTokenizer
from optimum.intel import IPEXModel

model_id = "faaany/bert-base-uncased-float32-traced"
model_id_tokenizer = "google-bert/bert-base-uncased"
model = IPEXModel.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id_tokenizer)
inputs = tokenizer("Paris is the capital of France.", return_tensors="pt").to("xpu")
print("________________")
print(model.device)
with torch.no_grad():
    outputs = model(**inputs)
    embeddings = outputs[0][:, 0]
    print(embeddings)

Please note that faaany/bert-base-uncased-float32-traced is just a test model, which is traced from "google-bert/bert-base-uncased". Since I didn't load any tokenizer config, so I pass model_id_tokenizer to AutoTokenizer in the example above.

@faaany faaany changed the title add xpu support for IPEXModel.from_pretrained add XPU support for IPEXModel.from_pretrained May 11, 2024
@faaany
Copy link
Contributor Author

faaany commented May 11, 2024

@echarlaix pls have a review. Thx!

@faaany
Copy link
Contributor Author

faaany commented May 11, 2024

@yao-matrix

@faaany
Copy link
Contributor Author

faaany commented May 14, 2024

Hi @IlyasMoutawwakil could you help review this PR? Thanks a lot!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@echarlaix
Copy link
Collaborator

To fix the code style test you can do the following :

pip install .[quality]
make style

faaany and others added 2 commits May 15, 2024 13:48
no device_map

Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com>
@faaany
Copy link
Contributor Author

faaany commented May 15, 2024

Hi @echarlaix, there are some CI tests failing. Do you know what I can do to fix them? Thx!

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the addition @faaany !

Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com>
@echarlaix echarlaix merged commit 3cfbc38 into huggingface:main May 15, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants