Commit Graph
31 Commits
Author SHA1 Message Date
Niko1221 adfcf9028e image gate tools: run_strata_image.py runs strata-image over the gate set like run_set.py runs sd-cli (step 5, piece 3)
tools/image/gate/run_strata_image.py: one strata-image process per prompt x seed, run_set.py's gate prompts and file
names (pics/<tag>/p<i>_s<seed>.png, .log, .json, results.jsonl with the stage times under run_set.py's names plus
open_s / png_s and the memory per stage), so compare.py and the floor / speed tables read both alike. Test-only.

Test: tools/test_run_strata_image.py with a stand-in program (command line, files, records, a failing picture);
p1006 11 passed with the image part tests (p1006-20261111-0745-aa7e).
2026-11-11 07:46:49 +01:00
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 1705c8b9f0 image: Qwen-Image-2.1 DiT step without ggml, and the strata-dit-step test program (D4, first piece)
One DiT step (latent + text condition + timestep -> velocity) in our own code, CUDA:
- src/image/dit/qi21_dit.cu, include/strata/image/qi21_dit.hpp: the weights read with
  strata/artifact/gguf_reader.hpp into one device buffer as the file's bytes (q, k, v of a
  block one after the other: one GEMM), 1-D norms as f32; own buffers and stream; every
  multiply through dit_gemm (D1+D2); the text prefix once per condition with its K / V kept,
  as the native runner does.
- src/image/dit/qi21_kernels.cu: the native runner's kernels moved out of the sd.cpp patch
  (LayerNorm + modulate + gated residual, q/k RMSNorm + RoPE + f16 K/V, SwiGLU, the causal /
  exact attention, the mma.sync attention for sm_80+, the gfx11 WMMA attention), plus the
  steps ggml still did: timestep sinusoid, SiLU, GELU (tanh form), txt_in's RMSNorm.
  The sd.cpp patch keeps its own copy for the test builds.
- src/image/dit/qi21_dit_step_main.cpp: strata-dit-step <dit.gguf> <out> <dump dirs>
  [--repeat N], on the stage-hook dumps of what sd.cpp fed its DiT.
- tools/image/gate/dit_step_check.py (+ test_dit_step_check.py, CPU): the velocity against
  dit_ref's f32 result, both emulations, the D1+D2 test build, stock and native.
Not used by any build or by sd-cli; sd.cpp stays the default and the fallback. HIP is
written but not compiled (no card tonight).

Measured on the GB10 (dgxspark-20261111-0538-11fc), Q8_0, velocity rel L2 to f32:
  512 p0: ours 0.00055 | float32-sum emulation 0.00052 (1.061) | exact-sum 0.00046 (1.179)
          | D1+D2 test build 0.00050 | stock 0.00658 | native 0.00570 | ours vs D1+D2 0.00026
  512 p5: ours 0.00058 | 0.00098 (0.594) | 0.00055 (1.061) | 0.00114 | 0.00492 | 0.00612
          | ours vs D1+D2 0.00107
  1024 p0: ours 0.00045 | 0.00050 (0.901) | 0.00056 (0.809) | 0.00049 | 0.00535 | 0.00518
          | ours vs D1+D2 0.00023
Three runs per case (the first with the text prefix pass) byte-identical.
Step time: 512 369-391 ms (first run with the prefix 588-716 ms), 1024 1316-1326 ms
(first 1524 ms). sd-cli sampling at 1024 divided by 8 steps (host side included): native
1.54 s, D1+D2 1.57 s, stock 2.45 s.
Device memory of the DiT's own buffers: 8.12 GB at 512, 8.91 GB at 1024 (weights 7.64 GB
= the GGUF's size, work 0.48 / 1.27 GB incl. the GEMM's f16 buffers).
2026-11-11 05:39:36 +01:00
Niko1221 09d67a33d4 image: own DiT GEMMs for the native Qwen-Image-2.1 runner (D1+D2, test builds only)
D1 and D2 together: every multiply of the native runner's DiT call on our own GEMM
(src/image/dit/dit_gemm.cu: weights decoded to f16 by te_dequant, activations to f16,
cuBLAS / hipBLAS GemmEx with float32 sums). Groups: blocks + img_in (D1); timestep MLP,
modulation, norm_out; txt_in; the head (D2). Wired into the pinned stable-diffusion.cpp
by tools/image/sdcpp_dit/apply.py (build_variant.py --dit) behind
--model-args strata_dit_gemm=1. No build or product path uses it; sd.cpp stays the
default and the fallback.

