Skip to content

Emit executable native VLM contracts - #418

Merged
justinchuby merged 1 commit into
mainfrom
vlm-wp-a-executable-contract
Jul 22, 2026
Merged

justinchuby merged 1 commit into
mainfrom
vlm-wp-a-executable-contract

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • emit typed graph-derived inputs/outputs for every native VLM component, including source classification and exact sparse KV ports
  • route every compatible sequence edge (including per_layer_inputs) and run sequence-producing embedding stages on every decode step
  • emit qualified typed image endpoints/transforms and validate executable closure before writing the sidecar
  • reject missing/duplicate input sources and dtype/rank-incompatible edges with actionable component.port errors

The real Gemma4 audio output is rank 3 while the embedding input is rank 2, so the old invalid edge is no longer guessed; the embedding audio port is explicitly external until optional-modality/typed-audio transform semantics land.

Validation

  • PYTHONPATH=$PWD/src python3 -m pytest src/mobius/integrations/onnx_genai/inference_metadata_test.py tests/cli_test.py -q — 62 passed
  • lintrunner 0.12.7 with repository Ruff 0.15.14 adapters — clean
  • offline optimized Gemma4 E2B fp16 export — closure validator passed against all four saved ONNX graphs
  • verified 15 K/V layers (30 inputs/30 outputs), mixed 256/512 head dimensions, fp16 pixels + int64 patch coordinates, both embedding→decoder edges, and embedding every_step

Derive typed component I/O, complete sequence dataflow, phases, and KV state from ONNX graph ports and validate closure before writing metadata.

Co-authored-by: Copilot <[email protected]>
@github-actions

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 00c8fac → 6ae7017

Model Sub-model Changes Status

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

Copy link
Copy Markdown

Performance Comparison

Comparing 00c8fac → 6ae7017

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 68 68 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 107 107 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 62 62 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 58 58 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 98 98 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 60 60 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 62 62 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 58 58 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 413 413 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades native VLM inference_metadata emission to be graph-derived and executable: every component now emits typed port declarations (dtype/rank/shape + source classification), dataflow edges include rank, image preprocessing outputs are qualified as component.port endpoints, and a new closure validator rejects incomplete/ambiguous/non-executable contracts.

Changes:

  • Emit typed per-port I/O metadata for decoder/encoders (including KV port shapes) and qualify preprocessing outputs as vision_encoder.<port>.
  • Route all compatible sequence-shaped edges (including per_layer_inputs) and mark upstream sequence-producing components as every_step with required token stream inputs.
  • Add validate_executable_closure() to ensure every real graph input is bound exactly once with consistent dataflow/stateful/generated/external classification.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/mobius/integrations/onnx_genai/inference_metadata.py Adds typed port serialization, sequence-edge routing, input source classification, and executable-closure validation for native VLM packages.
src/mobius/integrations/onnx_genai/inference_metadata_test.py Updates tests for typed I/O + rank-carrying edges, adds regression coverage for closure validation and Gemma4 audio/embedding routing expectations.

Comment on lines +113 to +122
def _shape_metadata(port: _Port) -> list[int | str | None]:
"""Return a YAML-safe graph shape without losing symbolic dimensions."""
shape: list[int | str | None] = []
for dim in port.dims:
if isinstance(dim, int):
shape.append(dim)
continue
value = getattr(dim, "value", None)
shape.append(str(value) if value is not None else None)
return shape
Comment on lines +135 to +138
def _same_dim(left: Any, right: Any) -> bool:
if isinstance(left, int) or isinstance(right, int):
return left == right
return getattr(left, "value", None) == getattr(right, "value", None)
Comment on lines +969 to +975
if source.dtype != target.dtype or source.rank != target.rank:
raise _closure_error(
target_endpoint,
f"edge {source_endpoint} has dtype/rank {source.dtype}/{source.rank}, "
f"but the consumer requires {target.dtype}/{target.rank}.",
"insert an explicit typed transform or remove the incompatible edge.",
)
for component, model in pkg.items()
}
incoming: dict[str, list[dict[str, Any]]] = {}
for edge in pipeline.get("dataflow", []):
@justinchuby
justinchuby enabled auto-merge (squash) July 22, 2026 11:01
@justinchuby
justinchuby merged commit 640c1cb into main Jul 22, 2026
22 of 23 checks passed
@justinchuby
justinchuby deleted the vlm-wp-a-executable-contract branch July 22, 2026 11:11
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.44444% with 73 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...bius/integrations/onnx_genai/inference_metadata.py 67.12% 27 Missing and 21 partials ⚠️
...integrations/onnx_genai/inference_metadata_test.py 26.47% 25 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants