Skip to content

Commit b6fb109

Browse files
justinchubyCopilot
andcommitted
feat: emit canonical shared-state pixel-flow metadata
Describe SenseNova U1.5 through a generic five-component workflow with exact image preprocessing, frozen shared KV, mixed-precision casts, CFG, x0 flow conversion, and loop execution. Add deterministic producer fixtures and positive metadata status coverage without changing the model implementation or real-weight evidence. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
1 parent a275bf9 commit b6fb109

13 files changed

Lines changed: 2544 additions & 68 deletions

File tree

‎docs/design/sensenova-u1-neo-unify.md‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -245,28 +245,28 @@ input; neither is required for correctness.
245245
## Runtime / metadata status
246246

247247
Export and execution are complete — all five graphs build, load, and run
248-
on CPU and CUDA. Canonical inference metadata is **not** emissible today,
249-
for three distinct and separately-tracked reasons:
250-
251-
1. **Image-processor contract.** `build_native_vlm_package_metadata`
252-
dispatches on the vision graph's input signature. The NEO tower takes
253-
a plain `(1, 3, height, width)` float image, and the Hub repo ships no
254-
`preprocessor_config.json`, so neither a registered processor program
255-
nor declared `image_mean` / `image_std` / `do_resize` values exist for
256-
the emitter to bind. This is a *metadata* blocker, not an export one.
257-
2. **No contract for the generation branch.** The current emitter shapes
258-
are diffusion, audio codec, multimodal VLM and speech-to-text. A
259-
unified any-to-any package — a text decoder plus a second transformer
260-
branch driven by a flow-matching outer loop over a shared KV cache —
261-
matches none of them, and emitting plain VLM metadata would describe
262-
only half the model.
263-
3. **Runtime.** ORT GenAI has no pipeline that alternates two weight
264-
branches over one KV cache with a sampler loop in between, so even a
265-
complete contract would not be executable today.
266-
267-
Until (1)-(3) are addressed the package is driven directly through
268-
onnxruntime; the sampler math (schedule, CFG, Euler step) is ~40 lines
269-
and lives outside the graphs by design, mirroring upstream.
248+
on CPU and CUDA. Mobius now emits canonical hashless metadata for all five
249+
components plus the exact synthesized processor asset: RGB decode, pixel-area
250+
resize aligned to 32 in the 512²–2048² range, `1/255` rescaling, and ImageNet
251+
normalization.
252+
253+
The generic workflow writes conditional and unconditional understanding KV
254+
once, casts the fp16 prefixes to fp32, and lets both CFG generation branches
255+
read the frozen state. The loop describes per-step image embedding, x0
256+
prediction, `v = (x0 - z) / max(1 - t, t_eps)`, and Euler integration. This is
257+
an architecture-neutral shared-state pattern; no model-family dispatch exists
258+
in the runtime.
259+
260+
PR CI uses deterministic tiny graphs to execute text-only, text-to-image, and
261+
reference-image-edit paths, including mixed precision, shared KV, CFG, and a
262+
two-step loop. Production evidence remains the pinned H200 run from PR #533:
263+
revision `1f6ec60423d29939dde4202fd82ae340b144e280`, stage-by-stage L4 parity,
264+
and L5 text/image/edit outputs. It is intentionally not repeated in ordinary CI
265+
because the checkpoint is about 50 GB. Before a release, rerun the same pinned
266+
export on an H200 with `mobius.build(..., revision=<revision>,
267+
load_weights=True)`, fp16 understanding and fp32 generation components, then
268+
repeat the shared-latent stage comparison and the three L5 output checks
269+
recorded in PR #533.
270270

271271

272272
## Dead or misleading upstream details

