Skip to content

idol: tf-idol-generate, one picture to a 3DGS PLY end to end on Metal (stacked on #1773, #1774, #1775) - #1780

Merged
ashhart merged 7 commits into
ashhart:mainfrom
jayleaton:idol-e2e
Nov 24, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
jayleaton:idol-e2e

Conversation

@jayleaton

@jayleaton jayleaton commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1773, #1774 and #1775 (and through them #1766). This branch merges those three; its own change is the last two commits (25b6e6f50, 883353480). Review after them.

What this changes

tf-idol-generate: one SDK-preprocessed picture to a 3DGS PLY and camera, natively on M5 Metal. The steps are DINOv3's feature1 (#1775), the FLUX.2 VAE's feature2 (#1774), the denoiser's condition and 50 guided steps (#1766), then the octree and Gaussian decoders (#1773). Each model loads when its stage starts and is freed when it ends. For #1757; with this, the issue's scope is covered on Metal except background removal. Details: the "End to end" part of docs/recipes/idol.md.

  • Background removal and cropping (BiRefNet, the SDK's preprocess) are not ported. The input is the picture preprocess returns, as the case tools write it.
  • Starting noise: torch.Generator("cpu").manual_seed(seed)'s randn, reimplemented (mt19937 and Box-Muller). The camera's five values are bit-equal to torch's; 28 of the 131,072 latent values are 1 ulp off, from torch's float cos and sin. The VAE posterior's noise and the octree's draws come from native seeded generators. --noise FILE injects recorded noise for parity.
  • The merge also moves the VAE case into tools/zig/idol_vae_case.py, as DINOv3's is, so the merged case tool stays under 600 lines.

CLI: extended by #1787

tf-idol-generate's arguments, flags, defaults and outputs here are the interface integrations build on. #1787 extends them additively and changes none of them:

  • PICTURE may also be a .png, .jpg, .jpeg or .webp photo, preprocessed natively (BiRefNet from SNAPSHOT_DIR/birefnet.safetensors);
  • new flags --mode synthetic|real (default synthetic) and --crop-margin X;
  • a photo also writes OUT_DIR/preprocessed.png;
  • a photo's tf-idol-generate.json adds preprocess_s and birefnet_s, and its load_s includes BiRefNet's load.

A safetensors PICTURE behaves exactly as in this PR.

On CUDA (#1862) the tool takes the same arguments, flags, defaults and outputs; its JSON's peak key is cuda_peak_allocated_gb where Metal's is metal_peak_allocated_gb.

Kernel contract

There are no new kernels. All of Idol's together, on the merged tree:

SUMMARY 57 kernels: 57 pass gates 1-4, 0 fail, 0 known findings; 57 controls: 57 red as planted, 0 missed; 0 limit problems

Receipt

  • Environment: Mac Studio M5 Ultra 256 GB, macOS 27; this branch; idol-sdk 4702a7f0 IdolPipeline.__call__ on torch 2.13.0 (MPS), each stage timed by wrapping its methods with torch.mps.synchronize(); the avocado example, seed 42, 50 steps, guidance 3, 262,144 Gaussians. The SDK's PLY is byte-identical to an earlier run of it.

  • Stage timings (ours: two fresh processes, weights in the page cache both times):

    stage ours SDK, MPS
    load (all models) 0.67 s 2.11 s (and 2.75 s of imports)
    preprocess (BiRefNet) not ported 0.51 s
    DINOv3 0.155 s 0.275 s
    VAE 0.241 s 0.119 s
    condition 0.071 s in the sampling
    denoise, 50 steps x 2 27.50 s 93.89 s
    octree 0.143 s 0.612 s
    Gaussian decoder 0.223 s 0.504 s
    PLY and camera 0.004 s 0.018 s
    total 29.1 s 100.8 s (95.4 s without preprocess)
  • Memory (/usr/bin/time -l, the whole process): ours 2.71 GB peak footprint (2.40 GB Metal allocated at most); the SDK 12.88 GB (5.01 GB MPS allocated, 12.64 GB driver).

  • Quality: the PLYs cannot be equal, because the SDK draws both its starting noise and the VAE posterior's noise from MPS's generator. Symmetric nearest-neighbour distance between 4,096-point samples, where two samples of the SDK's own PLY sit 0.00896 apart:

    run NN opacity mean
    the SDK 0.00906 0.885
    ours, native noise 0.0462 0.423
    ours, the SDK's VAE noise only 0.0463 0.425
    ours, the SDK's VAE and starting noise 0.00922 0.887
    the SDK itself, same features, CPU-seeded starting noise 0.0462 0.422

    The starting noise, not the port, makes the gap. The SDK's own run with CPU-seeded noise lands as far from its MPS-noise run as ours does, and its sample has cosine 0.479 to that run's. Given the SDK's noises, ours is as close as sampling resolves: sample cosine 0.99835, camera yaw/pitch/fov 1.6956/0.5397/0.1094 against 1.7006/0.5413/0.1096. Every PLY has 262,144 finite Gaussians, and repeated runs of ours are byte-identical. I did not render them side by side.

  • Parity chain, with the SDK's recorded features and CPU-seeded noise: the sample has cosine 0.999991 to the SDK's from the same inputs, and the camera is within 0.0022. The PLY sits at NN 0.00981 (baseline 0.00944) from the SDK's decode of its own sample. From the picture through our encoders, the sample moves to cosine 0.9944 with native VAE noise and 0.9995 with the SDK's.

  • Tests: zig build test test-golden -Dcpu=apple_m1: 585 of 585 steps, 8,958 of 9,011 tests pass, 53 skipped, 0 fail. zig fmt --check build.zig zig: clean. lean_check.py: 424, the same as main.

  • Not run: CUDA (only the denoiser has a CUDA port, idol: Idol's denoiser on CUDA (stacked on #1766) #1767, not yet run on a GPU). Metal M1 to M4: refused at load (no tensor units).

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (No token path.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt. (No new kernels; the combined SUMMARY is above.)
  • Prompt processing is no slower than the last release. (Not touched.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @jayleaton. The noise table settles the PLY question: with the SDK's noise injected, ours lands as close as sampling resolves. It waits on #1773, #1774 and #1775. Once they're on main, please rebase onto main, and we'll run tf-idol-generate end to end on an Apple M5 Ultra.

@AIFlowML

Copy link
Copy Markdown
Contributor

On ab0437c7, zig build tf-idol-generate -Dcpu=apple_m1 -j6 --summary all passed 64/64 on an M5 Max with Zig 0.17.0. Before weight loading, I confirmed two --seed 42 runs wrote identical start.f32, seed 43 changed the bytes, and a generated --noise file's F32 latent and camera appeared byte for byte. --steps 0 exited 2 without creating an output directory.

I found a picture-layout validation gap. Create a safetensors file with a tensor named pixels, dtype F32, shape [1024,1024,3], and 3,145,728 values. Passing it as PICTURE reaches DINO weight opening, just like shape [3,1024,1024]. picture() checks element count but then reads pixels as CHW, so HWC input can be interpreted as a scrambled image. Checking Tensor.is(.f32, &.{3, 1024, 1024}) for pixels and [1024,1024,3] for image rejected the malformed tensor in scratch while the valid layout still reached weight opening. Using nonexistent weight directories makes this input check reproducible without downloading model assets.

The trial merge into main f9f070a4 still conflicts in nine parent-stack files. My run covers startup and input fixtures only. Full image-to-PLY and the M5 Ultra comparison remain open after the parent rebases.

Igor Lessio - AIFLOW LABS

@jayleaton

Copy link
Copy Markdown
Contributor Author

Thanks @AIFlowML for finding the picture-layout gap. Fixed and rebased at de2fb84f5, on #1774 and #1775's new heads on main 328a566e2:

Host checks (Linux): zig fmt, git diff --check, lean 0 new against main, pr_check 0 errors, and test-kernel-contract 247 of 247. I have no Mac, so tf-idol-generate's build and your startup fixtures should be rerun on this head; the full image-to-PLY run is still open.

@AIFlowML

Copy link
Copy Markdown
Contributor

I retested the picture fix on fc25b718 in a scratch merge with main 25586070b. The five overlaps resolve by keeping main's contract notes and GLM prompt registration, then adding this PR's generation tool, picture export and recipe link. The build passed 67/67 steps on M5 Max with Zig 0.17.0.

zig build tf-idol-generate tf-kernel-contract -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j4 --summary all

I passed seven synthetic safetensors fixtures to the real tf-idol-generate SNAPSHOT_DIR VAE_DIR DINO_DIR PICTURE OUT_DIR --steps 1 CLI with nonexistent weight directories. Valid CHW pixels and HWC image reached weight loading. Transposed or flat pixels, BF16 pixels, and transposed image were refused first. With invalid pixels beside valid image, the command still refused pixels. That closes the original input-layout finding. Full image-to-PLY remains a model-backed check.

Igor Lessio - AIFLOW LABS

@jayleaton

Copy link
Copy Markdown
Contributor Author

Thanks @AIFlowML for the M5 Max retest of the picture fix: 67/67 steps, with valid CHW pixels and HWC image reaching weight loading and all five malformed fixtures refused.

Rebased onto main c35d9f7. The new head is 6e4d936. #1775 has merged, so this branch now carries only its own four commits. Git resolved the overlaps on its own, the same way your scratch merge did: main's contract notes and GLM prompt registration are kept, and this PR adds tf-idol-generate, the idol.picture export and the idol-generate.md recipe link. The condensed Idol paragraph in docs/kernel-contract.md still names the denoiser, decoders, VAE and DINOv3 controls. The file is 667 lines, down from main's 670.

Host checks on 6e4d936:

  • fmt, git diff --check and lean (0 new) are clean. pr_check --pr 1780 gives 0 errors, plus its advisory warning that no Unreleased bullet names this PR, as before.
  • test-kernel-contract passes 277/277.
  • tf-idol-generate and tf-kernel-contract compile for -Dtarget=aarch64-macos -Dcpu=apple_m1. The link needs the macOS SDK, which this Linux host doesn't have, so your M5 Max build remains the device check.

@AIFlowML

Copy link
Copy Markdown
Contributor

Confirmed the rebased 6e4d9366bb55ab24e0f6cefa50ef0480e06af609 trial-merges cleanly into c35d9f73c and passes git diff --cached --check. With Zig 0.17.0 on M5 Max, zig build tf-idol-generate -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all built and linked in 64/64 steps.

The seven synthetic safetensors cases from the earlier review still behave as expected through the CLI: both valid layouts reach weight loading, and all five malformed cases are refused before loading. The full checkpoint-to-PLY run remains separate.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks for the end-to-end Idol tool and the picture-layout checks, @jayleaton.

The recipe says the five camera values are bit-equal to torch's, but the repo has no recorded values for that short draw. Could you add a small regression with torch's values for seed 42 (the [8192, 16] draw, then [5]), so this path stays pinned?

  • Synthena

@jayleaton

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pushed 8c28d5f, a fast-forward from 6e4d936.

  • I moved torch's CPU generator out of tf-idol-generate into zig/src/families/idol/torch_rng.zig, so its test runs on the host without Metal.
  • The new test checks seed 42's [8192, 16] draw, then [5]. The five camera values must match bit for bit (0x3fb5a113, 0xbf66bf0d, 0xbf991081, 0x3f1039dc, 0xbf1e8dff). These use torch's normal_distribution<double>, and AVX2 torch gives the same bits.
  • The latent's first and last four values are checked within 3 ulps, and its float64 sum is checked as well.
  • How the values were produced: torch 2.5.1+cpu in a scratch venv on x86-64 Linux, running g = torch.Generator("cpu").manual_seed(42); torch.randn([8192, 16], generator=g); torch.randn([5], generator=g) with ATEN_CPU_CAPABILITY=default. That setting forces the scalar normal_fill_16, which is the path the Mac takes; torch's default here uses its AVX2 kernel, whose latent differs from it by a few ulps. The test states this.
  • The latent tolerance exists because torch's float logf/cosf/sinf come from the platform's libm. On glibc, 5,854 of the 131,072 values differ by up to 3 ulps; on the Mac it was 28 values at 1 ulp. The recipe now says this and names the test.
  • If the cached second Box-Muller sample is dropped, the test fails.

Checks: fmt, git diff --check and lean (0 new) are clean. pr_check --pr 1780 gives 0 errors and the existing advisory warning about the changelog bullet. test-kernel-contract passes 273/273, and the new host test passes. tf-idol-generate and tf-kernel-contract compile for aarch64-macos -Dcpu=apple_m1, but they need the macOS SDK to link, which this Linux host doesn't have.

ashhart and others added 3 commits November 24, 2026 04:31
…oders, the denoiser and the decoders to a PLY

Each stage is timed and each model freed after it. The starting noise is torch's CPU-seeded randn, reimplemented;
the VAE's posterior noise and the starting noise can be given for parity with the SDK's MPS draws. The recipe's
End to end section has the stage timings, memory and PLY comparison against the SDK's own IdolPipeline run.
…as AIFlowML found

picture() checked only the element count, so `pixels` as float32
[1024, 1024, 3] (HWC) passed and was then read as CHW: a scrambled image
reached both encoders. families/idol/picture.zig now requires `pixels`
to be exactly float32 [3, 1024, 1024] and `image` exactly
[1024, 1024, 3], and its host test plants the HWC `pixels`, a flat
tensor, a bf16 one and a CHW `image`, each refused.
jayleaton and others added 4 commits November 24, 2026 04:31
… idol.md under 600 lines; the picture's layouts
tf-idol-generate's torch CPU generator moves to idol/torch_rng.zig, so its
test runs without Metal. It checks the [8192, 16] then [5] draw for seed 42
against torch 2.5.1+cpu's values, produced with ATEN_CPU_CAPABILITY=default
(the scalar normal_fill_16 the Mac runs): the camera's 5 values bit for bit,
the latent's ends within 3 ulps and its sum, since torch's float logf, cosf
and sinf are the platform's libm.
@ashhart
ashhart merged commit 1092163 into ashhart:main Nov 24, 2026
2 of 12 checks passed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @jayleaton. 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.

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