Repository navigation
MiniMax-H3 / H3-Image: reference defaults for sizing, edit pre-scaling, posterior, still-latent decode, schedule and steps - #89
Merged
Conversation
… does Add sd::resize_lanczos_8bit (Pillow's LANCZOS on 8-bit values, truncated in and read back as value / 255) and sd::fit_short_edge_size. MiniMax-H3-Image: the VAE copy of a reference now has its short edge scaled into 1024-2048 with both sides on the 32 px grid (no top-left crop to 16 px cells, no crop of the latent to whole patches), and the text encoder copy is resized to a 1024 short edge on the same grid. A picture already at its size is used as it is; any other goes through the 8-bit Lanczos instead of the float one. MiniMax-H3 video: reference pictures and reference video frames use the 8-bit Lanczos instead of nearest, and their sizes round halves to even.
…es a still latent as a chunk The image VAEs condition on the seeded posterior sample (seed 42); the reference keeps it in float32, so drop the float16 rounding of the H3-Image sample. A single latent through the video VAE is now decoded as a whole 5-latent chunk of copies and keeps the first real frame (after the 3 pre-padding frames), as the reference does, instead of being decoded alone.
…ce workflows The H3-Image model sigmas now follow the reference: timestep t + 1 of 1000 read linearly off the ascending PDD grid in float32 with the two-sided fused lerp, so the simple scheduler reproduces the reference's simple sigmas bit for bit. The default scheduler becomes simple (Euler, 6 steps), as in the reference templates; --scheduler discrete keeps the exact PDD grid. The image transformer takes t = 1 - timestep / 1000 in double and rounds it once, as the reference does (three of the six default steps differed by one ulp).
minimax-h3-image: Euler on the simple schedule, 6 steps, 2048 x 2048 (the model is tuned for that area). minimax-h3-fl2va / minimax-h3-ref2va: res_multistep on the simple schedule, 20 steps, 124 frames (5 s at 24 fps).
…t plane resize_lanczos_8bit now quantizes each input row into a per-thread buffer, keeps a single 8-bit plane between the two passes, runs both passes over rows with parallel_for and accumulates the vertical pass tap-major along contiguous rows, so it vectorizes. Output is unchanged bit for bit. The H3-Image sizing no longer copies a reference that is already at its target size (master copied it on every call).
…ference geometry Add sd::resize_area (torch's area filter), sd::scale_total_pixels_to_multiple (and its size rule) and sd::center_crop_to_aspect. MiniMax-H3 FL2VA / I2VA: without --image-preprocess rules the first frame is stretched to the canvas and the last frame cover-cropped to its aspect, both with the 8-bit Lanczos, as the reference does. Before, both went through the generic center crop and a nearest resize. MiniMax-H3-Image edits: picture 1 is scaled to 4 MP with the area filter and then covered and centre-cropped to multiples of 32 before the model sees it, as the reference edit template does.
…when none is given ModelSamplingPolicy gains default_sample_steps (20; 6 for MiniMax-H3-Image), used when sample_steps is <= 0, and sd_get_default_sample_steps() reports it. sd-cli leaves --steps unset by default (-1) so the model default applies; sd-server keeps advertising 20, its recipes carry the per-model counts. A request with neither width nor height set (sd-cli without -W / -H) now takes the model's default size: 512 x 512 as before for every model except MiniMax-H3-Image, which renders 2048 x 2048 for text-to-image and, for an edit, the 4 MP multiple-of-32 size of picture 1, as the reference templates do.
The 8-bit Lanczos takes an optional crop window and reads it in place, so the cover-cropped last keyframe needs no cropped copy (center_crop_window replaces center_crop_to_aspect). The edit picture's cover resize computes only the centred window, so neither the full cover image nor the two slice copies are made. Output is unchanged bit for bit.
sd-cli fills an unset size from the first loaded picture, so a MiniMax-H3-Image edit without -W / -H rendered at the picture's own size instead of the template's 4 MP size. When the size came only from the first reference, sd-cli now passes -1 and the library picks it: that reference's size for every other model, as before, and the 4 MP multiple-of-32 size for MiniMax-H3-Image.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
danielhanchen
added a commit
to unslothai/unsloth
that referenced
this pull request
Nov 15, 2026
#17824) ## Summary Moves Studio's pinned stable-diffusion.cpp prebuilt from `master-982-0518b34-u2217753` to `master-982-0518b34-u27b9ddc`. The only change between the two builds is unslothai/stable-diffusion.cpp#89 (MiniMax-H3 / H3-Image reference defaults for sizing, edit pre-scaling, the condition posterior, still-latent decode, the schedule and the step count), so GGUF MiniMax-H3 renders on the native engine now follow the same recipe the diffusers path uses. Existing installs pick the new build up on their next start: Studio reinstalls the bundle when the pin moves (`UNSLOTH_SD_CPP_AUTO_UPGRADE=0` keeps the old one). ## Checks - The new release ships the same 14 assets as the old one (names equal after the tag), so every platform the old pin covered still resolves: Linux CUDA 12 / 13, Vulkan, CPU, aarch64, Windows CPU x64 / arm64, CUDA 12 / 13, Vulkan, and macOS arm64 / x86_64. - The compare between the two fork commits is exactly one commit ahead (`2217753...27b9ddc`). - Tests that name the asset files and the pin were updated: `test_diffusion_more_families.py`, `test_sd_cpp_args.py`, `test_sd_cpp_cuda_cpu_torch.py`, `test_sd_cpp_vulkan_cpu_torch.py` (337 passed; 1 Vulkan fallback test errors identically on the base here, on a host CUDA probe). ## GPU check (A100-40GB, release CUDA 13 bundles of both tags) Same jobs, seeds and Studio sampler flags on both binaries; the old binary rerun is byte-identical, so every delta below comes from the build. | job | sampling s, old / new | peak GiB, old / new | result | |---|---|---|---| | MiniMax-H3-Image GGUF text-to-image, 1024x1024 | 7.10 / 7.27 | 29.84 / 29.82 | LPIPS to a bf16 reference 0.1706 -> 0.1640 | | MiniMax-H3-Image GGUF edit, one 1470x815 picture | 19.89 / 27.49 | 31.33 / 31.52 | picture now scaled to 2720x1504 (about 4 MP, as the reference workflow does); LPIPS to reference 0.2018 -> 0.1996 | | FLUX.2 klein 4B GGUF text-to-image | 2.73 / 2.60 | 12.08 / 12.08 | byte-identical PNG | The edit is slower on a small input picture by design: it carries about four times the reference tokens. Not run: L4 / T4 / Blackwell cards, the CUDA 12, CPU, Vulkan, ROCm, Metal and Windows bundles, and multi-picture edits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves the remaining MiniMax-H3-Image and MiniMax-H3 video defaults onto what the reference implementation does: how edit references and keyframes are sized and resized, the edit template's 4 MP pre-scaling and output size, the H3-Image posterior sample, how a single video latent is decoded, the default schedule, step count and size, the timestep rounding, and the built-in server recipes. Each change was checked on CPU against the reference implementation's own functions (bit for bit where the arithmetic allows it); the checks stay local, per CONTRIBUTING.md.
Changes
Reference pictures
sd::resize_lanczos_8bit(threaded over rows, one 8-bit plane at a time, vectorized vertical pass): Pillow'sLANCZOSon 8-bit values (the input is scaled to 0..255 and truncated, resized in Pillow's fixed point with a horizontal then a vertical pass, each rounded to 8 bits, and read back as value / 255). The reference resizes every picture this way. Newsd::fit_short_edge_size: the aspect-preserving size whose short edge lies in a range, both sides rounded (halves to even) to a multiple.Keyframes and the edit picture
sd::resize_area(torch's area filter: the float sum of each input box, row by row, divided by the box height and then its width),sd::scale_total_pixels_to_multiple(and its size rule) andsd::center_crop_window.--image-preprocessrules, the first frame is stretched to the canvas and the last frame cover-cropped to the canvas aspect, both with the 8-bit Lanczos, as the reference does. Before, both went through the generic preprocessing (centre crop and a nearest resize). The Lanczos reads the crop window in place, so no cropped copy is made. Explicit rules still replace this geometry.<Picture 1>is scaled to 4 MP with the area filter, then covered and centre-cropped to the nearest smaller multiple of 32 on each side, exactly as the reference edit template does before its conditioning node. A 1360x768 picture becomes 2720x1536 and a 1024x1024 one 2048x2048. The cover pass computes only the cropped window.VAE
H3-Image sampling
t_to_sigmanow follows the reference model sampling: timestept + 1of 1000 read linearly off the ascending PDD grid, in float32 with torch's two-sided fused lerp. Thesimplescheduler therefore reproduces the reference'ssimplesigmas bit for bit for every step count.simpleinstead ofdiscrete, with Euler, as in the reference templates. At 6 steps it lands next to the PDD grid (within 9e-4); the PDD heads are picked by the nearest grid point, as in the reference.--scheduler discrete(and--sigmas minimax-h3-image) still samples the exact grid with master's code.t = 1 - timestep / 1000in double and rounds it once, as the reference does. The float path differed by one ulp on three of the six default steps.adaln_t_tablerows, same index clamp); it is unchanged.Defaults when nothing is requested
ModelSamplingPolicy::default_sample_steps(20; 6 for MiniMax-H3-Image) applies whensample_stepsis <= 0, andsd_get_default_sample_steps()reports it.sd-clinow leaves--stepsunset by default, so H3-Image runs 6 steps and H3 video 20, as in the reference templates; every other model still runs 20.sd-serverkeeps advertising 20, and its recipes carry the per-model counts.-Wnor-H,sd-clipasses -1 and the library picks the model's size: 512 x 512 as before for every model except MiniMax-H3-Image, which renders 2048 x 2048 for text-to-image and, for an edit, the 4 MP size of picture 1 (2720x1536 for a 1360x768 picture), as the reference templates do.Server recipes
minimax-h3-image: Euler onsimple, 6 steps, 2048 x 2048 (the custom sigma list is dropped). The reference templates render a 4 MP square, and the model is tuned for that area, so this recipe keeps 2048 x 2048 as PiD does.minimax-h3-fl2va,minimax-h3-ref2va:res_multisteponsimple, 20 steps, 124 frames (5 s at 24 fps), 1344 x 768. They had Euler, no step count and 56 frames, while the library default was alreadyres_multisteponsimple.defaults.mdand the two model guides are updated to match.Defaults compared with the reference templates
--steps(sd-cli)-W/-H(sd-cli)Tests
Verified with a standalone C++ harness linked against a CPU build of this branch, compared with the reference implementation's own Python functions (run outside this repository, on CPU). Per CONTRIBUTING.md the harness is not part of the PR.
sd::fit_short_edge_size+sd::resize_lanczos_8bitagainst the reference's_size_short_edgeand its Pillow-basedlanczos, Pillow 10.4): 25 cases, all bit-identical in size and pixels. They cover random pictures at 1500x1100, 800x600, 3000x2000, 1024x1536, 1030x1030, 2048x2048, 4000x500, 333x777, 1504x1088 and 2049x1500 through both the VAE rule (1024-2048) and the encoder rule (1024), plus the model'sexamples/reference1.pngfitted and resized to 1344x768, and the 8-bit round trip at the same size. Master's sizing on the same cases: wrong sizes on 3 of them (1488x1088 instead of 1504x1088, 2992x2000 instead of 3008x1984, 2048x1488 instead of 2048x1504), a top-left crop instead of a resize at 1030x1030 (max abs 1.0), and pixel differences up to 0.78 wherever it resized (float Lanczos). Master's nearest resize of a video reference to 1344x768 differs by up to 0.75.sd::scale_total_pixels_to_multipleand its size rule against the reference's ownscale_total_pixels+scale_to_multiple_coverwith theareafilter): 11 cases bit-identical in size and pixels, the size rule matching every time. They cover 1360x768, 1024x1024, 800x600, 3000x2000, 2720x1536, 2048x2048, 4000x500, 333x777, 1920x1080, 5000x3333 andexamples/reference1.png._resizewithdisabledandcenter): 6 cases bit-identical (1920x1080, 1024x1024, 1344x768 and 1080x1920 to 1344x768; 800x600 to 768x1344; 857x481 to 960x544).MiniMaxH3ImageDenoiserwith thesimplescheduler against the reference'ssimple_scheduleronMiniMaxH3ImageModelSamplingwith the checkpoint'spdd_sigmas): bit-identical in float32 for every n from 1 to 50. At 6 steps both give 1, 0.96765357, 0.88770843, 0.75, 0.53364283, 0.23261039, 0. Master's default (discrete) differs from that by up to 8.7e-4.--scheduler discreteat 6 steps stays within 6e-8 of the grid, as before.ton all of them; master's float path is one ulp off on 3.addcmulwith the seed 42 noise to 2.4e-7. The old float16 rounding moved it by up to 1.0e-3. End to end (encoder + posterior + normalization) the latents agree to 1.0% of the latent range (max abs 0.025, mean abs 2.3e-4), and the encoder moments alone differ by the same amount (max abs 0.026, mean abs 5.5e-4): that is the encoder's own conv arithmetic, which this PR does not touch.minimax_h3_video_vae_fp16.safetensors, a seeded 8x12 latent, CPU): sd.cpp now matches the reference'sdecode(5 copies, first real frame) to 2.2e-3 max abs (1.1e-4 mean), which is the float16-weight arithmetic. The old decode-alone path differs from the reference by up to 0.98 (mean 0.081).sd-serverstarted on this branch lists the three MiniMax-H3 recipes with the new defaults and reports no catalog errors.sd-cliandsd-serverbuild cleanly on CPU. Only the changed lines were checked with clang-format (--lines), which reports no changes.GPU renders against the reference (Colab G4, RTX PRO 6000 Blackwell)
Same seed (42), one VM, three arms:
master-982-0518b34-u2217753prebuilt (fork master).e23683ain the first run,4dd7bb6in the second (a fresh VM; the REF renders of the first run are reused).Both sd.cpp arms use the Q8_0 GGUF, the Q4_K_M text encoder and the release VAE. Text-to-image uses the template size, 2048 x 2048. The edit uses the model's
examples/reference1.pngwithprompt.edit.txt. Every arm rendered pixel-identical images on its two repeats.-W/-H(4dd7bb6)--steps/--schedulerran 6 steps on thesimpleschedule.e23683a, HEAD without-W/-Hrendered the edit at 1024 x 1024 instead of the reference's 2048 x 2048, because sd-cli filled the size from the picture before the library could apply the template rule. At4dd7bb6the same command renders 2048 x 2048, pixel-identical to the run with the size given, so it lands on the same 0.0147 LPIPS.4dd7bb6ande23683arender pixel-identical text-to-image images, and an identical edit when the size is given. BASE and the REF scores reproduce exactly on the second VM.Wall time is the whole
sd-cliprocess, model loading included. The second run (4dd7bb6) measured BASE at 9.28 / 8.98 s and 12.99 / 13.07 s, and HEAD at 8.93-8.96 s and 17.74-17.87 s (with or without-W/-H), with the same VRAM and host memory.MiniMax-H3 FL2VA render (same G4,
4dd7bb6)A short FL2VA run checks the keyframe change end to end:
minimax_h3_fl2va_pruned-UD-Q3_K_XL.gguf, 512 x 288, 22 frames, 4 steps, seed 42. The first keyframe is the squarereference1.pngand the last a 4:3 picture, so stretching and cover-cropping give very different frames. The table compares the decoded first and last frame against both geometries (Pillow Lanczos):HEAD's first frame now follows the stretched keyframe, as in the reference workflow, where BASE cropped it. The last frame is cover-cropped by both builds. Both runs logged
MiniMax-H3 FL2VA, wrote all 22 frames, and sampled withres_multistepon thesimpleschedule. Sampling took 2.33 s against 2.30 s, and decode 0.72 s for both.Performance
CPU only, on a shared host (load average about 700 on 192 cores), so wall times are noisy; the tables use the minimum process CPU time over 7 repetitions, with each arm run twice in ABBA order (the pair is the A/A spread). Master is fork master
2217753for the decode and master's code path for the resizes. Memory is the peak RSS growth over the input picture.Reference picture sizing and resizing (single thread):
Keyframes and the edit pre-scaling (CPU ms, min over 7 runs, two runs per arm; master's keyframe arm is its crop-resize with nearest):
The pre-scale is new work that master did not do, about 50 ms with 32 threads. Its memory is the 4 MP picture the reference also builds, plus one intermediate at the scaled size. Fusing the cover resize with the crop took it from 112 ms and 238 MiB to 52 ms and 143 MiB. The larger effect is downstream: like the reference template, an edit now runs at the picture's 4 MP size when no size is given. The new step default makes H3-Image runs without
--steps3.3x shorter (6 steps instead of 20).Single-latent video VAE decode (16x16 latents, 32 threads,
minimax_h3_video_vae_fp16):The chunk decode is about 5.4x slower and uses about 290 MiB more, because the reference decodes 5 copies through a decoder that attends over the whole chunk, and no shortcut gives the same frame. Video generation never takes this path: it only runs when a single latent is decoded with the video VAE.
Everything else costs nothing at run time. The posterior change removes a loop. The H3-Image sigma and timestep changes are a few scalar operations per step.
res_multistepruns one model evaluation per step, like Euler.The new recipe defaults are heavier on purpose because they follow the reference templates: 2048 x 2048 instead of 1024 x 1024 for H3-Image, and 124 frames instead of 56 for H3 video. Requests can still pick a smaller size.
Not covered
sd-serverstill uses 20 steps for a MiniMax-H3-Image request that sends none when no recipe applies (the recipe carries 6), and its OpenAI-compatible image route still defaults to 512 x 512.--rng cpu, also the posterior noise) matchestorch.randnbit for bit on 83% of values and within 3 ulp on the rest; torch's vectorized Box-Muller uses its own log / sin / cos. This is unchanged here.