Skip to content

Studio: run MiniMax-H3's Qwen3-VL conditioner from the hosted INT8 checkpoint - #8283

Merged
danielhanchen merged 15 commits into
mainfrom
h3-te-quant
Aug 10, 2026
Merged

danielhanchen merged 15 commits into
mainfrom
h3-te-quant

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The problem

The MiniMax-H3 Diffusers path runs every component under ComponentsManager.enable_auto_cpu_offload, so its VRAM floor is the largest single resident component, not their sum. That is why seeding the 20 GB pre-quantized denoiser moved H3_DIFFUSERS_VRAM_BASE_GB by exactly nothing: the 66.7 GB Qwen3-VL conditioner was already the larger of the two and simply took over as the maximum.

text_encoder_quant was accepted on this path and then silently ignored. _load_h3_modular_pipeline did not take the argument at all, and the resolved record hardcoded (None, "off", "released bfloat16 components").

What this does

Wires text_encoder_quant=int8 through to the hosted ConvRot INT8 conditioner in Comfy-Org/MiniMax-H3, the repo the Diffusers path already pulls its VAEs from, so this adds no new component dependency.

The artifact is seeded before load_components, in the same place and for the same reason as the denoiser. Quantizing at load time would defeat the point twice over: a runtime cast has to materialise the dense encoder first, so its peak is the bfloat16 size we are trying to avoid, and on this workflow it would also have to download the 62 GB dense component the checkpoint replaces.

Measured before and after

960x544, 124 frames, 8 steps, cfg 1.0, seed 11, int8 denoiser pinned, one B200, torch.cuda.max_memory_allocated:

conditioner peak VRAM wall time
bfloat16 (released, 66.7 GB) 94.62 GB 48.2 s
int8 (hosted, 27.1 GB) 55.20 GB 27.4 s

The 39.4 GB drop is the conditioner delta to within 0.2 GB. Same seed, same prompt, visually identical output: same composition, same subject position frame for frame.

Is the 50-layer truncation lossless

Yes, and provably rather than empirically.

MiniMax-H3 conditions the transformer on hidden_states[50] of its Qwen3-VL conditioner and never calls the language-model head:

  • diffusers/modular_pipelines/minimax_h3/modular_pipeline.py, MiniMaxH3ModularPipeline.text_encoder_layer returns 50: "MiniMax-H3 reads hidden_states[50], not the final one: the last layer is post-norm and is not the conditioning the released weights were trained against."
  • diffusers/modular_pipelines/minimax_h3/encoders.py, get_qwen3vl_prompt_embeds calls text_encoder.model(..., output_hidden_states=True) and returns outputs.hidden_states[text_encoder_layer]. Its own comment: "MiniMax-H3 reads hidden_states[50] and never uses the language-model head."

Decoder layers 51-64 and lm_head therefore cannot influence the conditioning by construction. Comparing the hosted file's 902 tensor names against MiniMaxAI/MiniMax-H3's own text_encoder/model.safetensors.index.json confirms the artifact drops exactly that set: every hosted name maps 1:1 onto a released one, and the only released names left over are decoder layers 50-63 (0-based), model.language_model.norm.weight and lm_head.weight.

Verified end to end as well. Against the released 64-layer bfloat16 encoder on the same tokens, the hosted INT8 conditioner's hidden_states[50] differs by 0.4% relative error over three prompts (0.9% on a single-token prompt), cosine similarity 1.0000.

There is one mechanical catch, and it is why the loader builds 51 layers rather than 50. output_hidden_states yields [embeddings, layer_0_out, ..., layer_{N-1}_out] where the last entry is post-norm, so a stack truncated to exactly 50 layers returns a normalized hidden_states[50], which is not the conditioning the released weights were trained against. Diffusers refuses that case outright. The loader adds a 51st pass-through slot so the read lands on the raw state, for no weights and no compute, and keeps len(layers) == config.num_hidden_layers so the diffusers guard passes on a true statement.

The memory preflight

estimate_h3_diffusers_vram_gb now rebuilds the floor from the components a load actually holds, keyed on the ENGAGED schemes rather than the request.

That surfaced a second bug. A pinned pre-quantized denoiser is taken out of the offload rotation, so it stays resident alongside whatever is running and the floor becomes additive rather than a max. The shipped flat 68.5 GB under-states the pinned bfloat16-conditioner case by 26 GB against the 94.62 GB measured above, which is the direction that lets a doomed generation start. The new model is calibrated against both measured runs and covers each on the conservative side.

The no-argument call still returns exactly 68.5, so nothing that does not pass a size changes.

