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 phi3 support in ONNX exporter #1870

Merged
merged 7 commits into from
May 24, 2024
Merged

Add phi3 support in ONNX exporter #1870

merged 7 commits into from
May 24, 2024

Conversation

JingyaHuang
Copy link
Collaborator

What does this PR do?

as per title

Fixes #1826

Example

(Needs transformers>=4.41.0)

  • CLI
optimum-cli export onnx --model microsoft/Phi-3-mini-4k-instruct phi3_onnx/
  • ORTModel
from transformers import AutoTokenizer

from optimum.onnxruntime import ORTModelForCausalLM


# [Export]
model_id = "microsoft/Phi-3-mini-4k-instruct"
model = ORTModelForCausalLM.from_pretrained(model_id, export=True)
model.save_pretrained("phi3_onnx/")

# [Inference]
model_id = "phi3_onnx/"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = ORTModelForCausalLM.from_pretrained(model_id)
inputs = tokenizer(["Hello, my dog is cute"], return_tensors="pt")
outputs = model.generate(**inputs, max_length=50)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@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.

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 @JingyaHuang !

tests/exporters/exporters_utils.py Outdated Show resolved Hide resolved
Copy link
Member

@IlyasMoutawwakil IlyasMoutawwakil left a comment

Choose a reason for hiding this comment

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

LGTM ! thank you @JingyaHuang 🤗

@JingyaHuang
Copy link
Collaborator Author

Merging since failed CIs are irrelevant to the phi3 support.

@JingyaHuang JingyaHuang merged commit 7184ef4 into main May 24, 2024
50 of 64 checks passed
@JingyaHuang JingyaHuang deleted the improve-phi-support branch May 24, 2024 13:53
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.

Phi3 support
4 participants