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

Help needed to export Phi3v in ONNX #685

Closed
ladanisavan opened this issue Jul 8, 2024 · 4 comments
Closed

Help needed to export Phi3v in ONNX #685

ladanisavan opened this issue Jul 8, 2024 · 4 comments
Assignees
Labels

Comments

@ladanisavan
Copy link

Hi there,

I'm seeking guidance on exporting a custom fine-tuned Phi-3 Vision model to ONNX. I've followed the ONNX build model guide from this link.

The build command I used was:
python3 -m onnxruntime_genai.models.builder -i ep_2_grad_32_lr_3e-5/ -o onnx_output/ -p int4 -e cuda --extra_options int4_block_size=32 int4_accuracy_level=4

The build process was successful and generated the following files:

  • genai_config.json
  • model.onnx
  • model.onnx.data
  • special_tokens_map.json
  • tokenizer.json
  • tokenizer_config.json

However, the number of files generated doesn't match the file count in the official HF repo for ONNX microsoft/Phi-3-vision-128k-instruct-onnx-cuda

Files highlighted in red below are missing:
Screenshot 2024-07-05 at 5 56 00 PM

Additionally, while loading the model using ONNX Runtime, the following error occurs:
OrtException: Load model from onnx_output failed: Protobuf parsing failed.

I have also noticed that sections for "embedding" and "vision" are missing from the genai_config.json

Can someone help me identify if I'm missing anything? Thanks

@kunal-vaishnavi
Copy link
Contributor

kunal-vaishnavi commented Jul 9, 2024

The Phi-3 vision ONNX models are created as follows.

  • The vision component (phi-3-v-128k-instruct-vision.onnx) is created using torch.onnx.export with some modifications to the original PyTorch source code.
  • The text embedding component (phi-3-v-128k-instruct-text-embedding.onnx) is created using the ONNX helper APIs.
  • The text component (phi-3-v-128k-instruct-text.onnx) is created using the model builder with --extra_options exclude_embeds=true enabled. The model builder prints a warning that only the text component is created.
    elif config.architectures[0] == "Phi3VForCausalLM":
    print("WARNING: This is only generating the text component of the model. Setting `--extra_options exclude_embeds=true` by default.")
  • The genai_config.json and processor_config.json are created manually.

I can open-source the scripts used to create these ONNX models and run them with ONNX Runtime GenAI.

@2U1
Copy link

2U1 commented Jul 9, 2024

@kunal-vaishnavi If you open-source it, I would really appreciate it!

@ladanisavan
Copy link
Author

@kunal-vaishnavi open-source scripts would be really helpful to the Phi community.

@kunal-vaishnavi
Copy link
Contributor

I have uploaded the necessary files in each of the Hugging Face repos and created this PR to show how to use them.

kunal-vaishnavi added a commit that referenced this issue Jul 17, 2024
### Description

This PR open-sources the scripts used to generate the Phi-3 vision ONNX
models that run with ONNX Runtime GenAI. The extra files needed for
generating the Phi-3 vision ONNX models have been uploaded to the
Hugging Face repos.

-
[`microsoft/Phi-3-vision-128k-instruct-onnx-cpu`](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx-cpu/tree/main/onnx)
-
[`microsoft/Phi-3-vision-128k-instruct-onnx-cuda`](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx-cuda/tree/main/onnx)
-
[`microsoft/Phi-3-vision-128k-instruct-onnx-directml`](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx-directml/tree/main/onnx)

### Motivation and Context

This PR allows users to build the ONNX models needed for Phi-3 vision.
It also helps the following issues.

- #571
- #685
skyline75489 pushed a commit that referenced this issue Jul 17, 2024
### Description

This PR open-sources the scripts used to generate the Phi-3 vision ONNX
models that run with ONNX Runtime GenAI. The extra files needed for
generating the Phi-3 vision ONNX models have been uploaded to the
Hugging Face repos.

-
[`microsoft/Phi-3-vision-128k-instruct-onnx-cpu`](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx-cpu/tree/main/onnx)
-
[`microsoft/Phi-3-vision-128k-instruct-onnx-cuda`](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx-cuda/tree/main/onnx)
-
[`microsoft/Phi-3-vision-128k-instruct-onnx-directml`](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx-directml/tree/main/onnx)

### Motivation and Context

This PR allows users to build the ONNX models needed for Phi-3 vision.
It also helps the following issues.

- #571
- #685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants