-
Notifications
You must be signed in to change notification settings - Fork 48
Add Fara-7b recipes #384
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
Open
apsonawane
wants to merge
10
commits into
main
Choose a base branch
from
asonawane/fara-recipes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Fara-7b recipes #384
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
46a8753
Add Fara-7b recipes
apsonawane a99914b
Address copilot comments
apsonawane 4a3d5f8
Merge branch 'main' into asonawane/fara-recipes
apsonawane 59184c1
Add eval script
apsonawane 0f6dea8
Potential fix for pull request finding 'Empty except'
apsonawane 4c2b82d
Potential fix for pull request finding 'Unused local variable'
apsonawane 7cd95f9
Merge branch 'main' into asonawane/fara-recipes
apsonawane 34dc067
Merge branch 'main' into asonawane/fara-recipes
apsonawane a9947a0
Merge branch 'main' into asonawane/fara-recipes
apsonawane bcc3f28
Address comments on PR
apsonawane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Generated model artifacts | ||
| models/ | ||
|
|
||
| # Python bytecode | ||
| __pycache__/ | ||
| *.pyc | ||
|
|
||
| # Olive cache | ||
| .olive-cache/ | ||
|
|
||
| # Temp and log files | ||
| *.temp | ||
| *.bak | ||
| *.log | ||
| *_log.txt | ||
| optimize_log.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Fara-7B ONNX Runtime GenAI Example | ||
|
|
||
| This example demonstrates how to convert [Fara-7B](https://huggingface.co/microsoft/Fara-7B) vision-language model to ONNX format using Olive and run inference with ONNX Runtime GenAI. | ||
|
|
||
| Fara-7B is Microsoft's agentic small language model designed for computer use, based on Qwen 2.5 VL (7B). The pipeline exports three sub-models (vision encoder, text embedding, text decoder), applies graph optimizations, and quantizes all three sub-models. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ```bash | ||
| pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| Install ONNX Runtime GenAI based on your target device: | ||
|
|
||
| | Device | Install Command | | ||
| |--------|-----------------| | ||
| | GPU (CUDA) | `pip install onnxruntime-genai-cuda --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple` | | ||
| | CPU | `pip install onnxruntime-genai --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple` | | ||
|
|
||
| ## Steps | ||
|
|
||
| ### 1. Export & Optimize Models | ||
|
|
||
| All graph transformations and quantization are declared in the JSON config files inside `cpu_and_mobile/` and `cuda/`. The top-level `optimize.py` script orchestrates the three Olive runs and generates the GenAI runtime configs. | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `python optimize.py --config-dir cpu_and_mobile --device cpu` | Full pipeline: export, optimize, INT4 quantize (CPU) | | ||
| | `python optimize.py --config-dir cuda --device gpu` | Full pipeline with FP16 + INT4 (CUDA) | | ||
| | `python optimize.py --config-dir cpu_and_mobile --skip-export` | Regenerate configs only (models already exported) | | ||
|
|
||
| > **Note:** The text model is always exported as INT4 via ModelBuilder. The vision encoder is graph-optimized and quantized by Olive passes. The embedding model's Gather-based embedding table is quantized using GatherBlockQuantized. | ||
| > | ||
| > The vision encoder is exported for a single image using the Dynamo exporter. At runtime, ONNX Runtime GenAI handles multiple images by calling the vision encoder once per image and concatenating the results — so there is no upper bound on the number of images passed to the model. | ||
|
|
||
| ### 2. Run Inference | ||
|
|
||
| From the top-level model directory: | ||
|
|
||
| ```bash | ||
| # Text-only (CPU models, default) | ||
| python inference.py --prompt "What is the capital of France?" | ||
|
|
||
| # With a single image | ||
| python inference.py --prompt "Describe this image" --image screenshot.png | ||
|
|
||
| # CUDA models | ||
| python inference.py --model_path cuda/models --prompt "Describe this image" --image screenshot.png | ||
|
|
||
| # Interactive mode | ||
| python inference.py --interactive | ||
| ``` | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| ``` | ||
| microsoft-Fara-7B/ | ||
| └── builtin/ | ||
| ├── optimize.py # End-to-end Olive pipeline + GenAI config generation | ||
| ├── user_script.py # Olive callbacks: model loading, dummy inputs, IO configs | ||
| ├── inference.py # ONNX Runtime GenAI inference | ||
| ├── codes/ # Custom Qwen2.5-VL PyTorch model adapted for ONNX export | ||
| ├── cpu_and_mobile/ | ||
| │ ├── embedding.json # Olive config: export → optimize → INT4 | ||
| │ ├── vision.json # Olive config: Dynamo export → graph surgeries → INT4 | ||
| │ ├── text.json # Olive config: ModelBuilder INT4 | ||
| │ └── models/ # Exported ONNX models (generated) | ||
| └── cuda/ | ||
| ├── embedding.json # Olive config with FP16 + CUDA EP | ||
| ├── vision.json # Olive config with FP16 + CUDA EP | ||
| ├── text.json # ModelBuilder INT4 with CUDA EP | ||
| └── models/ # Exported CUDA ONNX models (generated) | ||
| ``` | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.