Skip to content

Commit 82ccead

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/gguf-q6k-and-bytelevel-tokenizer
2 parents fbec513 + 9603636 commit 82ccead

11 files changed

Lines changed: 900 additions & 119 deletions

File tree

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,31 @@ once, casts the fp16 prefixes to fp32, and lets both CFG generation branches
255255
read the frozen state. The loop describes per-step image embedding, x0
256256
prediction, `v = (x0 - z) / max(1 - t, t_eps)`, and Euler integration. This is
257257
an architecture-neutral shared-state pattern; no model-family dispatch exists
258-
in the runtime.
258+
in the runtime. Each CFG branch derives its image temporal positions from its
259+
own prompt length, so unequal positive and negative prefixes remain valid.
259260

260261
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.
262+
reference-image-edit paths, including mixed precision, shared KV, CFG, seeded
263+
noise, and a two-step loop. The workflow also accepts an optional external
264+
latent for controlled parity. When supplied, its actual tensor dimensions
265+
determine downstream resolution-dependent noise-scale conditioning instead of
266+
silently trusting potentially inconsistent request dimensions.
267+
268+
The pinned production exports from PR #533 were subsequently assembled into
269+
the same canonical metadata package and executed by ONNX GenAI's generic
270+
metadata engine on H200. Revision
271+
`1f6ec60423d29939dde4202fd82ae340b144e280` produced fp16 text-prefill logits,
272+
a 512x512 text-to-image result in 6.99 seconds, and a 512x512 reference-image
273+
edit in 16.68 seconds for 20-step requests. Peak observed device memory was
274+
91,256 MiB. The published 49 GB package, typed requests, raw outputs, PNGs,
275+
timings, and VRAM samples are at
276+
<https://huggingface.co/justinchuby/sensenova-u1.5-8b-mot-onnx-canonical>.
277+
278+
The earlier #533 controlled-latent evidence remains the numerical L4/L5
279+
reference (final-image Pearson 0.998606 and PSNR 36.42 dB). The canonical run
280+
uses the portable counter RNG rather than PyTorch's RNG, so its seeded final
281+
image is not falsely presented as a same-latent numerical comparison.
282+
Ordinary CI never downloads the approximately 50 GB production package.
270283

271284

272285
## Dead or misleading upstream details

‎src/mobius/generation/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
build_greedy_sampler,
4141
build_guidance_combine,
4242
build_identity_model_input,
43+
build_image_dimensions,
4344
build_image_grid_positions,
45+
build_image_noise_geometry,
4446
build_integer_add,
4547
build_integer_minimum,
4648
build_integer_row_broadcast,
@@ -64,6 +66,7 @@
6466
build_speculative_acceptance,
6567
build_speculative_state_rollback,
6668
build_tensor_cast,
69+
build_tensor_clamp,
6770
build_tensor_scale,
6871
build_termination_batch_initializer,
6972
build_token_block_identity,
@@ -119,7 +122,9 @@
119122
"build_grammar_logits_processor",
120123
"build_greedy_sampler",
121124
"build_guidance_combine",
125+
"build_image_dimensions",
122126
"build_image_grid_positions",
127+
"build_image_noise_geometry",
123128
"build_identity_model_input",
124129
"build_integer_add",
125130
"build_integer_minimum",
@@ -145,6 +150,7 @@
145150
"build_speculative_state_rollback",
146151
"build_tensor_scale",
147152
"build_tensor_cast",
153+
"build_tensor_clamp",
148154
"build_termination_batch_initializer",
149155
"build_token_block_identity",
150156
"build_token_state_update",

‎src/mobius/generation/_policy_components.py‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,26 @@ def build_tensor_scale(dtype: ir.DataType = ir.DataType.FLOAT) -> PolicyComponen
16421642
return _component("mobius.policy.auxiliary@1", graph, {})
16431643

16441644

1645+
def build_tensor_clamp(
1646+
dtype: ir.DataType = ir.DataType.FLOAT,
1647+
*,
1648+
minimum: float,
1649+
maximum: float,
1650+
) -> PolicyComponent:
1651+
"""Clamp a rank-4 tensor to an explicitly declared numeric range."""
1652+
graph, builder = _make_graph("tensor_clamp")
1653+
op = builder.op
1654+
tensor = builder.input("tensor", dtype, ["batch", "channels", "height", "width"])
1655+
clamped = op.Clip(
1656+
tensor,
1657+
op.Cast(op.Constant(value_float=minimum), to=dtype),
1658+
op.Cast(op.Constant(value_float=maximum), to=dtype),
1659+
)
1660+
clamped.shape = tensor.shape
1661+
builder.add_output(clamped, "clamped")
1662+
return _component("mobius.policy.auxiliary@1", graph, {})
1663+
1664+
16451665
def build_zeros_like(dtype: ir.DataType = ir.DataType.FLOAT) -> PolicyComponent:
16461666
"""Produce a zero tensor shaped like its reference, for state initializers."""
16471667
graph, builder = _make_graph("zeros_like")
@@ -1785,11 +1805,69 @@ def build_image_grid_positions(
17851805
return _component("mobius.policy.auxiliary@1", graph, {})
17861806

17871807

1808+
def build_image_dimensions(
1809+
dtype: ir.DataType = ir.DataType.FLOAT,
1810+
) -> PolicyComponent:
1811+
"""Read pixel height and width from a rank-4 image tensor."""
1812+
graph, builder = _make_graph("image_dimensions")
1813+
op = builder.op
1814+
tensor = builder.input("tensor", dtype, ["batch", "channels", "height", "width"])
1815+
height = op.Shape(tensor, start=2, end=3)
1816+
width = op.Shape(tensor, start=3, end=4)
1817+
height.shape = width.shape = ir.Shape([1])
1818+
builder.add_output(height, "height")
1819+
builder.add_output(width, "width")
1820+
return _component("mobius.policy.auxiliary@1", graph, {})
1821+
1822+
17881823
_RNG_MODULUS = 2147483647
17891824
_RNG_MULTIPLIER = 48271
17901825
_RNG_STRIDE = 2654435761
17911826

17921827

1828+
def build_image_noise_geometry(
1829+
*,
1830+
channels: int = 3,
1831+
token_stride: int = 32,
1832+
base_image_sequence_length: int = 64,
1833+
noise_scale: float = 1.0,
1834+
maximum_noise_scale: float = 16.0,
1835+
) -> PolicyComponent:
1836+
"""Derive image-noise shape, token grid, and resolution-dependent scale."""
1837+
graph, builder = _make_graph("image_noise_geometry")
1838+
op = builder.op
1839+
height = builder.input("height", ir.DataType.INT64, [1])
1840+
width = builder.input("width", ir.DataType.INT64, [1])
1841+
1842+
row_shape = op.Concat(
1843+
op.Constant(value_ints=[channels]),
1844+
height,
1845+
width,
1846+
axis=0,
1847+
)
1848+
row_shape.shape = ir.Shape([3])
1849+
token_height = op.Div(height, op.Constant(value_int=token_stride))
1850+
token_width = op.Div(width, op.Constant(value_int=token_stride))
1851+
token_height.shape = token_width.shape = ir.Shape([1])
1852+
1853+
image_sequence_length = op.Mul(token_height, token_width)
1854+
relative_length = op.Div(
1855+
op.Cast(image_sequence_length, to=ir.DataType.FLOAT),
1856+
op.Constant(value_float=float(base_image_sequence_length)),
1857+
)
1858+
resolved_scale = op.Min(
1859+
op.Mul(op.Sqrt(relative_length), op.Constant(value_float=noise_scale)),
1860+
op.Constant(value_float=maximum_noise_scale),
1861+
)
1862+
resolved_scale.shape = ir.Shape([1])
1863+
1864+
builder.add_output(row_shape, "row_shape")
1865+
builder.add_output(token_height, "token_height")
1866+
builder.add_output(token_width, "token_width")
1867+
builder.add_output(resolved_scale, "noise_scale")
1868+
return _component("mobius.policy.auxiliary@1", graph, {})
1869+
1870+
17931871
def _counter_uniform(op, key, counter):
17941872
"""Map a counter-based ``(key, counter)`` pair onto a uniform in ``(0, 1)``.
17951873

‎src/mobius/generation/_policy_components_test.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
build_grammar_logits_processor,
2929
build_greedy_sampler,
3030
build_guidance_combine,
31+
build_image_dimensions,
32+
build_image_grid_positions,
33+
build_image_noise_geometry,
3134
build_integer_minimum,
3235
build_integer_row_broadcast,
3336
build_last_token_logits,
@@ -43,6 +46,7 @@
4346
build_shape_constant,
4447
build_speculative_acceptance,
4548
build_speculative_state_rollback,
49+
build_tensor_clamp,
4650
build_tensor_scale,
4751
build_termination_batch_initializer,
4852
build_token_state_update,
@@ -1155,6 +1159,54 @@ def test_counter_rng_is_reproducible_and_row_private(tmp_path):
11551159
assert abs(float(noise.std()) - 1.0) < 0.1
11561160

11571161

1162+
def test_image_noise_geometry_resolves_shape_grid_and_scale(tmp_path):
1163+
row_shape, token_height, token_width, noise_scale = _run(
1164+
build_image_noise_geometry(),
1165+
tmp_path,
1166+
{
1167+
"height": np.array([512], np.int64),
1168+
"width": np.array([768], np.int64),
1169+
},
1170+
)
1171+
np.testing.assert_array_equal(row_shape, [3, 512, 768])
1172+
np.testing.assert_array_equal(token_height, [16])
1173+
np.testing.assert_array_equal(token_width, [24])
1174+
np.testing.assert_allclose(noise_scale, [np.sqrt(384 / 64)], rtol=1e-6)
1175+
1176+
1177+
def test_image_positions_and_dimensions_follow_their_actual_inputs(tmp_path):
1178+
latent = np.zeros((1, 3, 64, 96), dtype=np.float32)
1179+
conditional_positions, conditional_grid = _run(
1180+
build_image_grid_positions(pixels_per_token=32),
1181+
tmp_path,
1182+
{
1183+
"latent": latent,
1184+
"prompt_tokens": np.zeros((1, 5), dtype=np.int64),
1185+
},
1186+
)
1187+
unconditional_positions, unconditional_grid = _run(
1188+
build_image_grid_positions(pixels_per_token=32),
1189+
tmp_path,
1190+
{
1191+
"latent": latent,
1192+
"prompt_tokens": np.zeros((1, 2), dtype=np.int64),
1193+
},
1194+
)
1195+
np.testing.assert_array_equal(conditional_positions[0], 5)
1196+
np.testing.assert_array_equal(unconditional_positions[0], 2)
1197+
np.testing.assert_array_equal(conditional_positions[1:], unconditional_positions[1:])
1198+
np.testing.assert_array_equal(conditional_grid, [2, 3])
1199+
np.testing.assert_array_equal(unconditional_grid, [2, 3])
1200+
1201+
height, width = _run(
1202+
build_image_dimensions(),
1203+
tmp_path,
1204+
{"tensor": np.zeros((1, 3, 256, 384), dtype=np.float32)},
1205+
)
1206+
np.testing.assert_array_equal(height, [256])
1207+
np.testing.assert_array_equal(width, [384])
1208+
1209+
11581210
def test_tensor_scale_and_zeros_like_shape_from_their_input(tmp_path):
11591211
sample = np.arange(12, dtype=np.float32).reshape(1, 3, 2, 2)
11601212
(scaled,) = _run(
@@ -1167,6 +1219,19 @@ def test_tensor_scale_and_zeros_like_shape_from_their_input(tmp_path):
11671219
np.testing.assert_array_equal(zeros, np.zeros_like(sample))
11681220

11691221

1222+
def test_tensor_clamp_enforces_declared_range(tmp_path):
1223+
sample = np.array([[[[-2.0, -0.5], [0.5, 2.0]]]], dtype=np.float32)
1224+
(clamped,) = _run(
1225+
build_tensor_clamp(minimum=-1.0, maximum=1.0),
1226+
tmp_path,
1227+
{"tensor": sample},
1228+
)
1229+
np.testing.assert_array_equal(
1230+
clamped,
1231+
np.array([[[[-1.0, -0.5], [0.5, 1.0]]]], dtype=np.float32),
1232+
)
1233+
1234+
11701235
def test_scalar_and_shape_constants_publish_their_values(tmp_path):
11711236
(value,) = _run(build_scalar_constant(0.18215), tmp_path, {})
11721237
np.testing.assert_allclose(value, 0.18215, rtol=1e-6)

‎src/mobius/integrations/gguf/_builder.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,6 @@ def _expand(perm: torch.Tensor, stride: int) -> torch.Tensor:
822822
def _index_dim0(t: torch.Tensor, idx: torch.Tensor) -> torch.Tensor:
823823
return t.index_select(0, idx)
824824

825-
def _index_dim1(t: torch.Tensor, idx: torch.Tensor) -> torch.Tensor:
826-
return t.index_select(1, idx)
827-
828825
def _apply_rows(stem: str, idx: torch.Tensor) -> None:
829826
# Permute axis 0 of a float weight or a quantized triplet in place.
830827
for suffix in (".weight", ".scales", ".zero_points"):

‎src/mobius/integrations/gguf/_config_mapping_test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_nextn_not_greater_than_block_count(self) -> None:
218218

219219

220220
class TestQwen35RopeInterleave:
221-
"""``rope.dimension_sections`` is M-RoPE section metadata, not a GPT-J adjacent-pair rotation signal.
221+
"""M-RoPE section metadata is not a GPT-J adjacent-pair rotation signal.
222222
223223
Qwen3.5/3.8 rotate with split-half (NEOX) semantics. Deriving the flat
224224
``rope_interleave`` from section presence corrupts RoPE — the exported

0 commit comments

Comments
 (0)