Measured together, not D1 alone: D1 alone was 0.00331 from the f32 reference against
the emulation's 0.00065 (5x); only all four groups together reach the emulation's level,
because the multiplies left on ggml's MMQ (8-bit activations) then dominate.
vel_0 rel L2 to f32, 512 prompts 0-3 (mean), per group switched on:
  none (native runner) 0.00609 | all (D1+D2) 0.00065 | D1 0.00331 |
  D1 + timestep/modulation/norm_out 0.00271 | D1 + txt_in 0.00342 | D1 + head 0.00200 |
  f16 emulation 0.00065 | stock 0.00678

Stage rule (coordinator's restated rule: mean within 1.25x the emulation, no case above
1.5x, every case closer than stock and native). Nine cases (prompts 0-7 at 512, prompt 0
at 1024), velocity rel L2 to f32:
  against the emulation with float32 sums (dit_ref mode f16acc32): mean ratio 1.039,
  largest 1.177 (512 p6); against the emulation with exact sums (mode f16op): mean
  ratio 1.116, 512 p5 at 2.078. Every case 0.00048-0.00114 from f32; stock 0.0049-0.0090,
  native 0.0052-0.0083.
The comparison was changed to the float32-sum emulation after the measurement
(coordinator, 11-11): on prompt 5 the exact-sum emulation moves from 0.00055 to 0.00086
when started from inputs that differ by 3e-6; a per-block trace found no step that differs
from the emulation's arithmetic (block 20 replayed from our input agrees to 0.0002). Both
modes stay in dit_ref.py; tools/image/gate/dit_acc32_cases.py reproduces the table.

Gate (a): with the argument off, 16 pictures (prompts 0-7, seeds 42 and 1234, 1024)
byte-identical to the build before D1: 16 of 16 (dgxspark-20261111-0513-8147).
Pictures, 16 against stock sd.cpp, PSNR mean / min, SSIM mean / min (GB10):
  sd.cpp cuBLAS-forced 33.35 / 23.06 dB, 0.979 / 0.937
  sd.cpp native runner 34.32 / 21.32 dB, 0.982 / 0.923
  ours (D1+D2)         34.45 / 23.74 dB, 0.982 / 0.948
  ours vs native       35.90 / 20.71 dB, 0.982 / 0.912
Sampling median at 1024: stock 19.57 s, native 12.32 s, ours 12.54 s.

Also: te_type_supported / te_row_bytes moved into te_dequant.cu (needed without the
host decoder); run_set.py --model-arg; test-only trace hooks in apply.py
(STRATA_DIT_TRACE_DIR / STRATA_DIT_TRACE_BLOCK, read after a backend sync, change no
value); dit_replay.py / dit_replay2.py (the prompt-5 trace tools).
Tests: tools/test_sdcpp_dit.py, tools/image/gate/test_dit_ref.py (modes).
2026-11-11 05:26:49 +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 384e336f79 Image generation gate tools: dit_ref.py, a numpy reference of one Qwen-Image-2.1 DiT call (test-only), and stage hooks for the DiT's inputs and RoPE tables
tools/image/gate/dit_ref.py computes the velocity sd.cpp 2988060's QwenImage21Runner returns for one call: the
timestep embedding and modulation (image rows t, text rows t = 0), txt_in, img_in, 32 blocks over [text ; image]
(LayerNorm x (1 + m), per-head q/k RMSNorm, interleaved RoPE on axes 16 / 56 / 56, text rows causal over the text,
image rows over everything, tanh gates, SwiGLU), the output head. Modes "f32" (exact weights, float64 products) and
"f16op" (step 4's arithmetic: f16 weights and GEMM inputs, exact accumulation, f16 Q / K / V and probabilities).
Inputs come from new stage hooks (stage_hooks.py): dit_x_<k> / dit_t_<k> (the DiT's latent and timestep of model
call k) and pe_stock_<k> / pe_native_<k> (the RoPE table each runner built).

GB10, 512x512 prompts 0-3 seed 42, model call 0 (t = 1000), relative L2 of the velocity against the f32 reference:
f16 emulation 0.00065 mean / 0.00091 max; sd.cpp stock (MMQ, 8-bit GEMM inputs) 0.0068 / 0.0090; sd.cpp native
runner 0.0061 / 0.0072. The stock and native runners built byte-identical RoPE tables at 512, 1024, 1536x1024 and
for a 1,025-token prompt.

Tests: test_dit_ref.py (positions, RoPE rotation, timestep embedding, norms / activations, the attention masks);
test_stage_hooks.py covers the new hooks.
2026-11-11 02:53:35 +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
Niko1221 d663e0c63c Image generation gate tools: te_ref.py, a numpy reference of Qwen-Image-2.1's text encoder (test-only)
tools/image/gate/te_ref.py computes what stable-diffusion.cpp 2988060 hands the DiT as the condition for a prompt:
sd.cpp's Qwen2 tokens (its own vocabulary construction, special literals and prompt-weight parser), the Qwen3-VL-8B
text model (36 layers, q/k norms, NEOX rope, causal attention, SwiGLU), the residual stream after the last layer
without the final norm, the system tokens dropped. Two modes: "f32" (weights dequantized exactly, float64 products)
and "f16op" (the arithmetic of our GPU encoder: f16 weights and GEMM inputs, exact accumulation). It reports the
activation ranges and compares with sd.cpp's cond.bin dumps.

On the 8 gate prompts (GB10): f16op is 0.0012 relative L2 from f32; sd.cpp's CUDA condition 0.055, its cuBLAS text
encoder 0.009, its CPU one 0.085. Largest GEMM input 6349 (fits f16).

stage_hooks.py also dumps the token ids sd.cpp feeds its text encoder (tokens.bin, tokens.start), and
te_ref.py --tokens-from compares its own ids with them.

Tests: test_te_ref.py (block decoders against a scalar transcription of dequant.hpp, the prompt-weight parser's
documented cases as its code runs them, tokenizer pieces, a tiny model: causality, f16op close to f32, rope);
test_stage_hooks.py (every hook lands once, the token dump sits before LLMEmbedder's call, a second run changes
nothing).
2026-11-11 01:05:36 +01:00
Niko1221 56630caca0 Image generation: images "vae_decoder" switches sd-cli to Strata's own VAE decoder (CUDA / HIP builds; default stays stable-diffusion.cpp's)
The images section takes "vae_decoder": "sdcpp" (default, also when absent) or "strata".  "strata" adds strata_vae=1
to the one --model-args string sd-cli gets (serve/images.py sd_cli_args), next to qwen_image_2_1_native=1 and
strata_noise=1.  Hidden flags build it in: setup.py --image-vae on|off and tools/image/install.py --vae on|off, honoured
for cuda and hip only; the sd-cli build stamp gets "vae_decoder" = qimage.vae_hash() (apply.py and every file it
copies, CRLF-neutral), so a build without the switch keeps its stamp and nobody compiles again unasked.

A config that asks for the decoder where it cannot run is refused before sd-cli starts (ImageGen.vae_problem(), also
printed once by the server at start), in the owner's wording of 11-11:
- the sd-cli here was built without it: "Image generation is set to use Strata's own picture decoder ("vae_decoder":
  "strata" in the images settings), but the image program here was built without it. Run setup again with: --images
  qwen-image --image-vae on"
- another backend: "Image generation is set to use Strata's own picture decoder ("vae_decoder": "strata" in the images
  settings), which needs the CUDA (NVIDIA) or ROCm (AMD) build of the image program; this one was built for {backend}.
  Set "vae_decoder" to "sdcpp" in the images settings."
- setup --image-vae on for another backend warns and carries on without it: "Strata's own picture decoder runs with
  CUDA or ROCm only; image generation on {backend} keeps stable-diffusion.cpp's decoder"

