Repository navigation
Add SenseNova-U1.5-8B-MoT (NEO-unify) unified any-to-any support - #533
justinchuby wants to merge 4 commits into
Conversation
Adds full Mobius support for sensenova/SenseNova-U1.5-8B-MoT, a native unified multimodal model (understanding + image generation + editing). Architecture (root-caused from the upstream reference implementation at github.com/OpenSenseNova/SenseNova-U1 @ feat/u1.5 — the HF repo declares auto_map entries for configuration_neo_chat.py / modeling_neo_chat.py but does not ship those files, so the GitHub package is the only source): * Mixture of Transformers (MoT): all 42 Qwen3 decoder layers carry two complete, disjoint weight sets. The understanding branch handles text and reference images; every module suffixed `_mot_gen` handles the noisy image tokens of the flow-matching sampler. Attention is shared — the generation pass reads the KV cache written by the understanding pass, which is how text conditioning reaches image tokens. Upstream raises NotImplementedError for a mixed forward, so exporting the two branches as two graphs is the only faithful decomposition. * Three rotary axes inside head_dim 128: temporal [0:64) at rope_theta, image height [64:96) and width [96:128) at rope_theta_hw. QK-norm is applied per half (q_norm over 64 temporal dims, q_norm_hw over 64 spatial dims), matching the checkpoint's [64]-shaped norm tensors. * Block-causal attention: allow[i][j] = (t[j] == t[i]) or (j <= i), so patches of one image attend bidirectionally. * Vision tower has no transformer blocks — Conv2d patchify, GELU, interleaved 2-D RoPE, Conv2d 2x2 merge into the LLM width. * No VAE: use_pixel_head drives a pixel-shuffle ConvDecoder that decodes generation hidden states straight to RGB. Ships SenseNovaU1Config (lifts text fields from the nested llm_config), a bare vision extractor hook, SenseNovaU1Model, SenseNovaU1Task building five graphs (model / vision / embedding / image_gen_embedding / image_gen_denoiser), and registry wiring for model_type `neo_chat`. All 1116 checkpoint tensors map onto ONNX initializers with zero unmapped keys and zero shape mismatches; the only initializers without a checkpoint source are derived RoPE and timestep-frequency tables. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
Two defects surfaced only when running the real 17.5B checkpoint through onnxruntime on CUDA; both are fixed here: * `_TimestepEmbedder` built its sinusoidal basis in float32 but read the frequency table after `_cast_module_dtype` had demoted it to the model dtype, producing a `Mul` with mismatched operand types that made the `image_gen_embedding` graph unloadable in fp16. The table is now cast up explicitly, keeping the basis in float32 as upstream does. * The denoiser graph dropped its `present_key`/`present_value` outputs. ORT's CUDA Attention kernel requires them whenever `past_key`/`past_value` are supplied, so every denoise step failed at layer 0. They are now registered; the sampler still discards them, which preserves upstream's `update_cache=False` semantics (the understanding prefix stays frozen across flow-matching steps). `_ConvDecoder` also derives its upsample factor from `pixels_per_token` instead of hardcoding 32x. That is exactly `patch_size * merge_size` for the released checkpoint (so `conv2` keeps its 192 = 3*8*8 channels), but it no longer silently produces wrongly-sized images for other geometries. Adds docs/design/sensenova-u1-neo-unify.md recording what was verified against the checkpoint and the reference implementation: the Hub packaging gap (declared-but-absent remote code, shard-numbering slack), the parameter budget, MoT routing, the three rotary axes, block-causal masking, the transformer-free vision tower, the VAE-free pixel head, and the upstream code paths that are dead for inference. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
Renames the package components from `model`/`vision` to `decoder`/ `vision_encoder`, matching VisionLanguageTask, VisionLanguage3ModelTask and HunYuanVLMoTTask. Beyond consistency this makes the package recognisable to `is_native_vlm_package`, so the metadata emitter now reports a specific, actionable failure instead of the generic "unrecognised multi-component package shape". Records `neo_chat` in `_SPECIALIZED_TEST_MODEL_TYPES`: the co-located test module covers it, and the generic VLM harness cannot -- the package carries an image-generation branch the harness has no notion of. Adds TestInferenceMetadataStatus, which pins the exact current blocker so the documented status cannot drift from reality: * Export and execution are complete for all five graphs. * Metadata emission blocks in the image-processor contract: the NEO vision tower takes a plain (1, 3, H, W) image and the Hub repo ships no preprocessor_config.json, so no processor program binds and no image_mean/image_std are declared. * No emitter shape describes a unified any-to-any package (a text decoder plus a flow-matching branch sharing one KV cache), and ORT GenAI has no runtime pipeline for one, so a contract alone would not be executable. The design doc gains the runtime/metadata status section and the precision finding that the `_mot_gen` branch -- stored F32 upstream -- overflows fp16 during sampling and must be exported at float32, while the BF16 understanding branch exports cleanly to float16. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
* `preprocess_weights` now honours `tie_word_embeddings`. Only an explicit `language_model.lm_head.weight` populated `decoder.lm_head` before, so a tied `neo_chat` variant would leave that initializer unfilled. The released 8B checkpoint is untied, so this was latent, but the registry declares a family/variant pair that anticipates siblings. Mirrors the existing HunYuan VL-MoT handling. Covered by two new tests. * Drops the `update_cache` parameter from `_MoTAttention`, `_MoTDecoderLayer` and `_SenseNovaU1DecoderBody`. It was declared, threaded through three modules, and never read: ONNX `Attention` always emits `present = concat(past, new)`. The understanding prefix stays frozen because the *caller* discards the denoiser's present outputs, which is documented at that contract boundary in the task. Keeping a flag that implied graph-level behaviour it did not have was a trap. * Removes the unused expanded `mask` in the embedding model. `op.*` calls emit IR nodes, so `del mask` dropped only the Python name — the Unsqueeze/Expand survived until DCE. Also drops the vestigial `num_heads` argument from `_rotate_half_axis`. * Documents why GQA fusion cannot fire for either decoder graph (the block-causal bias contains an `Or`, the denoiser has no attention_mask input, and the three-axis RoPE is not `op.RotaryEmbedding`), so the CUDA/fp16 export warning is not misdiagnosed later. Verified graph-identical to the exported artifacts: all five components match the on-disk node counts exactly, and the end-to-end image is bit-identical to the pre-refactor run. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
Performance Comparison
|
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
There was a problem hiding this comment.
Pull request overview
Adds Mobius support for the SenseNova-U1.5 NEO-unify unified any-to-any model (model_type: neo_chat) by introducing a new 5-component task/model split (understanding + generation branches) plus config extraction, registry wiring, tests, and architecture documentation.
Changes:
- Introduces
SenseNovaU1ModelandSenseNovaU1Taskto export five ONNX components (decoder,vision_encoder,embedding,image_gen_embedding,image_gen_denoiser). - Adds
SenseNovaU1Configwith composite config extraction (lift text fields fromllm_config) and a per-model vision hook forneo_chat. - Wires the new model into the registry and adds co-located unit/execution/contract tests and a design write-up.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/build_graph_test.py | Marks neo_chat as a specialized model type (outside generic VLM harness). |
| src/mobius/tasks/_sensenova_u1.py | New 5-component task building the understanding + generation graphs. |
| src/mobius/tasks/init.py | Exposes SenseNovaU1Task and registers task name sensenova-u1. |
| src/mobius/models/sensenova_u1.py | New NEO-unify model implementation (MoT branches, 3-axis RoPE, block-causal mask, pixel head) + weight routing. |
| src/mobius/models/sensenova_u1_test.py | Co-located tests for graph contracts, config extraction, weight routing, and CPU execution. |
| src/mobius/models/init.py | Exports SenseNovaU1Model. |
| src/mobius/_registry.py | Registers neo_chat → SenseNovaU1Model + default model ID mapping. |
| src/mobius/_configs/per_model/_sensenova_u1_vision.py | Adds a neo_chat vision-config extractor hook handling upstream quirks. |
| src/mobius/_configs/per_model/init.py | Imports the new per-model vision hook module. |
| src/mobius/_configs/_base.py | Adds SenseNovaU1Config and composite extraction logic. |
| src/mobius/_configs/init.py | Exports SenseNovaU1Config. |
| docs/design/sensenova-u1-neo-unify.md | Adds architecture/source-of-truth documentation for the model. |
| docs/design/index.md | Adds the new design doc to the index. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| latent = builder.input( | ||
| "latent", | ||
| dtype=config.dtype, | ||
| shape=[1, 3, height, width], | ||
| ) |
| batch = ir.SymbolicDim("batch") | ||
| seq_len = ir.SymbolicDim("sequence_len") | ||
| num_features = ir.SymbolicDim("num_image_tokens") | ||
|
|
||
| graph, builder = _make_graph(name="embedding") | ||
| op = builder.op | ||
| input_ids = builder.input( | ||
| "input_ids", | ||
| dtype=ir.DataType.INT64, | ||
| shape=[batch, seq_len], | ||
| ) | ||
| image_features = builder.input( | ||
| "image_features", | ||
| dtype=config.dtype, | ||
| shape=[1, num_features, config.hidden_size], | ||
| ) | ||
| image_mask = builder.input( | ||
| "image_mask", | ||
| dtype=ir.DataType.BOOL, | ||
| shape=[batch, seq_len], | ||
| ) |
|
Canonical hashless metadata and executable generic shared-state workflow validation are now implemented in #540, with the runtime contract in justinchuby/onnx-genai#1700. #540 carries this branch's model implementation rebased onto current main and preserves the existing L4/L5 evidence; ordinary CI uses only deterministic tiny graphs. |
## Summary This rebases the existing SenseNova U1.5 implementation from #533 onto current `main` and removes its canonical-metadata waiver. - structurally detect a generic five-component shared-state pixel-flow package - emit hashless canonical metadata for embedding, vision encoder, understanding decoder, generation embedding, and generation denoiser - synthesize the exact missing processor asset: DecodeImage/RGB, pixel-area resize aligned to 32 (512²–2048²), Lanczos, `1/255`, ImageNet normalization - express conditional/unconditional frozen KV groups, fp16→fp32 boundaries, per-step embedding, CFG, x0 prediction, `v=(x0-z)/max(1-t,t_eps)`, Euler update, and pixel output using generic workflow IR - add a deterministic no-network five-component conformance package and committed reviewable fixture - replace `TestInferenceMetadataStatus` negative coverage with positive hashless metadata and processor assertions No model implementation, weight mapping, or existing L4/L5 evidence is changed. No model-family fields, hashes/fingerprints, IR version, or ONNX opsets are added to canonical metadata. ## Validation split ### Ordinary PR CI - tiny graph construction and producer tests - schema/admission validation - executable synthetic text-only path - executable two-step text-to-image CFG/flow loop - executable reference-image edit path - shared frozen KV and mixed fp16-understanding/fp32-generation boundaries ### Pinned real H200 validation The existing #533 evidence remains authoritative and is documented rather than downloaded in CI: - model revision `1f6ec60423d29939dde4202fd82ae340b144e280` - 17.5B parameters / ~50 GB checkpoint - L4 stage parity for prefix KV, image embedding, step-0/step-7 x0, and final image - L5 coherent text, 512x512 text-to-image, and reference-image edit outputs ## Local validation - `PYTHONPATH=src python -m pytest src/mobius/models/sensenova_u1_test.py -q` — 25 passed - generate + compare all ONNX GenAI workflow fixtures — pass - ONNX GenAI schema/admission of `shared_state_pixel_flow` — pass - ONNX GenAI executable conformance matrix — text, generation, edit all pass Depends on justinchuby/onnx-genai#1700 for generic `read_only` state aliases and dynamic image-adapter dimensions. --------- Signed-off-by: justinchuby <[email protected]> Signed-off-by: justinchuby <[email protected]> Co-authored-by: Copilot <[email protected]>
|
Superseded by #540, which rebased and merged the complete SenseNova U1.5 implementation and its existing L4/L5 evidence onto current Post-merge corrections discovered by executing the real pinned 17.5B package through ONNX GenAI's canonical engine are in #545 (seeded noise, independent CFG prefix/KV symbols, forward x0 flow schedule, and bounded image output). Generic runtime support and synthetic execution are tracked in justinchuby/onnx-genai#1700. Published validated package: https://huggingface.co/justinchuby/sensenova-u1.5-8b-mot-onnx-canonical Closing this PR to avoid maintaining two divergent implementations; its evidence remains preserved here and in the merged design documentation. |
## Summary Follow-up to merged #540 that incorporates findings from real canonical-engine execution of the pinned SenseNova U1.5 package. - derive deterministic image noise from generic `seed`/`width`/`height` request roles; caller latent remains an optional override - keep positive and negative CFG prefixes and their frozen KV sequence symbols independent - integrate the x0 flow from `t=0` to `t=1` using `v=(x0-z)/max(1-t,t_eps)` - clamp generic pixel output to the declared `[-1, 1]` range - add reusable image-noise geometry and tensor-clamp policy components - regenerate the hashless canonical fixture and document production H200 evidence No SenseNova/NEO dispatch or family-specific metadata fields are added. ## Validation - `python3 -m pytest src/mobius/models/sensenova_u1_test.py src/mobius/generation/_policy_components_test.py -q --tb=short` — **78 passed** - generated fixture exactly matches `tests/fixtures/onnx_genai_workflows/shared_state_pixel_flow/inference_metadata.yaml` - targeted Ruff format/check and `git diff --check` pass ## Real canonical runtime evidence Executed by ONNX GenAI `Engine::from_pipeline_dir` on H200 using the pinned 17.5B export (`1f6ec60423d29939dde4202fd82ae340b144e280`), not custom orchestration: - text understanding prefill: logits `[1, 28, 151936]` - 512×512 text-to-image, 20 steps: **6.99 s** - 512×512 reference-image edit, 20 steps: **16.68 s** - peak observed VRAM: **91,256 MiB** - final outputs finite and bounded exactly to `[-1, 1]` Published package: https://huggingface.co/justinchuby/sensenova-u1.5-8b-mot-onnx-canonical Upload commit: `f3f2eaf79f4991febee107cdabd0b27f0161b06e` A clean 24 MB selective download of metadata, policies, graph descriptors, tokenizer, and processor assets passes canonical admission. ## Remaining runtime limitations - text path currently validates understanding prefill, not full autoregressive decode - generic Images/A1111 bindings cannot yet select a path-specific image chat template or construct reference-image placeholder masks for this unified package - portable counter RNG is deterministic but intentionally does not reproduce PyTorch RNG, so final pixels are not directly comparable to #533's controlled-latent reference Runtime support and synthetic executable coverage are in justinchuby/onnx-genai#1700. --------- Signed-off-by: justinchuby <[email protected]> Signed-off-by: justinchuby <[email protected]> Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot <[email protected]>
Adds Mobius support for
sensenova/SenseNova-U1.5-8B-MoT(model_type: neo_chat, architectureNEOChatModel) — a native unified any-to-any model doing multimodal understanding, text-to-image generation and image editing from one backbone.Pinned revision
1f6ec60423d29939dde4202fd82ae340b144e280, Apache-2.0. 17,532,854,464 parameters (≈50.2 GB) despite the8Bin the name.Upstream source: a Hub packaging gap, resolved
The HF repo declares remote code it does not ship —
configuration_neo_chat.pyandmodeling_neo_chat.pyboth 404 at the pinned revision and atmain, sotrust_remote_code=Truecannot work against the Hub repo alone. The model card resolves it: the reference implementation is thesensenova_u1package at OpenSenseNova/SenseNova-U1 (branchfeat/u1.5), undersrc/sensenova_u1/models/neo_unify/. That package is the authority used here — nothing was inferred from names.Two further packaging quirks, both verified benign:
model-000{02,03,04}-of-00016.safetensorsare absent, butmodel.safetensors.index.jsonreferences no tensor in them. All 1116 tensors resolve; the checkpoint is complete. Numbering slack, not missing weights.preprocessor_config.jsonand notokenizer.json— image preprocessing exists only in code, and the tokenizer must be built fromvocab.json+merges.txt. This has a direct consequence for metadata (below).Architecture, root-caused
Mixture of Transformers. All 42 Qwen3 layers carry two complete, disjoint weight sets. The understanding branch handles text and reference images; every module suffixed
_mot_genhandles the noisy image tokens of the flow-matching sampler. There is nolm_head_mot_gen— the generation branch feeds the image head instead.Routing is per forward call, not per token, and upstream
Qwen3Attention.forward/Qwen3DecoderLayer.forwardraiseNotImplementedErrorfor a mixed pass (upstream issue #207). Production always splits at token-type boundaries: an understanding pass writes a KV cache, then the generation pass reads that frozen cache once per denoise step. Exporting two decoder graphs is therefore the only faithful decomposition, not a convenience.Three rotary axes inside
head_dim128 — temporal[0:64)atrope_theta5e6, height[64:96)and width[96:128)atrope_theta_hw1e4. QK-norm applies per half (q_normover the 64 temporal dims,q_norm_hwover the 64 spatial dims), which is why the checkpoint's norm tensors are shape[64], not[128].Block-causal attention:
allow[i][j] = (t[j] == t[i]) or (j <= i). All patches of one image share a temporal index, so they attend bidirectionally. For pure text every index is distinct and this degenerates to plain causal — which is exactly why text-only parity passes even with a naive causal mask and image parity does not.Vision tower has no transformer blocks at all —
Conv2d(3,1024,k16,s16)→ GELU → interleaved 2-D RoPE →Conv2d(1024,4096,k2,s2). One LLM token covers a 32×32 pixel tile.No VAE.
use_pixel_headdrives a pixel-shuffleConvDecoder(ONNXDepthToSpacemode="CRD") straight to RGB. It predicts x0, and the sampler converts viav = (x0 - z) / max(1 - t, t_eps).Full write-up, including the upstream code paths that are dead for inference, in
docs/design/sensenova-u1-neo-unify.md.What's added
SenseNovaU1Config(lifts text fields from the nestedllm_config), a bare vision extractor hook,SenseNovaU1Model,SenseNovaU1Task, and registry wiring forneo_chat. Five components:embeddingembed_tokens+ reference-image scattervision_encoderdecodernorm+lm_headimage_gen_embeddingvision_model_mot_gen+ timestep / noise-scale embeddersimage_gen_denoiser_mot_genlayers +norm_mot_gen+ pixel headdecoderandimage_gen_denoisershare the KV-cache layout, which is what lets the denoiser consume the prefill cache.Validation
Weight alignment — all 1116/1116 checkpoint tensors map onto ONNX initializers: 0 unmapped, 0 missing, 0 shape mismatches. The only initializers without a checkpoint source are derived RoPE/timestep tables.
L1/L2 — 24 co-located tests: graph build for f32/f16/bf16, I/O contracts, config extraction, weight routing, and executable CPU checks including
batch=2with ragged padding and a test that image tokens sharing a temporal index really do attend bidirectionally.L3 synthetic parity vs upstream PyTorch, component by component (fp32, tiny config):
fm_headConvDecoderL4/L5 real 17.5 B weights on an H200 — exported with
mobius.build(..., load_weights=True)(35.16 GB fp16 + 31 GB fp32 generation branch) and run through onnxruntime CUDA.Upstream PyTorch reference for comparison: 35.07 GB bf16, 35.41 GB CUDA peak, 2.52 steps/s.
Stage-by-stage vs upstream, shared initial latent (so every delta is attributable to the export, not sampling randomness):
image_embeds, step 0Final-image PSNR 36.42 dB — consistent with fp16-vs-bf16 drift, not architectural error. The two images are visually indistinguishable (below).
Precision finding
The two branches must be exported at different precisions, matching how the checkpoint itself stores them:
NaNpart-way through sampling (reproducibly at step 15 of 20 at 512×512). It needs float32.Mixing works end to end — the sampler casts the fp16 KV cache once after prefill.
Known gaps (deliberate, documented, test-pinned)
Canonical inference metadata is not emissible yet. Export and execution are complete; the blockers are elsewhere and are separated precisely by
TestInferenceMetadataStatusso the docs cannot drift:(1, 3, H, W)image and the Hub ships nopreprocessor_config.json, so no processor program binds and noimage_mean/image_stdare declared.GQA fusion does not fire for either decoder graph on CUDA/fp16 (Mobius warns at export). Three independent guards each decline correctly: the block-causal bias contains an
Or; the denoiser has noattention_maskinput; the three-axis RoPE is notop.RotaryEmbedding. Correctness is unaffected; documented so it isn't misdiagnosed later.Waivers
The fast suite reports 23 pre-existing failures, all
TypeError: save() got an unexpected keyword argument 'max_shard_size_bytes'. These come from the installedonnx_ir0.2.1 lacking that kwarg whileorigin/main's_model_package.pyalready passes it. That file is untouched by this branch (git diff --name-only origin/main...HEADconfirms). Excluding them: 4218 passed, ruff check and format clean.Test commands
Real outputs
Controlled comparison — identical initial latent, 8 steps, 512×512
Upstream PyTorch (bf16) vs Mobius ONNX (fp16 understanding + fp32 generation). Pearson r = 0.998606, PSNR 36.42 dB.
Text-to-image, 20 steps, cfg 4.0
Independently sampled (numpy vs torch RNG), so these are different draws of the same prompt — both photoreal, confirming the exported model is not merely close to the reference but genuinely generative.
Image editing through ONNX
Input: the upstream image above. Prompt: "Change the sky to a dramatic starry night. Keep the mountains, lake and rocks unchanged."
The reference image is encoded by the
vision_encodertower (32×32 patches → 256 tokens), scattered into the prompt by theembeddinggraph, and conditions the_mot_genbranch. Mountains, shoreline, reflection and foreground rocks are preserved while the sky is replaced — end-to-end proof that the understanding image path,get_thw_indexesposition derivation and edit conditioning are all correct.Text decoding through ONNX
TTFT 0.225 s, 53.06 tok/s, fp16 on H200: