Skip to content

Studio: whole-model NVFP4 for the video families with hosted pre-quantized denoisers - #10729

Merged
danielhanchen merged 38 commits into
mainfrom
studio-nvfp4-video
Sep 25, 2026
Merged

danielhanchen merged 38 commits into
mainfrom
studio-nvfp4-video

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Whole-model NVFP4 for the video families (Wan2.2-TI2V-5B, Wan2.2-T2V-A14B with its two experts, HunyuanVideo-1.5 at 480p and 720p) on the existing torchao backend, with hosted pre-quantized denoisers so a load never has to quantise 5 to 28 GB of dense weights on the fly. Every admitted linear (min 512 features, in and out divisible by 16) is NVFP4; nothing is per-layer here. The per-layer image policies and the flashinfer kernel backend come in the two PRs stacked on this one.

nvfp4 stays an explicit opt-in for three of the four families: the promotion gates below pass speed and memory on the flashinfer backend but not accuracy for Wan 5B and both HunyuanVideo variants. Wan2.2-T2V-A14B passes all four and gets its auto row in the stacked backend PR, where the condition it needs (the flashinfer backend being selected) lives. The numbers are in the PR so each decision is measured rather than a default.

What changes

  • One auto walk, and a per-family head in front of it (diffusion_transformer_quant.py). select_transformer_quant_scheme and auto_scheme_candidates computed their orders separately; they now share _auto_scheme_order, and _FAMILY_AUTO_PREFER lets a family whose shapes were measured put its own head in front of the arch-wide tier (dropped below a capability floor and on consumer parts). The table ships empty for video; a parametrised test pins the two callers to one answer. divisible_for_scheme replaces an inline map.
  • Zero-row guard, a live bug (diffusion_quant_pad.py, ZeroRowSafeLinear). torchao's nvfp4 activation path calls torch.max on the input and raises on an empty batch. HunyuanVideo-1.5's attention trim hands image_embedder.linear_1/2 an empty image stream on every text-to-video render, and context_embedder_2 can see an empty second text stream. The guard returns zeros + bias for an empty input, bit-exact with F.linear, and is inert otherwise; it wraps the two listed modules on the HunyuanVideo families only, installed after apply_small_m_padding on both the runtime and the pre-quantized paths. Micro-repro: nn.Linear(1152, 3072) under the runtime nvfp4 config with a (1, 0, 1152) input raises without it.
  • What the hosted artifacts carry. The tooling that BUILDS them is not in this repo and not in this PR: it lives in the private scripts repo, with the fingerprint differ and the gate recorder. What this PR adds is the loader's side of the contract, so the artifact format is stated here for the reviewer. Each file records the component it holds (transformer_2 for the second A14B expert, stamped into metadata and into the filename), the require_divisible the filter ran with, the base repo a local mirror declares itself a mirror of, and a packed-weight fingerprint block (md5-packed-v1, per module over qdata, scale, per_tensor_scale). Publishing is gated on a second, independent build reproducing that fingerprint, which is why the table below can say every file was built twice.
  • Loader gates (diffusion_prequant.py). The fingerprint is verified on load (UNSLOTH_PREQUANT_FINGERPRINT=full|sample|off, full by default: 5 s for the 5B, 14 s per A14B expert), a mismatch falls back to the dense path with the first five differing modules logged; artifacts without a block (the existing fp8 and int8 files) are accepted. Coverage includes torchao 0.18's Int8Tensor, so a newly baked int8 artifact is verified rather than recorded with an empty block. component and require_divisible in the metadata are checked against what the load asked for, so the second expert's file can never be loaded as the first. -nvfp4 and -mxfp8 join the suffix strip.
  • Conventional video pre-quant seeding (video_denoiser_prequant.py, video.py). The pipeline is built with every hosted denoiser component pre-loaded through pipe_kwargs, all components or none (a dual-expert model with one artifact is uncovered, not half covered). The plan-time scheme (_video_auto_denoiser_scheme) requires an artifact for every component and is pinned into the load so plan and load cannot disagree; the memory plan uses the artifact's resident size instead of the dense build peak, resolved before the unified-memory check and re-planned at bf16 if seeding returns nothing; the download plan drops both experts' dense shards and keeps both configs. h3_denoiser_pinned becomes denoiser_pinned. Offload plus pre-quant stays refused.
  • Registry rows (video_families.py) for unsloth/Wan2.2-TI2V-5B-NVFP4, unsloth/Wan2.2-T2V-A14B-NVFP4 (two files, the second through the task slot so it gets no filename fallback) and unsloth/HunyuanVideo-1.5-NVFP4 (480p and 720p files). Repos are private pending review.

Hosted artifacts

Every file was built twice in separate processes and published only on an identical fingerprint. The primaries are the tuned builds with baked activation scales (used by the stacked flashinfer PR, ignored by torchao); the plain RTN builds sit alongside as -RTN.pt for A/B.

file linears size vs fp8 file
Wan2.2-TI2V-5B-NVFP4.pt 304 2.82 GB -40%
Wan2.2-T2V-A14B-NVFP4.pt, -transformer_2-NVFP4.pt 404 each 8.05 GB each -42%
HunyuanVideo-1.5-Diffusers-480p_t2v-NVFP4.pt 781 4.69 GB -41%
HunyuanVideo-1.5-Diffusers-720p_t2v-NVFP4.pt 781 4.69 GB -41%

Measurements

B200, torch 2.12.1+cu130, torchao 0.18, default speed tier (compile on, step cache off, attention trim on), interleaved rotations paired on prompt and seed, LPIPS against the bf16 arm on held-out prompts, four seeds. The flashinfer rows come from the stacked backend PR run against these artifacts; they are included because they are what decides promotion.

Wan2.2-TI2V-5B, 1280x704x121, 50 steps:

arm p50 denoise vs fp8 steady GiB LPIPS SSIM
bf16 57.5 s 22.6
fp8, runtime torchao 54.9 s 1.00x 17.9 0.194 0.759
nvfp4 RTN, runtime torchao 66.4 s 0.83x 15.9 0.350 0.664
nvfp4 artifact, torchao 66.3 s 0.83x 15.9 0.345 0.654
nvfp4 artifact, flashinfer 47.5 s 1.16x, 10/10 wins 15.9 0.362 0.646

Wan2.2-TI2V-5B at a small grid, 832x480x49, 50 steps (Studio VideoBackend, default speed tier, 3 prompts x 3 seeds, one load per arm, flashinfer backend for NVFP4, per-frame LPIPS against bf16 of the same prompt and seed):

arm mean denoise LPIPS mean / worst clip
bf16 8.43 s
fp8 8.02 s 0.160 / 0.329
nvfp4 artifact, flashinfer 15.31 s 0.274 / 0.521

At this size the per-call overhead of the NVFP4 path outweighs the smaller GEMMs, so NVFP4 is about 1.8x slower than bf16 while still drifting further than fp8. It stays explicit-only for this family; auto never picks it.

HunyuanVideo-1.5 480p, 832x480x121, 50 steps:

arm p50 denoise vs fp8 steady GiB LPIPS SSIM
bf16 115.6 s 31.5
fp8 115.1 s 1.00x 23.8 0.465 0.475
nvfp4 RTN, torchao 128.9 s 0.89x 20.4 0.765 0.391
nvfp4 artifact, flashinfer 106.0 s 1.09x, 10/10 wins 20.5 0.581 0.436
nvfp4 artifact, flashinfer, W4A16 at steps 0 to 3 and 49 (stacked PR) 107.4 s 1.07x 20.5 0.474 (32-pair gap vs fp8 +0.028, 95% upper +0.061) 0.521

Wan2.2-T2V-A14B, 1280x720x81, 50 steps, and HunyuanVideo-1.5 720p, 1280x720x121, 50 steps:

family arm p50 denoise vs fp8 steady GiB LPIPS
A14B fp8 482 s 1.00x 38.6 0.431
A14B nvfp4 RTN, torchao 520 s 0.93x 26.2 0.552
A14B nvfp4 artifact, torchao 561 s min (p50 592 s under host contention) 0.86x 26.2 0.360
A14B nvfp4 artifact, flashinfer 432 s 1.12x, 5/5 wins 26.2 0.356 (paired gap vs fp8 -0.075, 95% upper -0.025; SSIM 0.571 vs fp8 0.510)
720p fp8 504 s 1.00x 23.8 0.531
720p nvfp4 RTN, torchao 539 s 0.93x 20.4 0.791
720p nvfp4 RTN + baked scales, torchao 539 s 0.93x 20.4 0.801
720p nvfp4 RTN + baked scales, flashinfer 477 s 1.06x, 5/5 wins 20.5 0.797 (paired gap vs fp8 +0.266; SSIM 0.314 vs fp8 0.424)
720p nvfp4 artifact (720p build), flashinfer 483 s 1.04x, 5/5 wins 20.5 0.685 (paired gap vs fp8 +0.154, 95% upper +0.196; SSIM 0.356 vs fp8 0.424)