‎src/mobius/generation/__init__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
build_duplex_user_stream_merge,
3131
build_duplex_waveform_append,
3232
build_effectful_identity,
33+
build_empty_batched_features,
3334
build_empty_features,
3435
build_eos_termination,
3536
build_euler_model_input,
@@ -39,6 +40,7 @@
3940
build_greedy_sampler,
4041
build_guidance_combine,
4142
build_identity_model_input,
43+
build_image_grid_positions,
4244
build_integer_add,
4345
build_integer_minimum,
4446
build_integer_row_broadcast,
@@ -61,6 +63,7 @@
6163
build_shape_constant,
6264
build_speculative_acceptance,
6365
build_speculative_state_rollback,
66+
build_tensor_cast,
6467
build_tensor_scale,
6568
build_termination_batch_initializer,
6669
build_token_block_identity,
@@ -77,6 +80,7 @@
7780
build_video_latent_initializer,
7881
build_video_latent_permute,
7982
build_video_latent_unscale,
83+
build_x0_flow_velocity,
8084
build_zeros_like,
8185
rotary_axis_count,
8286
)
@@ -107,13 +111,15 @@
107111
"build_duplex_waveform_append",
108112
"build_effectful_identity",
109113
"build_empty_features",
114+
"build_empty_batched_features",
110115
"build_eos_termination",
111116
"build_euler_model_input",
112117
"build_euler_solver_step",
113118
"build_flow_match_solver_step",
114119
"build_grammar_logits_processor",
115120
"build_greedy_sampler",
116121
"build_guidance_combine",
122+
"build_image_grid_positions",
117123
"build_identity_model_input",
118124
"build_integer_add",
119125
"build_integer_minimum",
@@ -138,6 +144,7 @@
138144
"build_speculative_acceptance",
139145
"build_speculative_state_rollback",
140146
"build_tensor_scale",
147+
"build_tensor_cast",
141148
"build_termination_batch_initializer",
142149
"build_token_block_identity",
143150
"build_token_state_update",
@@ -153,6 +160,7 @@
153160
"build_video_latent_initializer",
154161
"build_video_latent_permute",
155162
"build_video_latent_unscale",
163+
"build_x0_flow_velocity",
156164
"build_zeros_like",
157165
"rotary_axis_count",
158166
]

‎src/mobius/generation/_policy_components.py‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,21 @@ def build_empty_features(dtype: ir.DataType, feature_size: int) -> PolicyCompone
639639
return _component("mobius.policy.auxiliary@1", graph, {})
640640

641641

642+
def build_empty_batched_features(
643+
dtype: ir.DataType,
644+
feature_size: int,
645+
) -> PolicyComponent:
646+
"""Build ``(1, 0, hidden)`` features for an optional single-image path."""
647+
graph, builder = _make_graph("empty_batched_features")
648+
features = builder.op.ConstantOfShape(
649+
builder.op.Constant(value_ints=[1, 0, feature_size]),
650+
value=ir.tensor([0.0], dtype=dtype),
651+
)
652+
features.shape = ir.Shape([1, 0, feature_size])
653+
builder.add_output(features, "features")
654+
return _component("mobius.policy.auxiliary@1", graph, {})
655+
656+
642657
def rotary_axis_count(position_value: ir.Value) -> int | None:
643658
"""Number of rotary axes a decoder's ``position_ids`` input carries.
644659
@@ -1670,6 +1685,106 @@ def build_guidance_combine(dtype: ir.DataType = ir.DataType.FLOAT) -> PolicyComp
16701685
)
16711686

16721687

1688+
def build_tensor_cast(
1689+
source_dtype: ir.DataType,
1690+
target_dtype: ir.DataType,
1691+
dims: Sequence[str] = ("batch", "heads", "sequence", "head_dim"),
1692+
) -> PolicyComponent:
1693+
"""Cast a typed tensor at an explicit component precision boundary."""
1694+
graph, builder = _make_graph("tensor_cast")
1695+
value = builder.input("value", source_dtype, list(dims))
1696+
cast = builder.op.Cast(value, to=target_dtype)
1697+
cast.type = ir.TensorType(target_dtype)
1698+
_set_public_shape(cast, list(dims))
1699+
builder.add_output(cast, "cast")
1700+
return _component("mobius.policy.auxiliary@1", graph, {})
1701+
1702+
1703+
def build_x0_flow_velocity(
1704+
dtype: ir.DataType = ir.DataType.FLOAT,
1705+
*,
1706+
t_eps: float = 0.02,
1707+
) -> PolicyComponent:
1708+
"""Convert a clean-sample prediction into flow velocity.
1709+
1710+
Unified pixel-space generators commonly predict ``x0`` rather than
1711+
velocity. Their flow-matching derivative is
1712+
``(x0 - sample) / max(1 - timestep, t_eps)``.
1713+
"""
1714+
graph, builder = _make_graph("x0_flow_velocity")
1715+
op = builder.op
1716+
sample = builder.input("sample", dtype, ["batch", "channels", "height", "width"])
1717+
x0 = builder.input("x0", dtype, ["batch", "channels", "height", "width"])
1718+
timestep = builder.input("timestep", dtype, ["batch"])
1719+
one = op.CastLike(op.Constant(value_float=1.0), timestep)
1720+
epsilon = op.CastLike(op.Constant(value_float=float(t_eps)), timestep)
1721+
denominator = op.Max(op.Sub(one, timestep), epsilon)
1722+
denominator = op.Unsqueeze(denominator, op.Constant(value_ints=[1, 2, 3]))
1723+
velocity = op.Div(op.Sub(x0, sample), denominator)
1724+
velocity.type = ir.TensorType(dtype)
1725+
_set_public_shape(velocity, ["batch", "channels", "height", "width"])
1726+
builder.add_output(velocity, "velocity")
1727+
return _component("onnx-genai.flow-velocity@1", graph, {})
1728+
1729+
1730+
def build_image_grid_positions(
1731+
dtype: ir.DataType = ir.DataType.FLOAT,
1732+
*,
1733+
pixels_per_token: int,
1734+
) -> PolicyComponent:
1735+
"""Derive a three-axis image position grid from a pixel-space latent."""
1736+
graph, builder = _make_graph("image_grid_positions")
1737+
op = builder.op
1738+
latent = builder.input("latent", dtype, ["batch", "channels", "height", "width"])
1739+
prompt_tokens = builder.input(
1740+
"prompt_tokens", ir.DataType.INT64, ["batch", "prompt_sequence"]
1741+
)
1742+
batch = op.Shape(latent, start=0, end=1)
1743+
height = op.Div(
1744+
op.Shape(latent, start=2, end=3),
1745+
op.Constant(value_ints=[pixels_per_token]),
1746+
)
1747+
width = op.Div(
1748+
op.Shape(latent, start=3, end=4),
1749+
op.Constant(value_ints=[pixels_per_token]),
1750+
)
1751+
count = op.Mul(height, width)
1752+
flat = op.Range(
1753+
op.Constant(value_int=0),
1754+
op.Squeeze(count, op.Constant(value_ints=[0])),
1755+
op.Constant(value_int=1),
1756+
)
1757+
token_shape = op.Concat(batch, count, axis=0)
1758+
height_positions = op.Expand(
1759+
op.Unsqueeze(
1760+
op.Div(flat, op.Squeeze(width, op.Constant(value_ints=[0]))),
1761+
op.Constant(value_ints=[0]),
1762+
),
1763+
token_shape,
1764+
)
1765+
width_positions = op.Expand(
1766+
op.Unsqueeze(
1767+
op.Mod(flat, op.Squeeze(width, op.Constant(value_ints=[0])), fmod=0),
1768+
op.Constant(value_ints=[0]),
1769+
),
1770+
token_shape,
1771+
)
1772+
prompt_length = op.Shape(prompt_tokens, start=1, end=2)
1773+
temporal = op.Expand(prompt_length, token_shape)
1774+
positions = op.Concat(
1775+
op.Unsqueeze(temporal, op.Constant(value_ints=[0])),
1776+
op.Unsqueeze(height_positions, op.Constant(value_ints=[0])),
1777+
op.Unsqueeze(width_positions, op.Constant(value_ints=[0])),
1778+
axis=0,
1779+
)
1780+
positions.shape = ir.Shape([3, "batch", "image_tokens"])
1781+
token_grid = op.Concat(height, width, axis=0)
1782+
token_grid.shape = ir.Shape([2])
1783+
builder.add_output(positions, "position_ids")
1784+
builder.add_output(token_grid, "token_grid")
1785+
return _component("mobius.policy.auxiliary@1", graph, {})
1786+
1787+
16731788
_RNG_MODULUS = 2147483647
16741789
_RNG_MULTIPLIER = 48271
16751790
_RNG_STRIDE = 2654435761

‎src/mobius/integrations/onnx_genai/__init__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
write_multimodal_pipeline_metadata,
6464
write_speech_to_text_pipeline_metadata,
6565
)
66+
from mobius.integrations.onnx_genai.shared_state_flow_metadata import (
67+
build_shared_state_pixel_flow_workflow_metadata,
68+
is_shared_state_pixel_flow_package,
69+
write_shared_state_pixel_flow_workflow_metadata,
70+
)
6671
from mobius.integrations.onnx_genai.workflow_metadata import (
6772
build_audio_codec_workflow_metadata,
6873
build_decoder_workflow_metadata,
@@ -103,12 +108,14 @@
103108
"build_pipeline_metadata_for_workflow",
104109
"build_speculative_workflow_metadata",
105110
"build_speech_to_text_pipeline_metadata",
111+
"build_shared_state_pixel_flow_workflow_metadata",
106112
"build_tts_workflow_metadata",
107113
"build_video_diffusion_workflow_metadata",
108114
"build_vlm_workflow_metadata",
109115
"convert_comfyui_workflow",
110116
"decoder_metadata_from_config",
111117
"load_diffusers_scheduler_config",
118+
"is_shared_state_pixel_flow_package",
112119
"moe_metadata_from_config",
113120
"parse_comfyui_workflow",
114121
"parse_comfyui_workflow_file",
@@ -126,6 +133,7 @@
126133
"write_onnx_genai_config",
127134
"write_speculative_workflow_metadata",
128135
"write_speech_to_text_pipeline_metadata",
136+
"write_shared_state_pixel_flow_workflow_metadata",
129137
"write_tts_workflow_metadata",
130138
"write_video_diffusion_workflow_metadata",
131139
"write_vlm_workflow_metadata",

‎src/mobius/integrations/onnx_genai/auto_export.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from __future__ import annotations
1414

15+
import json
1516
import logging
1617
import os
1718
from typing import Any
@@ -26,6 +27,10 @@
2627
load_diffusers_scheduler_config,
2728
load_diffusers_vae_scaling_factor,
2829
)
30+
from mobius.integrations.onnx_genai.shared_state_flow_metadata import (
31+
is_shared_state_pixel_flow_package,
32+
write_shared_state_pixel_flow_workflow_metadata,
33+
)
2934
from mobius.integrations.onnx_genai.workflow_metadata import (
3035
write_audio_codec_workflow_metadata,
3136
write_ctc_asr_workflow_metadata,
@@ -752,6 +757,47 @@ def write_onnx_genai_config(
752757
``scheduler`` / ``guidance_scale`` set the loop.
753758
"""
754759
os.makedirs(output_dir, exist_ok=True)
760+
if is_shared_state_pixel_flow_package(pkg):
761+
resolved_config = config if config is not None else getattr(pkg, "config", None)
762+
if resolved_config is None:
763+
raise ValueError("shared-state pixel-flow metadata requires a model config")
764+
path = write_shared_state_pixel_flow_workflow_metadata(
765+
pkg,
766+
resolved_config,
767+
output_dir,
768+
num_inference_steps=num_inference_steps,
769+
guidance_scale=4.0 if guidance_scale is None else guidance_scale,
770+
)
771+
artifacts = {"inference_metadata": path}
772+
artifacts.update(_copy_runtime_assets(output_dir, source, revision=revision))
773+
processor_path = os.path.join(output_dir, "preprocessor_config.json")
774+
if not os.path.isfile(processor_path):
775+
with open(processor_path, "w", encoding="utf-8") as handle:
776+
json.dump(
777+
{
778+
"do_convert_rgb": True,
779+
"do_resize": True,
780+
"min_pixels": 512 * 512,
781+
"max_pixels": 2048 * 2048,
782+
"size_multiple": 32,
783+
"resample": "lanczos3",
784+
"do_rescale": True,
785+
"rescale_factor": 1.0 / 255.0,
786+
"do_normalize": True,
787+
"image_mean": [0.485, 0.456, 0.406],
788+
"image_std": [0.229, 0.224, 0.225],
789+
},
790+
handle,
791+
indent=2,
792+
)
793+
handle.write("\n")
794+
artifacts["preprocessor_config"] = processor_path
795+
if "tokenizer" not in artifacts:
796+
tokenizer_path = _write_hf_tokenizer(output_dir, source, revision=revision)
797+
if tokenizer_path is not None:
798+
artifacts["tokenizer"] = tokenizer_path
799+
return artifacts
800+
755801
if _looks_like_language_diffusion(pkg):
756802
path = write_language_diffusion_workflow_metadata(
757803
pkg,

0 commit comments

Comments
 (0)