open-standards/wai/wai-rs/examples/gen_preview.rs
Transaction Science de4dee51bb wai: generative-replicate — deterministic byte-exact GENERATION (wai.generate.spectral)
Extends "conformance is a hash" from codecs (replicate) to GENERATION (create).
Every other generative path (wai.semantic.*) is float + similarity-judged, so its
output varies by hardware and can never go in a receipt. This is the opposite: a
generator whose ENTIRE pipeline is integer/fixed-point, pinned to (model, prompt,
seed, steps), so the GENERATED image is byte-identical on every machine — its hash
is portable and receiptable even though there is no original. Generation-equivalence.

- src/generate.rs (feature `generate`, pure i64, no float/ONNX, wasm-ready):
  fixed-point spectral synthesis — prompt+seed fold into a splitmix64 PRNG that
  draws K = base + steps·step integer sinusoid components (fx, fy, amp, phase);
  each pixel sums amp·sine_lut[(fx·x+fy·y+phase+colour_phase) mod T]; the field is
  normalized to [0,255] by integer min/max. The float sin() that bakes the LUT runs
  once at model-build (tools/wai_generate_model.py), NEVER at generation.
- ReplicateClass::GenerativeDeterministic — the create-side quadrant, distinct from
  Behavioral (similarity, the semantic path) and the neural-decode classes. Wired
  wai.generate.spectral (Lossless tier, royalty-free) + SPEC §6 + capabilities table.
- Committed pinned vector (tests/vectors/generate/): the model bundle + generate.json
  pin. NEVER-skip test: the pin reproduces fnv1a 10b690999f6c5616 byte-for-byte,
  regeneration is identical (determinism), and prompt/seed/steps each change the
  output (it is conditioned, not constant). examples/gen_preview.rs dumps a preview.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-25 18:48:21 -04:00

10 lines
688 B
Rust

//! Dump a generated image to raw RGB for preview: cargo run --example gen_preview --features generate -- <prompt> <seed> <steps> <size> <out>
fn main() {
let a: Vec<String> = std::env::args().collect();
let m = wai::generate::SpectralModel::from_value(
&serde_json::from_slice(&std::fs::read("tests/vectors/generate/generate_spectral_model.json").unwrap()).unwrap());
let (prompt, seed, steps, n, out) = (&a[1], a[2].parse().unwrap(), a[3].parse().unwrap(), a[4].parse::<usize>().unwrap(), &a[5]);
let rgb = wai::generate::generate(&m, prompt, seed, steps, n, n);
std::fs::write(out, &rgb).unwrap();
eprintln!("{n}x{n} -> {out} ({} bytes)", rgb.len());
}