Honesty and fallbacks

  • A declined request reads as a fallback with a reason ("no hosted quantized fp8 conditioner for minimax-h3; loaded the released bfloat16 encoder instead"), never erased into a bare "off" that looks like the caller never asked.
  • _VideoLoadState.text_encoder_quant records the ENGAGED scheme, so a dense fallback cannot claim a quant the resident encoder does not have, and the preflight cannot under-state the floor by 39 GB.
  • A missing, unreadable, renamed or mismatched artifact returns None and the load continues with the released encoder. strict=True on the state dict load is the safety argument: it proves the artifact and the skeleton describe the same 902 tensors.
  • The download plan, the byte estimate, the pre-fetch and the load all key off one resolver, so none can stage an encoder another skipped. Only an artifact already on disk earns the right to drop the dense text_encoder/ shards; the component configs are kept because the loader meta-inits from them.
  • nvfp4 (14.61 GiB) is deliberately not wired: it is an AWQ layout with two levels of scale and needs its own numerical verification. The table is the one place to add it.

Default behaviour with no text_encoder_quant is unchanged.

Tests

studio/backend/tests/test_video_h3_te_quant.py, 20 tests beside the denoiser prequant ones: the resolver, the name mapping, the ConvRot arithmetic (including the control that dequantizing without the rotation is noise, not a small error), the read layer pinned against the installed diffusers constant, the memory floor against both measured runs, the download-plan hooks and the resolved record.

Full backend suite against the same merge base, line sets compared: baseline 3 failed / 15 errors, this branch 2 failed / 15 errors, a strict subset (one flaky test_orphan_cleanup_kills_under_real_root passed here). All are pre-existing environment failures. hub/tests 429 passed on both.

danielhanchen and others added 2 commits August 9, 2026 20:10
…eckpoint

The H3 Diffusers path runs every component under ComponentsManager auto CPU
offload, so its VRAM floor is the largest single resident component rather than
their sum. Seeding the 20 GB pre-quantized denoiser therefore moved that floor by
nothing: the 66.7 GB Qwen3-VL conditioner was already the larger of the two and
simply took over as the maximum. text_encoder_quant was accepted on this path and
then silently ignored.

Wire it through to the hosted ConvRot INT8 conditioner in Comfy-Org/MiniMax-H3,
the repo the Diffusers path already pulls its VAEs from. The artifact is seeded
before load_components, in the same place and for the same reason as the
denoiser: a runtime cast has to materialise the dense encoder first, so its peak
is the bfloat16 size we are trying to avoid, and it would also have to download
the 62 GB dense component the checkpoint replaces.

Measured at 960x544x124, 124 frames, 8 steps, cfg 1.0, seed 11, with the int8
denoiser pinned, torch.cuda.max_memory_allocated:

  bfloat16 conditioner   94.62 GB   48.2 s
  int8 conditioner       55.20 GB   27.4 s

Same seed, visually identical output. Against the released 64-layer bfloat16
encoder the conditioning it produces differs by 0.4% relative error over three
prompts, cosine similarity 1.0000.

The hosted encoder carries 50 of the released 64 decoder layers and no lm_head,
which is lossless rather than approximate: MiniMax-H3 conditions on
hidden_states[50] and never calls the language-model head. Comparing tensor names
against the base repo's own shard index, the artifact drops exactly decoder
layers 50-63, the final norm and lm_head, and nothing else. output_hidden_states
puts the post-norm state last, so a stack truncated to exactly 50 layers would
return a normalized hidden_states[50]; the loader builds a 51st pass-through slot
so the read lands on the raw state instead, for no weights and no compute.

Also rebuild the memory preflight from the components a load actually holds
instead of a flat constant. That surfaced a second bug: a pinned pre-quantized
denoiser is out of the offload rotation, so it is resident alongside whatever is
running and the floor is additive, not a max. The shipped 68.5 GB under-states
the pinned bfloat16-conditioner case by 26 GB against the 94.62 GB measured
above. The no-argument call still returns 68.5, so nothing that does not pass a
size changes.

Declined requests report as fallbacks with a reason rather than being erased, and
a missing, unreadable or mismatched artifact falls back to the released encoder.
Default behaviour with no text_encoder_quant is unchanged.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ts config read

Three fixes from review:

- The hosted ConvRot INT8 conditioner is cut from MiniMaxAI/MiniMax-H3, but the
  resolver engaged it for any modular-workflow pick. A derivative selected by
  detection or family_override can keep the Qwen3-VL architecture and carry
  different conditioner weights, and the strict load cannot tell the difference,
  so it would have silently conditioned on someone else's encoder. Gate on
  te_base_equivalent, the same test the pre-cast encoder path uses, and route the
  loader through the one resolver so the plan, the estimate, the pre-fetch and the
  load all agree.

- AutoConfig.from_pretrained ignored the live cache root, so the component config
  resolved against huggingface_hub's import-time default. Pass cache_dir like
  every other loader call here, and prefer the already-staged snapshot, whose
  text_encoder/config.json the scoped pre-download deliberately keeps.

- The conditioner artifact comes from a third repo, so register it in the
  in-flight asset set. Without it the delete-cached guard would let it go while
  the fetch, or the base pull that no longer carries a dense encoder, is running.