Promotion gates (all four must hold for an auto row): speed p50 <= fp8 with >= 80% rotation wins; accuracy, paired LPIPS gap vs fp8 <= +0.02 with 95% upper bound <= +0.05 (the absolute 0.10 bar assumed the incumbent clears it, which fp8 does not on a 50-step video, so the paired form is the discriminating one and both are reported); health, no black or non-finite frames and SSIM within 0.02 of fp8's; steady resident <= fp8. Every family passes speed and memory on flashinfer; A14B passes accuracy and health as well (it is closer to bf16 under NVFP4 than under fp8) and gets the auto row in the stacked backend PR, conditioned on flashinfer being the selected backend since the same artifact on torchao is 0.86x fp8. The three smaller families fail accuracy and stay explicit opt-ins. Video LPIPS is not image LPIPS: fp8 itself sits at 0.19 to 0.53 against bf16 on these families because a 50-step trajectory diverges under any perturbation, so the paired gap against fp8 (0.12 to 0.17 here) is the meaningful accuracy number. The tuned build is a large lever on HunyuanVideo (0.765 to 0.581) and almost none on Wan (0.350 to 0.345); the baked static activation scale the fast kernel needs costs about 0.017 on Wan.

First-use costs: the hosted artifacts load in 19 to 26 s on every family, under fp8's own load; the runtime nvfp4 arm quantises on the fly and loads in 47 s (5B), 73 s (HV15) and 213 s (A14B). Compile on the torchao nvfp4 path is 1.5x to 2.8x fp8's; on flashinfer it is slightly under fp8's.

Tests

test_diffusion_transformer_quant.py (auto head per family, floor, consumer, deny, probe, anti-drift between the two callers, divisible_for_scheme, zero-row tokens), test_diffusion_quant_pad.py (guard shape, inert on non-empty, keys unchanged), test_video_families.py (rows resolve, no fallback for the second expert, 480p and 720p differ), test_video_prequant.py (seeding both experts, second-expert failure seeds nothing, skipped under offload, memory plan and revert, pinned scheme), test_video_backend.py (pre-quant twin of the dual-DiT quant test, runtime quant skipped for seeded components, shard drop keeps configs, byte totals, resolved record, HV15 guard installed), test_diffusion_prequant.py (one flipped byte refused with the fqn logged, absent block accepted, sample and off modes, component and require_divisible mismatches, suffix strip, Int8Tensor stub and real torchao round trip).

Full studio/backend/tests on this branch (test_blender_managed.py excluded), 821 files in 10 batches: 41355 passed, 124 failed, 223 skipped, 15 errors. That run predates the build tooling moving to the private scripts repo, so it also counted the builder's own test ids, which are no longer in this tree; nothing else in the count moved. Every failing id reproduces on the merge base (95feb6979) file by file, in 19 files this PR does not touch (chat generation lease and supervisor, llama admission, mcp_*, native audio, openai catalog, gpu arch gate, offload planner seam, sandbox files, studio_api). hub/tests: 683 passed.

Not changed

  • No _FAMILY_AUTO_PREFER row in this PR; the A14B row needs the backend condition and lands with the flashinfer backend PR. The registry rows here carry the measured resident sizes (denoiser term in decimal GB: 2.9, 16.2 for the expert pair, 4.8, 4.8; 0.28 to 0.29 of the bf16 term on every family) so the memory plan for a seeded load is right.
  • The first compiled render's 146 to 155 GiB peak on these families is pre-existing and the same on every arm.
  • The whole-model 0.33 steady factor for nvfp4 is left in place for families without a measured row.

UI evidence

