Repository navigation
Studio: install flashinfer on demand for NVFP4 without moving torch - #11730
Merged
Merged
Conversation
…tized 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.
…gated auto row Whole-model NVFP4 does not pay on the image DiTs. A per-layer policy that puts NVFP4 on the few linears whose activations tolerate it and keeps fp8 everywhere else does: a memory lever at fp8-parity quality, not a speed win. - diffusion_nvfp4_policy.py: exact dotted-suffix rules with expected counts, so a diffusers rename breaks the resolution instead of shipping a different model - the _v3 policy checkpoint format, biconditional with a declared policy, and baked activation global scales in place of the running-min calibration that was behind the flux black-frame latch - diffusion_nvfp4_ops.py / diffusion_nvfp4_linear.py: a flashinfer mm_fp4 backend that re-expresses the torchao payload rather than requantising it, with two custom ops so the layer compiles fullgraph with no graph breaks - diffusion_nvfp4_protect.py: per-step W4A16 on the same bytes, opt-in, default off - the reviewed gate record, the only thing that can put nvfp4 into the auto ladder, and the conditional Wan2.2-T2V-A14B row that needs flashinfer to be the selected backend - diffusion_speed.py: stream-merging DiTs compile regionally with dynamic=False, which is what FLUX.1's CantSplit inductor failure needed The tooling that builds, calibrates and gates these artifacts is not in this repo. It lives in the private scripts repo with the rest of the quant generation tooling.
…nt barrier, bias path, cached dispatch) Four items on the flashinfer NVFP4 path, all found while measuring it: - every flashinfer call sits inside a device guard, enforced by a source test, because a missing guard has taken cards down on a multi-GPU host - the one-element barrier between quantiser and GEMM becomes persistent rather than allocated per call, which is what makes it capture-safe - diffusion_nvfp4_bias.py: a Triton bias add with a measured numel floor and ceiling, so the kernel only runs where it beat the eager path - the backend dispatch is resolved once per load and cached, instead of re-probing per layer Carries the same strip as the branches below it: the quant generation tooling lives in the private scripts repo, not here.
# Conflicts: # studio/backend/tests/test_diffusion_backend.py
# Conflicts: # studio/backend/core/inference/diffusion.py
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.
# Conflicts: # studio/backend/core/inference/diffusion_prequant.py # studio/backend/core/inference/diffusion_quant_pad.py # studio/backend/core/inference/diffusion_transformer_quant.py # studio/backend/core/inference/video.py # studio/backend/core/inference/video_denoiser_prequant.py # studio/backend/core/inference/video_families.py # studio/backend/tests/test_diffusion_prequant.py # studio/backend/tests/test_video_backend.py # studio/backend/tests/test_video_prequant.py
# Conflicts: # studio/backend/core/inference/diffusion_nvfp4_linear.py # studio/backend/core/inference/diffusion_nvfp4_ops.py
# Conflicts: # studio/backend/core/inference/diffusion_prequant.py # studio/backend/core/inference/diffusion_transformer_quant.py # studio/backend/core/inference/video.py # studio/backend/tests/test_diffusion_prequant.py # studio/backend/tests/test_video_backend.py
Adopt main's int8-first auto ladder: the gated image rows now read int8, fp8, nvfp4, mxfp8 and the a14b row nvfp4, int8, fp8, mxfp8. Tests follow the new order.
Z-Image now hosts an NVFP4 checkpoint, so the no-hosted-artifact case uses mxfp8.
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 25, 2026
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/backend/core/inference/diffusion.py
shaojun
pushed a commit
to shaojun/unsloth
that referenced
this pull request
Sep 29, 2026
…e check (unslothai#11763) * Pin the legacy store outcome in the failed-delete data settings check The failed-delete check asserted that the Clear chats confirmation closes when the backend refuses the clear. The app closes it only when the legacy IndexedDB clear succeeds: with both stores failed, clearStoredChats throws and the confirmation stays open, armed for a retry, by design since unslothai#7029. Which of the two happens is decided by the legacy store gate (unslothai#9446). Any legacy read slower than 1 s shuts it for the life of the page, after which a clear reports the legacy store as failed. Firefox on the Windows runner occasionally crosses that line, and the check then fails at line 216 with the confirmation still on screen. Seen on main at 288b1a3 and on unslothai#11730 and a87d180, with Chromium passing in the same job. The fixture now refuses legacy writes on request, so the check drives the outcome it asserts instead of inheriting whatever the gate did earlier: the clear settles, the confirmation is still open with its action and switch re-enabled, no chat is lost, and Cancel closes it with no further delete. It is pinned to the confirmation by its switch, not `.last`, which slides onto Settings once the confirmation goes. * Record the dialogs still mounted when the data settings check fails A Firefox run on the Windows runner failed in reset() with one hidden dialog left 5 s after closing Settings, and the only evidence was a blank screenshot. The report now lists every [role=dialog] still in the DOM with its data-state, display, opacity and running animations, so the next occurrence says whether an exit animation held the dialog or something else kept it mounted.
shaojun
pushed a commit
to shaojun/unsloth
that referenced
this pull request
Sep 29, 2026
…nslothai#11730) * 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. * studio: per-layer NVFP4 image policies, flashinfer FP4 backend and a gated auto row Whole-model NVFP4 does not pay on the image DiTs. A per-layer policy that puts NVFP4 on the few linears whose activations tolerate it and keeps fp8 everywhere else does: a memory lever at fp8-parity quality, not a speed win. - diffusion_nvfp4_policy.py: exact dotted-suffix rules with expected counts, so a diffusers rename breaks the resolution instead of shipping a different model - the _v3 policy checkpoint format, biconditional with a declared policy, and baked activation global scales in place of the running-min calibration that was behind the flux black-frame latch - diffusion_nvfp4_ops.py / diffusion_nvfp4_linear.py: a flashinfer mm_fp4 backend that re-expresses the torchao payload rather than requantising it, with two custom ops so the layer compiles fullgraph with no graph breaks - diffusion_nvfp4_protect.py: per-step W4A16 on the same bytes, opt-in, default off - the reviewed gate record, the only thing that can put nvfp4 into the auto ladder, and the conditional Wan2.2-T2V-A14B row that needs flashinfer to be the selected backend - diffusion_speed.py: stream-merging DiTs compile regionally with dynamic=False, which is what FLUX.1's CantSplit inductor failure needed The tooling that builds, calibrates and gates these artifacts is not in this repo. It lives in the private scripts repo with the rest of the quant generation tooling. * studio: NVFP4 flashinfer backend kernel items (device guard, persistent barrier, bias path, cached dispatch) Four items on the flashinfer NVFP4 path, all found while measuring it: - every flashinfer call sits inside a device guard, enforced by a source test, because a missing guard has taken cards down on a multi-GPU host - the one-element barrier between quantiser and GEMM becomes persistent rather than allocated per call, which is what makes it capture-safe - diffusion_nvfp4_bias.py: a Triton bias add with a measured numel floor and ceiling, so the kernel only runs where it beat the eager path - the backend dispatch is resolved once per load and cached, instead of re-probing per layer Carries the same strip as the branches below it: the quant generation tooling lives in the private scripts repo, not here. * Studio: trim NVFP4 kernel comments * 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 * Tighten the NVFP4 image comments and docstrings * Studio: trim NVFP4 kernel docstrings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix pipeline prequant tests for the selector's base_repo keyword Z-Image now hosts an NVFP4 checkpoint, so the no-hosted-artifact case uses mxfp8. * Keep a resident video model's NVFP4 state when a replacement fails early * Prewarm NVFP4 checkpoints in the shared prequant loader * 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. * Studio: install flashinfer on demand for NVFP4 loads An explicit NVFP4 image or video load (or an nvfp4 prequant seed) now installs FlashInfer when it is missing, instead of silently falling back to torchao. - Pins flashinfer-python 0.6.6, the version the dispatch allowlist and the op fakes were checked against, plus the flashinfer-jit-cache built for the running CUDA (cu128 / cu129 / cu130, newest same-major build not newer than the runtime). Without a jit-cache the host must have nvcc, else it refuses. - Every installed distribution is pinned to its exact version through a constraints file, so the resolver can only add packages. Afterwards the metadata set, torch.__version__ / torch.version.cuda (fresh interpreter) and `import flashinfer` are verified; any drift or failure uninstalls what was added and restores anything moved. - Linux + CUDA torch + a device in the flashinfer NVFP4 set only. Refuses with a reason on ROCm, macOS, Windows, CPU, other archs, offline mode, an unreachable index, UNSLOTH_NVFP4_FLASHINFER_INSTALL=0, a broken existing flashinfer, or a stray jit-cache/cubin of another version. - Once per process under a lock; policy refusals are not memoised. - Runs outside the load locks, next to the attention-kernel pre-install. - Image and video status gain transformer_quant_backend_reason, set when an NVFP4 load runs torchao. * Studio: no flashinfer install on local-only loads; keep the NVFP4 fallback reason per backend A local_files_only load downloads nothing, so the installer now refuses there instead of probing indexes and fetching wheels. The torchao fallback reason is kept per loading backend object, so the image and video status routes report the reason for their own loaded model rather than the last call anywhere. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: bind the NVFP4 fallback reason to the loaded device, and record it only after the swap * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: install flashinfer only for model kinds the NVFP4 dense path can reach * Studio: name the real reason an explicit transformer quant is declined, not the GPU * [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 * Studio: NVFP4 policy lookup on the pipeline fallback, a protect controller per model * Studio: honour UV_OFFLINE before the flashinfer install probes an index * Studio: serialise the flashinfer install across processes sharing one environment * Studio: hand a pip-only index mirror to uv for the flashinfer install * 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. * Plan pipeline denoiser seeds with the base and prequant probe _pipeline_planned_denoiser_scheme asked select_transformer_quant_scheme and auto_scheme_candidates without base_repo or has_prequant, so AUTO dropped every prequant-only rung (the gated nvfp4 head) and the plan could seed a different scheme than the load resolves. Route the winner through _planned_quant_scheme and hand the rung walk the same probe. * Studio: one index per uv flashinfer step, and report a transient preflight fallback The jit-cache step now passes its index through _installer_prefix, which drops a pip-only mirror instead of adding a second --index-url that uv rejects. A transient (allocation) preflight failure is still not memoised for backend selection, but is kept per device so the status route can say why the resident model fell back to torchao. A later memoised preflight on that device replaces it. * Studio: hand a uv-only index to the pip fallback of the flashinfer install Without uv, pip ignores UV_DEFAULT_INDEX / UV_INDEX_URL, yet the preflight skipped the pypi.org probe because a mirror was configured. Pass the uv index as --index-url to pip when PIP_INDEX_URL is unset. * 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. * Autotune each NVFP4 GEMM shape on its first eager call The loaders prewarm only M = 1, and a graph's warm-up only the token counts its top-level inputs imply, so a video's real token count and a graphed Z-Image's patchified plus caption sequence reached mm_fp4 outside flashinfer.autotune and ran the fallback tactic for the whole load. The first eager GEMM of every unseen (M, K, N) now tunes under autotune(True), sharing the prewarm's process-wide set and never inside a capture. * Studio: wait for an in-flight flashinfer install and isolate the jit-cache index flashinfer fixes its jit-cache directory once, at import. A second Studio process that imported it between another process's flashinfer-python and jit-cache steps kept JIT-compiling for its whole life. When the pinned flashinfer-python is on disk without its jit-cache and flashinfer is not yet imported, wait on the shared install lock before importing; nothing is installed or modified, and every other state returns without touching the lock. The jit-cache step now runs without UV_INDEX, UV_EXTRA_INDEX_URL, UV_FIND_LINKS and the pip equivalents in its environment. Those outrank uv's --index-url, so under uv's first-index strategy a mirror listing any flashinfer-jit-cache hid the pinned flashinfer index and the install rolled back. * Studio: do not import flashinfer after a timed-out install wait, and honor uv index sources in the preflight A wait for another process's in-flight install that times out now reports flashinfer not ready for this load (not memoised) instead of importing without the jit-cache. With uv as the installer, UV_INDEX and UV_EXTRA_INDEX_URL count as a configured mirror, so the public PyPI probe is skipped; the pip fallback still probes it. * Studio: honor pip and uv configuration files in the flashinfer install, and pin the jit-cache CUDA build - Pin flashinfer-jit-cache to its full local version (0.6.6+cu130) and refuse a present cache built for another CUDA: flashinfer only checks the public version, and ==0.6.6 is satisfied by any local tag, so a leftover cu128 cache was kept on a cu130 host. - Read the installer's effective settings before probing or installing: pip via `pip config list` (environment over [install] over [global], PIP_CONFIG_FILE and every pip.conf), uv via UV_CONFIG_FILE, UV_NO_CONFIG and the project, user and system uv.toml. A configured mirror skips the pypi.org probe; no-index, offline, no-deps, target, prefix, root and require-virtualenv outside a venv refuse before anything is touched, not memoised. - The uv jit-cache step also passes the pinned index as --index, which outranks a uv.toml [[index]] or extra-index-url that would otherwise hide it under first-index. - Skip the reachability probes when the installer goes through a proxy urllib does not use (ALL_PROXY only, pip's proxy setting), and count a failed TLS handshake as a route. * Trim comments * Trim comments * Trim comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: wait for the install lock when both flashinfer distributions are present An install that has written flashinfer-python and its jit-cache still holds the environment lock for its drift checks and import verify, and may roll both back. A second process that skipped the lock on seeing both distributions could import flashinfer right before the rollback uninstalls it. * Studio: count pip extra indexes and find-links as a mirror in the flashinfer preflight pip falls through an unreachable pypi.org to an extra index or find-links source, so with only PIP_EXTRA_INDEX_URL, PIP_FIND_LINKS or their pip.conf keys set, probing pypi.org refused an install pip would have completed. * Bind the video NVFP4 install reason only when the load commits A superseded video NVFP4 load blocked in the FlashInfer install could return after a newer load committed and overwrite its per-device reason. Call ensure without an owner and record the outcome under the lock at the _VideoLoadState commit, past the token check, mirroring the image loader. * Studio: install FlashInfer only when a hosted NVFP4 checkpoint will load FlashInfer only serves a pre-quantised NVFP4 checkpoint; an on-the-fly NVFP4 build always runs on torchao. The image and video pre-install hops fired on any explicit NVFP4 load, so a private, gated or unpublished checkpoint repo (or a base with none hosted) still bought the 1.2-1.8 GB wheel the load could not use. Both hops now install only when the plan already settled NVFP4 or the checkpoint is reachable: a local override or a cached file counts, otherwise the Hub listing is asked, and offline loads ask the cache only. The video gate also covers the MiniMax-H3 modular dispatch and skips a conventional load whose plan declined the seed; the image gate skips a LoRA bake, which never takes the prequant. * Treat a hosted prequant this user cannot fetch as no prequant The hosted NVFP4 checkpoints can be private or gated. For a user without access the Hub answers 401 / 403 / 404 on the repo itself: - _prequant_source_hub_entry raised RepositoryNotFoundError, which the planner recorded as a failure, so an explicit NVFP4 download plan came back plan_failed and download-only refused to run. A refused repo now reads as no hosted checkpoint and the dense shards stay in the plan. Transient errors still propagate. - The dense-quant prefetch decision trusted the family table's prequant candidate, so an unreachable checkpoint still kept the base transformer shards out of the staged download and the load pulled them inline after the phase switched to finalizing, outside progress, cancel and the disk check. The prequant now only suppresses the shards when it is cached, local, or the Hub lists it for this user; an unanswerable probe keeps the previous verdict. download_plan passes the user's token to that probe. * studio: count UV_FIND_LINKS as a mirror, refuse reinstall settings, rebind install reason on skip - UV_FIND_LINKS is uv's env form of --find-links, so a wheelhouse-only host with pypi.org blocked now reaches uv instead of being refused by the pypi.org probe, as uv.toml find-links and PIP_FIND_LINKS already were. - uv reinstall / reinstall-package and pip force-reinstall / ignore-installed (config or env) can replace an installed dependency at the same version, which the version-only drift check cannot see or roll back. They are refused before anything moves, not memoised, like the other settings the install cannot honor. - Every image and video load commit now binds the install reason, the skipped-gate case included, so an on-the-fly NVFP4 load no longer reports the previous model's install or offline reason. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Size an unreachable hosted prequant as the dense build at load time The download plan already treats a hosted NVFP4 checkpoint this user cannot fetch (401 / 403 / 404) as no prequant and stages the dense transformer shards. The load did not get that answer: resolve_dense_quant_candidate reads the family table alone, so the candidate stayed prequant. The offload replan then budgeted the small checkpoint (22,930 MiB for a GGUF + NVFP4 pick where main budgets the 28,561 MiB dense build) and forbade the dense fallback the plan had staged the shards for, and the resident path skipped the dense decline in favour of a download that answers 401. The prefetch decision now records the refused scheme in the load kwargs, and load_pipeline sizes and fit-checks that scheme as the dense bf16 build, exactly as when the family names no checkpoint. A reachable or cached checkpoint keeps the prequant budget. * 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. * Studio: test the NVFP4 kill switch on the image surfaces With UNSLOTH_NVFP4_DIFFUSION unset, the gated and flashinfer-keyed auto rows are dropped before any gate record or backend probe runs, flashinfer is never imported or preflighted for NVFP4, the hosted FLUX.1-schnell and Z-Image-Turbo NVFP4 rows resolve to nothing and the per-layer policy factor is not applied. With it set, the flashinfer row leads auto again and both hosted repos resolve. * Studio: test that the NVFP4 kill switch keeps the flashinfer dispatch cold The fast dispatch is only reached through nvfp4_preflight and the NVFP4 layers, both behind the switch; with it unset, neither the dispatch probe nor its verify pass runs. * Studio: no flashinfer install under the NVFP4 kill switch With UNSLOTH_NVFP4_DIFFUSION unset, ensure_flashinfer_for_nvfp4 returns before importing flashinfer, taking the install lock or running any subprocess, and records no reason. Both loaders skip the install gate (the switch is its second conjunct), so neither asks the Hub whether an NVFP4 checkpoint will load, and the status route reports no install reason. With the switch on, the install runs exactly as before. * Studio: name how to enable NVFP4 in the disabled backend reason * [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 * [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 * 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 pip.conf extra sources out of the pinned jit-cache install The pip fallback's jit-cache step dropped index environment variables but still read pip.conf, whose extra-index-url and find-links pip searches beside --index-url, so a corporate or stale flashinfer-jit-cache wheel could be picked over the probed FlashInfer index. That step now runs with PIP_CONFIG_FILE=os.devnull, which skips every pip configuration file, and carries pip.conf's proxy, cert, client-cert, trusted-host, timeout and retries over as environment variables. The main install and the uv path are unchanged. * Studio: do not wait on another FlashInfer install for a load that declined one A local_files_only load, or one with UNSLOTH_NVFP4_FLASHINFER_INSTALL=0, waited up to 900 s on the environment lock while another process downloaded the jit-cache, before its own no-install checks ran. Those loads now try the lock once: if the other install is still running they stay off flashinfer without importing it mid-transaction, and if it has finished they import it as before. * Studio: install FlashInfer only for an NVFP4 seed the live-memory plan keeps The prefetch settles the NVFP4 denoiser seed against total device capacity, and the loader re-plans it against live free memory, dropping the seed when that plan would offload. The install ran before that re-plan, so a card with enough capacity but little free memory downloaded about 1.5 GB of FlashInfer and then loaded the released bf16 denoiser. Video installs after its teardown and outside every lock, so a conventional load now installs right after the plan settles and only for a kept NVFP4 seed; the MiniMax-H3 dispatch is unchanged. The image install must precede its teardown, so it asks the same seeded plan beforehand, with this process's own device allocation (freed by the teardown) credited as free. The seeded plan is one helper shared by the gate and the locked re-plan. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * 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. * Studio: treat an uncached hosted prequant as unreachable in local-only mode The loader may not fetch it under local_files_only, so the Hub listing must not keep the load sizing a packed artifact that never arrives. * Roll back only the packages the FlashInfer install itself added Parse what uv / pip reported installing and uninstall only those new distributions, so packages another installer added concurrently stay. When the installer reported nothing, fall back to the flashinfer dependency tree instead of the whole before/after diff. * [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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * 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: cover the image family NVFP4 repos in the checkpoint refusal table * 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: re-pick the NVFP4 image policies at the storage/quality frontier Replace the shipped per-layer policies with points from the storage/quality frontier whose paired LPIPS(vgg) gap to the same model's fp8 build stays under 0.05 at the upper 95% bootstrap bound, measured on 48 held-out pairs (24 frozen prompts x seeds 1234 and 4321, 1024 px, flashinfer backend): - z-image: zimg_rg76_v1 (76 nvfp4 / 195 fp8 / 5 bf16), 5.204 GiB, +0.022 [0.002, 0.040] - flux.1 schnell: flux_r420_v1 (187 / 312 / 3), 9.040 GiB, +0.024 [0.016, 0.031] - qwen-image-2.1: qwen21_r020_v1 (48 / 181 / 3), 6.044 GiB, +0.028 [0.012, 0.046] - qwen-image 2512: qwen2512_m120_attn8_v1 (600 / 243 / 3), 14.427 GiB, +0.028 [0.008, 0.050] flux_r600_v1 and qwen21_r040_v1 were built first and missed the bound (+0.044 [0.034, 0.053] and +0.039 [0.022, 0.057]), so each model steps back one frontier point. zimg_f8mod_toq34_v1 and flux_mod_single_v1 are removed, so an artifact built at either is refused on load rather than half-matched. Qwen-Image-2.1 gets a hosted nvfp4 row and a gated auto head like the other image families; Qwen-Image-2512 gets its own nvfp4 variant row while Qwen/Qwen-Image keeps its deny. The gate record now holds the three published GPTQ artifacts (z-image, flux.1 schnell, qwen-image-2.1), each with its 24/28 pair accuracy gate and the paired fp8 result. Steady factors come from measured resident bytes. Everything here stays behind UNSLOTH_NVFP4_DIFFUSION, default off. * [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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: record the Qwen-Image-2512 NVFP4 gate verdict The qwen2512_m120_attn8_v1 GPTQ artifact is now hosted privately at unsloth/Qwen-Image-2512-NVFP4 (sha256 665e8f9a12d3...). It passed the 28 pair accuracy gate on flashinfer with graphs on, and its paired LPIPS(vgg) gap to the 2512 fp8 build is +0.028 [0.008, 0.050] over 48 held-out pairs. The record lifts the qwen-image nvfp4 deny for the 2512 base only; Qwen/Qwen-Image keeps it, which a new test pins. Still behind UNSLOTH_NVFP4_DIFFUSION, default off. * 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: pass the base repo to the NVFP4 runtime-quant scheme selector * Studio: keep the flashinfer auto-row test off the runner's own card * Studio: finish an interrupted flashinfer install, scope its rollback and redact the backend reason * Studio: tune the collected-layer dispatch test's shape so it reaches the cached path * Studio: judge an explicit precision on the load's base at the route gate * Studio: redact credentials from quoted flashinfer installer output * Studio: name the GPU, not the family deny, when a gated base's NVFP4 is declined The route precision gate already selects on the pipeline base, so a per-base gate record (Qwen-Image-2512) lifts the family deny there. The refusal text was built without that base and reported a missing accuracy record instead of the GPU that declined. Pass the same base. * Studio: keep a concurrent upgrade when an unreported flashinfer step is rolled back A step that dies without its summary gave the rollback no report to filter by, so it restored every drifted package, including one the built-in terminal upgraded meanwhile. The constraints pin every installed package, so this transaction cannot have moved those: restore only what the constraints could not pin. * [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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: judge a GGUF pick's explicit NVFP4 on its gated base before the card tag resolves A GGUF load that names no base_repo takes it from the repo card at load time, but the network-free route gate saw no base and refused NVFP4 under the Qwen-Image family deny that the Qwen-Image-2512 gate record lifts. When the family denies NVFP4 and the base is not known yet, judge the scheme on the base a passing record covers; the loader still refuses any other base once the card resolves. * Studio: keep the superseded-policy gate test off one rewritten file The gate loader caches on (path, mtime_ns, size). The test rewrote one path three times and its first and third documents are the same size, so on Windows' coarse write clock the third read served the first document and the test failed there. Write the two flux documents to separate files. * Studio: compile a quantised stream-merging DiT static on the max tier too On max, automatic dynamic generalises the sequence length at the first new resolution, and a torchao fp8 FLUX single block then raises inductor CantSplit (reproduced on a real-dimension block: 4096 -> 1024 image tokens), dropping the DiT to eager for the session. Compile that case static, as the default tier already does; bf16 keeps automatic dynamic, which handled the same shapes. * Studio: keep the flashinfer install module on the 3.10 floor and order the rollback test by count tomllib is 3.11 but already falls back to tomli or None; mark the import novermin so the floor lint sees the guard. The rollback wait test compared two clock stamps under -n 4; it now records how many imports ran before the rollback, which is the ordering it asserts. * Studio: trim comments in the NVFP4 video layer * Studio: trim comments in the NVFP4 kernels layer * Studio: trim comments in the NVFP4 image layer * Studio: trim comments in the flashinfer autoinstall layer * Studio: no flashinfer install for an image load whose plan declined the NVFP4 seed A declined seed loads the released denoiser, so no pre-quantised checkpoint opens and FlashInfer serves nothing. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * 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 * [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 * [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 * [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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Let the GGUF quant planner test stub accept base_repo --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #10731 (base
studio-nvfp4-kernels).Why
The NVFP4 FlashInfer backend from #10730 / #10731 only engages when
flashinferis already installed. Studio does not ship it, so a user who picks NVFP4 lands on the slower torchao path without knowing why. This installs it on demand, the first time an NVFP4 load needs it. It never moves torch, triton, CUDA or any other installed package.What it does
core/inference/diffusion_nvfp4_install.pyaddsensure_flashinfer_for_nvfp4(device, ...) -> (ok, reason), which never raises. The image loader (diffusion.py) and the video loader (video.py) call it for an explicitnvfp4request or an NVFP4 prequant seed, before the load locks, and only when a hosted NVFP4 checkpoint will actually load. FlashInfer only serves a pre-quantised checkpoint; an on-the-fly NVFP4 build always runs on torchao, so installing for it would buy 1.2-1.8 GB the load cannot use. The install goes ahead when the download plan already settled NVFP4, when a local override or cached checkpoint exists, or when the Hub listing shows the checkpoint. A private, gated or unpublished repo, a base with no hosted checkpoint, a LoRA bake or a declined video seed installs nothing. Offline loads check only the cache. The video gate also covers the MiniMax-H3 modular path.flashinfer-python==0.6.6, the version the fast-dispatch allowlist and op fakes were checked against.flashinfer-jit-cache==0.6.6+cuXYZ(the full local version, as flashinfer's own installer pins it) fromflashinfer.ai/whl/cuXYZwith--no-deps. This step dropsUV_INDEX,UV_EXTRA_INDEX_URL,UV_FIND_LINKSand the pip index variables from its environment, and under uv also passes the pinned index as--index, so neither an environment nor a uv.toml mirror can outrank it; the flashinfer-python step still uses the user's mirrors. It picks the newest cu128 / cu129 / cu130 build with the running torch's CUDA major and a minor no newer than it. With no matching build it installs flashinfer-python alone only ifnvccexists, and otherwise refuses, since every kernel would otherwise compile on first use.--only-binary :all:(uv, with pip as the fallback). The resolver can only add packages.torch.__version__/torch.version.cudaand import flashinfer 0.6.6. Anything else rolls back everything the install added.UNSLOTH_NVFP4_FLASHINFER_INSTALL=0UNSLOTH_NVFP4_BACKEND=torchaosys.prefix. A process that finds the pinned flashinfer-python on disk without its jit-cache, before importing flashinfer, waits on that file lock so it does not import halfway through another process's install; it never modifies that install. If that install outlasts the wait, the load reports flashinfer not ready rather than importing it without the jit-cache. Refusals are not remembered, so a later load can still install once the condition clears.transformer_quant_backend_reason. A failed flashinfer preflight on the loaded device is reported there too, including a transient out-of-memory one, which is still not cached for backend selection.diffusion_nvfp4_dispatch.forget_availability()drops the cached "flashinfer missing" answer once an install succeeds.Installer environment handling
The installer that will run (uv, else pip) is asked what it is configured to do before anything is probed or installed.
UV_INDEX_URL,UV_DEFAULT_INDEX,UV_INDEX,UV_EXTRA_INDEX_URL,PIP_INDEX_URL) and from configuration files: pip's effective settings viapip config list(environment over[install]over[global], every pip.conf andPIP_CONFIG_FILE), uv's viaUV_CONFIG_FILE,UV_NO_CONFIGand the project, user and systemuv.toml. A configured mirror skips the pypi.org probe; a mirror only one installer reads is handed to the other unless that one has its own.UV_OFFLINEor uvoffline, pip or uvno-index(so find-links-only setups), pip or uvno-deps, piptarget/prefix/rootand uv[pip] target/prefix(they install outside this interpreter's environment), and piprequire-virtualenvoutside a venv.HTTPS_PROXY/NO_PROXYare used by the probe itself. With onlyALL_PROXY, or pip's ownproxysetting, the probes are skipped and the installer decides. A failed TLS handshake counts as reachable, so pip'scertor uv's native TLS decide trust, not the probe.UV_PYTHON,UV_PROJECT_ENVIRONMENTandVIRTUAL_ENVlose to the explicit--python.PIP_CONSTRAINT/UV_CONSTRAINTthat conflicts with the pins fails the resolve before anything moves, and the reason is reported.UV_OVERRIDEthat moves a pinned package is caught by the drift check and rolled back, at the cost of the download.PIP_USERis left to pip: it refuses inside a venv, and outside one the user site is importable.UV_EXCLUDE_NEWER,UV_INDEX_STRATEGY, prerelease settings) either resolve 0.6.6 or fail cleanly before installing.Evidence
A real install ran on a scratch venv with torch 2.12.1+cu130 and triton 3.7.1, stubbing only the device-capability check:
uv pip freezediff.torchread2.12.1+cu130 13.0before and after, andimport flashinferreported 0.6.6. A second call found flashinfer already installed and ran nothing.packaging==23.2installed (flashinfer needs 24.2 or newer), the installer refused instead of upgrading it, and nothing changed.Tests
test_diffusion_nvfp4_install.pyhas 95 hermetic tests, which cover:test_diffusion_backend.py/test_video_backend.pydrive image, GGUF, Wan-A14B, Wan-5B and MiniMax-H3 NVFP4 loads up to the install hop. When the checkpoint repo returns 401 /RepositoryNotFoundError/GatedRepoError, lacks the file or is not hosted, nothing is installed; those tests fail on the previous head. When the checkpoint is reachable, the install still runs. Offline loads check only the cache.tests/test_diffusion*.py tests/test_video*.py tests/test_nvfp4*.py(CPU): 4437 passed. The failure list matches the base branch exactly: 15 environment-only failures intest_diffusion_dataset_api.py.Not covered
mm_fp4/nvfp4_quantizeon sm_100 / sm_120 withoutnvcc, or that flashinfer-cubin is not needed for the cutlass path.NVFP4 kill switch
NVFP4 for image and video generation is off by default until the hosted
unsloth/*-NVFP4repos are public.UNSLOTH_NVFP4_DIFFUSION=1(alsotrue,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_DEFAULTinstudio/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 throughnvfp4_diffusion_enabled().Added on this branch, with the switch off:
ensure_flashinfer_for_nvfp4returns before importing flashinfer, taking the install lock or running any subprocess, and records no install reason.With the switch on, the install runs exactly as before.