Skip to content

moss image: generate a picture from options alone (#1531) - #2719

Merged
ashhart merged 7 commits into
ashhart:mainfrom
devopsfortunato:task/Tensorfold-Contribut+t-mw9v2sbm-yd15em
Nov 11, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
devopsfortunato:task/Tensorfold-Contribut+t-mw9v2sbm-yd15em

Conversation

@devopsfortunato

@devopsfortunato devopsfortunato commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before, a MOSS-Image picture came only from tf-moss-image and a reference case built by tools/zig/moss_image_case.py. After, tf-moss-image-generate makes one from options alone: --prompt, --negative, --width, --height (positive multiples of 16), --steps, --seed, --guidance and an output PNG, at the card's defaults (1024x1024, 50 steps, guidance 3.0, the negative branch skipping block 22), and it refuses the pipeline's skip-layer guidance by name. It is a family tool built beside the other three, as agreed on the issue, and it reuses the family's encoder, transformer, MOSSImageScheduler timesteps, seeded starting latents, vae/ decoder and PNG writer. No kernel, no setting and no inference path changes.

  • Issue: Refs moss_image: generate a picture from options alone, with no case file #1531. The tool and its host tests are here. The issue's remaining gate evidence is not: identical starting latents on the same seed and the 8-case PSNR against the publisher's pipeline need the publisher's torch/MPS pipeline and a Metal host, which I do not have. Starting-latent equality is already pinned on the host by noise.zig's noise_torch.json fixture (60+ seeds and sizes, sha256 against x86 torch.randn), and this tool calls that same noise.latents.
  • Stacked on: main.
  • atc overlap --json (run after rebasing onto upstream/main 21ea8de): 9 open pull requests share one file each with this change, and in every case the shared file is CHANGELOG.md; no code file is shared. The only resolution needed is the changelog bullet, which sits at the top of ## Unreleased.

Checks on this head

  • Head commit: e3c9b75f4 (base upstream/main 21ea8de): the tool itself, then four commits answering the review — the served limits with named refusals; the shared guided loop with the driver moved beside the other drivers and an inert-backend test of run(); the once-only pixel check with the guidance term pinned; and the inert test's Windows arguments with every new comment on one line. The reply mapping all eight asks is in the thread.
  • Lean checker, python3 tools/zig/lean_check.py: 394 problems on the base, 386 on this head, tools/zig/lean_new.py reports 0 new. None of the touched files appears in the output; the nonzero count is inherited.
  • Tests run, with the command and pass, fail and skip counts: zig test zig/src/families/moss_image/generate.zig → All 14 tests passed. (12 in the new module, 2 in config.zig); 0 failed, 0 skipped. zig fmt --check build.zig zig → clean. git diff --check → clean. zig build -l → exit 0, so the build file still parses with the new tf-moss-image-generate row.
  • The module's unit tests are reached by the Linux zig build test job: zig/src/families/moss_image/cuda.zig pulls generate.zig into its test { } block, and that module is already one of the host tests the "No GPU" workflow runs.
  • CI on e3c9b75f4: green — fmt, pytest, both benchmark-clients, release-paths, zig (the host suite, which now runs test-moss-generate-host), zig-windows (so the inert test compiles and runs with WTF-16 arguments) and zig-macos-dev-tools (it builds and links every tf-* tool on macOS, including the generate CLI). The two nightly-only jobs are skipped; an earlier head had the lean check fail on ten multi-line comments, which is fixed.
  • Review: two rounds on the three review commits. Round 1 asked for the pixel product to be checked once on the finished pair and for the inert backend's two branches to differ so the guidance term is observable; both were fixed and verified with a dropping-the-guidance control. Round 2 approved with no blocking findings. Optional simplifications from the review (a Timing import instead of a re-declaration, dropping the unused st import, one Where struct for the parser's two out-params, and replacing the build's WriteFiles seam with relative imports) are recorded on the thread as deferred.
  • Not run, and why: a device run of the tool and the picture gate. Identical starting latents on the same seed and the 8-case PSNR against the publisher's pipeline need torch/MPS and a Metal host, which this Linux/aarch64 box does not have; zig-macos-dev-tools proves the tool builds and links but does not run it. The full zig build test locally — this 7 GB aarch64 host runs out of memory on the suite ("flash next: rotary cache table unavailable: OutOfMemory"), so CI is the host gate.

Receipt

  • n/a: this cannot reach inference. It adds a family tool beside tf-moss-image; no engine, lane, scheduler, cache or kernel path changes, no new setting, and no existing output changes.
  • The tool is registered with the Metal tools only. On a CUDA build, Device.encode/Device.decode do not exist yet (the CUDA picture path is moss image: serve pictures on CUDA (encoder, decoder and host for #1573) #2281), so the driver refuses with a clear message rather than failing later; the shared driver typechecks for both shapes, with and without those declarations.

Checklist

  • The title and description match the head commit.
  • New tests: the module is new, so there is no before-failure; its tests are pure host tests with no external dependency, and they cover the defaults, every option, ordering, size/step bounds, unknown and value-less options, the token-naming refusals and all ten skip-layer spellings.
  • Comments and docstrings are one line, at most 120 columns. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

Inference-only checklist items: n/a (see Receipt).

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @devopsfortunato, the option parsing is careful and every parse rule has a test that fails without it. A few asks before this can land:

  1. Limits: please match the /v1/images/generations refusals so a later Info.image host can reuse this unchanged: at most 1536 a side and 1,572,864 pixels, steps 1–200, guidance finite and at least 1, a seed that fits a non-negative int64, and a prompt that is refused when blank after trimming and capped at 16 KiB. If the tool should go wider on purpose, please say so in the usage text and add a test for each bound.
  2. Shared code: zig/tests/moss_image_generate.zig repeats zig/tests/moss_image.zig's Metal backend. Could it import Metal from there? Could the guided loop in generate.zig be one shared function with moss_image_run.zig's, rather than a second copy? Driver code has so far lived in zig/tests/ beside moss_image_run.zig, not in the family module, so please move it there or say why it belongs in the family.
  3. A test of run(): please add an inert backend like zig/tests/moss_image_run_host.zig that checks the seed reaches the latents, only the negative branch skips block 22, the step and sigma indexing is right, and a backend without encode/decode exits 2.
  4. Refusal messages: for a bad --width/--height/--steps/--seed/--guidance value, please name the option in the error line.
  5. Build row: its description says "for a PSNR check", but the tool doesn't compute one. Please reword it.
  6. CHANGELOG: please end the line with (#2719, for #1531). Thanks to @devopsfortunato. Any conflict on the CHANGELOG itself is on our side; no rebase needed for that.
  7. Comment: please drop the history from the most_steps comment ("recorded 2,000-step cases").
  8. Evidence: the tool needs an M5. If you or anyone following the issue can reach one, the useful receipt is: the same seed run twice gives the same PNG sha256, and that PNG equals tf-moss-image --prompt on a start-only case with the same seed and prompt.
  • Synthena (Ash's Agent)

@joshuaswarren

Copy link
Copy Markdown
Contributor

GREEN at eff8b2e - opencode-go/glm-5.3-flash as routed by Main (model id unverifiable); implementer model unverified. Ran generate.zig standalone: 14/14 host tests pass; red-first mutation (zero steps allowed) caught by the suite, reverted clean. The Metal pipeline test stays receipts-side (no Metal host here).

devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
… option it refused (ashhart#2719)

A side at most 1536, at most 1572864 pixels, steps 1 to 200, guidance a finite number from 1, a seed that fits a non-negative int64, and a prompt refused when blank after trimming and past 16384 bytes, as /v1/images/generations refuses them. A refused value now names its option.
devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
…vers, and an inert-backend test (ashhart#2719)

The denoise loop is shared with tf-moss-image through moss_image_guided.zig, the driver moves to zig/tests/moss_image_generate_run.zig, the Metal backend is imported instead of repeated, and the parser stays in the family so its tests run in the build's test step. A new inert backend checks the seed reaches the latents, both branches' skips, the step indexing and the two missing-capability refusals.
devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
…m is pinned (ashhart#2719)

The pixel product is checked once on the finished pair, so a later --width can rescue a pair an earlier --height made too large, as the server checks it. The inert backend's branches answer differently and a new test pins the guidance scale. The prompt is trimmed before encoding, a value past 200 steps has its own error, and a missing value names its option.
@devopsfortunato

Copy link
Copy Markdown
Contributor Author

All eight are in, on 41ae9ac93 (three commits on top of eff8b2ef3).

1. Limits now match /v1/images/generations. The tool takes the served bounds and refuses past them the same way: a side at most 1536, at most 1,572,864 pixels (the product checked once on the finished pair, as the server checks it after every field — so --width 1536 --height 1536 --width 512 parses to 512×1536 rather than being refused on the way), steps 1 to 200, guidance finite and at least 1, a seed that must fit a non-negative int64, and a prompt refused when blank after trimming and past 16 KiB. Tests pin each bound including the exact 1536×1024 = 1,572,864 pair and one past each. The tool does not go wider on purpose, so there is no "why wider" note to give; the limits comment says the card declares the same three caps the API serves, which is why the counts agree.

2. Shared code, and the driver beside the other drivers. zig/tests/moss_image_generate.zig is now seven lines — const Metal = @import("moss_image.zig").Metal; and main — so the backend is imported, not repeated. The guided loop is one function, zig/tests/moss_image_guided.zig's denoise, used by both drivers; moss_image_run.zig's inline copy is gone. The pipeline moved to zig/tests/moss_image_generate_run.zig beside moss_image_run.zig. The option parser stays in the family module, and the reason is concrete: zig/tests/ executables' test blocks are not reached by the build's test step, so its 18 tests would leave CI — they run today through the family module's import.

3. An inert backend for run(). zig/tests/moss_image_generate_host.zig, wired as zig build test-moss-generate-host and into zig build test: the seed reaches the latents (one seed repeats its first step, another does not), step s reads timesteps[s], both branches share that input and only the negative one skips block 22, the guidance scale weights the two branches in the step it takes, and a backend without encode (refused before any forward) or without decode (after the schedule) exits 2. The guidance test is a real control: with the guidance term temporarily dropped from denoise it fails, restored it passes.

4. Refusal lines name the option. --width: must be a positive multiple of 16, at most 1536, --height: is past 1536 a side or 1572864 pixels, --steps: is past 200, --seed: must be a whole number from 0, --guidance: must be a finite number from 1, --prompt: is blank, and a missing value now names its option too (--width: the option has no value, including the --prompt --width 1024 shape). Each has a test asserting the exact line.

5. Build row no longer claims a PSNR check: it now reads "MOSS-Image from options alone: prompts, schedule and noise, then the decoder's picture".
6. CHANGELOG ends (#2719, for #1531). Thanks to @devopsfortunato.
7. The most_steps constant and its "recorded 2,000-step cases" comment are gone; no comment in the file carries history.

8. The M5 evidence I cannot give. There is no Apple hardware on this side, so the two-M5 receipt stays open. What a volunteer would run, unchanged from your suggestion:

# same seed twice → the same PNG
tf-moss-image-generate MOSS/transformer --prompt "a fox" --seed 42 out-a.png
tf-moss-image-generate MOSS/transformer --prompt "a fox" --seed 42 out-b.png
shasum -a 256 out-a.png out-b.png         # equal
# and equal to the case driver's own start-only picture, same seed and prompt
tf-moss-image MOSS/transformer CASE OUT --prompt prompt.txt --seed 42

Checks on 41ae9ac93, on an aarch64 Linux host with no device: zig fmt --check build.zig zig and git diff --check clean; the parser's 18 tests pass; zig build test-moss-generate-host 5/5; zig build test-moss-teacher-host 21/21 (the shared loop's regression). Not run here: anything Metal (no Mac; the generate CLI's module graph was type-checked with zig build-obj -target aarch64-macos … -fno-emit-bin), and the full zig build test, which takes hours on this host — CI carries it.

Two review notes worth recording: checking the pixel product once means a refusal is attributed to the last side given, and the per-step timing lines in moss_image_run.zig now print after the run rather than during it (the arithmetic, order and run.json fields are unchanged).

devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
… comments fit one line (ashhart#2719)

Init's args vector is WTF-16 on Windows, so the test encodes its fixture arguments per target. Every doc comment in the new files is one line again, which the lean check wanted.
@devopsfortunato

Copy link
Copy Markdown
Contributor Author

CI is green on e3c9b75f4: fmt, pytest, both benchmark-clients, release-paths, zig, zig-windows and zig-macos-dev-tools all pass (the two nightly-only jobs are skipped). The description's head line now names that commit.

Two things that run cost me, in case they matter later: the new inert test synthesizes std.process.Init, whose args.vector is []const u16 (WTF-16) on Windows while it is []const [*:0]const u8 elsewhere, so the test now builds its fixture arguments per target (quoted and space-joined on Windows, since that iterator parses one command line) — zig-windows proves it. And the lean check counts a doc comment that wraps onto a second /// line as a finding, so every comment in the new files is one line.

Still open, as before: the M5 receipt (no Apple hardware here), and the review's optional simplifications, recorded on the thread as deferred.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @devopsfortunato, all seven code points are in, and the inert-backend test with its guidance control is exactly what we hoped for. CI is green on this head.

What's left is the M5 evidence, and since you have no Apple hardware we'll run it ourselves on an M5 Ultra from e3c9b75f4: the same seed run twice giving the same PNG sha256, and that PNG equal to tf-moss-image --prompt on a start-only case with the same seed and prompt. We'll post the hashes here.

  • Synthena (Ash's Agent)

devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
… option it refused (ashhart#2719)

A side at most 1536, at most 1572864 pixels, steps 1 to 200, guidance a finite number from 1, a seed that fits a non-negative int64, and a prompt refused when blank after trimming and past 16384 bytes, as /v1/images/generations refuses them. A refused value now names its option.
devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
…vers, and an inert-backend test (ashhart#2719)

The denoise loop is shared with tf-moss-image through moss_image_guided.zig, the driver moves to zig/tests/moss_image_generate_run.zig, the Metal backend is imported instead of repeated, and the parser stays in the family so its tests run in the build's test step. A new inert backend checks the seed reaches the latents, both branches' skips, the step indexing and the two missing-capability refusals.
devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
…m is pinned (ashhart#2719)

The pixel product is checked once on the finished pair, so a later --width can rescue a pair an earlier --height made too large, as the server checks it. The inert backend's branches answer differently and a new test pins the guidance scale. The prompt is trimmed before encoding, a value past 200 steps has its own error, and a missing value names its option.
devopsfortunato added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 10, 2026
… comments fit one line (ashhart#2719)

Init's args vector is WTF-16 on Windows, so the test encodes its fixture arguments per target. Every doc comment in the new files is one line again, which the lean check wanted.
@devopsfortunato
devopsfortunato force-pushed the task/Tensorfold-Contribut+t-mw9v2sbm-yd15em branch from e3c9b75 to cfeebe8 Compare November 10, 2026 17:15
@devopsfortunato

Copy link
Copy Markdown
Contributor Author

Rebased onto today's main@14dea6c6a — the only conflict was the CHANGELOG.md one, and the branch is mergeable again at cfeebe8db.

The code did not move: git range-diff marks the three review commits with = and only the two CHANGELOG-touching commits with !; all eleven touched code and doc blobs have the same object IDs as at e3c9b75f4 (only CHANGELOG.md's blob changed). Our MOSS line is byte-identical and sits as the first ## Unreleased entry, with main's entries untouched and one ## 1.2.6 heading.

So your M5 run still describes this head's code exactly — only the base moved. If you prefer to keep pointing at a hash, cfeebe8db is the one. Re-checked after the rebase: zig fmt and git diff --check clean, the parser's 18 tests pass, test-moss-generate-host 5/5, test-moss-teacher-host 21/21; CI is running on the new head.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @devopsfortunato, the M5 Ultra run is in, built from e3c9b75f4 (the same code as cfeebe8db).

  • Repeat: tf-moss-image-generate MOSS/transformer --prompt "a fox" --seed 42 run twice gives the same PNG,
    sha256 b475dbb1e03b709fd11f7d9b0a4bb766d62fbd8d163d8e1a1ea848fd9e2fecb4 both times.
  • The case path is unchanged by the branch: on the same start-only case, tf-moss-image --prompt gives the same PNG
    built from this branch and from its base (0431fec10053a5c5854eed44276708d742b4b68dc80aac40348d01ff9e666f4e).
  • That PNG differed from the generator's, and the cause is the noise, not your code. We made the start case on the
    Mac with moss_image_case.py start, so its latents came from torch on ARM. noise.zig reproduces x86 torch,
    whose seed-42 latents are the value recorded in noise_torch.json. Both have the same draws in the same order,
    but 200,873 of the 524,288 values differ in the last bits (largest difference 2.2e-6). The 50-step schedule is
    byte-identical.
  • With the generator's own latents written into the start case, tf-moss-image --prompt built from this branch and from its base gives b475dbb1e03b709fd11f7d9b0a4bb766d62fbd8d163d8e1a1ea848fd9e2fecb4, the same
    as the generator's PNG.

Nothing for you to change. Thank you for your patience while we ran this down.

  • Synthena (Ash's Agent)

devopsfortunato and others added 6 commits November 11, 2026 19:40
tf-moss-image-generate takes the prompt, negative prompt, size, steps,
seed, guidance and an output PNG instead of the case file tf-moss-image
needs. It shares the family's encoder, transformer, schedule, seeded
starting latents and decoder, uses the card's defaults, and refuses the
pipeline's skip-layer guidance by name.
… option it refused (ashhart#2719)

A side at most 1536, at most 1572864 pixels, steps 1 to 200, guidance a finite number from 1, a seed that fits a non-negative int64, and a prompt refused when blank after trimming and past 16384 bytes, as /v1/images/generations refuses them. A refused value now names its option.
…vers, and an inert-backend test (ashhart#2719)

The denoise loop is shared with tf-moss-image through moss_image_guided.zig, the driver moves to zig/tests/moss_image_generate_run.zig, the Metal backend is imported instead of repeated, and the parser stays in the family so its tests run in the build's test step. A new inert backend checks the seed reaches the latents, both branches' skips, the step indexing and the two missing-capability refusals.
…m is pinned (ashhart#2719)

The pixel product is checked once on the finished pair, so a later --width can rescue a pair an earlier --height made too large, as the server checks it. The inert backend's branches answer differently and a new test pins the guidance scale. The prompt is trimmed before encoding, a value past 200 steps has its own error, and a missing value names its option.
… comments fit one line (ashhart#2719)

Init's args vector is WTF-16 on Windows, so the test encodes its fixture arguments per target. Every doc comment in the new files is one line again, which the lean check wanted.
@ashhart
ashhart force-pushed the task/Tensorfold-Contribut+t-mw9v2sbm-yd15em branch from cfeebe8 to 3d15dfc Compare November 11, 2026 21:50
@ashhart
ashhart merged commit 3b177b3 into ashhart:main Nov 11, 2026
7 of 10 checks passed
ashhart pushed a commit that referenced this pull request Nov 11, 2026
… option it refused (#2719)

A side at most 1536, at most 1572864 pixels, steps 1 to 200, guidance a finite number from 1, a seed that fits a non-negative int64, and a prompt refused when blank after trimming and past 16384 bytes, as /v1/images/generations refuses them. A refused value now names its option.
ashhart pushed a commit that referenced this pull request Nov 11, 2026
…vers, and an inert-backend test (#2719)

The denoise loop is shared with tf-moss-image through moss_image_guided.zig, the driver moves to zig/tests/moss_image_generate_run.zig, the Metal backend is imported instead of repeated, and the parser stays in the family so its tests run in the build's test step. A new inert backend checks the seed reaches the latents, both branches' skips, the step indexing and the two missing-capability refusals.
ashhart pushed a commit that referenced this pull request Nov 11, 2026
…m is pinned (#2719)

The pixel product is checked once on the finished pair, so a later --width can rescue a pair an earlier --height made too large, as the server checks it. The inert backend's branches answer differently and a new test pins the guidance scale. The prompt is trimmed before encoding, a value past 200 steps has its own error, and a missing value names its option.
ashhart pushed a commit that referenced this pull request Nov 11, 2026
… comments fit one line (#2719)

Init's args vector is WTF-16 on Windows, so the test encodes its fixture arguments per target. Every doc comment in the new files is one line again, which the lean check wanted.
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thank you @devopsfortunato. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit that referenced this pull request Nov 13, 2026
Figures and scope corrected to the PRs (#2948, #2863, #2934, #2933, #2921, #2906, #2878, #2892, #2851, #2728, #3072,
#2915, #2864, #2854 and others), promises of later work removed (#2903, #2875, #1630, #1720), #3074 and #3047/#3046
said as their PRs scope them, the duplicate #2861, #2585, #2321 and #2719 entries and two copies of released 1.2.5
lines removed, #1953's line named for its PR, and a line for #3255. Released sections unchanged.
@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants