Skip to content

Commit 2f100bf

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/moe-packed-fused-expert-weights
# Conflicts: # CHANGELOG.md
2 parents 94ee2a6 + 0665542 commit 2f100bf

259 files changed

Lines changed: 86584 additions & 2886 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/attention-optimization/SKILL.md‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,24 @@ TRT FusedRunner → MEA → Unfused
201201

202202
### Contrib GroupQueryAttention (`com.microsoft`)
203203

204-
Cascade: XQA → Flash → MEA → Unfused. **Rejects `attention_bias`
205-
entirely.**
204+
Cascade: XQA → Flash → MEA → Unfused. **None of the CUDA fused kernels
205+
(XQA/Flash/MEA) accept `attention_bias`**, so supplying one on CUDA
206+
forces the Unfused fallback.
207+
208+
> Correction (verified against stock ORT 1.29.0, CPU EP, 2026-08):
209+
> despite the above, GQA is **not** a blanket-reject op — the CPU EP
210+
> genuinely computes with both `attention_bias` and `head_sink` when
211+
> supplied (not silently ignored), confirmed by direct numerical probes
212+
> against the bundled library. "Rejects `attention_bias` entirely" was
213+
> inaccurate as a general statement about the op; it only holds for the
214+
> CUDA fused-kernel cascade below. Separately, onnx-genai's own native
215+
> CPU+CUDA kernels are a *stricter* subset of what stock ORT supports:
216+
> historically both rejected `attention_bias`, and only the CUDA kernel
217+
> implemented `head_sink` (see
218+
> `crates/onnx-runtime-ep-cpu/src/kernels/group_query_attention.rs`,
219+
> which now also implements `head_sink` on CPU; `attention_bias` remains
220+
> unimplemented there by design, matching the CUDA fused-kernel
221+
> limitation above, not an oversight).
206222
207223
| Kernel | Required conditions |
208224
|--------|---------------------|
@@ -297,8 +313,12 @@ use custom per-layer `GQAContext`s instead.
297313
`past_key`/`past_value` inputs (so it is prefill-only in the *growing*
298314
cache mode), but it is used at **every** step in the static-cache mode
299315
(full cache in the `key`/`value` slots).
300-
3. **GQA contrib op rejects `attention_bias`** — use standard ONNX
301-
`Attention` if you need bias with GQA.
316+
3. **GQA's CUDA fused kernels reject `attention_bias`** (Unfused CUDA
317+
still accepts it, and stock ORT's CPU EP genuinely supports it too —
318+
see the correction above) — use standard ONNX `Attention` if you
319+
need bias with a CUDA fused GQA kernel, or if targeting onnx-genai's
320+
own native kernels (which don't implement `attention_bias` on GQA
321+
either, CPU or CUDA).
302322
4. **SM≥8.0** (Ampere+) required for Flash on all paths.
303323
5. **Float bias is safer** than bool mask for complex attention patterns.
304324
6. **MEA requires alignment** — `total_kv % 4 == 0` for bias tensors.

‎.gitignore‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ __marimo__/
213213
*.onnx.data
214214
*.gguf
215215