No before/after pair is attached, because nothing a user sees changes. Two identical screens under a BEFORE and an AFTER label would read as evidence, and it would be evidence of nothing. What was checked, on the current head against this branch's own merge base:

  • The video model picker's rows, labels, badges and advertised sizes are built from the frontend catalog plus /api/system. This PR touches neither: the diff under studio/frontend is empty and studio/backend/main.py is untouched. No route serves a family's prequant_repos to the client, so a new row in the family table cannot reach the picker.
  • Precision is a fixed option list that already offers NVFP4 (Blackwell), so the new rows add no option and rename none.
  • Every new row is nvfp4, and nvfp4 is not in _AUTO_LADDER. _FAMILY_AUTO_PREFER ships EMPTY on this branch, so _auto_scheme_order returns exactly the tier it returned before and an unset or auto precision resolves to the same scheme on every host. _video_auto_denoiser_scheme therefore answers None on the default path for all four families, before and after.
  • On an EXPLICIT nvfp4 pick the resolved record's reason names the checkpoint it seeded from, but resolvedBadge returns null for an honored explicit request, so that string never reaches the screen. The two paths that DO render a reason, auto and a declined request, are asserted free of a repo id in test_video_backend.py.
  • The one surface that would move is the staged download footprint for an explicit nvfp4 pipeline pick, and only where the hosted denoiser is reachable. Those checkpoints are not published, so there is nothing here a reviewer could reproduce and nothing worth photographing.

The speed, memory and accuracy this PR is actually for are in the tables above, which is where a number belongs; a screenshot cannot carry them.

NVFP4 kill switch

