Repository navigation
Commit b2b8213
Add LFM2.5-VL multimodal support (#507)
## Summary
Adds production Mobius support for
[`LiquidAI/LFM2.5-VL-3B`](https://huggingface.co/LiquidAI/LFM2.5-VL-3B)
(`model_type=lfm2_vl`) at immutable revision
`5a414ead75d45db003906d06fb62bd5b6846cec0`.
The implementation exports a standardized three-model package:
- `vision_encoder`: SigLIP2 NaFlex patch embeddings, dynamic antialiased
position interpolation, masked vision attention, pixel-unshuffle, and
the LFM2-VL projector
- `embedding`: token embedding plus image-feature substitution,
including zero-image cached decode
- `decoder`: existing LFM2 hybrid short-convolution/full-attention
decoder with convolution and KV cache reuse
It also pins revisions through configuration, weights,
tokenizer/processor assets, CLI/runtime export, and golden generation;
adds ORT GenAI metadata for hybrid cache names/layer types; and
preserves the upstream adaptive-tiling processor contract.
## Architecture and integration checklist
- [x] Extract composite LFM2-VL text, NaFlex vision, and projector
configuration
- [x] Register `lfm2_vl` with the `lfm2-vl` three-model task
- [x] Use public Mobius components and `onnx_ir` only (no protobuf APIs)
- [x] Route all decoder, vision, projector, tied LM-head, and embedding
weights
- [x] Emit standardized `decoder`, `vision_encoder`, and `embedding`
keys
- [x] Preserve `pixel_values`, `pixel_attention_mask`, and
`spatial_shapes` processor inputs
- [x] Emit hybrid `layer_types`, convolution cache names/size, image
token ID, and `past_present_share_buffer=false`
- [x] Add immutable `--revision` CLI plumbing across config, weights,
assets, processor, and golden calls
- [x] Add real nonzero-image L4/L5 goldens using
`pipeline-cat-chonk.jpeg`
- [x] Lower `CausalConvWithState` to its standard Conv function body
only for CUDA-optimized exports; retain the portable local function for
default/CPU
## Validation evidence
Environment: Windows, NVIDIA RTX A1000 8 GB (driver 573.44), ONNX
Runtime 1.26.0, ONNX Runtime GenAI 0.15.2, Transformers 5.14.1.
### L1 / weight alignment / L3 synthetic parity
```powershell
$env:PYTHONPATH=(Resolve-Path src).Path
python -m pytest src\mobius\models\lfm2_test.py src\mobius\models\lfm2_vl_test.py src\mobius\components\_siglip2_naflex_test.py tests\build_graph_test.py tests\weight_alignment_test.py -q -k "lfm2 or naflex" --tb=short
```
Result after rebase: **30 passed**. This includes ONNX graph/checker
coverage, complete three-package Hugging Face weight alignment, NaFlex
vision/projector full-tensor parity (`rtol=atol=1e-4`), embedding
fusion, and full-logit LFM2 prefill plus cached-decode parity for both
portable and CUDA-optimized decoder graphs (`rtol=atol=1e-4`). The CUDA
structural regression also requires standard `Conv` and no remaining
`CausalConvWithState` node.
### L2 / YAML schema
```powershell
python -m pytest tests\yaml_schema_test.py -q --tb=short
python -m pytest tests\yaml_schema_test.py tests\arch_validation_test.py -q -k "lfm2_5 or lfm2_vl" --tb=short
```
Results: **247 passed** schema tests; **2 passed** targeted schema/full
pinned-config graph tests.
### L4 CUDA-specialized prefill (bf16)
```powershell
$env:MOBIUS_TEST_DEVICE='cuda'
$env:MOBIUS_TEST_BUILD_EP='cuda'
python -m pytest tests\e2e_golden_test.py -m golden -k "lfm2_5-vl-3b" -v --tb=short -s
```
Result after rebase: **1 passed** in 250.79s. Executes real processor →
CUDA-optimized ONNX NaFlex vision/projector → ONNX embedding fusion →
CUDA-optimized ONNX hybrid decoder on CUDAExecutionProvider and matches
the pinned upstream prefill golden.
### L5 CUDA-specialized cached deterministic generation (bf16)
```powershell
$env:MOBIUS_TEST_DEVICE='cuda'
$env:MOBIUS_TEST_BUILD_EP='cuda'
python -m pytest tests\e2e_golden_test.py -m generation -k "lfm2_5-vl-3b" -v --tb=short -s
```
Result after rebase: **1 passed** in 288.64s. Exact 15-token cached
decode:
```text
[41, 10299, 5140, 355, 11759, 383, 278, 10409, 415, 267, 34204, 5097, 435, 22, 124900]
```
Decoded: `A brown cat is walking on the snow with a fence behind it.`
### Float16 CUDA parity
The same L4 and L5 commands with the case dtype temporarily set to
`float16` both passed (**244.35s** and **244.15s**) with the same exact
15-token sequence. The committed canonical golden case remains bf16.
### CLI and runtime metadata
```powershell
python -m mobius build --model 'LiquidAI/LFM2.5-VL-3B' --revision '5a414ead75d45db003906d06fb62bd5b6846cec0' --dtype bf16 --ep cuda --runtime ort-genai <output-dir>
```
Result: successful export of `decoder/model.onnx`,
`vision_encoder/model.onnx`, `embedding/model.onnx`,
`genai_config.json`, pinned tokenizer/chat-template assets, and upstream
`processor_config.json`. Intrinsic checks verified all referenced files,
30 hybrid layer types, convolution cache size 2, NaFlex input mapping,
token IDs, and non-shared cache buffers.
### Formatting, lint, and broad regression
```powershell
lintrunner format -r origin/main --output oneline
lintrunner -a -r origin/main --output oneline
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
```
Result after rebase: lint **passed with no findings**; broad regression
**4059 passed, 58 skipped, 3 failed**. The three failures are unrelated
existing numerical tests: one GGUF Q4_0 dequantization parity case and
two decomposed softcap-attention parity cases. No LFM2-VL, revision, or
runtime-metadata test failed.
## Explicit waivers / runtime notes
- **ORT GenAI 0.15.2 model loading:** exported metadata is internally
valid, but the released runtime rejects the required NaFlex
`pixel_attention_mask` vision input as an unknown schema key. Current
ORT GenAI cannot represent LFM2-VL adaptive patch masking; direct
three-stage ONNX execution is fully covered by CUDA L4/L5. The upstream
`processor_config.json` is intentionally preserved rather than emitting
incorrect simplified transforms.
- **Real fp32 CUDA checkpoint:** the 3B checkpoint requires over 12 GB
for fp32 parameters before activations, exceeding the available 8 GB
GPU. Full-tensor fp32 synthetic vision/projector and decoder
prefill/cached-decode parity passes; real-checkpoint CUDA gates cover
bf16 and fp16.
## Review
- [x] Independent specialist review completed for the implementation
- [x] Follow-up review completed for CUDA lowering, EP scoping,
cached-decode parity, and post-rebase integration paths
- [x] No high-confidence correctness, architecture, weight-routing,
revision, cache, or metadata findings remained
---------
Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>1 parent 66e9c5e commit b2b8213
30 files changed
Lines changed: 3678 additions & 56 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 | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| 266 | + | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| |||
471 | 472 | | |
472 | 473 | | |
473 | 474 | | |
474 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
475 | 479 | | |
476 | 480 | | |
477 | 481 | | |
| |||
883 | 887 | | |
884 | 888 | | |
885 | 889 | | |
886 | | - | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
887 | 893 | | |
888 | 894 | | |
889 | 895 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
| |||
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
262 | | - | |
| 263 | + | |
263 | 264 | | |
264 | 265 | | |
265 | 266 | | |
| |||
275 | 276 | | |
276 | 277 | | |
277 | 278 | | |
| 279 | + | |
278 | 280 | | |
279 | 281 | | |
280 | 282 | | |
| |||
342 | 344 | | |
343 | 345 | | |
344 | 346 | | |
345 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
346 | 350 | | |
347 | 351 | | |
348 | 352 | | |
| |||
351 | 355 | | |
352 | 356 | | |
353 | 357 | | |
| 358 | + | |
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
| |||
424 | 429 | | |
425 | 430 | | |
426 | 431 | | |
| 432 | + | |
427 | 433 | | |
428 | 434 | | |
429 | 435 | | |
| |||
730 | 736 | | |
731 | 737 | | |
732 | 738 | | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
733 | 747 | | |
734 | 748 | | |
735 | 749 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1454 | 1454 | | |
1455 | 1455 | | |
1456 | 1456 | | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
1457 | 1495 | | |
1458 | 1496 | | |
1459 | 1497 | | |
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
455 | 465 | | |
456 | 466 | | |
457 | 467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
620 | 622 | | |
621 | 623 | | |
622 | 624 | | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
623 | 630 | | |
624 | 631 | | |
625 | 632 | | |
| |||
1044 | 1051 | | |
1045 | 1052 | | |
1046 | 1053 | | |
| 1054 | + | |
1047 | 1055 | | |
1048 | 1056 | | |
1049 | 1057 | | |
| |||
1267 | 1275 | | |
1268 | 1276 | | |
1269 | 1277 | | |
| 1278 | + | |
1270 | 1279 | | |
1271 | 1280 | | |
1272 | 1281 | | |
| |||
1339 | 1348 | | |
1340 | 1349 | | |
1341 | 1350 | | |
| 1351 | + | |
1342 | 1352 | | |
1343 | 1353 | | |
1344 | 1354 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
255 | 256 | | |
256 | 257 | | |
257 | 258 | | |
| |||
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
| 265 | + | |
| 266 | + | |
264 | 267 | | |
265 | 268 | | |
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
269 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
270 | 277 | | |
271 | 278 | | |
272 | 279 | | |
273 | 280 | | |
274 | | - | |
| 281 | + | |
275 | 282 | | |
276 | 283 | | |
277 | 284 | | |
278 | 285 | | |
279 | 286 | | |
280 | | - | |
| 287 | + | |
281 | 288 | | |
282 | 289 | | |
283 | 290 | | |
| |||
293 | 300 | | |
294 | 301 | | |
295 | 302 | | |
296 | | - | |
| 303 | + | |
297 | 304 | | |
298 | 305 | | |
299 | 306 | | |
| |||
304 | 311 | | |
305 | 312 | | |
306 | 313 | | |
307 | | - | |
| 314 | + | |
308 | 315 | | |
309 | 316 | | |
310 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
293 | 296 | | |
294 | 297 | | |
295 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
296 | 304 | | |
297 | 305 | | |
298 | 306 | | |
| |||
0 commit comments