Repository navigation
Ensure model package type correctness - #477
Conversation
`_add_explicit_io_to_file` augments an emitted `inference_metadata.yaml`
sidecar with the explicit `model.io` port contract (kv_inputs/kv_outputs/
state_pairs, token/logits roles) derived from the actual ONNX graph ports.
It previously bailed out silently when *any* in-memory package component
lacked a `.graph` attribute:
if not models or any(not hasattr(model, "graph") for model in models):
return # silent no-op -> ships THIN metadata
Large decoders built with external-data / streamed weights do not retain
the `ir.Graph` in memory, so this guard shipped thin metadata (only
`model.attention` + `kv_cache`, no `io`). This is exactly what produced the
Qwen3.6-27B int4 CUDA sidecar, forcing downstream runtimes to derive I/O
from the graph at load (onnx-genai native EP workaround) and breaking
ORT-genai, which could not resolve `model.io.token_input`.
Fix: when a component's graph is not in memory, reload it from the
`model.onnx` written next to the sidecar via `onnx_ir.load` (external data
resolves relative to the model file) and derive ports from that. The
disk-loaded `ir.Model` is a drop-in for `.graph` access. Only when the
graph is genuinely unavailable (missing in memory *and* on disk) do we
skip augmentation -- and then loudly via `logging.warning`, never silently
shipping thin metadata. The in-memory `.graph` fast path is preserved
(no unnecessary reload).
Attribute-driven: no model-name gates. Verified end-to-end against the real
Qwen3.6-27B graph -- the re-emitted sidecar gains a full `io` block (32 kv
entries + 96 conv/recurrent state_pairs).
Regression tests cover: graphless decoder reloads a hybrid (linear-attention
conv_state/recurrent_state + GQA KV) contract from disk; graphless with no
disk model warns and skips; in-memory `.graph` is never reloaded.
Co-authored-by: Copilot <[email protected]>
af4f38a to
e930574
Compare
Performance Comparison
|
There was a problem hiding this comment.
Pull request overview
This PR fixes cases where onnx-genai inference_metadata.yaml is emitted without an explicit model.io contract when the in-memory ModelPackage components don’t retain an ir.Graph (notably for large external-data / streamed-weight decoders). It preserves the in-memory fast path, and otherwise reloads the component graph from the emitted model.onnx on disk to derive kv_inputs/kv_outputs/state_pairs and token/logits roles; when neither in-memory nor disk graphs are available, it now logs a warning instead of silently producing thin metadata.
Changes:
- Reload missing component graphs from disk via
onnx_ir.load()when augmenting sidecarmodel.iometadata. - Emit loud warnings (instead of silent no-ops) when graph reload isn’t possible.
- Add regression tests covering disk-reload behavior, warning/skip behavior, and preserving the in-memory fast path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/mobius/integrations/onnx_genai/auto_export.py | Reloads component graphs from disk to derive explicit model.io, preserving fast path and warning on failure. |
| src/mobius/integrations/onnx_genai/auto_export_test.py | Adds regression tests for graphless decoders (reload succeeds, reload missing warns/skips, fast path doesn’t reload). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| graph in memory, in which case we reload the graph from the ``model.onnx`` | ||
| file already written next to the sidecar. Only when a component's graph is | ||
| truly unavailable (missing in memory *and* on disk) do we skip it — and then | ||
| loudly, never silently shipping thin metadata. |
|
@copilot can you instead uphold the invariant that the graph is available, and have a test to guard all new models? |
Require every ModelPackage component to retain an in-memory ONNX graph, so runtime metadata generation does not rely on reloading exported models. Signed-off-by: GitHub <[email protected]> Co-authored-by: justinchuby <[email protected]>
|
|
Implemented in 30ff64a. |
| assert pkg["new"] is m | ||
|
|
||
| def test_rejects_component_without_graph(self): | ||
| with pytest.raises(TypeError, match="must be an ir.Model with a graph"): |
| ModelPackage({"invalid": object()}) # type: ignore[arg-type] | ||
|
|
||
| pkg = ModelPackage() | ||
| with pytest.raises(TypeError, match="must be an ir.Model with a graph"): |
Ensure model package type