@danielhanchen

Copy link
Copy Markdown
Member Author

Round triaged. All three items were real; all three are fixed in d1cb3ff, and each one has a regression test that fails on 24bb196.

# Item Verdict What landed
3745113963 (P1) Restrict the hosted encoder to its verified base Correct _h3_te_quant_scheme now takes base and gates on te_base_equivalent(fam.base_repo, base), the same test the pre-cast encoder path uses. The seed in _load_minimax_h3_modular goes through that one resolver instead of calling h3_te_quant_scheme directly, so the plan, the estimate, the pre-fetch and the load cannot disagree.
3745113957 (P2) Load the encoder config from the staged cache Correct AutoConfig.from_pretrained now gets cache_dir, and prefers the staged snapshot via a new local_base. _base_download_files already keeps every component config when it drops the dense shards, so text_encoder/config.json is on disk there.
3745113967 (P2) Register the quant repo as an in-flight asset Correct H3_TE_QUANT_REPO goes into _loading.asset_repos in the same locked block that sets base_repo, before the fetch starts and for the whole assembly.

Why the base gate is the right shape rather than a stricter one: te_base_equivalent accepts the same repo, a local snapshot of it, a known mirror, or a verified byte-identical equivalence group, and refuses everything else. That is exactly the bar diffusion_te_prequant already holds pre-cast encoders to, and it matches what the pre-quantized denoiser gets for free from its baked base_model_id. A derivative now keeps its own conditioner and the resolved record says so, naming the base the artifact was cut from instead of reporting a bare "no hosted conditioner".

I checked the transformers plumbing rather than assuming it: PretrainedConfig.get_config_dict pops both cache_dir and subfolder and passes them to cached_file, so the pin reaches the resolution.

Tests, studio/backend/tests/ on CUDA_VISIBLE_DEVICES=0,1, same mask both sides, excluding the three collection-error files:

24bb196 (before) d1cb3ff (after)
result 63 failed, 20085 passed, 99 skipped, 15 errors 63 failed, 20089 passed, 99 skipped, 15 errors
FAILED/ERROR line set 78 lines the same 78 lines, byte for byte

The +4 passes are the new tests. The 78 pre-existing lines are this sandbox's huggingface-hub 1.27 against a transformers pinned to <1.0, not the PR. tests/test_video_h3_te_quant.py on its own: 25 passed, 1 failed, and that one failure (test_the_read_layer_matches_the_diffusers_pipeline) is the same import clash, since it imports the diffusers modular pipeline to read text_encoder_layer off it.

Separately, the two tests/test_diffusion_training.py diffusers-absent failures on the CPU Python matrix are inherited from main and fixed by #8281; nothing to do with this branch.

Still open and unchanged from the description: nvfp4 is not wired, there is no UI select for text_encoder_quant, and ref2va, the keyframe path and the unpinned estimator branch are not exercised on hardware.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1cb3ff76f

ℹ️ 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".