216+
# Generated conformance-package artifacts. The metadata beside them is the
217+
# contract under review and is committed; the graphs and adapter weights are a
218+
# deterministic function of
219+
# tests/generate_onnx_genai_validation_packages.py, so committing them would
220+
# store megabytes of bytes no reviewer reads. CI regenerates and validates
221+
# them; tests get them from the materialized_workflow_packages fixture.
222+
tests/fixtures/onnx_genai_workflows/**/*.safetensors
223+
224+
# Where CI and the test fixture materialize those packages in full. Nothing
225+
# here is reviewable input: it is the regenerated output the validate and
226+
# conformance steps consume.
227+
validation/
228+
216229
# Common test dirs
217230
output/**
218231
cache_dir/**

‎CHANGELOG.md‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,144 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6060

6161
---
6262

63+
### Fixed
64+
65+
- An exported graph is no longer transcribed into its own workflow component.
66+
A component backed by a shipped `.onnx` file now declares only `ports.roles`;
67+
the artifact answers every question about which ports exist and what shape
68+
they have, and the runtime resolves them against the live session. The
69+
removed block was a second statement of the same ABI with nothing keeping the
70+
two in agreement — the same defect as `model.io`, one level down. Package
71+
validation and runtime conformance both stay at 11/11 against the pinned ONNX
72+
GenAI branch, and the contract tests now resolve every role, invocation
73+
binding and state pair against the graph itself rather than against the
74+
metadata's agreement with a copy of itself, which is a strictly stronger
75+
check.
76+
77+
Policy graphs keep their contracts, and that boundary was measured rather
78+
than assumed: a workflow value inherits its dtype, rank and request axis from
79+
the port that produced it, so dropping them left row-wise emits untyped and
80+
made 4 of the 11 packages invalid. Those contracts type the workflow's own
81+
dataflow; they do not describe an external interface.
82+
83+
- Deep decoders are now covered where the cache layer annotation actually
84+
matters. Every metadata package built in the test suite had two layers, and
85+
below ten a cell label sorts identically whether ordered lexicographically,
86+
numerically or by insertion — so a `layer` derived from a cell's position
87+
rather than parsed from its port name would have passed every assertion while
88+
transposing caches on any real model. `canonical_workflow_contract_test` now
89+
builds twelve-layer dynamic, static-cache and hybrid decoders and pins that
90+
the declared layer restates the port name, that ordering by it recovers the
91+
buffer lists, and that a hybrid's alternating groups own layers their cells'
92+
positions never equal. A producer that dropped the parse leaves the 101
93+
pre-existing assertions green and fails seven of these.
94+
95+
- Every component a task builds now declares an optimization role. Qwen3-TTS's
96+
four loop-wiring graphs (`code_predictor_prefill`,
97+
`code_predictor_step_embedder`, `code_predictor_indices`, `talker_text_step`)
98+
were absent from `TTSTask.model_roles`, so `build_from_module` fell back to
99+
the `"decoder"` role and offered them the GQA / QKV-packing passes meant for
100+
attention stacks, and `inspect_components` under-reported the package by four
101+
components. They now declare a `"glue"` role: a parameter-free graph that
102+
reads every tensor it uses from a graph input. `arch_validation_test` fails
103+
any task that builds a component it does not declare, and a network-free unit
104+
test pins the same invariant for Qwen3-TTS.
105+
106+
### One canonical serialized representation
107+
108+
#### Changed
109+
110+
- **`pipeline.workflow` is now the only place a package describes its graph
111+
ABI.** No export emits `model.io`, including a bare single-file decoder: that
112+
case is a one-component workflow, not a different kind of document. `model`
113+
keeps package-wide geometry and capabilities and nothing else. Two writable
114+
statements of one fact are a defect whatever they contain — nothing forces
115+
them to agree, and a reader of either never learns the other exists — so a
116+
runtime that wants an optimized single-graph path derives it by lowering the
117+
workflow instead. Verified end to end: the ONNX GenAI runtime executes the
118+
fixed-capacity decode path from the workflow alone, with no `model.io` in the
119+
package.
120+
121+
#### Added
122+
123+
- An ONNX component that ships an artifact declares no port contracts. The
124+
`.onnx` file travels inside the package and is authoritative for which ports
125+
exist and what each one's dtype, rank and shape is, so transcribing that into
126+
YAML would be a second writable statement of one fact — the very thing this
127+
section removes — sitting one level below `model.io` rather than beside it.
128+
The runtime resolves ports against the live session, which catches a name the
129+
graph does not expose instead of agreeing with a stale echo of it. A
130+
producer-synthesized policy graph is the exception and states its contracts,
131+
because a workflow value takes its dtype, rank and request axis from the port
132+
that produced it: those contracts are the dataflow's type annotations, not a
133+
description of an external interface.
134+
- Every ONNX component declares `ports.roles`: what it *does* with a value bound
135+
to a port. An invocation records which SSA value reaches a port, not whether
136+
that port is tokens, a mask or logits. Mobius mints these port names in its own
137+
task builders, so it states the mapping (`input_ids`→`token_ids`,
138+
`inputs_embeds`, `attention_mask`, `position_ids`, `logits`,
139+
`last_hidden_state`→`hidden_states`, `encoder_hidden_states`,
140+
`audio_features`) rather than inferring it. A port outside that vocabulary
141+
carries no role.
142+
- State port aliases declare `role` (`key`/`value`) and `layer`. A layer's key
143+
and value buffers are the same dtype and shape, and a cell's label sorts
144+
lexicographically so `cache_10` precedes `cache_2` — pairing per-layer buffers
145+
positionally would silently transpose two layers' caches. Both fields are
146+
emitted together or not at all, so a recurrent or convolution cache is never
147+
given a fabricated index.
148+
- `IndexedScatter.kv_length_ports` names the port carrying the graph-visible
149+
valid length, beside the existing `write_indices_ports`. The two control
150+
vectors are both rank-1 integers and are therefore indistinguishable by shape;
151+
with both named, the whole fixed-capacity ABI is recoverable from the workflow.
152+
- `tests/canonical_workflow_contract_test.py` pins the invariant. It asks one
153+
set of shape-agnostic questions of dynamic, static-cache, FP8, heterogeneous
154+
and composite packages — and of all 11 checked-in fixtures — so a future
155+
feature cannot grow its own top-level block while every feature-specific test
156+
keeps passing.
157+
158+
### Fixed-capacity (static) KV cache and FP8 KV cache metadata
159+
160+
#### Added
161+
162+
- `--features static-cache` now produces onnx-genai metadata instead of being
163+
refused. The producer publishes the write cursor (`write_indices`), the valid
164+
length (`nonpad_kv_seqlen`), the fixed-capacity buffer contracts, the
165+
per-layer input/output pairs, and an `indexed_scatter` state-service update
166+
discipline naming the cursor, the capacity and the per-component port that
167+
carries it. The buffers are declared as `recurrence: {kind: invariant}` loop
168+
cells and the capacity as a `package.cache_capacity` literal workflow input.
169+
Nothing dispatches on model name; the ports are read from the graph.
170+
- Heterogeneous caches keep their own disciplines. Gemma 4's sliding layers stay
171+
on a growing rank-4 BNSH cache while its full-attention layers use rank-3
172+
fixed-capacity buffers, and only the layers that own a buffer bind ports in a
173+
state group — its KV-shared suffix owns none.
174+
- A `static_cache` package joined the checked-in onnx-genai conformance
175+
fixtures, so the engine exercises the fixed-capacity carry and the write
176+
cursor rather than only the growing-tensor path.
177+
178+
#### Fixed
179+
180+
- Gemma 4's shared-KV fallback pinned a 4-D BNSH shape onto *any* borrowed KV
181+
tensor whose rank was not 4. A static-cache source hands over a fully known
182+
rank-3 `[batch, capacity, kv_hidden]` buffer, so this overwrote a correct
183+
shape with a wrong one — corrupting the declared shape of
184+
`updated_key_cache.N` and defeating the rank-3 static-source test further
185+
down, which would then have transposed a rank-3 tensor as BNSH. The fallback
186+
now only supplies a shape when there is none.
187+
- Gemma 4's vision-language decoder dropped `attention_mask` whenever the export
188+
was static, but a Gemma 4 decoder is only *partly* static: its sliding layers
189+
keep a dynamic cache and build their bias from that mask. The hybrid decoder
190+
therefore lost all padding information. Both builders now apply one rule — a
191+
mask exists exactly when some layer still has a dynamic cache — so a fully
192+
static decoder carries no unused port and a hybrid one keeps its mask.
193+
- `--features fp8-kv-cache` no longer silently produces a float16 cache. The
194+
gate only tested whether GQA fusion was *expected*; the pass now reports how
195+
many caches it converted and the build fails when the answer is zero, naming
196+
the reason: FP8 KV storage needs an attention operator with `k_scale`/
197+
`v_scale` inputs, which a `TensorScatter` + `ai.onnx` `Attention` static-cache
198+
graph does not have.
199+
200+
63201
### Qwen3.5/3.6-MoE mixed float/quantized decoder (Olive checkpoints)
64202

65203
#### Fixed

‎README.md‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ multi-component export for pipelines.
3232
| **Multimodal** | Gemma 3/4, Phi-4MM (vision + audio + LoRA), Nemotron Parse, LLaVA, InternVL2, Mage-VL (image + streaming video), MiniCPM-V 4.6, Qwen2.5-VL, Qwen3-VL, Qwen3.5/3.6-VL, Pixtral |
3333
| **Encoder-only** | BERT, RoBERTa, ALBERT, DeBERTa, DistilBERT, ELECTRA, XLNet |
3434
| **Encoder-Decoder** | BART, T5/mT5, Marian, M2M-100, Pegasus, BigBird-Pegasus |
35-
| **Speech-to-Text** | Whisper, Moonshine, FastConformer-RNNT, FunASR, Qwen3-ASR, SenseVoice |
35+
| **Speech-to-Text** | Whisper, Moonshine, FastConformer-RNNT, FunASR, GLM-ASR, Qwen3-ASR, SenseVoice |
3636
| **Audio** | Wav2Vec2, HuBERT, WavLM, SpeechT5 |
3737
| **Vision** | ViT, BEiT, DeiT, DINOv2, Swin, CLIP, SigLIP |
3838
| **Diffusion** | Stable Diffusion (UNet + VAE + ControlNet), Flux, SD3, DiT, QwenImage / Qwen-Image-Edit-2509, HunyuanDiT, CogVideoX |
@@ -104,27 +104,36 @@ See the [EP quickstart](docs/ep_quickstart.md) and
104104
### CLI
105105

106106
```sh
107-
mobius build --model Qwen/Qwen2.5-0.5B output_dir/
107+
mobius build --model Qwen/Qwen2.5-0.5B --output output_dir/
108108

109109
# Build for CUDA with f16
110-
mobius build --model meta-llama/Llama-3.2-1B output_dir/ --ep cuda --dtype f16
110+
mobius build --model meta-llama/Llama-3.2-1B --output output_dir/ --ep cuda --dtype f16
111111

112112
# Build a diffusers pipeline (all components)
113-
mobius build --model Qwen/Qwen-Image-2512 output_dir/
113+
mobius build --model Qwen/Qwen-Image-2512 --output output_dir/
114114

115115
# Build encoder-decoder model (produces encoder/model.onnx + decoder/model.onnx)
116-
mobius build --model openai/whisper-tiny output_dir/
116+
mobius build --model openai/whisper-tiny --output output_dir/
117117
```
118118

119119
Build-mode toggles use the cargo-style `--features` option. Available features
120120
are `static-cache`, `fp8-kv-cache`, `prune-prefill-prefix`, and `text-only`. Pass them
121121
as a comma-separated list or repeat the option:
122122

123123
```sh
124-
mobius build --model meta-llama/Llama-3.2-1B output_dir/ \
124+
mobius build --model meta-llama/Llama-3.2-1B --output output_dir/ \
125125
--features static-cache,prune-prefill-prefix --max-seq-len 2048
126126
```
127127

128+
Use `--release` with either `build` or `build-gguf` to potentially reduce saved model size
129+
by stripping build-time debug and provenance metadata. Functional metadata with keys prefixed by
130+
`mobius.` is preserved:
131+
132+
```sh
133+
mobius build --model meta-llama/Llama-3.2-1B --output output_dir/ --release
134+
mobius build-gguf model.gguf --output output_dir/ --release
135+
```
136+
128137
See the [CLI Reference](https://onnxruntime.github.io/mobius/cli_reference.html) for all subcommands and flags.
129138

130139
### Examples

‎docs/api/build_from_gguf.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ python -m mobius build `
177177
--config .\nemotron-bf16 `
178178
--dtype bf16 --ep cuda `
179179
--external-data safetensors --max-shard-size 5GB `
180-
.\nemotron-bf16-onnx
180+
--output .\nemotron-bf16-onnx
181181
```
182182

183183
After the BF16 package passes full-logit and generation parity, quantize its

0 commit comments

Comments
 (0)