Repository navigation
Studio: run MiniMax-H3's INT8 denoiser from the ConvRot checkpoint - #8293
Conversation
The hosted INT8 denoiser quantizes both sides of every GEMM to 8 bits, so its error is set by whichever side has the heaviest outliers, and a DiT's activations are outlier-heavy by construction. ConvRot spreads that magnitude across a block-Hadamard group: the weight is rotated offline, the activation is rotated online, and because the normalized Hadamard is symmetric and orthogonal the two cancel exactly in float. Nothing about the model changes; the quantizer just sees a flatter distribution on both sides. The conditioner already runs this rotation (#8283). This is the denoiser half. The recipe lives in the prequant checkpoint's own metadata, beside adaln_form / curve_dim / curve_grid: a kind, a group size, and the exact list of rotated FQNs. The list is recorded rather than recomputed on purpose. The two halves of the identity live in different places, and if they ever disagree about which Linears are rotated, the mismatched ones produce finite, plausible-looking, completely wrong pixels with nothing to raise and nothing to notice. A rule for "which Linears" can drift with a code change; a list cannot. Everything fails closed against that one failure mode: - rotated artifacts carry a v2 format tag, so a Studio predating this code refuses them outright instead of running them unrotated, and the tag and the declared rotation are checked as a biconditional in both directions; - the online half is installed in the prequant loader itself, not in a family hook, so no route can load a rotated checkpoint without it; - the loader raises on an FQN it cannot find, a target that is not a Linear, an in_features the group does not divide, or a kind it does not implement, and validates every target before swapping any, so a partial install is impossible. A raise becomes a refused checkpoint and a dense fallback. The artifact ships under its own filename with the plain one still behind it as the fallback, so an already-installed Studio keeps resolving the checkpoint it understands rather than refusing the v2 tag and falling back to the 66.3 GB dense download. build_convrot_hadamard and rotate_convrot_activation move out of video_minimax_h3_te into the shared module and are re-exported from their old home. The conditioner's rotation and the denoiser's have to agree with the same comfy-kitchen definition down to the normalizer, and two copies of a matrix nobody re-derives at review time is how they would stop agreeing.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d6f508b0b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| rotatable, not_divisible = rotatable_fqns(transformer, filter_fn, group) | ||
| rotate_linears_(transformer, rotatable, group) | ||
| rotation = rotation_metadata(group, rotatable) |
There was a problem hiding this comment.
Reject ConvRot builds with no rotatable linears
When the requested group is a valid power of four but divides none of the qualifying input widths (for example, a group larger than every Linear), rotatable is empty and this still creates rotation metadata and saves a v2 checkpoint. rotation_metadata_error explicitly rejects an empty FQN list, so the resulting multi-gigabyte artifact can never be loaded; fail the build before quantization/saving when this list is empty.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and the artifact it would have produced is unloadable by construction: rotation_metadata(group, ()) records the kind plus an empty fqn list, prequant_format_for then stamps v2, and rotation_metadata_error refuses an empty list at load time. Fixed in 7e5456e: convrot_refusal() returns a reason when the rotatable set is empty and main returns 2 before quantize_ and before the save. Covered by test_a_convrot_group_that_rotates_nothing_is_refused_before_anything_is_built, which also asserts the load-time refusal that makes it worth catching.
| p.add_argument( | ||
| "--convrot-groupsize", | ||
| type = int, | ||
| default = 0, | ||
| help = "bake a ConvRot block-Hadamard activation rotation at this group size (a power of " | ||
| "4; 0 = off). Every quantized Linear whose in_features the group divides has its " | ||
| "weight rotated before quantize_ so the quantizer sees a flatter distribution; the " | ||
| "exact fqn list is recorded in the checkpoint and the loader rotates the " | ||
| "activations of that list and nothing else. Writes the v2 format tag.", |
There was a problem hiding this comment.
Upload rotated checkpoints under a resolvable filename
When this new option is combined with --upload-repo, the existing upload path still publishes the v2 artifact as transformer_<scheme>.pt. For MiniMax-H3, the new resolver tries only MiniMax-H3-INT8-ConvRot.pt and then MiniMax-H3-INT8.pt, so it will never discover an artifact uploaded by this command; in other families, putting v2 under the legacy fallback also causes older Studio versions to fetch and reject it instead of retaining a plain fallback. The rotated upload needs a distinct configurable/derived destination matching prequant_filenames.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right about the destination. One correction to the specifics: detect_family() returns None for minimax-h3 (it is a VideoFamily), so this script exits 2 on --family minimax-h3 and cannot be the thing that produced the H3 artifact. The reachable half is the general one you name second: any rotated build with --upload-repo landed at transformer_.pt, which is the fallback name an older build resolves, so a v2 artifact there is fetched and refused by exactly the builds the tag exists to protect.
Fixed in 7e5456e. upload_destination() resolves the name the loader actually asks for: the family's declared prequant_filenames entry for a rotated build, the legacy transformer_.pt for a plain one (unchanged), and --upload-filename as an explicit override. A rotated build for a family that declares no name is refused rather than published over the fallback, and the whole thing is resolved before the dense load so it fails in a second instead of after the save. Two tests in test_build_prequant_checkpoint.py.
…artifact under the name the loader asks for Two ways the builder could spend GPU-hours and tens of gigabytes on a file nothing can ever use: - A group that divides no quantized input axis leaves the rotatable set empty, and the build still stamped the v2 tag with an empty fqn list. rotation_metadata_error refuses exactly that at load time, so the artifact was unloadable by construction. Refused up front instead. - --upload-repo published every build as the legacy transformer_<scheme>.pt. The loader asks for the family's declared prequant_filenames name first and the derived <Model>-<SCHEME>.pt second, so a rotated artifact at the legacy name is either never resolved or resolved as the fallback by a build too old to honour the rotation, which refuses the v2 tag and drops to the dense download. A rotated build now goes to the declared name, refuses when the family declares none, and --upload-filename is the escape hatch. Plain builds keep the legacy name. The destination is resolved before the dense load so an unpublishable build fails in a second.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
What this does
Runs MiniMax-H3's hosted INT8 denoiser from a ConvRot checkpoint: the weights ship in a block-Hadamard rotated basis and the loader rotates the activations to match.
The INT8 path quantizes both sides of every GEMM, so its error is set by whichever side has the heaviest outliers, and a DiT's activations are outlier-heavy by construction. A handful of channels carry most of the magnitude, the per-row amax is pinned by them, and every other channel spends its 8 bits on a fraction of the range it could have used. Rotating the input axis spreads that magnitude across the group:
His a normalized regular Hadamard, so it is symmetric and orthogonal and the two applications cancel exactly in float. Nothing about the model changes. The quantizer just sees a flatter distribution on both sides.The conditioner already runs this rotation (#8283). This is the denoiser half, and it shares the conditioner's Hadamard rather than adding a second one.
Where the recipe lives
In the prequant checkpoint's own
metadata, besideadaln_form/curve_dim/curve_grid:The fqn list is recorded, not recomputed. The two halves of the identity live in different places, one in the checkpoint's weights and one in the process, and if they ever disagree about which Linears are rotated then the mismatched ones compute
x @ H @ W.Torx @ (W @ H.T).T. That is finite, plausible-looking and completely wrong, with no exception to catch and no NaN to notice. The set today is "quantized Linears whose in_features the group divides", and both halves of that rule have moved before. A rule can drift with a code change; a list cannot.Failing closed
Everything here is built against that one failure mode, which is silence.
..._state_dict_v2. A Studio predating this code refuses the tag outright and falls back, instead of loading rotated weights and rendering wrong pixels forever. The tag and the declared rotation are checked as a biconditional in both directions, so neither a hand-edited tag nor a builder that recorded one half can produce something that loads.load_prequantized_transformeritself rather than by a family'sprepare_modelhook, so no route can load a rotated checkpoint without it.in_featuresthe recorded group does not divide, a target already rotated, or a rotation kind it does not implement. Every target is validated before any is swapped. A raise becomes a refused checkpoint and a dense fallback: slower and bigger, never wrong.Shipping without regressing an installed Studio
Refusing the v2 tag is the right answer for an old build, but on H3 the fallback is a 66.3 GB dense download, so nobody should have to take it. The artifact therefore ships under its own name with the plain one still behind it:
resolve_prequant_sourcealready had a primary/fallback chain; a family can now name the primary. Without an override nothing changes for any other family.Measured here
Everything in this section is fresh, on one B200, replaying the real transformer kwargs captured from a t2va render (
a red fox trotting through falling snow, cinematic, 384x640, 124 frames), against the pruned bf16 reference.The shipped artifact is the model the rotation was validated on. The quality gate was measured on an in-process arm that builds, rotates and quantizes in one go. The artifact takes a different route: rotate and quantize offline, save, reload through this loader. Comparing the two:
The residual forward difference is not the rotation. The same comparison on the plain artifact, with no rotation anywhere, gives 0.00143, 0.00154, 0.00154, the same three numbers. It is the research script's
norm_outcast against the production curve loader's, which is pre-existing and documented invideo_minimax_h3_adaln. Two independent loads of one artifact, and one model run twice, both give exactly 0.0, so this is not allocation noise.The loader rotates the recorded set and only that set. 313 Linears, matching the recorded contract exactly, with nothing extra and nothing missing. All 313 quantized Linears turn out to be divisible by 256, so the "left plain" set is empty for this model, which is recorded rather than assumed.
The silence is real. The same artifact with its rotation metadata stripped and its tag forced back to v1, which is what a loader that ignored the recipe would run:
That last row loaded clean and raised nothing. It is the entire reason for the format tag and the validator.
The three-step output-space A/B between plain and ConvRot (-5.9% mean) is a single prompt, single noise realisation, n = 3, and the per-step spread is wide (-51%, +36%, -21%). It is a sanity check, not a quality result. The quality result is below and it is prior.
Prior results, not re-measured here
These are the numbers ConvRot was gated on before this PR:
mlp.fc2at -30.5%, bestattn.out_projat -9.3%. Mean peak activation magnitude 5.07 to 4.10.The 948 / 948 bit-identical result above is what carries them onto the shipped artifact.
Tests
studio/backend/tests/test_diffusion_convrot.py, 42 tests: the Hadamard's symmetry and orthogonality at every group size, the rotate-then-unrotate identity (and the control that the weight side alone is not a no-op), that the loader rotates exactly the recorded fqns and leaves the other divisible Linear alone, that the class swap leaves the state dict untouched sostrict=Truestill holds, every way the contract can be unusable, that a refused apply rotates nothing at all, the format/rotation biconditional, and the end-to-end refusals throughload_prequantized_transformer. Plus one test pinning that the conditioner and the denoiser share one Hadamard function, so a future copy-paste fails there.Full backend suite against the same merge base, same
CUDA_VISIBLE_DEVICESmask, FAILED+ERROR line sets compared: 78 lines on base, 78 on this branch, identical sets, zero difference either way. All pre-existing environment failures.hub/tests429 passed on both.Note
The artifact itself is not published yet. This is the code that reads it.