Tests: serve/test_images.py VaeDecoderSwitch, tools/test_qimage.py VaeDecoder (the exact sentences included).
p1004-20261111-0012-8a8a: tools/image/gate, tools/test_sdcpp_vae.py, tools/test_qimage.py, serve/test_images.py
102 passed, 51 subtests passed.
2026-11-11 00:14:22 +01:00
Niko1221 97b14b6b06 Image generation, VAE decoder: faster open - the file read in parallel parts, every weight converted straight into one staging buffer over the image program's threads, one device allocation and one copy
The conversions are the per-value ones of src/image/vae/convert.hpp (bf16 -> f32 exact, f32 -> f16 round to nearest
even): the same bytes for any thread count.  sd-cli passes its own thread setting (n_threads), not all cores.  No
cache file, no changed rounding.  wan_vae_open_report says where the open time went; strata-vae-decode --threads N.
test_vae_convert.py: every one of the 65536 bf16 bit patterns (zeros, subnormals, infinities, NaN payloads, values
that round up into the next exponent) gives the same bytes with 1, 2, 7 and 16 threads, agrees with numpy's float16
on every non-NaN pattern and keeps NaN a NaN; the conv layout against numpy.  test_safetensors_lite.py: the parallel
read gives the same bytes as the per-tensor reads (1, 3, 16 parts).  45 passed on boston-20261110-1922-1874.

Pictures of the 16 gate latents byte-identical to cab47f3d2's on both vendors (Spark dgxspark-20261110-1920-2e41,
p620 p620-20261110-1921-b026).  Open, standalone (runtime start-up included):
  Spark 20 cores: 1 thread 1.11-1.22 s (read 253-262, convert 388-393, upload 27-29 ms); 20 threads 0.55-0.56 s
    (read 38-40, convert 37-38, upload 28-29 ms); before (cab47f3d2) 1.03-1.13 s.
  p620 64 threads: 1 thread 1.71-2.24 s (read 348-354, convert 578-579, upload 66-80 ms); 64 threads 1.34-1.35 s
    (read 40, convert 26, upload 68-71 ms; the rest is the HIP runtime's start, which sd-cli has done before).
sd-cli on the Spark (dgxspark-20261110-1926-7d4c), decode_first_stage with the switch, file open included:
0.66-0.69 / 1.23-1.27 / 1.64-1.69 s at 512 / 1024 / 1536x1024 (was 1.62-1.69 s at 1024; sd.cpp 1.03-1.06 /
3.37-3.40 / 4.89-4.95 s); pictures pixel-identical to the standalone decoder 16 of 16.
2026-11-10 19:31:22 +01:00
Niko1221 bd3c30f53f Image generation: sd-cli with Strata's VAE decoder builds for HIP (HIP_ARCHITECTURES on the library defined before enable_language(HIP)); build_variant.py keeps build_sd.py's ROCm environment
Found by the same-card gate on p620 (R9700, gfx1201): configure stopped with "HIP_ARCHITECTURES is empty for target
stable-diffusion", because the decoder's CMake block enables HIP after that library was defined; apply.py now gives
strata_vae and the library the architectures.  build_variant.py did not pass ROCM_PATH / HIP_PATH to a HIP
configure; it takes them from build_sd.py's --rocm-path.  tools/test_sdcpp_vae.py checks the CMake line.

Same-card gate, R9700 (p620-20261110-1901-8b76), sd-cli build-hipvae on the fixed latents, steps 1:
  ours (strata_vae=1) against sd.cpp's HIP decoder: PSNR worst / mean 71.42 / 72.36 dB at 512 (4), 70.14 / 72.11 dB
    at 1024 (8), 72.00 / 72.68 dB at 1536x1024 (4), max diff 1-2: vae_same_tiling pass; pixel-identical to the
    standalone HIP decoder 16 of 16.  (sd.cpp HIP against sd.cpp CUDA: 56.80 / 56.21 / 57.02 dB worst.)
  decode_first_stage including opening the VAE file: 1.95-2.02 / 2.32-2.51 / 2.74-2.84 s against sd.cpp's
    1.84-1.94 / 3.52-3.67 / 4.80-4.92 s (the decoder alone 0.73 / 1.10-1.11 / 1.45-1.46 s);
  VRAM peak of the whole picture (amdgpu counter): 13.7-13.8 / 15.0 / 15.9 GB against 14.8 / 20.7 / 24.6 GB.
2026-11-10 19:11:11 +01:00
Niko1221 cab47f3d2c Image generation, VAE decoder: f16 headroom for the block-4 shortcut (fixed shift 11), GEMM blocks on the picture's pixel grid (row bands byte-identical on HIP too), and no broken picture on a non-finite value
Operand range (strata-vae-decode --stats over the 16 gate latents, merged per convolution): the only layer within
16x of the f16 maximum under stable-diffusion.cpp's 2^-7 is up_blocks.4.resnets.0.conv_shortcut (largest input
3.48e6, 2.4x headroom); it gets the fixed shift 11 (38.5x).  The shift is a constant per layer (conv_shift()), never
from the picture's data; vae_ref.py carries the same table and a test checks they agree.  Next closest layers:
62.8x and 113x, kept at 7.

The row bands were not byte-identical on HIP (R9700: 8 of 16 differed; hipBLAS gives a row another reduction order
at another row position of the call).  Every convolution now runs its GEMM blocks on the picture's pixel grid, also
in a row window (rows outside the window are zero and dropped), so a pixel sits in the same row of a same-shape call
in both paths.  wan_vae_set_band_rows / --band-rows: vae_identity.py also checks band heights 48 and 100.

A picture with a non-finite value is an error (the sd-cli hook then logs "...; using stable-diffusion.cpp's decoder,
which may fail the same way", the approved line).  Test-only: wan_vae_set_range_stats / wan_vae_range_report.

Gates: identity (bands of 128, 48 and 100 rows against one pass, bands run to run) PASS 16 of 16 on CUDA
(dgxspark-20261110-1832-ea13) and on HIP (p620-20261110-1832-6e66).  Against sd.cpp's CUDA pictures, PSNR worst /
mean: CUDA 56.80 / 57.72, 56.20 / 57.50, 57.02 / 57.37 dB at 512, 1024, 1536x1024 (vae_same_tiling pass);
HIP 56.81 / 57.71, 56.21 / 57.50, 57.02 / 57.37 dB.  Against the previous commit's pictures 79.4-81.2 dB (max 1).
Stress, 1024 p4's latent x2 / x4: ours finite, 65.36 / 63.99 dB from the numpy f32 reference (sd.cpp's decoder
53.91 / 49.59 dB); the shortcut's headroom 113x / 133x.  Decode (bands) CUDA 0.46-0.48 / 1.03-1.08 / 1.46-1.50 s,
HIP 0.82-0.84 / 1.19-1.23 / 1.49-1.50 s.  CPU tests 98 passed with the other image tests (boston-20261110-1837-287a).
2026-11-10 18:52:32 +01:00
Niko1221 e09b23383e Image generation: the VAE decoder always takes the row-band path (coordinator 11-10: one path for small and big cards); the one-pass decode stays as the reference the byte-identity gate compares against
wan_vae_set_streaming defaults to on; strata-vae-decode --stream off and vae_decode_set.py --stream off give the
one-pass reference.  tools/image/gate/vae_identity.py is the gate: for every fixed latent of the sets named, the
row-band decode against the one-pass decode byte for byte, and the row-band decode run to run.

