Skip to content

Fix C# phi-2 test - #1050

Merged
Chester Liu (skyline75489) merged 3 commits into
mainfrom
jialli/csharp-phi2
Nov 18, 2024
Merged

Fix C# phi-2 test#1050
Chester Liu (skyline75489) merged 3 commits into
mainfrom
jialli/csharp-phi2

Conversation

@skyline75489

@skyline75489 Chester Liu (skyline75489) commented Nov 8, 2024

Copy link
Copy Markdown
Contributor

The C# phi-2 test was skipped due to the wrong model path. This PR intends to fix it.

@skyline75489
Chester Liu (skyline75489) marked this pull request as ready for review November 15, 2024 01:45
@skyline75489
Chester Liu (skyline75489) requested a review from a team November 15, 2024 01:45
@skyline75489

Copy link
Copy Markdown
Contributor Author

Note that there's still resource leaks in the C# tests. Will try to fix it later.

Comment thread test/csharp/TestOnnxRuntimeGenAIAPI.cs
Comment thread .github/workflows/mac-cpu-arm64-build.yml
@skyline75489
Chester Liu (skyline75489) deleted the jialli/csharp-phi2 branch November 18, 2024 03:40
Abhishek Jindal (ajindal1) pushed a commit that referenced this pull request Nov 21, 2024
The C# phi-2 test was skipped due to the wrong model path. This PR
intends to fix it.
Abhishek Jindal (ajindal1) added a commit that referenced this pull request Nov 22, 2024
Update Version and cherry pick PRs #1050 and #1066

---------

Co-authored-by: Chester Liu <4710575+skyline75489@users.noreply.github.com>
Co-authored-by: Baiju Meswani <bmeswani@microsoft.com>
Ti-Tai Wang (titaiwangms) added a commit that referenced this pull request Apr 26, 2026
## Summary

Adds Mistral3/Pixtral VLM support to onnxruntime-genai with multi-image
inference. Includes C++ image processor, PixtralVisionState for
per-image vision processing, Python export support, and comprehensive
tests.

## Changes

### C++ Runtime
- **Mistral3 image processor** — `[IMG]`/`[IMG_BREAK]`/`[IMG_END]` token
expansion based on image resolution and patch geometry, multi-image
support
- **PixtralVisionState** — per-image vision processing loop with bounds
checks and overflow guard; slices from padded batch tensor using
`image_sizes` metadata from ort-extensions `PixtralImageSizes` op
- **Virtual `SetExtraInputs`** — proper polymorphic dispatch for vision
state subclasses
- **`IsPixtralFamily()` model type detection** — enables
Pixtral-specific codepath
- **`processor_config.json`** — with `PixtralImageSizes` preprocessing
step
- **`context_length` / `max_length` separation** — `context_length`
controls KV cache allocation while `max_length` controls generation
stopping, preventing premature EOS with large image token counts
- **INT32 `input_ids`** — token IDs above 32767 (Pixtral `[IMG]`=128011)
require int32

### Python Export Support
- Mistral3 model classes (`Mistral3Config`,
`Mistral3ForConditionalGeneration`)
- FP8 dtype promotion for checkpoint loading
- `get_user_content()` handler for Mistral3 prompt formatting

## Multi-Image Architecture

Pixtral uses dynamic image sizes (28×28 to 1540×1540) so images can't be
batched in the vision encoder. `PixtralVisionState` processes each image
individually by:
1. Reading `image_sizes` tensor from ort-extensions `PixtralImageSizes`
op (provides per-image H×W)
2. Slicing the padded `[N, C, max_H, max_W]` batch tensor to extract
each image's actual pixels
3. Running vision encoder on each image separately
4. Concatenating vision embeddings for the decoder

## Dependencies

- **onnxruntime-extensions PR #1050** — `PixtralImageSizes` custom op
for image size metadata
- **PR #2076** — YaRN RoPE parity fixes (merged) ✅

## Testing

- 5 multi-image token expansion tests (various image sizes and counts)
- Virtual dispatch verification tests for `SetExtraInputs`
- YaRN RoPE parity tests (from merged #2076)
- E2E verified: multi-image (fish.jpg + challenge.jpg) correctly
describes both images

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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