Commit graph

2,479 commits

Author SHA1 Message Date
Daniel Han
2e855a018d Merge remote-tracking branch 'origin/diffusion-auto-badges' into fold-integration
# Conflicts:
#	studio/backend/models/inference.py
#	studio/frontend/src/features/images/images-page.tsx
2026-07-07 01:08:43 +00:00
Daniel Han
d1fbe62aeb Merge remote-tracking branch 'origin/diffusion-auto-install' into fold-integration 2026-07-07 01:06:57 +00:00
Daniel Han
1081808ae7 Merge remote-tracking branch 'origin/diffusion-fp16-accum' into fold-integration 2026-07-07 01:06:57 +00:00
Daniel Han
826a31d7b6 Merge remote-tracking branch 'origin/diffusion-auto-policy' into fold-integration 2026-07-07 01:06:57 +00:00
Daniel Han
e1dd2dda6b Merge remote-tracking branch 'origin/diffusion-train-perf2' into fold-integration
# Conflicts:
#	studio/backend/core/training/diffusion_dit_trainer.py
#	studio/backend/core/training/diffusion_train_common.py
2026-07-07 01:06:42 +00:00
Daniel Han
2dbfd3c4a9 Merge remote-tracking branch 'origin/diffusion-krea2' into fold-integration
# Conflicts:
#	studio/backend/core/training/diffusion_train_common.py
2026-07-07 01:03:21 +00:00
Daniel Han
b52e7a5cc2 Merge remote-tracking branch 'origin/diffusion-train-tab-2' into fold-integration 2026-07-07 01:01:00 +00:00
pre-commit-ci[bot]
a8494e25f3 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 15:24:16 +00:00
Daniel Han
0f2f4334e2 Reject dense DiT precisions on a CUDA-absent host before eviction; stabilize family-info tests
The start-route preflight caught the bf16-GPU and int8-torchao requirements but not the dense
precisions' CUDA requirement: on a GPU-less host bf16_unsupported_reason exempts CPU-only, so a
bf16/fp8 (or int8-with-torchao) DiT request passed the preflight, evicted resident workloads, then
raised only in the trainer child. Add the dense-mode CUDA gate mirroring _resolve_base_precision so
the doomed run is rejected up front. Also pin bf16_unsupported_reason in the two positive-path
family-info tests so they are deterministic across GPU types (a non-bf16 CUDA box would otherwise
empty every DiT family's advertised modes).
2026-07-06 15:22:58 +00:00
Daniel Han
b6b507c48b Key the auto step-cache on the pipe's default strength when the request omits it
The auto FBCache policy keyed on the full step count whenever strength was omitted, but the
loader only passes the strength kwarg when it is set, so an img2img/inpaint pipe then runs its
OWN signature default (< 1, e.g. FluxImg2ImgPipeline's 0.6). FBCache would engage on the full
28 steps while the pipe actually denoises ~16, degrading the image on exactly the short
trajectory the policy exists to keep uncached. Thread the pipe's signature default into the
policy via a new effective_request_strength helper (unit-tested), so the effective denoise count
matches what the pipe runs.
2026-07-06 14:49:47 +00:00
pre-commit-ci[bot]
d86c4c70e6 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 14:05:24 +00:00
Daniel Han
908cb86b8d Do not widen the dense prefetch under a forced-offload memory policy
_dense_quant_prefetch_needed widened the prefetch to pull the base repo's transformer/
shards whenever a dense-quant candidate resolved, but balanced/low_vram (and the legacy
cpu_offload flag) force load_pipeline onto offload unconditionally in plan_diffusion_memory,
so its re-plan never flips to OFFLOAD_NONE and the dense build never runs. The offloaded GGUF
path then never touches those shards, so the widened prefetch only wastes a multi-GB download,
and a disk-full on that begin_load pull has no GGUF fallback (unlike the in-load_pipeline dense
failure). Mirror plan_diffusion_memory's definite-offload gates so the prefetch stays scoped.
2026-07-06 14:04:47 +00:00
Daniel Han
9ab68825ee Give Krea-2-Raw its undistilled 52-step recipe instead of the distilled default
Krea-2-Raw is in _TRUSTED_NON_GGUF_REPOS, so it is inference-loadable, but the generic
"krea" generation-defaults key matched it too and applied Turbo's distilled 8-step / no-CFG
recipe, producing degraded output on the undistilled base. Add a more specific krea-2-raw key
(52 steps, guidance 3.5 per the model card) ahead of the generic one, in both the backend
table and the frontend MODEL_DEFAULTS so the Studio UI and the OpenAI images route agree.
2026-07-06 14:00:39 +00:00
Daniel Han
aa54a062ec Gate DiT training on functional torchao for explicit int8; hide always-400 DiT modes on non-bf16 GPUs
The start route preflight only rejected non-bf16 GPUs; an explicit int8 request on
a host with a missing or stub torchao passed the preflight, evicted resident GPU
workloads, then died in the trainer child (its int8 base quantizer has no fallback).
Fold both gates into training_precision_preflight_error so int8-without-torchao fails
fast before eviction. Also empty the advertised DiT precision_modes (and surface the
reason in vram_note, drop compile) whenever the bf16 preflight would reject the family,
so /info never offers an nf4 DiT option the route always 400s.
2026-07-06 13:35:43 +00:00
Daniel Han
89e5f69d90 Don't prefetch dense shards for a prequant load; surface resolved provenance
- _dense_quant_prefetch_needed widened the transformer/ prefetch to pull the base
  repo's full dense bf16 shards even when a prequant checkpoint is configured
  (candidate.prequant), contradicting its own docstring. That both defeats the
  prequant download savings and can hard-fail begin_load on a disk-full (no GGUF
  fallback there). Only widen for a real dense build (candidate is not None and
  not candidate.prequant).
- DiffusionStatusResponse declared no 'resolved' field, so Pydantic's default
  extra='ignore' silently dropped the per-control auto-policy provenance the
  backend records (build_resolved_record / state.resolved) -- the plumbing never
  reached any client. Declare the field so it round-trips.
2026-07-06 11:52:32 +00:00
Daniel Han
a1114bfdc3 Align LR-schedule copy with the diffusion two-card chart layout
DiffusionCharts deliberately renders only Training Loss + Gradient Norm (the LR
curve is the deterministic schedule the user picked), but the settings copy and two
comments still promised a live LR chart. Reword them so the UI no longer references a
chart that was intentionally dropped.
2026-07-06 11:21:06 +00:00
Daniel Han
2d974219bf Deploy Krea adapters on Turbo and use its distilled recipe over the API
- DiffusionFamily gains deploy_base_repo (krea/Krea-2-Turbo): deploying a LoRA
  trained on Raw now previews it on Turbo, not the non-distilled Raw checkpoint.
  Scoped to a same-precision override so it never turns an nf4 train base into a
  larger bf16 deploy load; exposed through family_train_infos -> the Train UI's
  onDeployClick / historical-run deploy resolve the deploy base.
- _GENERATION_DEFAULTS gains a Krea entry (8 steps, 0 CFG) so the OpenAI
  /v1/images/generations route matches the Create UI's documented distilled recipe
  instead of falling through to the generic (9, 0.0).
2026-07-06 11:16:25 +00:00
pre-commit-ci[bot]
cc6d7c96a6 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 11:04:54 +00:00
Daniel Han
6bd3e87c6f Gate DiT training precision: deny fp8 for Qwen, gate explicit int8 on torchao, gate advertised dense modes + route on bf16
- normalized() + family_train_infos() mirror the inference fp8 deny for
  Qwen-Image (activation outliers exceed fp8's range and corrupt the trained
  result); int8 stays allowed and the UI no longer advertises fp8 for it.
- _resolve_base_precision() gates an explicit int8 on a FUNCTIONAL torchao, the
  same gate auto and /info already apply, so a missing/stub torchao fails fast
  instead of silently loading dense with compile disabled.
- train_precision_modes() gates the dense modes (bf16/int8/fp8/auto) on
  torch.cuda.is_bf16_supported(), so a non-bf16 CUDA GPU (T4/V100/RTX 20xx) is
  offered only nf4 instead of a start that evicts resident models and then fails.
- start_diffusion_training preflights bf16 support for the DiT families BEFORE
  _free_gpu_for_diffusion_training(), so any DiT start (nf4 included, since the
  trainer requires bf16 unconditionally on CUDA) fails fast without eviction.
2026-07-06 11:04:07 +00:00
pre-commit-ci[bot]
e6bd256ad6 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 10:50:45 +00:00
Daniel Han
311d9da637 diffusion: disk-gate the dense-quant prefetch, keep Speed=off bit-exact
- _dense_quant_prefetch_needed widened the prefetch to pull the base repo's bf16 transformer/ shards
  whenever a dense-quant scheme could resolve, with no disk check. On the offload path that can fill
  the cache volume mid-download and hard-fail the load in a spot unload/cancel cannot preempt, instead
  of the disk guard falling back to running the GGUF as-is (the Dtype hint's documented disk fallback).
  Defer to resolve_dense_quant_candidate, the same disk-aware resolver load_pipeline re-plans against,
  so the prefetch widens only when the dense build would really run.
- An explicit Speed=off (bit-exact) load with an unset dtype was promoted to auto-quant by the Dtype
  default, silently engaging int8/fp8 + compile and breaking the bit-exact request (an auto DEFAULT
  overriding an EXPLICIT control). Suppress the auto-dtype default when speed is explicitly off, in both
  load_pipeline and the prefetch.
2026-07-06 10:50:09 +00:00
pre-commit-ci[bot]
477757eac7 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 10:42:55 +00:00
Daniel Han
6384fea272 dit trainer: preserve biases under mxfp8, gate explicit mxfp8 to Blackwell
- The torchao 0.17 MX training path swaps a matched frozen Linear's weight for a wrapper tensor
  whose linear override computes input @ weight_t and drops the bias, so mxfp8'ing a biased frozen
  linear silently loses its bias and corrupts the base output the LoRA regresses against (verified
  on Blackwell: the bias term is fully dropped). Skip biased linears in _mx_module_filter.
- _resolve_base_precision re-checked explicit dense modes against the live device but only rejected
  CPU, so an explicit mxfp8 request on a non-Blackwell CUDA GPU passed and then crashed at the first
  MX GEMM after a full dense-transformer load. /info only advertises mxfp8 on sm100+; mirror that
  gate here and fail fast for a stale or direct client below Blackwell.
2026-07-06 10:41:02 +00:00
pre-commit-ci[bot]
4f6aa1a3d4 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 10:31:37 +00:00
Daniel Han
06ec3b34dc diffusion speed: make the fp16-accum kill switch case-insensitive
UNSLOTH_DISABLE_FP16_ACCUM is the documented safety escape hatch for fp16-accumulation
numerical drift, but it was matched as .strip() in (1, true, yes) with no lowercasing, so
UNSLOTH_DISABLE_FP16_ACCUM=TRUE (or YES / On) was silently ignored and fp16 accumulation
stayed on. Lowercase before matching (the family-name check on the next line already does)
and accept on. Existing 1/true/yes still match.
2026-07-06 10:31:01 +00:00
Daniel Han
6e5d11a0a7 diffusion cache: floor the strength-scaled step count like diffusers
effective_denoise_steps computed ceil(steps * strength) (steps - int(steps - steps*strength)),
but diffusers get_timesteps denoises init_timestep = min(int(num_inference_steps * strength),
num_inference_steps), i.e. the floored product. The two differ by one whenever the product is
fractional, and that flips the auto FBCache decision in the (19, 20) band: a strength-0.7
28-step img2img denoises int(19.6) = 19 real steps (below FBCACHE_MIN_STEPS = 20) but the old
formula returned 20 and engaged FBCache on that short trajectory, exactly the quality hit the
auto policy exists to avoid. Return min(int(steps * strength), steps) to match diffusers, and
fix the two tests that replayed the old formula.

Also honor _default_threads' documented fallback: (os.cpu_count() or 8) // 2 yields 4 when the
count is unknown, contradicting the docstring's 'falls back to 8'. Return 8 in that case.
2026-07-06 10:01:03 +00:00
pre-commit-ci[bot]
7c72910487 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 08:49:31 +00:00
Daniel Han
092fc91e08 diffusion: don't double-count the prefetched transformer in the dense re-plan
The dense-quant re-plan passes transformer_resident_override_mib (the bf16 build
peak) AND computes companions via _companion_cache_bytes(base), which sums every
flat blob in the HF cache. Because the dense path prefetches the base transformer/
shards into that same cache before load_pipeline runs, the transformer is counted
twice, inflating the footprint (~44 GB instead of ~20 GB in the reproduction) and
wrongly forcing offload for models that fit resident -- the case this path exists
to enable. Add companion_override_mib and pass the auto-policy's own text-encoder
plus VAE estimate on the re-plan so the cache (with its prefetched transformer) is
not read for this artifact.
2026-07-06 08:48:13 +00:00
pre-commit-ci[bot]
db440d2252 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-06 08:46:11 +00:00
Daniel Han
7c8f4919d6 diffusion: fix step-cache Off, kernel-install dep clobber, retry-under-lock, effective steps
- Step cache 'Off' is preserved: the frontend defaulted to 'off' and mapped it
  to an omitted transformer_cache, which the backend now reads as 'auto', so
  leaving the control at Off silently enabled FBCache on 20+ step families.
  Default the control to Auto, add an explicit Auto option, and send
  auto -> omitted so Off maps to an explicit cache-off.
- Kernel auto-install adds --no-deps: 'pip install --only-binary :all: xformers'
  resolves xformers' pinned torch and replaces the running torch/triton. --no-deps
  installs only the best-effort kernel wheel; an ABI mismatch just fails to import
  and falls back to native, never clobbering core deps.
- Do not retry a failed kernel install under the load lock: the pre-install runs
  outside the locks, then the in-lock resolve re-attempts pip (up to 600s) while
  holding _generate_lock/_lock and blocking unload/cancel/new loads. Record the
  attempt in a process-level set so the in-lock call short-circuits to native.
- Cache auto-toggle keys on effective denoise steps: an image-conditioned run with
  strength < 1 (upscale default 0.35) denoises a fraction of the requested steps,
  so a 28-step request runs ~10 steps. Compute the effective count the way diffusers
  get_timesteps does and gate FBCache on it, only when strength is actually applied.
2026-07-06 08:45:17 +00:00
Daniel Han
cc23062077 Merge remote-tracking branch 'origin/diffusion-auto-install' into diffusion-auto-badges 2026-07-05 11:52:43 +00:00
Daniel Han
e2e10c4ee9 Merge branch 'diffusion-auto-install' of https://github.com/unslothai/unsloth into diffusion-auto-install 2026-07-05 11:48:48 +00:00
Daniel Han
9d3a1d3ff7 Invalidate import caches after a wheel install so the new kernel is importable
A successful on-demand wheel install writes into site-packages after the
import system already cached that directory's listing, so the very next
find_spec / import in the same process can miss the freshly installed
package when the install lands within the directory mtime's resolution.
That silently falls set_attention_backend back to native on first use.
Call importlib.invalidate_caches() after a successful install so the
kernel is picked up immediately, and cover both the success and failure
paths in the attention installer tests.
2026-07-05 11:48:34 +00:00
pre-commit-ci[bot]
995ce8ac5f [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:46:16 +00:00
pre-commit-ci[bot]
d398978349 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:45:40 +00:00
pre-commit-ci[bot]
1d4cf1d6aa [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:45:05 +00:00
pre-commit-ci[bot]
a45b4b2ec3 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:44:30 +00:00
pre-commit-ci[bot]
83bc33d04a [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:43:58 +00:00
pre-commit-ci[bot]
293b770c78 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:43:23 +00:00
pre-commit-ci[bot]
9caab52bfd [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:42:50 +00:00
pre-commit-ci[bot]
1a72a06b1d [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-05 11:42:17 +00:00
Daniel Han
af76745353 Merge branch 'diffusion-auto-install' into diffusion-auto-badges 2026-07-05 11:39:34 +00:00
Daniel Han
3c4dd8d118 Merge branch 'diffusion-fp16-accum' into diffusion-auto-install 2026-07-05 11:39:32 +00:00
Daniel Han
ac90e6cdab Merge branch 'diffusion-auto-policy' into diffusion-fp16-accum 2026-07-05 11:39:31 +00:00
Daniel Han
a20049bfc0 Merge branch 'diffusion-train-perf2' into diffusion-auto-policy 2026-07-05 11:39:30 +00:00
Daniel Han
66387c1533 Merge branch 'diffusion-krea2' into diffusion-train-perf2 2026-07-05 11:39:16 +00:00
Daniel Han
f543af6d27 Merge branch 'diffusion-train-tab-2' into diffusion-krea2 2026-07-05 11:39:15 +00:00
Daniel Han
5979d68a03 Merge branch 'diffusion-train-precision' into diffusion-train-tab-2 2026-07-05 11:39:14 +00:00
Daniel Han
2d466df322 Merge branch 'diffusion-train-perf' into diffusion-train-precision 2026-07-05 11:39:12 +00:00
Daniel Han
b88d0d49b8 Merge branch 'image-generation' into diffusion-train-perf 2026-07-05 11:39:11 +00:00