Spark (GB10, CUDA 13): VAE-IDENTITY PASS 16 of 16 (4 x 512, 8 x 1024, 4 x 1536x1024), bands run to run identical
16 of 16; the default-path pictures byte-identical to f7d8aa28e's one-pass pictures 16 of 16.  Peak device memory
of the decoder 1388 / 2565 / 3411 MiB (one pass 1626 / 4293 / 6003 MiB); decode 450-470 / 1034-1063 /
1438-1474 ms.
2026-11-10 18:08:00 +01:00
Niko1221 bbf2a5476c Image generation: the VAE decoder's small-card path, the same bytes as the one-pass decode in less memory (owner decision 11-10, option A); off unless asked for
wan_vae_set_streaming(on): block 3's upsample, block 4 and the head run in bands of 128 picture rows, each computed
with 7 rows more above and below (block 4's six 3x3 convolutions and conv_out need one each) from the complete
block-3 tensors.  Every kept pixel goes through the same operations on the same operands, GEMM bands included, so
the picture is the one-pass picture byte for byte.  The kernels take row windows (zero padding only at the picture's
own edges).  Blocks 2 and 3 keep their input for the DupUp shortcut without a copy (their first resnet writes a new
tensor anyway); this does not change any value.  The rule that turns the path on is not in this commit.
strata-vae-decode --stream on, vae_decode_set.py --stream on; diff_where.py says where two picture sets differ
(largest difference with its pixel and channel, share of pixels above 8/255, PSNR of the pictures as the server
sends them, flattened on white by serve/images.py flatten_png).

Spark (GB10), the 16 fixed latents: row bands against one pass, the float32 outputs byte-identical 16 of 16
(4 x 512, 8 x 1024, 4 x 1536x1024); one pass with these sources against the previous commit's pictures
byte-identical 16 of 16.  Decoder peak device memory one pass / row bands: 1626 / 1388 MiB at 512, 4293 / 2565 MiB
at 1024, 6003 / 3411 MiB at 1536x1024; decode time 455-457 / 457-466 ms, 1015-1039 / 1036-1068 ms,
1404-1444 / 1460-1466 ms.
2026-11-10 17:52:57 +01:00
Niko1221 379a2465dd Image generation: sd-cli gets Strata's VAE decoder behind --model-args strata_vae=1 (tools/image/sdcpp_vae/apply.py, CUDA / HIP builds only; nothing calls it yet)
apply.py copies src/image/vae and the headers it uses into src/strata_vae of the pinned stable-diffusion.cpp checkout,
builds them as a static library of our own (CUDA or HIP language with its own flags, none of ggml-cuda's
-use_fast_math; the cuBLAS / hipBLAS ggml links already) and hooks decode_first_stage: for a Qwen-Image-2.1 picture
with strata_vae=1 our decoder takes the VAE-space latent; sd.cpp's latent statistics, 8-bit conversion and PNG writer
stay.  If our decoder cannot open the VAE file or fails, sd-cli logs one warning with the reason and decodes with
stable-diffusion.cpp's decoder.  build_variant.py --vae builds the stage-hook tree with it.

Spark (GB10, CUDA 13), the 8 fixed 1024 latents of st_cuda_stock_A, steps 1:
  strata_vae=1: pixel-identical 8/8 to the standalone decoder (w3_vae_1024), 56.20 / 57.50 dB worst / mean from
    sd.cpp's decode (vae_same_tiling pass); decode_first_stage 1.62-1.69 s including opening the VAE file
    (decoder 0.87-0.89 s) against 3.37-3.40 s for the same build without the switch; the drop in free memory over
    the whole picture 17.3-18.3 GB against 22.2-22.6 GB without it.
  switch off: byte-identical 8/8 to sd.cpp's own pictures (st_cuda_vaeagain).
  fallback: a VAE file with F16 tensors (which our decoder refuses) logs "strata VAE decoder: wan_vae: tensor
    post_quant_conv.weight has dtype F16 (bf16 or f32 expected); using stable-diffusion.cpp's decoder" and the
    picture comes from sd.cpp's decoder (3.36-3.38 s).
tools/test_sdcpp_vae.py: the patch on stand-in files (copies, CMake target, hook, fallback, idempotent, together with
the native and noise patches in either order, another commit refused); 19 passed with the related tests on boston.
2026-11-10 17:43:42 +01:00
Niko1221 f7d8aa28ed Image generation: Strata's own VAE decoder for Qwen-Image-2.1 (src/image/vae, CUDA; HIP from the same source through hip_compat), not wired into anything yet
include/strata/image/wan_vae.hpp: open / decode / close, plus the latent denormalization.  Pixel-major float32
activations; every convolution is a gather of f16 operand rows (RMS norm, SiLU or the nearest-2x upsample fused in,
x 2^-7 as stable-diffusion.cpp does) for fixed bands of 8192 pixels, cuBLAS GemmEx f16 x f16 with f32 accumulation,
and an epilogue (x 2^7, bias, residual, the DupUp shortcut).  The mid-block attention is f32 SGEMM / softmax / SGEMM.
sd.cpp accumulates its convolutions in f16; we deliberately do not.  The band size never depends on the picture size
or the card's memory, so the picture is the one-pass result everywhere.  safetensors_lite.hpp reads the VAE file
(no third-party JSON code); strata-vae-decode (wan_vae_decode_main.cpp) decodes a dumped latent for the gate.

Gate on the Spark (GB10, CUDA 13), ours against sd.cpp's decode of the same fixed latents, PSNR worst / mean,
SSIM worst: 512 x4 56.80 / 57.71 dB, 0.99890; 1024 x8 56.20 / 57.50 dB, 0.99885; 1536x1024 x4 57.02 / 57.37 dB,
0.99865 (limit 45 dB / 0.998: pass).  Run to run byte-identical 16 of 16.  Decode, first run in a process:
0.44-0.46 / 1.02-1.05 / 1.41-1.44 s against sd.cpp's 1.03-1.06 / 3.34-4.36 / 4.89-4.95 s; opening the VAE file
1.03-1.10 s.  The numpy f32 reference (vae_ref.py) is 56.77-58.34 dB from sd.cpp's pictures at 512.
tools/image/gate/vae_decode_set.py runs the decoder over a stage set for compare.py / check_limits.py;
test_safetensors_lite.py tests the reader (11 passed with test_vae_ref.py on p1004).
2026-11-10 17:33:55 +01:00
Niko1221 d7611e03ca Image gate: a numpy reference of Qwen-Image-2.1's VAE decoder (vae_ref.py), as stable-diffusion.cpp 2988060 runs it for one picture
Test-only oracle for our own VAE decode (OWN-5 step 2): pixel-major float32, the Wan2.2-style residual decoder
(post_quant_conv, conv_in, mid resnet/attention/resnet, five up blocks with nearest-2x and the DupUp shortcut,
norm_out, SiLU, conv_out to RGBA), two modes: "f32" (exact weights, float32) and "f16op" (the f16 operands sd.cpp
and our GPU decoder use, accumulated exactly).  sd.cpp's 8-bit conversion and the latent denormalization are in
it too.  test_vae_ref.py checks DupUp against the Wan Python form, the 3x3 conv against direct loops, the RMS
norm by hand, the bf16 reader, and a tiny random decoder end to end (8 passed on p1004).
2026-11-10 17:22:34 +01:00
Niko1221 fccdb48a36 Tests for the image noise switch: the exact sd-cli argument list with the switch off, the merged model-args string, the refusal for a build without the generator, the build stamp and rebuild decisions; run_set.py --noise for the gates 2026-11-10 16:02:24 +01:00
Niko1221 4b9682183d Image generation: the noise switch. images "noise": "strata" (default "sdcpp", nothing changes) adds strata_noise=1 to sd-cli's --model-args, merged with the native runner's; setup --image-noise on (hidden) builds sd-cli with the generator and stamps the build, only then, so nobody compiles again unasked; a config that asks for it with an sd-cli built without it fails with a plain message and one next step 2026-11-10 16:02:24 +01:00
Niko1221 55b3fc77a1 Image gate: the sampler contract (numpy float32 euler and flow scaling, bit for bit against sd.cpp's final latent), a test for the noise patch and stream, and build_variant --noise 2026-11-10 16:02:24 +01:00
Niko1221 a9f27d0683 Image generation: Strata's noise generator for sd-cli (off unless --model-args strata_noise=1), tools/image/sdcpp_noise
The Linux x86 stream of stable-diffusion.cpp's default noise, computed with integer arithmetic only so it is the same on every OS and CPU: strata_noise.hpp, its tables, the packed table of the 109,290 sin results glibc has one unit off (compiled in as a C array by apply.py, no file read), strata_philox_rng.hpp, and apply.py, which puts them into src/core/ of the pinned stable-diffusion.cpp and hooks StableDiffusionGGML::init for the model arg. Kept apart from sdcpp_native so the native runner's build stamp does not change. The proof programs in tools/image/gate/noise now build the product header.
2026-11-10 16:02:24 +01:00
Niko1221 4808836061 Image gate: the stage limits as constants, each with the sd.cpp floor it was set from, and a checker for compare.py / stage_cmp.py results 2026-11-10 16:02:24 +01:00
Niko1221 abf297b353 Image generation gate harness and Strata noise generator (test tools only)
tools/image/gate: picture-set runner with sd-cli's exact command, pixel comparison, floor table, stage dump/replace hooks and stage comparison for a pinned stable-diffusion.cpp tree, model download with pinned sha256. tools/image/gate/noise: integer-only Philox + Box-Muller reproducing sd.cpp's Linux x86 noise bit for bit, with its packed sin exception table and the proofs (exhaustive domain check, many seeds). Nothing here is in a build or ship path.
2026-11-10 16:02:23 +01:00
Niko1221 5a30c2c4e8 Images (I2): NVIDIA mma.sync flash attention for the native runner, fused q/k/v GEMM
- k_attn_mma (sm_80+): m16n8k16 f16 -> f32, 8 warps x 16 queries, 64-key K/V tiles double-buffered with
  cp.async, ldmatrix (.trans for V), fp32 online softmax.  Bench on the RTX 3060 at 4096 x 4150 keys x 32
  heads: 23.7 TFLOPS vs ggml's flash_attn_ext_f16 15.4 (0.376 vs 0.577 s/step); CPU check 7e-5.
  STRATA_QI_GGML_ATTN=1 keeps ggml's.
- q, k and v of a block with one weight type load into one [3C x C] tensor: one GEMM and one activation
  quantize instead of three (STRATA_QI_NO_QKV_FUSE=1 keeps three).
- A float4 LayerNorm path with tanh(gate) once per step, off by default (STRATA_QI_FAST_LN=1): no measured gain.

RTX 3060, Q8_0 1024, seed 42, 3 interleaved rounds: steady step 2.09 s vs stock 2.61 (1.25x), denoise
17.93 s vs 22.13 (1.23x).
2026-10-13 05:53:21 +02:00
Niko1221 903cab02b0 Images (I2): warp-per-head q/k RMSNorm+RoPE kernel (float4, no shared memory; STRATA_QI_OLD_QKV=1 keeps the old one); WMMA attention fragment layer for gfx11 and gfx12 (gfx12 off unless STRATA_QI_GFX12_ATTN=1, not run yet) 2026-10-13 04:56:52 +02:00
Niko1221 c711ba071f Images (I2): setup builds the native DiT runner into sd-cli on CUDA / HIP; --image-native on|off (off by default) and the config's "native" add --model-args qwen_image_2_1_native=1 2026-10-13 01:07:28 +02:00
Niko1221 5be585a2cf Images (I2): native Qwen-Image-2.1 DiT runner inside stable-diffusion.cpp, opt-in
tools/image/sdcpp_native: a runner that replaces QwenImage21Runner::compute only (sd.cpp keeps the text
encoder, VAE, sampler and RNG), chosen with --model-args qwen_image_2_1_native=1 in CUDA / HIP builds.
- The text prefix runs once per condition (causal, the t = 0 modulation row) and leaves each layer's
  fp16 K/V; each step runs the 32 blocks on the image tokens only.
- GEMMs stay ggml graphs on the runner's backend (sd.cpp's MMQ / BLAS kernels and numerics); fused
  LayerNorm+modulate, gate+residual(+next LayerNorm), q/k RMSNorm+RoPE+fp16 K/V, SwiGLU and, on gfx11, a
  WMMA flash attention (8 waves x 16 queries, 64-key tiles, fp32 softmax) run on the backend's stream.
- apply.py copies the two files into the pinned checkout and makes two small edits (runner choice,
  SD_QI_NATIVE for CUDA / HIP builds); anything not covered falls back to the stock runner.

780M, Q8_0, seed 42: 512 2.11 s/step (stock 2.85), 1024 9.58 s/step (stock 14.2), image 96.5 s (131.8).
2026-10-13 00:52:46 +02:00
Niko1221 faf6c1c955 Images: Vulkan decodes in 256-pixel tiles at a quarter's overlap (the 780M's 1024x1024 VAE: 23 s instead of 45 s); docs/IMAGES.md speed table 2026-10-12 21:54:20 +02:00
Niko1221 a5b3b6c27b Image generation: Qwen-Image-2.1-Turbo through stable-diffusion.cpp (POST /v1/images/generations)
- serve/images.py: OpenAI's images API (prompt, size, n, response_format b64_json|url) plus seed and steps; one
  sd-cli process per request with the model card's arguments (8 steps, CFG 1, euler, Turbo's sigmas,
  --diffusion-fa), the PNGs returned unchanged.  The job takes the service's turn (one job at a time on the GPU)
  and the config's gpu_policy says what the text engine does meanwhile: keep, shrink (--vram-elastic), unload
  (its conversation saved to a session file and restored after the next start), auto.
- setup.py --images qwen-image (--image-quant, --image-backend, --image-gpu-policy): sd.cpp 2988060 + its ggml
  as zips, built for CUDA / HIP / Vulkan (LunarG SDK into third_party when the PC has no Vulkan dev files) / CPU;
  DiT quant by GPU memory (Q4_K_M <= 8 GB, Q6_K <= 12, Q8_0 above), VAE and the Qwen3-VL-8B UD-Q4_K_XL text
  encoder at pinned revisions, each checked against the Hub's SHA-256.  tools/image/install.py adds it to an
  existing install.
- Web page: an Images tab when the server has image generation.
- docs/IMAGES.md; tests: serve/test_images.py, tools/test_qimage.py.
2026-10-12 20:18:33 +02:00