Comment on lines +1026 to +1028
h3_te_skipped = self._fetch_h3_te_quant(
h3_te_scheme, kwargs.get("hf_token"), cancel_event = cancel_event
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate the quant artifact before omitting dense weights

When the downloaded or cached safetensors file exists but is corrupt or has incompatible metadata/keys, _fetch_h3_te_quant still returns ("text_encoder",), so this call stages a base snapshot without the dense encoder. The strict validation only happens later in load_h3_quantized_text_encoder, which catches the error and returns None; on an offline host, load_components then cannot obtain the omitted dense weights and the promised fallback is unusable. Even with the newly pinned config read, the fresh evidence is that the fetch path checks only download success while all artifact validation remains after the dense-shard skip; validate before returning the skip or retain a usable dense fallback.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not taking this one. It is the deliberate, documented contract of this fetch, and it is the same contract _fetch_te_prequant has carried since it merged: only a file already on disk earns the dense skip, and validation is the loader's job. _fetch_h3_te_quant's own docstring already states the consequence you are describing and why it is the right failure.

On the substance: a corrupt artifact costs a slower load, not a broken one. load_h3_quantized_text_encoder returns None, the seed is skipped, and load_components pulls the dense encoder from the modular index's own repo id inline, which is exactly the download the skip was avoiding. The offline escalation needs a corrupt cached artifact AND no cached dense encoder at the same time, and a host in that state had no dense encoder to fall back to before this PR either, because the only way to have one cached is a previous load that fetched it.

Diverging from _fetch_te_prequant on this one path would also be worse than either doing it in both or neither: the fetch's idea of "valid" would be a partial copy of the loader's, and the two disagreeing is a new failure mode rather than a fixed one.

If this becomes a real problem the right change is to both fetches at once, not to this one, and the trigger would be evidence of an artifact that lands intact and then fails to load, which is not something I have seen.

The VRAM floor was rebuilt from the engaged components; the host floor next to
it was still the released bfloat16 pair, so the configuration these hosted
components exist for was refused. An 80 GB device running the int8 conditioner
and the int8 denoiser clears the VRAM check at 55 GB and was then told it needed
150 GB of system RAM for 47.5 GB of weights.

estimate_h3_diffusers_host_ram_gb now takes the same resident sizes, and the
offload tier's floor is their sum plus a headroom derived from the shipped
constant, so the released pair still asks for exactly 150.0 and only a load
holding smaller components asks for less. The tier above 132 GB VRAM is
unchanged: there is no measurement here to justify moving it, and component size
is not what stands between a load and a generation on such a device.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

Second round on this PR, two items.

# Item Verdict Outcome
3745321752 (P2) Recompute the host-RAM floor for quantized components Correct Fixed in c529699
3745321755 (P2) Validate the quant artifact before omitting dense weights Declined Deliberate contract, unchanged

The host-RAM one is a genuine inconsistency this PR created. I rebuilt the VRAM floor from the engaged components and left the host floor beside it on the released bfloat16 pair, so an 80 GB device holding the int8 conditioner and the int8 denoiser clears the VRAM check at 55 GB and is then refused for wanting 150 GB of system RAM to hold 47.5 GB of weights. That is the configuration these components exist for. It never surfaced in my numbers because the measured runs were on a 180 GB host.

estimate_h3_diffusers_host_ram_gb now takes the same resident sizes. The offload tier parks every component on the host, so its floor is their sum, unlike the VRAM floor, which is the largest resident one:

components host floor
released bf16 pair (66.7 + 66.3 + 11.1 + 5.9) 150.0, exactly what shipped
hosted int8 pair (27.2 + 20.3 + 11.1 + 5.9) 64.5
any pair, at or above the 132 GB VRAM tier 85.0, unchanged

Two things I would rather state than let a reader infer. The 5.9 headroom is derived from the shipped 150.0 minus the released component sum, not newly measured, which is what makes the default byte-identical. And the tier above 132 GB VRAM is untouched, because there is no measurement here that would justify moving it.

The artifact-validation item I declined, with the reasoning on the thread. Short version: only a file already on disk earning the dense skip, with validation left to the loader, is the contract _fetch_te_prequant has carried since it merged, and _fetch_h3_te_quant's docstring already states this consequence and why the alternative is worse. A corrupt artifact costs a slower load, not a broken one, since load_components pulls the dense encoder inline. The offline escalation needs a corrupt cached artifact and no cached dense encoder at once, and a host in that state had no dense fallback before this PR either. Adding a partial copy of the loader's checks to one of the two fetches would create a new way for the two to disagree.

Tests, studio/backend/tests/ on CUDA_VISIBLE_DEVICES=0,1, same mask both sides:

24bb196 (before this round's work) c529699
result 63 failed, 20085 passed, 99 skipped, 15 errors 63 failed, 20090 passed, 99 skipped, 15 errors
FAILED/ERROR line set 78 lines the same 78 lines, byte for byte

The +5 are the new tests. test_video_families.py + test_video_h3_te_quant.py + test_video_backend.py + test_video_prequant.py: 247 passed, 1 failed, and that one is the sandbox's huggingface-hub 1.27 against a transformers pinned <1.0, not the PR.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: c529699b74

ℹ️ 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".

…ase name

The base gate compares repo ids through te_base_equivalent, which treats a
matching final path segment as the same model. A derivative stored in a
directory named MiniMax-H3, or a same-named repo, therefore passed it and could
still have its conditioner replaced.

The pipeline's modular index answers the actual question: it records the repo
each component would be loaded from, so a derivative that retrained its
conditioner names itself there, while one that reuses the released conditioner
still points at MiniMaxAI/MiniMax-H3, and quantizing exactly those weights is
what the hosted artifact is. Read off the spec diffusers has already parsed, so
it costs nothing and cannot disagree with the load. Unanswerable is a refusal.

The plan-side resolver keeps the name comparison: it runs before anything is
staged and is contractually network-free, and its worst case is now staging an
artifact the seed declines, which costs a download rather than the wrong
weights.
@danielhanchen

Copy link
Copy Markdown
Member Author

Third round, one item, and it deserved a better answer than a defence of the tolerance I shipped.

3745377313 is right that a repo-id comparison cannot settle model identity: te_base_equivalent falls through to _same_base_model, which matches on the final path segment, so a derivative stored as /models/MiniMax-H3 passed the gate I added last round. It is also right that verifying the encoder bytes is not available here, since the whole point of this path is that the 62 GB dense conditioner is never downloaded.

There is a third answer that is better than either. The pipeline's own modular_model_index.json records where each component would be loaded from, and diffusers has already parsed it by the time the pipeline object exists:

"text_encoder": ["transformers", "Qwen3VLForConditionalGeneration", {
    "pretrained_model_name_or_path": "MiniMaxAI/MiniMax-H3",
    "subfolder": "text_encoder", ...}]

A derivative that retrained its conditioner ships it under its own id and says so there. One that reuses the released conditioner still points at MiniMaxAI/MiniMax-H3, and the hosted artifact is precisely a quantization of those weights, so substituting it is correct by construction rather than by resemblance. It costs nothing and cannot disagree with the load, because it is the same spec load_components would have used.

Landed in cc36870:

gate where what it answers
te_base_equivalent(fam.base_repo, base) plan, estimate, pre-fetch cheap, network-free; is this worth staging
_h3_te_index_source(pipe) must name the canonical base the seed itself is this pipeline's conditioner the one the artifact quantizes

Unanswerable is a refusal, not a pass: a pipeline whose conditioner source cannot be read keeps its own encoder. The plan-side resolver keeps the name comparison deliberately, because it runs before anything is staged and a raise there costs the whole download plan; its worst case is now staging an artifact the seed declines, which costs a download rather than the wrong weights.

Checked against the installed diffusers rather than from memory: ModularPipeline.get_component_spec is public, ComponentSpec.pretrained_model_name_or_path is the field with repo as its deprecated spelling folded in by __post_init__ (both handled), and the real MiniMaxAI/MiniMax-H3 index carries the entry above. That entry shape is pinned in a test, so a schema change fails loudly instead of quietly declining every quantized conditioner.

Tests, studio/backend/tests/, CUDA_VISIBLE_DEVICES=0,1 both sides: 63 failed / 20092 passed / 15 errors against the baseline's 63 / 20085 / 15, with the FAILED and ERROR line sets identical at 78 lines. The +7 across the three rounds are the new tests.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 866b86fc02

ℹ️ 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".

The test asserted the AutoConfig call shape, but the loader imports accelerate
and safetensors first and is best-effort, so on a runner that has torch and not
those it returned None from the import line, never reached the call, and failed
on the assertions with a KeyError. Stub them alongside transformers so the test
means the same thing on any host.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The index gate reused te_base_equivalent, which falls through to
_same_base_model and accepts a matching final path segment. That is the
tolerance the gate exists to remove: a derivative whose index names
someone/MiniMax-H3 as its conditioner source is a different repo with different
weights and passed anyway.

_h3_te_canonical folds a known mirror onto the id it copies, then compares
trimmed and lowercased, and nothing else. A pipeline re-saved locally names
local paths in its index and is now refused, which costs the optimisation rather
than correctness. The plan-side comparison keeps the tolerant helper: it is a
staging hint, and the seed is what decides.
@danielhanchen

Copy link
Copy Markdown
Member Author

Fourth round, one item, and it is a fair hit on the fix I shipped last round.

3745599801: I built a gate whose whole purpose was to stop a same-named derivative, and then compared its result with te_base_equivalent, which falls through to _same_base_model and accepts a matching final path segment. An index naming someone/MiniMax-H3 passed the check designed to catch it.

Fixed in 3fd785f. The index comparison goes through _h3_te_canonical: fold a known mirror onto the id it copies, trim, lowercase, compare. Nothing else.

index says before now
MiniMaxAI/MiniMax-H3 accepted accepted
a registered mirror of it accepted accepted
someone/MiniMax-H3 accepted refused
/models/MiniMax-H3 accepted refused
unreadable refused refused

I deliberately did not honour the _TE_EQUIVALENT_BASES groups here either. They exist for components genuinely shared across model families, there is no entry for this conditioner, and applying them would be tolerance I cannot point at evidence for.

One consequence worth stating rather than leaving to be discovered: a pipeline re-saved locally names local paths in its index and is now refused. That costs the optimisation and not correctness, which is the right way round for this gate. The plan-side comparison keeps the tolerant helper on purpose, because it decides whether staging the artifact is worth it, not whether to substitute weights.

Test test_the_index_compare_has_no_tail_name_tolerance asserts the precondition first, that te_base_equivalent really does accept all three rejected forms, so it fails if the two ever converge again, plus test_a_known_mirror_is_still_the_same_conditioner over the mirror table.

Tests, studio/backend/tests/, CUDA_VISIBLE_DEVICES=0,1 both sides: 63 failed / 20094 passed / 15 errors against the baseline's 63 / 20085 / 15, FAILED and ERROR line sets identical at 78 lines.

The (Python 3.10-3.13) CPU matrix red is down to the two tests/test_diffusion_training.py diffusers-absent failures inherited from main and fixed by #8281. The third one in that job on the previous head was mine, a test that reached for accelerate and safetensors on a runner that has torch and not those; it is stubbed now (eb5fc0f) and gone.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

… verify before dropping shards

Three from review:

- assert_video_precision_available rewrote an H3 int8 request to fp8 (H3 has no
  keep-bf16 schedule) and then refused it for want of fp8 tensor cores, so a CPU
  load this path serves came back as a 409. The hosted conditioner uses neither
  torchao nor those tensor cores, so it is exempt from that gate; whether the
  artifact suits the base is decided at the seed, which is not a host-level
  impossibility.

- An explicit encoder precision that engaged nothing committed a dense pipeline,
  where the conventional path raises. It now raises the same refusal, before
  load_components so it costs nothing, covering all three ways it can end up
  dense, with precision_fallback_allowed as the escape hatch.

- The staging skip compared repo names, so a derivative had its dense encoder
  dropped and then the seed declined, leaving a 62 GB inline pull. The decision
  that commits reads the base's own modular index first, so the snapshot and the
  seed agree.
The verified staging resolver now reads the base's modular index, which the
suite blocks, so the test that is about the in-flight delete guard failed on the
network rather than on what it asserts.
@danielhanchen

Copy link
Copy Markdown
Member Author

Fifth round, three items, all three real and all three fixed in e82d88a.

# Item Verdict What landed
3745741756 (P1) Fail closed when explicit encoder quantization is declined Correct Raises the same refusal the conventional path does, before load_components.
3745741752 Exempt the hosted H3 encoder from generic precision gating Correct A resolvable hosted scheme returns early from that gate.
3745741747 Verify exact identity before omitting dense encoder shards Correct The decision that commits reads the base's own modular index first.

The gating one explains why the other two were reachable at all and I did not see them: on a CUDA host te_quant_supported passes for the rewritten fp8, so an H3 int8 request sails through and renders. The gate only bites where I did not measure. effective_te_quant("int8", "minimax-h3") returns fp8 because H3 has no keep-bf16 schedule, and the check then asks for tensor cores that this path uses no part of: the artifact is INT8 storage plus a Hadamard rotation and an ordinary F.linear, no torchao, and the modular loader supports device == "cpu" in its own right. The exemption is deliberately narrow. It is not "H3 skips precision checks", it is "this request does not go through the mechanism that gate reasons about"; whether the artifact suits the base is an identity question decided at the seed, which was never a host-level impossibility.

Failing closed is the policy the same file already applies to the conventional path a few hundred lines down, and I had written a modular path that records a reason and renders anyway. It now covers all three ways this ends up dense, because the caller cannot tell them apart from the result:

how it ends up dense before now
no hosted artifact for the scheme dense render refused
artifact is not this pipeline's conditioner dense render refused
artifact failed to load dense render refused
any of the above, UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACK set dense render dense render, reason recorded

It keys on the engaged scheme rather than the resolver, so it sits after the load attempt, and it still raises before load_components, so the refusal costs nothing instead of arriving once every component is built. The denoiser half of that block behaves the way the encoder used to, but that came in with #7989 and is not what this diff touched; it wants a follow-up rather than a silent widening here.

The third is the trade-off I explicitly accepted last round, and it was the wrong pair to choose between. Reading modular_model_index.json from the base costs a few KB and gets both: _h3_te_quant_scheme_verified takes the name-matched scheme and requires the same exact index match the seed does, so the dense shards are only dropped once the base agrees. An unreadable index keeps them. The pure resolver stays for download_plan, which must not raise and must not touch the network, and whose worst case is now a byte estimate that is high rather than a snapshot missing an encoder.

Tests, studio/backend/tests/, CUDA_VISIBLE_DEVICES=0,1 both sides: 63 failed / 20097 passed / 15 errors against the baseline's 63 / 20085 / 15, FAILED and ERROR line sets identical at 78 lines. One intermediate commit here is mine to own: the verified resolver made the delete-guard test reach for the network, which the suite blocks, so it is stubbed (2ba48f8-era fix, folded in before the push).

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 10, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80bc89a38f

ℹ️ 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".

Comment thread studio/backend/core/inference/video.py Outdated
Comment on lines +267 to +268
if getattr(fam, "modular_workflow", None) and h3_te_quant_scheme(te_mode) is not None:
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict the hosted-encoder exemption to pipeline loads

When MiniMax-H3 is loaded through its native GGUF path with text_encoder_quant="int8" (especially on CPU or a host without generic FP8 support), this return now lets the explicit request pass, but _run_load_h3_native discards it through **_ and instead selects its Q2/Q4 encoder solely from the denoiser filename. The load therefore succeeds at an unrelated encoder precision despite the strict explicit-precision contract; require model_kind == "pipeline" for this exemption or reject the option for native loads.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and it is my own exemption reaching further than it should. I wrote it to say "this request does not go through the mechanism that gate reasons about", but returning before the whole encoder block also covered the native GGUF path, which discards text_encoder_quant through **_ and picks its Q2/Q4 encoder off the denoiser filename. So the explicit request came out answered at an unrelated precision, one commit after I argued that exact outcome is the thing the fail-closed contract exists to stop.

Fixed in c88ff33ba: the exemption requires model_kind == "pipeline". The hosted conditioner is a Diffusers-path artifact, so that is not a narrowing for convenience, it is the actual scope. A native load asking for int8 is judged by the generic gate again, and refused, which is right until the native path either honours the option or rejects it explicitly.

Comment on lines +1835 to +1838
# And H3's quantized conditioner, which replaces the base repo's dense text_encoder/.
h3_te_repo, h3_te_files = self._h3_te_quant_hub_files(
self._h3_te_quant_scheme(fam, text_encoder_quant, base), api
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Verify the conditioner source before pruning the download plan

For a remote derivative whose repo tail is also MiniMax-H3 (for example someone/MiniMax-H3), _h3_te_quant_scheme accepts the base through the tolerant tail-name comparison, so this plan adds the hosted INT8 artifact and removes the derivative's dense encoder shards. The actual load uses _h3_te_quant_scheme_verified, reads the derivative's modular index, rejects the substitution, and downloads those roughly 62 GB of dense shards instead; consequently the advertised plan and disk preflight substantially undercount the load and stage 27 GB that will not be used. Apply the same index-source verification before setting h3_te_repo and pruning the plan.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and it shows my justification last round was wrong on its own terms. I said the plan's worst case was a byte estimate that is high. It is wrong in both directions at once: 27 GB added and staged that the load will decline, and 62 GB of dense shards removed that the load will then need.

Fixed in c88ff33ba: download_plan uses _h3_te_quant_scheme_verified too. That is in keeping rather than a new cost, because that function is already nothing but model_info calls inside a try, so a few-KB index read is the cheapest request it makes. The purity constraint belongs to _h3_te_quant_scheme itself, which the plan still calls through, not to the plan.

Both the entry and the exclusion now key on the same verified answer, so the advertised total and the disk preflight describe the load that will actually run.

Comment on lines +394 to +399
parent_path, _, leaf = target.rpartition(".")
parent = encoder.get_submodule(parent_path)
existing = getattr(parent, leaf)
slice_ = handle.get_slice(prefix + ".weight")
out_features, in_features = slice_.get_shape()
if (existing.out_features, existing.in_features) != (out_features, in_features):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate that every expected projection remains quantized

If the hosted artifact is re-uploaded with any formerly quantized projection stored as an ordinary dense floating-point weight and its scale/metadata removed, that prefix disappears from quantized, so the original nn.Linear remains and the dense key still passes the later strict=True load. A sufficiently broad format change can therefore be accepted and recorded as engaged INT8 while the resident encoder approaches the 51 GB dense size rather than the budgeted 27.2 GB, making the generation memory preflight unsafe. Validate the expected quantized-prefix set or projection count independently of the scale keys before accepting the artifact.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and it is a real gap in the safety argument I have been making for this loader. I have been leaning on strict=True throughout, and it proves the artifact and the skeleton name the same 902 tensors; it says nothing about whether they are quantized. A projection re-uploaded as a plain dense weight with its scale and metadata removed simply drops out of the prefix set, keeps its original bfloat16 Linear, and loads cleanly. The load is then recorded as engaged int8, and the VRAM preflight sizes the floor from the ENGAGED scheme, so it clears a generation against a budget the encoder no longer meets.

Fixed in c88ff33ba, structurally rather than against a count: after the swap, no ordinary nn.Linear may survive anywhere in the decoder stack. That stays true if the layer count or the projection set ever changes, which a hardcoded 350 would not. The vision tower keeps its own dense Linears and is deliberately out of scope, as are the embedding table and the norms. Int8ConvRotLinear is an nn.Module and not an nn.Linear subclass, so it cannot be mistaken for one, and the test pins that too.

Failure mode is the same as every other refusal here: the loader returns None and the caller loads the released bfloat16 encoder, recorded as a fallback rather than as engaged.

…se a part-dense artifact

Three from review:

- The precision exemption applied to any H3 int8 request, including the native
  GGUF path, which discards text_encoder_quant and picks its Q2/Q4 encoder off
  the denoiser filename. An explicit request was therefore answered at an
  unrelated precision, which is what the fail-closed contract exists to stop. It
  is a pipeline-load exemption now.

- download_plan still used the name comparison, so a derivative had 27 GB staged
  that the load then declined and 62 GB of dense shards left out of the total.
  The plan uses the verified resolver, which is in keeping: that function is
  already nothing but model_info calls.

- strict=True proves the artifact and the skeleton name the same tensors, not
  that they are quantized. A projection re-uploaded dense drops out of the swap
  and loads cleanly, and the load would be recorded as engaged int8 while the
  resident encoder crept back toward 51 GB, under a preflight that sizes the
  floor from the engaged scheme. No ordinary Linear may survive in the decoder
  stack; the vision tower keeps its own.
@danielhanchen

Copy link
Copy Markdown
Member Author

Sixth round, three items, all three real and all three caused by my own previous fixes. Fixed in fb1fc43.

# Item Verdict What landed
3745959289 (P1) Restrict the hosted-encoder exemption to pipeline loads Correct The exemption requires model_kind == "pipeline".
3745959296 Verify the conditioner source before pruning the download plan Correct download_plan uses the verified resolver too.
3745959301 Validate that every expected projection remains quantized Correct No ordinary nn.Linear may survive in the decoder stack.

The first is the exemption I added last round reaching past its own justification. I wrote it to mean "this request does not go through the mechanism that gate reasons about", then returned before the whole encoder block, which also covered the native GGUF path. That path discards text_encoder_quant through **_ and picks its Q2/Q4 encoder off the denoiser filename, so an explicit request came out answered at an unrelated precision, one commit after I argued that is exactly what the fail-closed contract exists to stop. The hosted conditioner is a Diffusers-path artifact, so pipeline is the real scope rather than a narrowing for convenience.

The second shows my justification last round was wrong on its own terms. I said the plan's worst case was a byte estimate that is high; it is wrong in both directions at once, 27 GB added and staged that the load declines and 62 GB of dense shards removed that the load then needs. The plan is already nothing but model_info calls inside a try, so a few-KB index read is the cheapest request it makes; the purity constraint belongs to _h3_te_quant_scheme, which it still calls through, not to the plan.

The third is a real gap in the safety argument I have been making for this loader throughout. strict=True proves the artifact and the skeleton name the same 902 tensors. It says nothing about whether they are quantized:

a projection re-uploaded as a plain dense weight before now
drops out of the prefix set yes yes
keeps its bfloat16 nn.Linear yes yes
passes strict=True yes yes
recorded as engaged int8 yes refused
VRAM preflight sized at 27.2 GB for a near-51 GB encoder yes no

Checked structurally rather than against a count of 350, so it stays true if the layer count or the projection set ever changes. The vision tower keeps its own dense Linears and is deliberately out of scope, and Int8ConvRotLinear is an nn.Module rather than an nn.Linear subclass, so it cannot be mistaken for one; the test pins that too. The failure mode is the same as every other refusal here: None, and the caller loads the released bfloat16 encoder recorded as a fallback.

Tests, studio/backend/tests/, CUDA_VISIBLE_DEVICES=0,1 both sides: 63 failed / 20098 passed / 15 errors against the baseline's 63 / 20085 / 15, FAILED and ERROR line sets identical at 78 lines.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: fb1fc43f58

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

Codex came back clean on fb1fc43, so this is where the review stands.

Seven rounds, sixteen items: fifteen taken with a fix and a regression test, one declined with the reasoning on its thread.

round items outcome
1 base identity gate, cache pin, in-flight asset repo all taken
2 host-RAM floor taken; artifact validation declined
3 exact index compare taken
4 precision gate exemption, fail closed, verified staging all taken
5 exemption scope, plan verification, part-dense artifact all taken

Half of the later items were consequences of my own earlier fixes, which is the honest shape of it: the identity question in particular took three passes to answer properly, ending at the pipeline's own modular index rather than at any comparison of repo names.

The one declined item is on 3745321755: validating the artifact inside the fetch rather than at load. That is the contract _fetch_te_prequant has carried since it merged, a corrupt artifact costs a slower load rather than a broken one, and giving one of the two fetches a partial copy of the loader's checks creates a new way for them to disagree. If it should change it should change for both, and the trigger would be an artifact that lands intact and then fails to load, which I have not seen.

Every round: studio/backend/tests/, both sides on CUDA_VISIBLE_DEVICES=0,1, FAILED and ERROR line sets compared rather than counts. Identical at 78 lines every time; the final run is 63 failed / 20098 passed / 15 errors against the baseline's 63 / 20085 / 15, the difference being thirteen new tests.

Remaining red is (Python 3.10-3.13), and it is now exactly two lines, both tests/test_diffusion_training.py diffusers-absent failures inherited from main and fixed by #8281. Nothing on this branch.

Unchanged from the description, and still worth a reader knowing: nvfp4 is not wired, there is no UI select for text_encoder_quant, and ref2va, the keyframe path and the unpinned estimator branch are not exercised on hardware. Two follow-ups fell out of this review and are deliberately not in it: the denoiser half of the modular precision block does not fail closed the way the encoder now does (that behaviour came in with #7989), and the native GGUF path neither honours nor explicitly rejects text_encoder_quant, so for now the generic gate refuses it.

@danielhanchen
danielhanchen merged commit 587590d into main Aug 10, 2026
41 of 45 checks passed
@danielhanchen
danielhanchen deleted the h3-te-quant branch August 10, 2026 02:34
danielhanchen added a commit that referenced this pull request Aug 10, 2026
…8293)

* Studio: run MiniMax-H3's INT8 denoiser from the ConvRot checkpoint

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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refuse a ConvRot build that rotates nothing, and publish the rotated 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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

1 participant