Repository navigation
Commit c3b7cf1
Add Mage-VL image and video support (#472)
## Summary
Adds first-class support for
[`microsoft/Mage-VL`](https://huggingface.co/microsoft/Mage-VL)
(`model_type: mage_vl`) as a standardized three-model package:
- `decoder`: Qwen3 text decoder with ordinary 1D RoPE
- `vision_encoder`: custom 24-layer Mage-ViT for images and streaming
video
- `embedding`: batch-safe text/visual feature mixer
The vision graph matches Mage-VL's fused biased QKV layout, exact 4:6:6
temporal/height/width RoPE, original sampled-frame temporal positions,
2x2 patch merger, and independent four-frame attention windows. CUDA/DML
builds use packed attention with dynamically derived window boundaries;
portable builds retain a standard-ONNX block-diagonal fallback.
This also adds remote config extraction, registry/public exports, exact
checkpoint weight routing, ordered mixed image/video processing, ORT
GenAI compatibility guardrails, real media fixtures, and L1-L5 coverage.
## Validation
- Unsupported status verified before implementation; no existing
`mage_vl` registry/config/model support was present.
- Upstream revision studied and pinned:
`d88b153285f1633a61b2f693c59c8576693af185`.
- Real processor path exercised with a nonzero Apache-2.0 image and
soccer video: 4,284 packed patches, five sampled frames, original
temporal indices `[0, 180, 360, 539, 719]`, and 1,138 prompt tokens.
- `python -m pytest tests/build_graph_test.py
tests/weight_alignment_test.py tests/mage_vl_parity_test.py -k "mage_vl"
-q`: **10 passed**.
- Includes exact checkpoint-key alignment, FP32 parity
(`atol/rtol=1e-4`), FP16 parity (`1e-2`), four-frame-boundary video
coverage, empty-media decode, multi-row media ordering, and packed-CUDA
graph coverage.
- `python -m pytest tests/yaml_schema_test.py
src/mobius/_testing/golden_test.py
src/mobius/integrations/ort_genai/auto_export_test.py -q`: **345
passed**.
- `python -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q
-k "not phi4mm and not apply_weights_unknown" --tb=short -n auto`:
**3,639 passed, 57 skipped**.
- `python -m pytest tests/quantization_integration_test.py -v`: **6
passed**.
- `lintrunner -a`: **clean**.
- Automated code review was run repeatedly; findings for batch indexing,
strict image-only processors, and quadratic video attention were fixed.
Final review reported no significant issues.
### Real checkpoint / GPU
Hardware: NVIDIA RTX A1000, 8,188 MiB; ORT 1.28.0 CUDA EP.
- BF16 L4 mixed real image/video, CUDA-specialized build and
`CUDAExecutionProvider`: **1 passed in 324.12s**.
- BF16 L5 deterministic generation, 24 new tokens, same real image/video
and CUDA path: **1 passed in 236.19s**.
- The committed HF golden's 24-token continuation begins: `The image
depicts a group of four men standing around a table in a stadium...`.
- No peak-memory number is claimed.
### CLI exports
Direct three-model ONNX export remains supported for CPU and CUDA
builds. `--runtime ort-genai` is explicitly rejected before any model
artifacts are saved because ORT GenAI cannot supply Mage-VL's required
`patch_positions` vision input or its 1D decoder `position_ids`.
```text
Error: ORT GenAI does not support Mage-VL's required patch_positions vision input or its 1D decoder position_ids contract. Export without --runtime ort-genai to save the runnable direct three-model ONNX package.
```
### Olive
Olive 0.10.2 NF4 quantization completed on the real FP16 decoder in
**74.46s**, reducing external weights from **8,112,046,080 bytes** to
**2,204,314,624 bytes**. The quantized decoder loaded in ORT CPU,
produced finite `(1, 3, 151936)` logits, and generated:
```text
The capital of France is Paris. The capital of Germany is Berlin
```
## Known runtime limits
- **ORT GenAI / Foundry Local:** unsupported until the runtime supports
both Mage-VL's required `patch_positions` input (including original
sampled-frame indices) and Mage-VL's 1D decoder positions. Mobius
rejects `--runtime ort-genai` instead of emitting a non-runnable
package.
- **Direct ONNX:** supported as the standardized `decoder` +
`vision_encoder` + `embedding` package and covered by real CUDA L4/L5
validation.
- **Full real-weight FP32/FP16 generation matrix:** FP32 and FP16 are
covered by independent synthetic numerical parity; FP16 is additionally
covered by full real-weight direct ONNX exports; native BF16 is covered
by real CUDA L4/L5. A full FP32 checkpoint run would approximately
double the 9.5 GB BF16 checkpoint footprint and was not repeated on this
8 GB GPU.
<!-- TODO: verify Foundry Local image/video generation once ORT GenAI
supports Mage-VL's 1D decoder positions and patch_positions input. -->
---------
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Co-authored-by: Copilot App <[email protected]>1 parent 62b093e commit c3b7cf1
31 files changed
Lines changed: 2883 additions & 59 deletions
File tree
- scripts
- src/mobius
- _configs
- per_model
- _testing
- components
- integrations/ort_genai
- models
- tasks
- testdata
- cases
- vision-language
- golden/vision-language
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
53 | 88 | | |
54 | 89 | | |
55 | 90 | | |
| |||
379 | 414 | | |
380 | 415 | | |
381 | 416 | | |
382 | | - | |
| 417 | + | |
383 | 418 | | |
384 | 419 | | |
385 | 420 | | |
| |||
439 | 474 | | |
440 | 475 | | |
441 | 476 | | |
442 | | - | |
| 477 | + | |
443 | 478 | | |
| 479 | + | |
444 | 480 | | |
445 | 481 | | |
446 | 482 | | |
| |||
451 | 487 | | |
452 | 488 | | |
453 | 489 | | |
| 490 | + | |
| 491 | + | |
454 | 492 | | |
455 | 493 | | |
456 | 494 | | |
| |||
477 | 515 | | |
478 | 516 | | |
479 | 517 | | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
485 | 529 | | |
486 | 530 | | |
487 | 531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
69 | 92 | | |
70 | 93 | | |
71 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
356 | 367 | | |
357 | 368 | | |
358 | 369 | | |
| |||
384 | 395 | | |
385 | 396 | | |
386 | 397 | | |
387 | | - | |
388 | 398 | | |
389 | 399 | | |
390 | 400 | | |
| |||
399 | 409 | | |
400 | 410 | | |
401 | 411 | | |
| 412 | + | |
402 | 413 | | |
403 | 414 | | |
404 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| 502 | + | |
| 503 | + | |
502 | 504 | | |
503 | 505 | | |
| 506 | + | |
| 507 | + | |
504 | 508 | | |
505 | 509 | | |
506 | 510 | | |
| |||
997 | 1001 | | |
998 | 1002 | | |
999 | 1003 | | |
| 1004 | + | |
| 1005 | + | |
1000 | 1006 | | |
1001 | 1007 | | |
1002 | 1008 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
185 | 188 | | |
186 | 189 | | |
| 190 | + | |
| 191 | + | |
187 | 192 | | |
188 | 193 | | |
189 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| 62 | + | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
618 | 619 | | |
619 | 620 | | |
620 | 621 | | |
| 622 | + | |
621 | 623 | | |
622 | 624 | | |
623 | 625 | | |
| |||
1023 | 1025 | | |
1024 | 1026 | | |
1025 | 1027 | | |
| 1028 | + | |
1026 | 1029 | | |
1027 | 1030 | | |
1028 | 1031 | | |
| |||
0 commit comments