NVFP4 for image and video generation is off by default until the hosted unsloth/*-NVFP4 repos are public. UNSLOTH_NVFP4_DIFFUSION=1 (also true, yes, on) restores the full NVFP4 behaviour of this stack, including private-repo access through the user's HF token; anything else, or unset, disables it. The default lives in one constant, NVFP4_DIFFUSION_DEFAULT in studio/backend/core/inference/diffusion_nvfp4_flag.py, so turning it on for everyone later is a one-line change. The switch is read at call time through nvfp4_diffusion_enabled().

Added on this branch (covers the surfaces on main and in this PR), with the switch off:

  • auto never picks nvfp4 for the dense transformer (ladder and family prefer rows), and no smoke probe is spent on it.
  • An explicit transformer_quant or text_encoder_quant of nvfp4 gets a 400 "NVFP4 is disabled in this build" from /images/load, /images/download-plan, /video/load and /video/download-plan, ahead of the precision fallback, so it is refused rather than swapped.
  • No hosted NVFP4 denoiser or encoder is resolved, seeded, planned or sized (family_prequant_repo, resolve_prequant_source, denoiser_prequant_sources, video_family_prequant_*), and the Hub helpers never ask about a *-NVFP4 repo. Dense shards are planned as on main.
  • /images/info estimates and the /api/system dense ladder omit nvfp4. /api/system reports nvfp4_diffusion, and the Precision and Text encoder selects hide NVFP4 when it is false.
  • The offline builder does not consult the switch. verify_prequant_backend.py and an explicit nvfp4 diffusion_bench.py run turn it on for themselves.

Existing NVFP4 test modules run with the switch on through a conftest fixture. test_nvfp4_diffusion_flag.py covers the default-off behaviour, and checks that the enabled path (auto, explicit, prequant lookup, the download plan) is still reachable end to end.

UI evidence

Images page, Advanced settings, with UNSLOTH_NVFP4_DIFFUSION unset (the default). BEFORE is main at 8d15d04, AFTER is this branch at a055823, each a separate install.sh --local Studio on a B200.

Precision select: BEFORE lists NVFP4 (Blackwell), AFTER omits it.

Precision select before and after

Text encoder precision select: BEFORE lists NVFP4 (Blackwell), AFTER omits it.

Text encoder precision select before and after

/api/system reports nvfp4_diffusion: false on AFTER; the field is absent on BEFORE.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T15:03:31.633665Z 04f70f4 Manual request
🔒 Security Review ✅ Completed 2026-09-10T14:38:46.198141Z ed34fe5 Manual request

Security findings

Finding details are still loading. Check the individual review comments.

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 10, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security 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: ed34fe5e68

ℹ️ 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 +1322 to +1326
if ckpt_component is None and logger is not None:
logger.debug(
"diffusion.prequant: checkpoint records no component; accepting it for %r",
component,
)

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 Reject unstamped checkpoints for non-default denoisers

When loading a non-default component such as transformer_2, accepting a checkpoint with no component stamp defeats the new expert-identity check: a legacy/default-expert artifact placed under the declared second-expert filename still matches the family, base, scheme, keys, and shapes, so it loads cleanly and produces silently incorrect denoising. The new explicit ckpt_component is None branch is fresh evidence that component-specific filename resolution alone does not close the earlier wrong-expert failure; require the stamp whenever the requested component is not transformer.

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 reachable: a task-specific filename has no fallback in resolve_prequant_source, the family declares a per-task row for transformer_2 only, and the builder stamps the component on every artifact it produces; both hosted transformer_2 files carry the stamp. An unstamped file under that name would have to be uploaded by hand. The tolerant branch covers legacy default-component artifacts, where it is correct.

Comment thread scripts/build_prequant_checkpoint.py Outdated
Comment on lines +422 to +424
try:
same = os.path.realpath(out_path) == os.path.realpath(verify_path)
except Exception: # noqa: BLE001 -- an unresolvable path is not provably the same file

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 Detect hard-linked verification targets

When --out and --verify-against are different hard links to the same inode, their realpath strings differ, so this guard accepts them; the subsequent torch.save through --out overwrites the shared inode, and verification compares the new artifact with itself before allowing upload. Use os.path.samefile or compare device/inode identities when both paths exist so the required independent-build gate cannot be bypassed by hard-linked paths.

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.

The check compares realpaths, which covers every way the tool itself can produce the same file. Two hard links to one inode have to be created by hand between builds; that is hardening rather than a defect on well-formed input.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

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

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 10, 2026

@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: 01368efe24

ℹ️ 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 +51 to +55
sources[component] = resolve_prequant_source(
fam,
wanted,
base_repo = base_repo,
task = task,

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 Require exact base identity before seeding forks

When an explicit NVFP4 load targets a hosted fork that preserves the upstream repository name, such as other-org/Wan2.2-TI2V-5B-Diffusers, this unconditionally resolves the family-default upstream artifact. _validate_checkpoint then accepts it because _same_base_model treats equal final path segments as equivalent, so the fork's modified denoiser is silently replaced with the upstream weights and produces results from the wrong model. Only offer the default hosted source for an exact/canonical base match, while retaining the tail-name exception for verified local mirrors.

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.

This PR follows the shipped convention: denoiser_prequant_sources calls resolve_prequant_source with the base exactly as the H3 video path and the image path do, and neither family_prequant_repo nor _same_base_model changes here. A fork that keeps the upstream tail name is offered the family artifact by the shipped fp8 and int8 paths today; prequant_excluded_bases is the existing escape hatch for a divergent fork.

Comment on lines +557 to +559
for key, tensor in items:
if key != "weight" and not str(key).endswith(".weight"):
continue

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 Fingerprint dense tensors as well

When a reproducibility fault or checkpoint mutation affects a bias, buffer, or one of the dense weights deliberately left unquantized, this loop either skips the key entirely or records only its name under skipped; neither --verify-against nor the load-time recomputation compares its bytes. A validly serialized artifact with a corrupted output bias or normalization weight can therefore pass the new publication gate and load without warning while changing every render. Include all serialized tensor payloads in a whole-state fingerprint, even if packed quantized tensors retain their specialized hashing.

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.

The fingerprint is defined over the packed quantised payloads, which is the corruption class it was added for; extending it to biases, buffers and deliberately dense weights is scope growth on the verify gate with no shipped path observed to corrupt a dense tensor.

Comment thread scripts/build_prequant_checkpoint.py Outdated
Comment on lines +757 to +762
print(
f" gptq idempotency: {gptq_idempotency['checked']} layers, max abs deviation "
f"{gptq_idempotency['max_abs']:.3e} ({gptq_idempotency['max_abs_fqn']}), "
f"{gptq_idempotency['frac_diff'] * 100:.3f}% of elements moved",
flush = True,
)

@danielhanchen danielhanchen Sep 10, 2026 •

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.

A nonzero deviation is the normal outcome here, not a fault: torchao's quantize_ re-rounds part of the stored weights on every hosted artifact, reproducibly, and the build's per-layer scores were measured through that same quantiser, so they describe the packed result. An abort on nonzero would refuse every shipped artifact. The report stays a report; the docstring premise is worth tightening separately.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
Comment thread scripts/build_prequant_checkpoint.py Outdated
Comment on lines +757 to +762
print(
f" gptq idempotency: {gptq_idempotency['checked']} layers, max abs deviation "
f"{gptq_idempotency['max_abs']:.3e} ({gptq_idempotency['max_abs_fqn']}), "
f"{gptq_idempotency['frac_diff'] * 100:.3f}% of elements moved",
flush = True,
)

@danielhanchen danielhanchen Sep 10, 2026 •

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.

A nonzero deviation is the normal outcome here, not a fault: torchao's quantize_ re-rounds part of the stored weights on every hosted artifact, reproducibly, and the build's per-layer scores were measured through that same quantiser, so they describe the packed result. An abort on nonzero would refuse every shipped artifact. The report stays a report; the docstring premise is worth tightening separately.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 10, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 15f15d5463

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 25, 2026
@danielhanchen danielhanchen self-assigned this Sep 25, 2026
@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: 7e9f88acba

ℹ️ 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 scripts/build_prequant_checkpoint.py Outdated
Comment on lines +351 to +352
# The subfolder built above: the loader refuses it as another denoiser (e.g. transformer_2).
"component": DEFAULT_PREQUANT_COMPONENT,

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 Support building non-default denoiser components

When producing the newly registered Wan A14B transformer_2 artifact, this script cannot create a loadable checkpoint: it always reads the transformer subfolder and stamps component='transformer', with no CLI option to select another component. Even if --upload-filename targets Wan2.2-T2V-A14B-transformer_2-NVFP4.pt, the loader requests component='transformer_2' and rejects the resulting artifact, so the shipped builder cannot reproduce the two-expert checkpoint set. Add a component/subfolder argument and use it for loading, metadata, and component-specific filename resolution.

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.

Fixed in 1819ead: the builder now takes --component (default transformer), uses it for the subfolder, the recorded component and the upload name (transformer_2 resolves to Wan2.2-T2V-A14B-transformer_2-NVFP4.pt, and refuses a component the family declares no row for), and falls back to the video registry so the Wan families resolve at all.

Add --component (default transformer) for the subfolder, metadata and upload name,
and resolve video families so the Wan and HunyuanVideo denoisers can be built.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 1819eadf1e

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

@shimmyshimmer

Copy link
Copy Markdown
Member

pre-commit.ci run

@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 04f70f464d

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 25, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 25, 2026
@danielhanchen
danielhanchen merged commit 8ecfd30 into main Sep 25, 2026
73 of 79 checks passed
@danielhanchen
danielhanchen deleted the studio-nvfp4-video branch September 25, 2026 23:22
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…tized denoisers (unslothai#10729)

* studio: whole-model NVFP4 for the video families with hosted pre-quantized denoisers

Wan2.2-TI2V-5B, Wan2.2-T2V-A14B (both experts), HunyuanVideo-1.5 480p and 720p run NVFP4 on the
torchao backend from hosted pre-quantized denoisers, so a load never quantises 5 to 28 GB of dense
weights on the fly. Every admitted linear (min 512 features, in and out divisible by 16) is NVFP4;
nothing is per-layer here.

- one shared auto walk with a per-family head in front of it, and divisible_for_scheme
- ZeroRowSafeLinear, a live bug: torchao's nvfp4 activation path raises on HunyuanVideo-1.5's
  empty image stream on every text-to-video render
- loader gates on the packed-weight fingerprint, the component and require_divisible
- conventional video pre-quant seeding, all components or none, with the memory plan taking the
  artifact's resident size rather than the dense build peak
- registry rows for the four hosted NVFP4 repos

nvfp4 stays an explicit opt-in here; no family gets an auto row on this branch.

The tooling that builds and fingerprints these artifacts is not in this repo. It lives in the
private scripts repo with the rest of the quant generation tooling.

* Tighten the comments and docstrings on the video prequant path

Collapse the long single-line comments this branch added to the repo's
wrap width, shorten the prose docstrings to the parts that say why, and
drop the test docstrings that only restate the test name. Comments,
docstrings and whitespace only: no code changes.

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

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

* Credit the resident video pipeline's memory in the seed plan

* Pin the residency check in the two-expert download plan test

* Credit only the target card's resident bytes and fingerprint built checkpoints

The residency plan counted every accelerator storage of the old pipeline as
reclaimable on the card the new load targets, so switching GPUs could skip the
dense denoiser shards on a card that never held them. Count only the target's.

The builder never wrote metadata["fingerprint"], so the loader's packed-weight
check had nothing to compare against for artifacts it produced.

* Fingerprint torchao 0.18 Int8Tensor prequant weights

torchao >= 0.18 int8 quantization produces Int8Tensor, which the packed
fingerprint payload map did not list, so every int8 weight was skipped
and the recorded fingerprint verified nothing. Hash its qdata, scale and
optional zero point / activation slots, with a stub test and a real
torchao round trip that catches a flipped byte.

* Apply the GEMM alignment floor in the offline prequant builder and record it

The runtime quantize_ skips Linears whose in/out features miss the scheme's
tiling floor, but build_prequant_checkpoint.py did not, so a ragged layer
could be baked as a quantized GEMM the runtime leaves dense. The builder now
passes divisible_for_scheme(scheme) to make_filter_fn and stamps
require_divisible so the loader can verify it.

* Trim comments

* Studio: NVFP4 kill switch for image and video, default off

The hosted unsloth/*-NVFP4 checkpoints are still private, so NVFP4 is
disabled in general until UNSLOTH_NVFP4_DIFFUSION is set to a truthy
value (1, true, yes, on). The default lives in one constant,
NVFP4_DIFFUSION_DEFAULT in core/inference/diffusion_nvfp4_flag.py, so
turning it on for everyone later is a one-line change. With the switch
on, behaviour is unchanged.

While it is off:
- auto never picks nvfp4 for the dense transformer (ladder and family
  prefer rows), and no smoke probe is spent on it;
- an explicit transformer_quant or text_encoder_quant of nvfp4 gets a
  400 "NVFP4 is disabled in this build" from every image and video
  load and download-plan route, ahead of the precision fallback;
- no hosted NVFP4 denoiser or encoder is resolved, seeded, planned or
  sized, and the Hub helpers never ask about a *-NVFP4 repo;
- /images/info estimates and the /api/system dense ladder omit nvfp4,
  and /api/system reports nvfp4_diffusion so the Precision and Text
  encoder selects hide NVFP4.

The offline builder does not consult the switch. Existing NVFP4 test
modules run with it on through a conftest fixture; the default-off
behaviour, and that the enabled path is still reachable end to end,
are covered in test_nvfp4_diffusion_flag.py.

* Studio: keep the diffusion bench NVFP4-capable under the kill switch

An explicit --transformer-quant or --text-encoder-quant nvfp4 turns the
switch on for the bench itself, like the other developer tools. The
switch tests ask auto the way a load does, with a hosted checkpoint
where the selector requires one, so the enabled-path check stays
meaningful on the branches that add that requirement.

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

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

* Studio: reset a hidden NVFP4 pick to Auto when the backend switch is off

A Precision or Text encoder select reseeded to nvfp4 by an earlier load kept
that value after a restart turned UNSLOTH_NVFP4_DIFFUSION off: the option was
filtered out, so the select rendered blank and the next load or Reapply sent
nvfp4 and got a 400. Once /api/system reports the switch off, a held nvfp4
now falls back to auto on the image and video pages. Nothing is reset before
system info arrives, since the switch reads off by default until then.

* Studio: keep the hosted video denoiser seed for an explicit scheme under Speed off

Only an auto precision is rewritten to off under Speed off; an explicit
scheme is still quantized (and upgrades the speed), so suppressing the seed
staged the dense denoiser for a runtime quantize. Matches diffusion.py.

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

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

* Studio: update the Speed off video plan test for the kept explicit seed

* Studio: refuse an NVFP4 checkpoint loaded directly as the model while NVFP4 is off

With UNSLOTH_NVFP4_DIFFUSION off, a hosted NVFP4 repo (or any repo or local
path whose pre-quant metadata records scheme nvfp4) picked as the model
itself named no precision, so none of the scheme gates saw it. The image and
video load and download-plan routes now 400 such a pick with the same
disabled message style. Detection reads the recorded scheme of a local file,
a local directory or a cached Hub snapshot, then the family NVFP4 repo tables,
then the -NVFP4 name. Switched on, the pick proceeds as before.

* Studio: format the NVFP4 checkpoint refusal tests

* Studio: skip pipeline roots and the thread hop in the NVFP4 checkpoint refusal

A diffusers pipeline loads from its component folders, so a stray root
artifact no longer makes its directory read as an NVFP4 checkpoint. With the
switch on the route helper returns before handing anything to a thread.

* Studio: stamp the built denoiser component and drop an unused metadata reader

* Studio: keep the NVFP4 flag and speed-off video plan tests off the runner's own GPU

* Studio: trim comments in the NVFP4 video layer

* Studio: check the hosted video seed rows before spending a quant smoke probe

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

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

* Studio: let the prequant builder target the second Wan A14B expert

Add --component (default transformer) for the subfolder, metadata and upload name,
and resolve video families so the Wan and HunyuanVideo denoisers can be built.

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

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

* [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>
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants