Commit Graph
5 Commits
Author SHA1 Message Date
Niko1221 9b4cedd08d image: the latent's VAE input and the 8-bit picture as stable-diffusion.cpp makes them (step 5, part 3)
include/strata/image/qi21_pixels.hpp, src/image/vae/qi21_pixels.cpp: the decoded float
picture to 8-bit pixels as sd.cpp 2988060's tensor_to_sd_image / preprocessing_float_to_u8
(0 at or below 0, 255 at or above 1, else (uint8)(v x 255 + 0.5) with two roundings: no
fused multiply-add, contraction off for the file), planar in, interleaved out. The latent's
preparation for the VAE is step 2's wan_vae_denormalize (sd.cpp's diffusion_to_vae_latents
for Qwen-Image-2.1: 64 channels, x std / 1 + mean; sd.cpp unpatchifies nothing before its
VAE). Nothing joined or hooked anywhere.

Test-only: stage_hooks.py dumps vae_in (what sd.cpp's VAE decoder gets) and vae_out (its
float picture before the 8-bit step) (+ test_stage_hooks.py); strata-vae-io-check
(src/image/vae/qi21_vae_io_check_main.cpp, nvcc, links wan_vae.cu); strata-pixels-check;
tools/image/gate/png_pixels.py (a PNG reader with all five row filters, for sd-cli's PNGs).
GB10 (dgxspark-20261111-0610-e738), sd-cli with the stage hooks (build te5bvio), prompt 0
at 512 (seeds 42, 1234) and 1024 (seed 42): wan_vae_denormalize(latent) byte-identical to
vae_in on all three; our 8-bit picture of vae_out identical to the pixels of sd-cli's own
PNG on all three (4 channels; a fused-multiply-add variant gave the same bytes here).
CPU test tools/test_qi21_pixels.py: 8,184 values of that picture with sd-cli's PNG bytes
(tools/image/gate/data/qi21_pixels_fixture.bin, 729 within 1e-3 of a rounding boundary)
and edge values from numpy float32, built -O2 and -O3 -ffp-contract=fast; p1006
p1006-20261111-0618-a6f6: 58 passed (with the other image tests).
2026-11-11 06:19:11 +01:00
Niko1221 89b4d9f1fd image: initial noise in our own code (step 5, part 2)
include/strata/image/qi21_noise.hpp, src/image/noise/qi21_noise.cpp: the noise of a picture
as stable-diffusion.cpp 2988060 makes it by default (PhiloxRNG, manual_seed(seed), one randn
over the latent), from Strata's integer-only Philox generator
(tools/image/sdcpp_noise/strata_noise.hpp, the same file the sd-cli patch uses; its sin
table from apply.py --prepare). Test program strata-noise-check. Nothing joined or hooked.

Reference: sd.cpp's x86 build. On x86 (p1006, g++ 13.3 -O3, p1006-20261111-0611-d91d),
sd.cpp's own core/rng_philox.hpp and ours give byte-identical noise for seeds 42, 1234, 7
and 2026 at 65,536 and 262,144 values (the 512 and 1024 latents); their sha256 are in
tools/image/gate/data/qi21_noise_sha.json for the CPU test tools/test_qi21_noise.py.
Against the dumps of sd-cli on the GB10 (aarch64, dgxspark-20261111-0602-6aba) 0.65-0.78%
of the values differ (435-1983 per picture, up to 1321 ulp): sd.cpp's aarch64 build does not
compute its own x86 stream (box_muller's float multiply-add can fuse on aarch64, and glibc's
aarch64 sin / log differ from x86's); the generator reproduces the x86 stream on every
platform by design. In those dumps the first DiT input equals the noise (sigma 1).
CPU test: p1006-20261111-0612-f905, 1 passed.
2026-11-11 06:13:15 +01:00
Niko1221 8ee4250e5a image: Turbo sampler in our own code, byte-identical to stable-diffusion.cpp (step 5, part 1)
include/strata/image/qi21_sampler.hpp, src/image/sample/qi21_sampler.cpp: Turbo's fixed
schedule (the --sigmas string serve/images.py passes, parsed as sd-cli's std::stof), the
DiT timestep sigma x 1000, and one Euler step with CFG 1 for the flow model in sd.cpp
2988060's order (c_skip 1, c_out -sigma, c_in 1; den = v c_out + x c_skip;
d = (x - den) / sigma; x += d (sigma_next - sigma)), each line its own pass, contraction off
for the file. CPU, plain float, no ggml. Nothing joined or hooked anywhere.

Test program strata-sampler-check (src/image/sample/qi21_sampler_check_main.cpp): chains all
8 steps from sd.cpp's own dumps (dit_x_0, then sd.cpp's vel_k) and requires dit_x_{k+1},
dit_t_k and, after the last step, the final latent byte-identical.
GB10 aarch64 (dgxspark-20261111-0604-05ed), dumps from sd-cli with its own noise
(dgxspark-20261111-0559-e8d7): 512 and 1024 x seeds 42 and 1234 (prompt 0) and 512 prompt 5:
every step byte-identical, timesteps identical, the final latent identical; built with g++
-O2 and with -O3 -ffp-contract=fast.
CPU test tools/test_qi21_sampler.py with tools/image/gate/data/qi21_sampler_fixture.bin
(512 values per step of steps 0-6, 512 p0 seed 42): 2 passed on p1006 x86 g++ 13.3
(p1006-20261111-0605-f597).
2026-11-11 06:05:39 +01:00
Niko1221 9b242bb5b4 Image generation, DiT: Qwen-Image-2.1's token positions and RoPE table in our own code, byte-identical to stable-diffusion.cpp's (not used by any build yet)
include/strata/image/qi21_rope.hpp, src/image/dit/qi21_rope.cpp: QwenImage21Layout::build's positions (text (p, p, p),
image (L, h - (H - H/2), w - (W - W/2))) and Rope::embed_nd's table (axes 16 / 56 / 56, theta 10000, 64 x
[cos, -sin, sin, cos] a token), written as sd.cpp writes them, float operation by float operation, with the C library's
cosf / sinf / powf. Test program strata-dit-rope.

Gate (GB10, against the tables sd.cpp's stock and native runners built, stage hook pe_*_0): 14 of 14 byte-identical -
512x512 with four prompts (25-32 text tokens), 1024x1024, 1536x1024, a 1,025-token prompt at 1024, both runners.

Test: tools/test_dit_rope.py compiles the table code with the system C++ compiler and checks the sha256 of 7 of
those tables (tools/image/gate/data/qi21_rope_sha.json, recorded from sd.cpp on aarch64 glibc); passed on the GB10
and on p1004 (x86 glibc). Another C library (MSVC, Apple) may differ in the last bit of some entries; not checked.
2026-11-11 02:54:58 +01:00
Niko1221 666bef70a8 Image generation, text encoder: our own Qwen2 tokenizer, prompt-weight parser and template, ids identical to stable-diffusion.cpp's (not used by any build yet)
include/strata/image/qwen2_tok.hpp, src/image/te/qwen2_tok.cpp build the token ids of Qwen-Image-2.1's text encoder
the way sd.cpp 2988060 does, with no regex library and no sd.cpp:
- sd-cli's <lora:NAME:WEIGHT> removal (its --lora-model-dir defaults to "."), parse_prompt_attention as its code runs
  (only "\(" loses its backslash, "\]" stays), the system / user / assistant template, each piece encoded alone;
- the 31 special literals with sd.cpp's ids (151643 + index; at 5 of those ids the GGUF lists [PAD151669] ..
  [PAD151673], sd.cpp names them <|boi_token|> .. <|tms_token|>; we follow sd.cpp);
- the Qwen2 pre-tokenizer regex as a scanner; \p{L}, \p{N}, \s and the contraction case folds (s also matches U+017F)
  are Oniguruma's own, dumped from sd.cpp's build over every code point (tools/image/gate/te_tok_probe.cpp ->
  te_tok_tables.py -> src/image/te/qwen2_tok_unicode.inc);
- byte-level BPE with the GGUF's merges (equal to sd.cpp's compiled-in 151,387, checked); invalid UTF-8 refused as
  sd.cpp refuses it.
No engine tokenizer to reuse: the engine takes ids from the Python server (tools/strata_tokenizer.py, qwen35 rule).

Gate: 408 prompts (tools/image/gate/te_tok_cases.py: the 8 gate prompts, the 1,025- and 4,002-token prompts, every
special literal and the 5 GGUF pad literals, 19 prompt-weight cases, 22 unicode cases (CJK, kana, hangul, emoji with
joiners / flags / skin tones, combining marks, right-to-left, other digits and spaces, case-fold traps), empty and
whitespace-only prompts, long words, 5 invalid UTF-8, 300 random prompts from a fixed seed); sd.cpp's ids, weights and
system-token count recorded through the stage hook (stage_hooks.py: tokens.weights and OWN5_EXIT_AFTER_TOKENS, which
exits before any model loads; te_tok_collect.py). GB10 with the full merges: 408 of 408 identical (sd.cpp refuses the
5 invalid-UTF-8 prompts, so do we).

Test: tools/test_te_tokenizer.py compiles the tokenizer with the system C++ compiler and checks all 408 cases from
tools/image/gate/data/te_tok_expected.json with the 2,557 merges they use (te_tok_merges.txt, ranks kept): no GPU, no
sd.cpp, no model file. Passed on the GB10 (aarch64) and p1004 (x86).
2026-11-11 02:36:03 +01:00