Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Condense module docstrings, keeping the guarantees they state (#15594)

Daniel Hancb678f53d9dc
diff --git a/scripts/build_ltx25_te_int8_convrot.py b/scripts/build_ltx25_te_int8_convrot.py
index b08afb495af..3f6ca386ba6 100644
--- a/scripts/build_ltx25_te_int8_convrot.py
+++ b/scripts/build_ltx25_te_int8_convrot.py
@@ -1,20 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Build the hosted int8 ConvRot Gemma 4 encoder LTX-2.5's text-encoder sidecar loads instead of quantizing at load.
-
-The file IS the sidecar's own at-load build, written once: this runs the worker's ``_load`` (transformers 5.10
-sidecar, ``from_pretrained(torch_dtype = bfloat16)``, the dead-tail trim, then ``quantize_int8_convrot_`` on the card)
-and saves the resulting state dict. So every key is the loaded model's own name (transformers 5 renames some
-checkpoint keys at load), every decoder projection is the ``Int8ConvRotLinear`` buffers (``<name>.weight`` int8,
-``<name>.weight_scale`` float32 [out, 1]) and every other tensor is the bf16 tensor the at-load path holds. The tied
-``lm_head`` has no key (it is re-tied to the embedding at load). The header is the plain-tensor container the prequant
-readers share (``unsloth_format`` + ``unsloth_metadata`` + ``tensor_names``), written canonically, so a rebuild on the
-same device kind is byte-identical.
-
- python scripts/build_ltx25_te_int8_convrot.py \\
- --out outputs/te_default/unsloth/LTX-2.5-FP8/LTX-2.5-text_encoder-INT8-ConvRot.safetensors
-"""
+"""Builds the int8 ConvRot Gemma 4 encoder for LTX-2.5's sidecar; keys use the loaded model's names."""
from __future__ import annotations
diff --git a/scripts/build_prequant_checkpoint.py b/scripts/build_prequant_checkpoint.py
index 6444cbbffa5..f022ab4455c 100644
--- a/scripts/build_prequant_checkpoint.py
+++ b/scripts/build_prequant_checkpoint.py
@@ -1,22 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Build a pre-quantized transformer checkpoint for the Unsloth diffusion fast path.
-
-Quantise a model's dense bf16 DiT transformer ONCE and save the quantized state dict, so
-the backend can load the already-quantized weights at runtime (meta-init +
-load_state_dict(assign=True)) instead of materialising the dense bf16 on the GPU. That
-drops the transformer GPU load peak ~2x and the download ~2x for fp8 (measured on Z-Image:
-12.9 -> 6.3 GB peak, 12 -> 6.28 GB on disk), with bit-identical output -- it is the exact
-same torchao config + min_features filter the runtime path uses, applied ahead of time.
-
-Run on one CUDA (Blackwell / Ada / Hopper) GPU. fp8 works on torch 2.9+; the FP4/MX schemes
-need the newer kernels (see scripts/nvfp4_t211_probe.py).
-
- python scripts/build_prequant_checkpoint.py \
- --base Tongyi-MAI/Z-Image-Turbo --family z-image --scheme fp8 \
- --out outputs/quant_research/prequant_fp8/transformer_fp8.pt [--upload-repo ORG/REPO]
-"""
+"""Quantizes the DiT once so runtime loads it with assign=True, skipping the dense bf16 GPU load peak."""
from __future__ import annotations
diff --git a/scripts/build_segmenter_prequant_checkpoint.py b/scripts/build_segmenter_prequant_checkpoint.py
index 931bcfe3177..4b8ef4881da 100644
--- a/scripts/build_segmenter_prequant_checkpoint.py
+++ b/scripts/build_segmenter_prequant_checkpoint.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Build a pre-quantized SAM 3 / SAM 3.1 detector (Mask from text) for Unsloth Studio.
-
-The segmenter counterpart of scripts/build_prequant_checkpoint.py: the same torchao config, filter, ConvRot rotation,
-safetensors container (torchao flatten layout + ``unsloth_format`` / ``unsloth_metadata``) and canonical fingerprint,
-reached through ``core.inference.diffusion_segment_quant`` so the artifact matches what Studio's loader checks
-(scheme, min_features, exclusions, rotation contract). Deterministic for a given source, scheme and torchao.
-
- python scripts/build_segmenter_prequant_checkpoint.py --src <Sam3Model dir> --base-model-id unsloth/sam3.1 \\
- --source-revision <sha> --scheme int8 --convrot-groupsize 256 --out sam3.1-INT8-ConvRot.safetensors
-"""
+"""SAM 3 / 3.1 segmenter builder; reuses diffusion_segment_quant so Studio's loader checks pass."""
from __future__ import annotations
diff --git a/scripts/build_te_int8_convrot_checkpoint.py b/scripts/build_te_int8_convrot_checkpoint.py
index 4d694fdac59..b86b3be138f 100644
--- a/scripts/build_te_int8_convrot_checkpoint.py
+++ b/scripts/build_te_int8_convrot_checkpoint.py
@@ -1,30 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Build an int8 ConvRot weight-only text-encoder checkpoint for the Unsloth TE prequant path.
-
-Every decoder projection of the dense encoder (q/k/v/o and gate/up/down in each
-``model.language_model.layers.N``, or ``model.layers.N`` for a text-only Qwen3) is rotated by
-the group-256 Hadamard and stored int8 with a float32 per-output-channel scale (``diffusion_te_prequant.quantize_int8_convrot_weight``); the
-vision tower, embedding table and norms are copied bf16, bit for bit; ``lm_head`` is left out
-(the pipelines that load this file read hidden states only). Each quantized Linear carries a
-``<name>.comfy_quant`` JSON blob naming the format, and the header is the plain-tensor container
-the TE prequant loader reads (``tensor_names`` + ``unsloth_format`` + ``unsloth_metadata``).
-
-Reads one source tensor at a time, so host RAM peaks at about the output size. Deterministic: the
-same source and group give a byte-identical file.
-
- python scripts/build_te_int8_convrot_checkpoint.py \\
- --base Qwen/Qwen-Image-2.1 --family qwen-image-2.1 \\
- --out Qwen-Image-2.1-text_encoder-INT8-ConvRot.safetensors
-
-``--load transformers`` builds any other encoder from the module the pipeline instantiates (``--te-class``, default
-the config's architecture): the dense encoder is loaded with ``from_pretrained`` and its runtime state dict is
-written, so the keys are the ones the loader's strict ``load_state_dict`` expects even where a checkpoint stores an
-older layout (Qwen2.5-VL's ``model.layers`` / ``visual``). Every Linear whose module name matches
-``diffusion_te_prequant.TE_INT8_CONVROT_LINEAR`` is quantized: decoder q/k/v/o + gate/up/down (Qwen, Llama, Mistral,
-Gemma; never a vision tower, which names its blocks differently) and T5's SelfAttention q/k/v/o + DenseReluDense.
-"""
+"""Int8 ConvRot TE checkpoint, group-256 Hadamard; keys must match the strict load_state_dict the
+loader expects; lm_head omitted, pipelines read hidden states only"""
from __future__ import annotations
diff --git a/scripts/build_te_prequant_checkpoint.py b/scripts/build_te_prequant_checkpoint.py
index 58cf9149861..329c31a11e0 100644
--- a/scripts/build_te_prequant_checkpoint.py
+++ b/scripts/build_te_prequant_checkpoint.py
@@ -1,27 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Build a pre-cast text-encoder checkpoint for the Unsloth TE prequant path.
-
-Apply the runtime layerwise-fp8 STORAGE cast (``diffusion_precision._cast_fp8``) to a
-model's dense text encoder ONCE and save the cast state dict, so the backend can load the
-~half-size artifact (meta-init + ``load_state_dict(assign=True)``, see
-``core/inference/diffusion_te_prequant.py``) instead of downloading the full bf16 encoder
-and casting on every load. The cast is a deterministic storage transform, so the loaded
-encoder is bit-identical to dense-load-then-cast by construction. CPU-runnable: the cast
-touches storage dtypes only, no kernels.
-
- python scripts/build_te_prequant_checkpoint.py \
- --base Lightricks/LTX-2 --family ltx-2 --component text_encoder \
- --out outputs/te_prequant/ltx2/text_encoder_fp8.pt
-
-Ideogram 4 ships its Qwen3-VL encoder as vendor fp8 + weight_scale, which ``from_pretrained`` cannot read;
-``--loader ideogram4`` builds it through Studio's own loader first:
-
- python scripts/build_te_prequant_checkpoint.py \
- --base unsloth/ideogram-4-fp8 --base-model-id ideogram-ai/ideogram-4-fp8 --family ideogram-4 \
- --loader ideogram4 --out temp/te_default_build/ideogram-4-text_encoder-FP8.pt
-"""
+"""Pre-casts the TE to layerwise fp8 storage once; Ideogram 4's vendor fp8 needs --loader ideogram4."""
from __future__ import annotations
diff --git a/scripts/check_new_install_scripts.py b/scripts/check_new_install_scripts.py
index 9814f365218..a0c809bb2f8 100644
--- a/scripts/check_new_install_scripts.py
+++ b/scripts/check_new_install_scripts.py
@@ -2,21 +2,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Diff two `package-lock.json` files and flag NEW install-script deps.
-
-A `"hasInstallScript": true` package runs preinstall/install/postinstall
-hooks on every `npm ci` -- the lever behind recent npm supply-chain
-compromises (attacker publishes a malicious version of a trusted dep).
-This refuses to land a newly-introduced install-script dep without a
-maintainer eyeball; pre-existing ones are not re-flagged.
-
-Supports lockfileVersion 1 (recursive `dependencies`) and 2/3 (flat
-`packages` with `node_modules/.../node_modules/...` nesting). For each
-new entry we best-effort fetch the registry metadata to recover the
-postinstall command body; the finding is still emitted if unreachable.
-
-Exit codes: 0 = none; 1 = one or more (on stderr); 2 = internal error.
-"""
+"""Fails on newly added hasInstallScript deps in package-lock.json; existing ones are not flagged;
+registry metadata fetch is best-effort and the finding is still emitted if unreachable"""
from __future__ import annotations
diff --git a/scripts/clef_train_bench.py b/scripts/clef_train_bench.py
index 311716db699..5366fc07110 100644
--- a/scripts/clef_train_bench.py
+++ b/scripts/clef_train_bench.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Clef training step benchmark and head parity check, one JSON line on stdout.
-
-python scripts/clef_train_bench.py --model Cloudflare/clef-flash --load-in-4bit --seq-len 8192
-python scripts/clef_train_bench.py --model tiny --fast off --dtype fp16
-
---fast on|off sets UNSLOTH_CLEF_FAST (Unsloth's batched, chunked and checkpointed head, compiled
-too under UNSLOTH_CLEF_COMPILE=1, vs the per-record head). Whatever the arm, the first batch's head is also run both ways on the same
-hidden states, so `parity` compares the two heads' logits and gradients in this process.
-"""
+"""Clef benchmark; --fast sets UNSLOTH_CLEF_FAST; parity compares batched vs per-record head logits."""
import argparse
import json
diff --git a/scripts/compare_engines.py b/scripts/compare_engines.py
index 3499c55593c..d05c56f689f 100644
--- a/scripts/compare_engines.py
+++ b/scripts/compare_engines.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Head-to-head: PyTorch (diffusers GGUF) vs native stable-diffusion.cpp.
-
-Same Z-Image GGUF transformer, same VAE + text encoder, same resolution / steps /
-seed, both resident (no CPU offload) on the same GPU. Reports per-engine compute
-latency (model already loaded) so the denoise + VAE + TE work is compared fairly;
-for sd.cpp it also reports the one-shot wall time (compute + the per-call model
-reload, which a persistent sd-server would remove).
-
-PyTorch runs first (load / warmup / median), is unloaded, then sd.cpp runs.
-"""
+"""PyTorch vs sd.cpp on the same resident Z-Image GGUF; sd.cpp wall time adds a per-call model reload."""
from __future__ import annotations
diff --git a/scripts/compile_probe.py b/scripts/compile_probe.py
index c006def594c..7a3cd69c915 100644
--- a/scripts/compile_probe.py
+++ b/scripts/compile_probe.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Probe: does regional ``torch.compile`` work on the GGUF diffusion transformer?
-
-The speed layer gates ``compile_repeated_blocks`` OFF for GGUF (it dequantises
-per-op). Since the backend is GGUF-only, that makes regional compile dead on
-every shipping model. This probe loads a GGUF transformer exactly as
-``diffusion.py`` does, runs an eager generation, then compiles the repeated
-denoiser block and runs the same seed again, reporting: whether compile raised,
-per-generation latency eager vs compiled, and PSNR(compiled vs eager). If compile
-is clean and PSNR is high, the gate can be relaxed for this family.
-
-Run on one CUDA GPU. Read-only w.r.t. the backend (does not import the gate).
-"""
+"""Checks whether regional torch.compile works on GGUF transformers, which the speed gate disables."""
from __future__ import annotations
diff --git a/scripts/diffusion_bench.py b/scripts/diffusion_bench.py
index 4c0bf951302..3613ec90400 100644
--- a/scripts/diffusion_bench.py
+++ b/scripts/diffusion_bench.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Standalone GPU benchmark + regression harness for the Unsloth diffusion backend.
-
-Drives ``DiffusionBackend`` directly (no HTTP server) to measure load time, peak VRAM and generation latency for a single GGUF image model, plus an accuracy guard: a fixed-seed image is rendered and compared (PSNR) against a stored reference, so a precision/dtype/guard regression that silently changes output is caught, not just speed and memory.
-
-Two modes: --write-baseline PATH runs once and saves the metrics JSON plus reference.png next to it, and --compare PATH runs again, diffs against the baseline and exits nonzero if a latency, VRAM or PSNR threshold is exceeded.
-
-torch and diffusers are imported lazily (only after argument parsing and only inside functions) so ``--help`` works on a host without them. Not part of CPU CI; this needs a real GPU and a downloadable model.
-
-Example: `python scripts/diffusion_bench.py --write-baseline outputs/diffusion_bench/baseline.json --model unsloth/Z-Image-Turbo-GGUF --gguf z-image-turbo-Q4_K_M.gguf`, then the same command with --compare after making changes.
-"""
+"""GPU benchmark of DiffusionBackend; --compare exits nonzero past latency, VRAM or PSNR thresholds;
+torch and diffusers are imported lazily so --help works without them"""
from __future__ import annotations
diff --git a/scripts/diffusion_quality.py b/scripts/diffusion_quality.py
index b9227b0b8a7..032a79a70f0 100644
--- a/scripts/diffusion_quality.py
+++ b/scripts/diffusion_quality.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Image quality-vs-quant harness for the Unsloth diffusion backend.
-
-The accuracy analogue of the KLD workflow: hold the prompt and seed fixed, render a grid with a high-fidelity reference quant (default BF16), then render the same grid with each candidate quant and measure how far the output drifts from the reference. Per quant it records mean PSNR / SSIM (pixel and structural fidelity against the reference image), optional CLIP scores (prompt alignment plus similarity to the reference), file size, generation latency and peak VRAM, then prints a quality-vs-cost table and recommends the smallest quant that stays within a quality budget, so "retain accuracy" becomes a number you can set defaults from.
-
-Lean by design: PSNR and SSIM are pure numpy (no skimage/scipy); CLIP is optional and gated on ``--clip`` (uses transformers, downloads a small CLIP once). torch / diffusers / the backend are imported lazily so ``--help`` and ``--selftest`` work on a host without them. Not part of CPU CI for the GPU path; ``--selftest`` is CPU-only.
-
-Examples: `python scripts/diffusion_quality.py --selftest` for a CPU metric sanity check, or `--model unsloth/Z-Image-Turbo-GGUF --reference-quant z-image-turbo-BF16.gguf --quants z-image-turbo-Q8_0.gguf z-image-turbo-Q4_K_M.gguf z-image-turbo-Q2_K.gguf --clip` for a GPU sweep against the BF16 reference.
-"""
+"""Ranks quants by PSNR and SSIM drift from a BF16 reference, recommends the smallest within budget;
+torch and diffusers are imported lazily so --help and --selftest work without them"""
from __future__ import annotations
diff --git a/scripts/fbcache_flux_probe.py b/scripts/fbcache_flux_probe.py
index bb5c444465a..a5ebef93118 100644
--- a/scripts/fbcache_flux_probe.py
+++ b/scripts/fbcache_flux_probe.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Validate First-Block-Cache (FBCache) on a MANY-step DiT (Flux.1-dev), vs the compiled
-baseline. FBCache reuses the transformer tail across denoise steps when the first block's
-residual barely changes -- a real speedup only when there are enough steps (it is why it is
-gated OFF for few-step distilled models like Z-Image-Turbo). Reports median latency,
-speedup, peak VRAM, and LPIPS vs the no-cache baseline. One CUDA GPU."""
+"""Probes FBCache on Flux.1-dev; it only pays off on many-step DiTs, so Z-Image-Turbo gates it off."""
from __future__ import annotations
diff --git a/scripts/fp8_overflow_check.py b/scripts/fp8_overflow_check.py
index 48196f3aace..53e41c6834d 100644
--- a/scripts/fp8_overflow_check.py
+++ b/scripts/fp8_overflow_check.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Empirically check that fp8 dynamic quant with fast accumulation does not overflow.
-
-Hooks every quantised Linear's output during a real Z-Image generation and reports the
-global max |output| and any non-finite (Inf/NaN) count, for use_fast_accum True vs False.
-The concern fast_accum raises is accumulation *precision*, not overflow (the accumulator
-stays FP32-range and torchao's dynamic per-row scale keeps FP8 inputs <= 448); this proves
-it on the real model, including Z-Image's large (~9e5) activation peaks. Run on one CUDA GPU.
-"""
+"""Verifies fp8 use_fast_accum does not overflow on real Z-Image: max |output| and non-finite counts."""
from __future__ import annotations
diff --git a/scripts/int8_linear_probe.py b/scripts/int8_linear_probe.py
index 1b55f2ee793..744c899be4a 100644
--- a/scripts/int8_linear_probe.py
+++ b/scripts/int8_linear_probe.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Examine which Linear layers the int8 dense-quant filter would select, to find the large M=1
-modulation/embedder projections that crash torch._int_mm (M>16). Loads each transformer on the
-META device (no weights, no GPU) from its base-repo config, lists nn.Linear fqn/in/out, and marks
-those that pass min_features=512. CPU-only, fast."""
+"""Finds M=1 modulation/embedder Linear layers that crash torch._int_mm (M>16) under int8 dense quant."""
from __future__ import annotations
diff --git a/scripts/kv_cache_multiturn_benchmark.py b/scripts/kv_cache_multiturn_benchmark.py
index 4d767830822..93c1c0d5324 100644
--- a/scripts/kv_cache_multiturn_benchmark.py
+++ b/scripts/kv_cache_multiturn_benchmark.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Multi-turn generate(): re-encode the whole conversation vs continue from a KV cache of the history.
-
-python scripts/kv_cache_multiturn_benchmark.py --model unsloth/Llama-3.2-1B-Instruct --turns 4 8 16 32
-"""
+"""Benchmarks multi-turn generate(): re-encoding the full conversation vs continuing from a KV cache."""
import argparse
import time
diff --git a/scripts/leverage_probe.py b/scripts/leverage_probe.py
index 809e8ffac1b..2df4c224d4f 100644
--- a/scripts/leverage_probe.py
+++ b/scripts/leverage_probe.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Probe two candidate levers from the optimization research, on the real GGUF path:
-
- * `coordinate_descent_tuning` (Inductor) -- lossless extra kernel autotuning.
- * FirstBlockCache (diffusers `apply_first_block_cache`) -- step-skip cache, lossy,
- evaluated at a low (8) step count where its ceiling is lower.
-
-Each config is a fresh pipeline load (so Inductor config / compile artifacts don't
-cross-contaminate). Reports latency + PSNR vs the eager reference. Run on one CUDA GPU.
-"""
+"""Probes coordinate_descent_tuning (lossless) and FirstBlockCache (lossy, 8 steps) vs eager PSNR."""
from __future__ import annotations
diff --git a/scripts/lint_backend_python_floor.py b/scripts/lint_backend_python_floor.py
index 71a56224294..8ebe8ff02d2 100644
--- a/scripts/lint_backend_python_floor.py
+++ b/scripts/lint_backend_python_floor.py
@@ -2,16 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Refuse backend source that needs a newer interpreter than the matrix floor.
-
-A pull request runs Backend CI on the NEWEST interpreter only. Every older leg still runs on the push to main, so a version-specific break is caught at merge rather than never, but between opening a pull request and merging it nothing executes the backend on the oldest one. This closes as much of that gap as a static check can.
-
-Syntax is the easy half and ``tests/test_python39_compatibility.py`` already covers it by parsing at the version ``pyproject.toml`` declares; it is also not the shape this regression takes. The realistic mistake is reaching for a stdlib name that does not exist yet (``core/research_runs.py`` already uses ``anext``, which is 3.10), which parses perfectly on every version and fails only when the line runs.
-
-So this asks vermin, which reads both syntax and stdlib API availability, and compares the answer against the oldest leg the workflow declares rather than a number written here. Raise the floor and this follows; use a symbol from above it and this fails in seconds on every pull request instead of on main in 23 minutes.
-
-What it cannot do: it does not run anything. Two interpreters that both accept a line can still behave differently on it, and a ``sys.version_info`` branch is only ever parsed here, never taken. That is what the full matrix on main is for.
-"""
+"""Fails on stdlib APIs newer than the oldest CI interpreter (via vermin); syntax checks miss these."""
from __future__ import annotations
diff --git a/scripts/lockfile_supply_chain_audit.py b/scripts/lockfile_supply_chain_audit.py
index e09221766d2..b1a8971e000 100644
--- a/scripts/lockfile_supply_chain_audit.py
+++ b/scripts/lockfile_supply_chain_audit.py
@@ -2,14 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Lockfile supply-chain audit for the Unsloth frontend and Tauri shell.
-
-Runs BEFORE `npm ci` / `cargo fetch` in CI and refuses to proceed when a lockfile carries patterns indicating supply-chain injection (npm Shai-Hulud waves, cargo crates.io brand-squats). package-lock.json (lockfileVersion 2/3): `resolved` must be the npm registry (direct git/github/file refs are the injection vector), `integrity` SHA must be present, known IOC substrings grepped from the body. Cargo.lock: `source` must be the crates.io registry index, plus known cargo IOC substrings.
-
-Exit codes: 0 clean (or skip env var set to a justification >=5 chars, not '1'/'true'), 1 findings, 2 internal error.
-
-Only PARSES the lockfiles, never executes or networks, and fires before any third-party install script runs on the runner. Complements rather than replaces `npm audit` / OSV-Scanner / the advisory-DB pipeline.
-"""
+"""Audits lockfiles before npm ci/cargo fetch; only parses them and rejects non-registry sources."""
from __future__ import annotations
diff --git a/scripts/make_dmg_background.py b/scripts/make_dmg_background.py
index 4b46a7f20c4..fc1077e06cc 100644
--- a/scripts/make_dmg_background.py
+++ b/scripts/make_dmg_background.py
@@ -2,19 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Render the macOS DMG install-window background.
-
-Writes studio/src-tauri/dmg/background.tiff, the image Finder draws behind the
-app icon and the Applications alias when the disk image opens.
-
-The layout is tied to the Finder coordinates in studio/src-tauri/tauri.macos.conf.json.
-Finder maps icon positions onto the background from the same origin, so the base
-page has to match dmg.windowSize exactly or the artwork slides out from under the
-icons. tests/studio/test_tauri_branding_contract.py holds that contract.
-
-Output is a two-page TIFF: a base page at window size and a second page at twice
-that, which is how Finder picks up a sharp image on a retina display.
-"""
+"""Renders the DMG background TIFF; its base page must match dmg.windowSize in tauri.macos.conf.json."""
from __future__ import annotations
diff --git a/scripts/notebook_validator.py b/scripts/notebook_validator.py
index f385480bf21..2e8a37c80e8 100644
--- a/scripts/notebook_validator.py
+++ b/scripts/notebook_validator.py
@@ -2,32 +2,8 @@
# coding: utf-8
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team.
-"""
-Static + lightweight-dynamic validator for unslothai/notebooks.
-
-Built to catch the bug classes that landed in (at minimum):
-- unslothai/notebooks#258 (Colab torchao 0.10 vs peft 0.19 floor)
-- unslothai/notebooks#260 (DONT_UPDATE_EXCEPTIONS coverage drift)
-- unslothai/notebooks#261 (torch/torchcodec ABI; --no-deps tokenizers)
-- unslothai/notebooks#264 (transformers/tokenizers window with --no-deps)
-- unslothai/notebooks#221 (removed unsloth APIs in user cells, git+ install)
-- unslothai/notebooks commit 51b1462 (template/notebook drift)
-
-CPU-only by design: never imports torch / unsloth at module load. The
-api subcommand introspects unsloth under the existing
-tests/_zoo_aggressive_cuda_spoof.py harness (PR #5312) so it works on
-ubuntu-latest without a GPU.
-
-Usage:
- python scripts/notebook_validator.py drift --notebooks-dir <dir>
- python scripts/notebook_validator.py convert --notebooks-dir <dir> --out _converted
- python scripts/notebook_validator.py lint --notebooks-dir <dir> [--colab-pin <file>]
- python scripts/notebook_validator.py exceptions --notebooks-dir <dir>
- python scripts/notebook_validator.py api --converted-dir _converted --surface _api_surface.json
- python scripts/notebook_validator.py all --notebooks-dir <dir>
- python scripts/notebook_validator.py refresh-colab --out scripts/data/colab_pip_freeze.gpu.txt
- python scripts/notebook_validator.py refresh-colab --all --snapshot-dir scripts/data
-"""
+"""CPU-only notebook validator with subcommands drift, convert, lint, exceptions, api, all, refresh-
+colab; never imports torch or unsloth at module load"""
from __future__ import annotations
diff --git a/scripts/nvfp4_probe.py b/scripts/nvfp4_probe.py
index 97b2e994116..e49ee5301c4 100644
--- a/scripts/nvfp4_probe.py
+++ b/scripts/nvfp4_probe.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Probe NVFP4 via torchao with use_triton_kernel=False (no MSLK) on the real dense
-Z-Image transformer: is it a genuine FP4-tensor-core speedup over fp8, and is quality
-in-bar? Reference for LPIPS is dense bf16 eager. Run on one CUDA (Blackwell) GPU."""
+"""Probes NVFP4 via torchao (use_triton_kernel=False, no MSLK) on dense Z-Image vs bf16 eager."""
from __future__ import annotations
diff --git a/scripts/nvfp4_t211_probe.py b/scripts/nvfp4_t211_probe.py
index 77437c179dd..e4f36d7c272 100644
--- a/scripts/nvfp4_t211_probe.py
+++ b/scripts/nvfp4_t211_probe.py
@@ -1,17 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""torch>=2.11 NVFP4 probe. Three parts:
-
- A. diagnostics -- torch/torchao versions, cpp-extension load state, device.
- B. GEMM micro -- isolated per-linear forward latency (bf16 / fp8 / nvfp4-cutlass /
- nvfp4-triton) at Z-Image-like shapes, to measure raw FP4
- tensor-core throughput free of pipeline overhead.
- C. end-to-end -- real dense Z-Image transformer, latency + LPIPS + PSNR + VRAM,
- reference = dense bf16 eager.
-
-Run on one CUDA (Blackwell) GPU. This is the experiment that decides whether NVFP4
-becomes a genuine speedup once torch>=2.11 + torchao's CUTLASS FP4 GEMM is present."""
+"""Decides whether NVFP4 is a real speedup on torch>=2.11 (Blackwell; GEMM and end-to-end Z-Image)."""
from __future__ import annotations
diff --git a/scripts/online_tokenization_ab.py b/scripts/online_tokenization_ab.py
index 260009ef4fe..97f6a720cec 100644
--- a/scripts/online_tokenization_ab.py
+++ b/scripts/online_tokenization_ab.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Eager vs online preparation, measured through Unsloth's real training path.
-
-Drives ``UnslothTrainer.load_model`` -> ``prepare_model_for_training`` ->
-``load_and_format_dataset`` -> ``start_training``, so the integrated gating is
-what gets measured. The arms differ only by ``UNSLOTH_STUDIO_ONLINE_TOKENIZATION``:
-
- python scripts/online_tokenization_ab.py --arm eager --dataset <split> --out ab_eager.json
- python scripts/online_tokenization_ab.py --arm online --dataset <split> --out ab_online.json
-
-Same seed, rows and order, so per-step losses must match; a mismatch means the
-lazy transform is not producing the rows the eager map produced.
-"""
+"""A/B eager vs online tokenization (UNSLOTH_STUDIO_ONLINE_TOKENIZATION); per-step losses must match."""
from __future__ import annotations
diff --git a/scripts/perf_levers_probe.py b/scripts/perf_levers_probe.py
index cdd4bef6b7e..6c567a15e6a 100644
--- a/scripts/perf_levers_probe.py
+++ b/scripts/perf_levers_probe.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Measure the next-phase diffusion levers on the real model, vs today's compiled baseline.
-
-Variants (Z-Image dense bf16, regional compile = the shipped "default" speed profile):
- baseline -- channels_last + compile_repeated_blocks (reference image)
- inductor_flags -- + the lossless inductor autotune flags (conv_1x1_as_mm,
- coordinate_descent_tuning(+all_dirs), epilogue_fusion=False)
- attn_cudnn -- + set_attention_backend("_native_cudnn") (exact)
- attn_flash4 -- + set_attention_backend("flash_4_hub") (exact, SM100)
- attn_sage -- + set_attention_backend("sage") (INT8 QK, quantized)
- fbcache -- + First-Block-Cache (threshold 0.12) (few-step headroom test)
-
-Reports median latency, vs-baseline speedup, peak VRAM, and LPIPS vs baseline. One CUDA GPU."""
+"""Benchmarks inductor flags, attention backends and FBCache against the compiled Z-Image baseline."""
from __future__ import annotations
diff --git a/scripts/perf_verify.py b/scripts/perf_verify.py
index f45e93af39a..24b177f887d 100644
--- a/scripts/perf_verify.py
+++ b/scripts/perf_verify.py
@@ -1,21 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GPU verification for the diffusion performance pass (Phase 7).
-
-Drives the real ``DiffusionBackend`` through several loads in one process and
-checks, at a fixed seed:
-
- 1. speed: ``default`` (compile + cudnn.benchmark + channels_last) vs ``off``
- -- expect a large denoise speedup at high PSNR (near-lossless).
- 2. the TF32-leak fix: load ``max`` (flips global TF32 / cudnn.benchmark), unload,
- then load ``off`` -- the ``off`` image must be byte-identical (PSNR inf) to a
- fresh ``off`` baseline, proving the globals were restored on unload.
- 3. ``balanced`` is now bit-identical: with VAE tiling restricted to the low tiers,
- streamed (group) offload should match the resident image (PSNR inf).
-
-Run on one CUDA GPU with the GGUF + base repo cached.
-"""
+"""Verifies TF32 leak fix (off after max is byte-identical), default speedup and balanced parity."""
from __future__ import annotations
diff --git a/scripts/prequant_probe.py b/scripts/prequant_probe.py
index ffad88b917a..1d90a9664c4 100644
--- a/scripts/prequant_probe.py
+++ b/scripts/prequant_probe.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Does a *pre-quantized* checkpoint fix the dense-quant load-VRAM spike?
-
-The current fast-transformer path materialises the dense bf16 transformer on the GPU
-and quantises it in place -> ~2x the GGUF load peak. This probe checks the fix: quantise
-once, ``torch.save`` the quantized state dict, then load it onto an empty (meta) model
-with ``load_state_dict(assign=True)`` so the bf16 never touches the GPU.
-
-Modes (run each in its own process so peak VRAM is clean):
- build -- load dense bf16, quantize_ fp8, torch.save the state dict + on-disk size.
- baseline -- current path: from_pretrained bf16 -> quantize_ on GPU. Report load peak + gen.
- prequant -- meta-init -> load_state_dict(saved, assign=True) -> cuda. Report load peak + gen.
-
-Run on one CUDA (Blackwell) GPU. Reference image for LPIPS is the baseline path."""
+"""Tests whether a pre-quantized checkpoint (assign=True onto meta) avoids the bf16 GPU load spike."""
from __future__ import annotations
diff --git a/scripts/quant_probe.py b/scripts/quant_probe.py
index bf50fe776ef..7be8119ba14 100644
--- a/scripts/quant_probe.py
+++ b/scripts/quant_probe.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Empirical quant probe: torchao int8/fp8/fp4 dynamic quant vs GGUF+compile.
-
-Question this answers: GGUF stores the Z-Image DiT at 4-bit but dequantizes to bf16
-per matmul, so it runs at bf16 tensor-core rate. Can a low-precision *tensor-core*
-path (int8dq on any Ampere+, fp8dq on Ada+, NVFP4/MXFP8 on Blackwell), loaded from
-the dense bf16 transformer, beat GGUF+compile on speed while staying inside the
-quality bar -- and how does its quality compare to GGUF's own 4-bit loss?
-
-Reference for all quality numbers is the DENSE bf16 EAGER image (the best this model
-can do). Each config is a fresh pipeline (no compile/quant cross-contamination).
-Reports median latency, PSNR + LPIPS vs reference, and peak VRAM. Run on one CUDA GPU.
-"""
+"""Compares torchao int8/fp8/fp4 dynamic quant with GGUF+compile, scored against dense bf16 eager."""
from __future__ import annotations
diff --git a/scripts/run_ruff_format.py b/scripts/run_ruff_format.py
index e2cebd02803..d8cc8770444 100755
--- a/scripts/run_ruff_format.py
+++ b/scripts/run_ruff_format.py
@@ -1,11 +1,5 @@
#!/usr/bin/env python3
-"""Run `ruff-unsloth format`, then the string-merge / redundant-pass post-pass.
-
-ruff-unsloth (https://github.com/unslothai/ruff) is ruff 0.6.9 patched to write the
-repo's kwarg spacing, def-signature and short-assert magic-comma rules and the
-nested-import blank-line rule itself, so the only Python left is
-scripts/enforce_kwargs_spacing.py --residual, which skips every file that cannot
-need it."""
+"""Runs ruff-unsloth format, then enforce_kwargs_spacing.py --residual, which skips unneeded files."""
from __future__ import annotations
diff --git a/scripts/scan_npm_packages.py b/scripts/scan_npm_packages.py
index 256246e2751..48d9805d41e 100644
--- a/scripts/scan_npm_packages.py
+++ b/scripts/scan_npm_packages.py
@@ -3,35 +3,9 @@
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
# security-audit.yml's npm-scan-packages job depends on this path.
-"""scan_npm_packages.py -- npm-side content scanner.
-
-npm counterpart to scripts/scan_packages.py. Reads
-studio/frontend/package-lock.json, downloads each resolved tarball
-DIRECTLY from registry.npmjs.org (never via `npm install` -- no
-lifecycle scripts run), verifies the lockfile integrity hash, unpacks
-each into a sandboxed temp dir behind size/count/path-escape/symlink
-guards, and pattern-scans extracted contents for npm supply-chain
-attack signatures: malicious lifecycle scripts, C2 / exfil hosts,
-credential-stealing references, known IOC filenames, and obfuscation
-shapes.
-
-Safety stance (ingests attacker-controlled archives; assumes worst):
- 1. Downloads ONLY from registry.npmjs.org; other hosts refused.
- 2. Tarball download size-capped via Content-Length probe + chunked
- read that aborts on overflow.
- 3. SHA-512 integrity verified against the lockfile entry BEFORE the
- tarball is opened; mismatch aborts that package (no fallback).
- 4. tar extraction via `safe_extract`: rejects symlinks, absolute /
- `..` paths, device files; enforces per-file, cumulative, and
- member-count caps; streams (`r|gz`) so oversize is caught early.
- 5. NOTHING extracted is executed -- files are read as bytes and
- grepped only.
- 6. Tempdir resolved and atexit-wiped on every termination path.
- 7. Stdlib only (a dep would be a supply-chain liability itself).
-
-Exit codes: 0 = no HIGH+ findings; 1 = HIGH/CRITICAL or pre-scan
-structural anomaly; 2 = internal error. Run in CI per-PR and nightly.
-"""
+"""Scans npm lockfile tarballs for IOCs without running them; downloads only from
+registry.npmjs.org; SHA-512 checked before opening, mismatch aborts; safe_extract guards; stdlib
+only; exit 1 on HIGH+."""
from __future__ import annotations
diff --git a/scripts/sd_cpp_smoke.py b/scripts/sd_cpp_smoke.py
index 3eeb8b1eb29..f67b2b1b634 100644
--- a/scripts/sd_cpp_smoke.py
+++ b/scripts/sd_cpp_smoke.py
@@ -1,23 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""End-to-end smoke for the native stable-diffusion.cpp engine.
-
-Drives the real ``SdCppEngine`` over a built ``sd-cli`` and a set of split GGUF
-assets (the same the diffusers path consumes), running one txt2img generation
-and reporting wall time. This is the GPU/native analogue of
-``scripts/diffusion_bench.py``: it proves the engine wiring (finder -> command
-builder -> subprocess -> output PNG) works against real weights.
-
-Example (Z-Image-Turbo on one GPU):
-
- SD_CLI_PATH=.../sd-cli CUDA_VISIBLE_DEVICES=6 python scripts/sd_cpp_smoke.py \\
- --family z-image \\
- --diffusion-model .../z-image-turbo-Q4_K_M.gguf \\
- --vae .../ae.safetensors \\
- --llm .../Qwen3-4B-Instruct-2507-Q4_K_M.gguf \\
- --memory-mode balanced --steps 8 --cfg-scale 1.0 --width 512 --height 512
-"""
+"""Real-weights txt2img smoke for SdCppEngine and sd-cli; needs a GPU and split GGUF assets."""
from __future__ import annotations
diff --git a/scripts/sdpa_mask_backend_probe.py b/scripts/sdpa_mask_backend_probe.py
index 87c62163814..e60ad6b1ffb 100644
--- a/scripts/sdpa_mask_backend_probe.py
+++ b/scripts/sdpa_mask_backend_probe.py
@@ -1,9 +1,7 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which SDPA backends tolerate a dense bool attn_mask, and at what cost, at Hunyuan's real
-joint shape (B=1, H=16, N=50345, D=128, bf16)? Decides whether nulling the all-True mask is
-the real win on the PRODUCTION cuDNN path (not just the native math fallback)."""
+"""Checks whether nulling an all-True attn_mask helps SDPA on the production cuDNN path."""
import time
import torch
diff --git a/scripts/sparse_accum_probe.py b/scripts/sparse_accum_probe.py
index 2acb50e704c..3d6fb11cc51 100644
--- a/scripts/sparse_accum_probe.py
+++ b/scripts/sparse_accum_probe.py
@@ -1,20 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Probe two consumer-GPU-motivated levers on the real dense Z-Image transformer:
-
- * fp8 fast_accum on/off -- on consumer Blackwell, fp8 with FP16 accumulate is ~2x
- fp8 with FP32 accumulate (838 vs 419 TFLOPS). torchao defaults use_fast_accum=True,
- so this confirms we are already on the fast path and quantifies it (muted on a B200,
- which is not nerfed, but the knob still moves latency).
- * 2:4 semi-structured sparsity -- doubles tensor-core rate in theory. Two blockers to
- test empirically: (a) QUALITY -- inference-only 2:4 magnitude-pruning drops 50% of
- weights with no fine-tune; (b) it does NOT compose with torch.compile, so the real
- sparse path runs eager. We measure sparse-no-compile speed vs our fp8+compile
- baseline (the bar it must beat) and the LPIPS of 2:4 pruning.
-
-Reference for quality is the dense bf16 eager image. Run on one CUDA GPU.
-"""
+"""Probes fp8 fast_accum and 2:4 sparsity on Z-Image; 2:4 is eager-only and lossy without fine-tuning."""
from __future__ import annotations
diff --git a/scripts/sync_shared_ps1_helpers.py b/scripts/sync_shared_ps1_helpers.py
index d21df9210a0..1b140cf4fd0 100644
--- a/scripts/sync_shared_ps1_helpers.py
+++ b/scripts/sync_shared_ps1_helpers.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Copy the shared Windows preflight helpers from install.ps1 into studio/setup.ps1.
-
-install.ps1 has to run standalone, before any repo exists, so it cannot dot-source
-setup.ps1 and instead carries byte-identical copies of a handful of helpers.
-tests/studio/install/test_denied_llama_cpp_preflight.py fails when the two drift.
-Editing one and running this keeps them together, rather than hand-copying and
-finding out from CI.
-
-Usage:
- python3 scripts/sync_shared_ps1_helpers.py [--check]
-
---check exits 1 without writing when setup.ps1 is out of date, for use in CI.
-"""
+"""Syncs byte-identical helpers from install.ps1 into studio/setup.ps1; --check exits 1 on drift."""
from __future__ import annotations
diff --git a/scripts/verify_comment_only_diff.py b/scripts/verify_comment_only_diff.py
index b2bb695d39f..d487d3029a5 100644
--- a/scripts/verify_comment_only_diff.py
+++ b/scripts/verify_comment_only_diff.py
@@ -9,30 +9,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
-"""Deterministic comment / docstring-only verifier.
-
-Compares a list of changed files between two git refs and reports whether
-each diff is strictly comments / docstrings (Python) or comments
-(YAML / GitHub Actions). Useful for gating a "comment trim" /
-"docstring refactor" PR against accidental code drift.
-
-Per .py file: parse both revs into AST, strip module / class / function
-docstrings, then compare ast.unparse output. Pure Python comments are
-discarded by the parser by construction, so any post-strip diff is real
-code. Per .yml file: yaml.safe_load both sides and compare the parsed
-Python object; if scalar values differ, also strip shell comments inside
-``run: |`` block bodies before comparing. Exit code 0 = all OK, 1 = at
-least one file has a real (non-comment) diff or an error.
-
-Usage:
- python scripts/verify_comment_only_diff.py [--base REF] [--head REF] path ...
-
-Defaults: --base origin/main, --head HEAD. Paths are repo-relative.
-
-Example:
- git diff --name-only origin/main..HEAD \\
- | xargs python scripts/verify_comment_only_diff.py --base origin/main
-"""
+"""Verifies a git diff changes only comments/docstrings (AST compare for .py, YAML compare for .yml)."""
from __future__ import annotations
diff --git a/scripts/verify_import_hoist.py b/scripts/verify_import_hoist.py
index c6d90545e95..f7821d5fdd7 100644
--- a/scripts/verify_import_hoist.py
+++ b/scripts/verify_import_hoist.py
@@ -1,46 +1,7 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Deterministic, scope-aware verifier for import-hoisting / alias-rename refactors.
-
-The risk when moving `from a import b as _b` (or `import b as _b`) to module top
-and normalizing `_b` -> `b` is twofold:
-
- 1. DANGLING ALIAS - a `_b` reference is left un-normalized; it now resolves to
- nothing (NameError) or, worse, to some *other* module-level `_b`.
- 2. RENAME CLASH - `_b` was an alias on purpose because `b` already meant
- something else in that scope; normalizing `_b` -> `b` silently re-points the
- reference at the wrong object (no NameError, no pyflakes warning).
-
-This tool parses BEFORE (a git ref, default origin/main) and AFTER (default HEAD)
-for each file, builds a real LEGB scope model (functions, classes, lambdas,
-comprehensions, global/nonlocal, args, walrus, star-imports), and resolves every
-Name load to its binding. It then compares, PER SCOPE:
-
- * UNRESOLVED-NEW : loads that resolve to nothing in AFTER but did in BEFORE
- (or are newly present) -> catches dangling aliases.
- * TARGET-MISSING : an import *target* (e.g. module `glob`, or
- `importlib.metadata.version`) that a function resolved to
- in BEFORE but no longer resolves to in AFTER -> catches a
- function that lost access to a module it still uses.
- Robust to alias renames because it compares the *target*,
- not the local name.
- * TARGET-CHANGED : a load whose resolved import target differs BEFORE vs
- AFTER -> catches a rename that re-points to a different
- module (the clash case).
- * AMBIGUOUS-BIND : a name bound by BOTH an import and a non-import in the same
- scope in AFTER (and not in BEFORE) -> the "alias was on
- purpose / now collides" smell.
- * MODULE-DUP-IMPORT: a module-level name imported and also defined/assigned at
- module level (introduced by the change).
- * NEW-UNUSED-IMPORT: a module-level import added in AFTER that nothing resolves
- to (informational; re-exports are a known false positive).
-
-Usage:
- verify_import_hoist.py [--before REF] [--after REF] <file>... # compare
- verify_import_hoist.py --self-test # prove it catches bugs
-Exit code 1 if any non-informational finding.
-"""
+"""Scope-aware check for dangling aliases and silent rename clashes in import hoists (_b -> b)."""
from __future__ import annotations
diff --git a/scripts/verify_prequant_backend.py b/scripts/verify_prequant_backend.py
index cb7e513c56a..f17be80ecb3 100644
--- a/scripts/verify_prequant_backend.py
+++ b/scripts/verify_prequant_backend.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GPU verification of the Phase 9 pre-quantized load path through the real backend code.
-
-Exercises the actual product functions (``load_prequantized_transformer`` and the runtime
-``quantize_transformer``), not a reimplementation:
-
- prequant -- load the checkpoint built by build_prequant_checkpoint.py via the real
- ``load_prequantized_transformer`` (meta-init + assign), measure GPU load peak,
- generate.
- runtime -- the existing path: from_pretrained dense bf16 -> ``quantize_transformer`` on
- device, measure GPU load peak, generate (the LPIPS reference).
-
-Asserts the prequant load peak is far below the dense one and the images match (LPIPS ~0).
-Run each mode in its own process for a clean peak. One CUDA GPU."""
+"""Asserts pre-quantized load peak memory is far below runtime quantize and images match (LPIPS ~0)."""
from __future__ import annotations
diff --git a/studio/backend/_platform_compat.py b/studio/backend/_platform_compat.py
index 0cc6adf510e..ec8eafecf96 100644
--- a/studio/backend/_platform_compat.py
+++ b/studio/backend/_platform_compat.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Import before structlog/rich: Anaconda's ``|...|`` metadata in sys.version makes
-platform._sys_version() raise (cpython#102396, wontfix), so seed its cache first."""
+"""Import before structlog/rich to seed platform's cache; Anaconda's sys.version breaks _sys_version()."""
import platform
import re
diff --git a/studio/backend/auth/bootstrap_timeout.py b/studio/backend/auth/bootstrap_timeout.py
index b974231a265..be88bddfdc3 100644
--- a/studio/backend/auth/bootstrap_timeout.py
+++ b/studio/backend/auth/bootstrap_timeout.py
@@ -1,17 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Auto-shutdown for an exposed first-run Unsloth whose admin password is unchanged.
-
-On a fresh install the seeded bootstrap admin password stays a valid login credential until first login changes
-it. When the web UI is put on the network (``--secure`` / ``0.0.0.0``) and nobody completes that first-login
-change within a deadline, tear Unsloth down so a fresh, unconfigured instance does not stay publicly reachable
-indefinitely. If the password was changed, Unsloth keeps running.
-
-Scope: web UI launches only (never ``--api-only``, which authenticates by API key rather than the admin
-password, and never Colab). Configurable via ``UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT`` (seconds; default 3600; ``0``
-disables).
-"""
+"""Shuts down an exposed UI still on its bootstrap password after a deadline; web UI only, never
+--api-only or Colab; UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT (default 3600, 0 disables)."""
import os
import sys
diff --git a/studio/backend/auth/terminal_prompt.py b/studio/backend/auth/terminal_prompt.py
index eec5c2243c8..62e5f3a6e24 100644
--- a/studio/backend/auth/terminal_prompt.py
+++ b/studio/backend/auth/terminal_prompt.py
@@ -1,15 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Interactive terminal prompt that forces a bootstrap password change before
-Unsloth becomes reachable: a public Cloudflare URL (``--secure`` / ``--cloudflare``)
-or a raw non-loopback bind such as ``-H 0.0.0.0``.
-
-Masked input echoes one ``*`` per keystroke (unlike ``getpass``). Works on Windows (``msvcrt``) and Linux/macOS
-(``termios``). All output goes to stderr so redirected stdout never swallows the prompt. Mirrored for the CLI at
-``unsloth_cli/commands/_password_prompt.py`` (the CLI cannot import the Unsloth backend package); keep the two
-in sync.
-"""
+"""Forces bootstrap password change before public exposure; all prompt output to stderr; keep
+unsloth_cli copy in sync (CLI cannot import backend)."""
from __future__ import annotations
diff --git a/studio/backend/auth/x_api_key.py b/studio/backend/auth/x_api_key.py
index 9b7ab25c058..3edf9bf9aee 100644
--- a/studio/backend/auth/x_api_key.py
+++ b/studio/backend/auth/x_api_key.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Accept an sk-unsloth key in ``x-api-key``, the header Anthropic clients send (SDKs, the Microsoft 365
-add-ins). Rewritten to a Bearer before anything runs, so every ``Authorization`` reader (auth dependency,
-keyless classifier, keep-warm, MCP) sees one credential instead of learning a second scheme."""
+"""Rewrites an sk-unsloth key from x-api-key into a Bearer Authorization header before auth runs."""
from __future__ import annotations
diff --git a/studio/backend/cloudflare_tunnel.py b/studio/backend/cloudflare_tunnel.py
index 1aefaef4bf3..50d1595a44d 100644
--- a/studio/backend/cloudflare_tunnel.py
+++ b/studio/backend/cloudflare_tunnel.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Free Cloudflare quick tunnel for Unsloth's 0.0.0.0 launches.
-
-The raw http://<ip>:<port> is often unreachable (https-vs-http, blocked ports, closed security groups); a
-cloudflared quick tunnel gives a free https://*.trycloudflare.com URL that works anywhere, with no account or
-domain. Best-effort throughout: any failure collapses to "no URL" and Unsloth keeps running. Stdlib only
-(back-end imports are lazy) so it is safe to import early.
-"""
+"""Cloudflared quick tunnel for 0.0.0.0 launches; best-effort, failure gives no URL and Unsloth
+keeps running; stdlib only, lazy backend imports, safe to import early."""
from __future__ import annotations
diff --git a/studio/backend/core/_msvc_env.py b/studio/backend/core/_msvc_env.py
index aedbefb1d8d..dab7dd6ec00 100644
--- a/studio/backend/core/_msvc_env.py
+++ b/studio/backend/core/_msvc_env.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Gate torch.compile on Triton's C toolchain, on Windows (#7595). `import triton` succeeding does not
-mean a compile will: Triton's clang-cl JIT dies on `'stdlib.h'` mid-run when the CRT headers are absent.
-It passes its own `/I` dirs and never reads `INCLUDE`, so there is nothing to repair, only a state to refuse."""
+"""Gates torch.compile on Windows: triton imports without CRT headers, and clang-cl ignores INCLUDE."""
from __future__ import annotations
diff --git a/studio/backend/core/_torchao_stub.py b/studio/backend/core/_torchao_stub.py
index 53cc40bbc48..e690fc93d87 100644
--- a/studio/backend/core/_torchao_stub.py
+++ b/studio/backend/core/_torchao_stub.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Shared Windows-ROCm import stubs.
-
-torchao (pulled in by transformers.quantizers) imports distributed_c10d.py
-unconditionally, which crashes on Windows ROCm because the RCCL backend
-(torch._C._distributed_c10d) is absent. Stubbing torchao short-circuits its
-import chain; _StubSubpackageFinder handles any depth of torchao.xxx.yyy.
-Worker subprocesses call install_torchao_windows_rocm_stub() before importing
-transformers / unsloth_zoo.
-
-xformers hits the same absent backend and takes diffusers with it, so the diffusion paths
-install both stubs before importing diffusers. They also hide an xformers built for a newer
-torch than the venv has, which fails the same import on any platform.
-"""
+"""Stubs torchao and xformers on Windows ROCm, which lack RCCL; install before transformers/diffusers."""
from __future__ import annotations
diff --git a/studio/backend/core/_xpu_triton_toolchain.py b/studio/backend/core/_xpu_triton_toolchain.py
index 71a74db455b..5fc50054fd6 100644
--- a/studio/backend/core/_xpu_triton_toolchain.py
+++ b/studio/backend/core/_xpu_triton_toolchain.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Windows XPU Triton builds its helpers with icpx, else cl, else $CXX, and uses MSVC flags only when
-the path contains `cl.EXE`; Studio is not started from a Developer Prompt, so load vcvars and hand it
-`cl.EXE`, plus the Level Zero SDK the helpers link against (#14807)."""
+"""Windows XPU Triton tries icpx, then cl, then $CXX; MSVC flags only for cl.EXE; Studio loads
+vcvars and hands it cl.EXE plus the Level Zero SDK."""
from __future__ import annotations
diff --git a/studio/backend/core/chat_originals.py b/studio/backend/core/chat_originals.py
index 959398bbf50..87b8bab0618 100644
--- a/studio/backend/core/chat_originals.py
+++ b/studio/backend/core/chat_originals.py
@@ -1,18 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The original files of documents sent in chat.
-
-A chat keeps a document's extracted text for the model; the file itself (a PDF, a Word document, a
-workbook or a deck) is kept here so it can be opened as it looked. Each is stored once under its
-SHA-256, which the attachment records as ``{"original": {"sha256", "sizeBytes"}}``: a fork or an
-import copies the reference, never the bytes, and a retried send stores nothing new. While the python
-tool runs, any other attached file is kept too, so the tool can be handed a copy.
-
-A file no attachment references any more is removed by ``sweep``, once it is older than an hour, so
-one uploaded moments before its message is saved is never taken. A sweep that leaves such a file for
-being too new schedules another for when it is not.
-"""
+"""Original chat document files keyed by SHA-256; sweep removes unreferenced ones older than an
+hour, so a just-uploaded file is never removed."""
from __future__ import annotations
diff --git a/studio/backend/core/export/__init__.py b/studio/backend/core/export/__init__.py
index f7241cd925b..18202dc7ecc 100644
--- a/studio/backend/core/export/__init__.py
+++ b/studio/backend/core/export/__init__.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Export submodule - model export operations.
-
-get_export_backend() returns an ExportOrchestrator that delegates to a
-subprocess. The original ExportBackend runs inside the subprocess and can be
-imported directly from .export when needed.
-"""
+"""get_export_backend() returns ExportOrchestrator; the real ExportBackend runs in a subprocess."""
from .orchestrator import ExportOrchestrator, get_export_backend
diff --git a/studio/backend/core/export/decision.py b/studio/backend/core/export/decision.py
index 06176df7724..c1adf8a6c47 100644
--- a/studio/backend/core/export/decision.py
+++ b/studio/backend/core/export/decision.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GGUF export of decision models (Clef, Laya) for the Export page.
-
-The server side (``decision_preview``) only reads files: the parent process must not import
-unsloth. The worker side (``run_decision_gguf_export``) calls unsloth.models.decision_gguf,
-whose ``gguf_eligibility`` is the authoritative gate.
-"""
+"""Decision-model GGUF export; server must not import unsloth; worker's gguf_eligibility is the gate."""
import json
from pathlib import Path
diff --git a/studio/backend/core/export/drafter_export.py b/studio/backend/core/export/drafter_export.py
index 1368b209ce0..97dec6cef60 100644
--- a/studio/backend/core/export/drafter_export.py
+++ b/studio/backend/core/export/drafter_export.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Carry a drafter trained with the fine-tune (core/training/drafter.py) into merged and GGUF exports.
-
-The MTP head needs no copying: the export reload re-attaches `mtp_head.safetensors` and the merged / GGUF
-savers stitch it. An EAGLE-3 drafter is a separate model, copied next to the export. Each export gets a
-`drafter.json` saying how to serve the pair; Studio's llama-server launcher reads it beside a GGUF.
-"""
+"""EAGLE-3 drafters copied beside exports; MTP heads re-attach on reload; drafter.json for serving."""
from __future__ import annotations
diff --git a/studio/backend/core/export/orchestrator.py b/studio/backend/core/export/orchestrator.py
index 6b73333531d..cf508361a9b 100644
--- a/studio/backend/core/export/orchestrator.py
+++ b/studio/backend/core/export/orchestrator.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Export orchestrator: same API as ExportBackend, but delegates all ML work to a persistent
-subprocess spawned on first checkpoint load and reused for later exports. Switching between
-checkpoints that need different transformers versions kills the old subprocess and spawns a new
-one. Pattern follows core/inference/orchestrator.py."""
+"""Same API as ExportBackend; ML runs in a subprocess respawned on transformers version change."""
from core.training.account_jobs import (
account_process_spec,
diff --git a/studio/backend/core/export/q4nx.py b/studio/backend/core/export/q4nx.py
index 192d75b7133..8e466e5ef8c 100644
--- a/studio/backend/core/export/q4nx.py
+++ b/studio/backend/core/export/q4nx.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""FastFlowLM Q4NX output for the AMD Ryzen AI NPU (XDNA 2).
-
-Kept free of torch/unsloth imports: the backend process converts an existing GGUF directly,
-without loading a model into the export worker.
-"""
+"""FastFlowLM Q4NX for AMD Ryzen AI NPUs; no torch/unsloth imports, converts GGUF directly."""
from __future__ import annotations
diff --git a/studio/backend/core/external_import/__init__.py b/studio/backend/core/external_import/__init__.py
index 9c60d705b78..5aff284fe61 100644
--- a/studio/backend/core/external_import/__init__.py
+++ b/studio/backend/core/external_import/__init__.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Import another tool's local conversations into Studio, one Studio project per source project.
-
-Re-imports are how new turns arrive, so whatever the user changed in Studio wins: titles,
-project placement, archived flags, edited or deleted messages, deleted chats.
-"""
+"""Imports other tools' local chats, one project each; re-imports keep user edits in Studio."""
from __future__ import annotations
diff --git a/studio/backend/core/external_import/codex.py b/studio/backend/core/external_import/codex.py
index 569e8b387c2..2acd5c0fa0a 100644
--- a/studio/backend/core/external_import/codex.py
+++ b/studio/backend/core/external_import/codex.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Codex: ``$CODEX_HOME/sessions/YYYY/MM/DD/rollout-<ts>-<id>.jsonl[.zst]``, grouped by ``session_meta.cwd``.
-
-Lines are ``{timestamp, type, payload}`` (codex-rs ``RolloutLine``). Text comes from the
-``user_message`` / ``agent_message`` events, which is what Codex's own thread history replays:
-the ``response_item`` user messages also carry injected AGENTS.md / environment context.
-"""
+"""Codex text comes from user_message/agent_message events, not response_item (injected context)."""
from __future__ import annotations
diff --git a/studio/backend/core/external_import/cursor.py b/studio/backend/core/external_import/cursor.py
index 9303fd8a91e..385bbb6b6d1 100644
--- a/studio/backend/core/external_import/cursor.py
+++ b/studio/backend/core/external_import/cursor.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Cursor: ``~/.cursor/projects/<slug>/agent-transcripts/<session>[/<session>].jsonl``.
-
-Cursor stores no tool results or per-line timestamps, so calls import without ``result``
-and times are file creation + 1 ms per message (as the frontend does).
-"""
+"""Cursor transcripts lack tool results and timestamps; times are file creation plus 1 ms per message."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/_html_to_md.py b/studio/backend/core/inference/_html_to_md.py
index d3ea9adef20..75cfe476815 100644
--- a/studio/backend/core/inference/_html_to_md.py
+++ b/studio/backend/core/inference/_html_to_md.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""
-Minimal HTML-to-Markdown converter using only the standard library.
-
-Replaces the external ``html2text`` (GPL-3.0) dependency with a ~250-line
-``html.parser.HTMLParser`` subclass. Covers headings, links, bold/italic,
-lists, tables, blockquotes, code blocks, and entity decoding.
-
-``main_content=True`` also applies a readability-style heuristic: scope
-conversion to the page's ``<article>`` (else ``<main>``) subtree when it
-carries substantial text, and strip known boilerplate fragments (skip-links,
-error placeholders, session banners, cookie prompts) from the result.
-"""
+"""Stdlib HTML-to-Markdown (replaces GPL html2text); main_content=True scopes to article/main."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/anthropic_compat.py b/studio/backend/core/inference/anthropic_compat.py
index 790f388d37a..9a153845849 100644
--- a/studio/backend/core/inference/anthropic_compat.py
+++ b/studio/backend/core/inference/anthropic_compat.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""
-Anthropic Messages API ↔ OpenAI format translation utilities.
-
-Pure functions plus stateful stream emitters; no FastAPI, no I/O.
-"""
+"""Anthropic Messages <-> OpenAI format translation; pure functions and stream emitters, no I/O."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_codecs.py b/studio/backend/core/inference/audio_codecs.py
index 5b6e1dfc0c4..9d1f0969545 100644
--- a/studio/backend/core/inference/audio_codecs.py
+++ b/studio/backend/core/inference/audio_codecs.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""
-Audio codec loading and decoding for TTS inference.
-Supports: SNAC (Orpheus), CSM (Sesame), BiCodec (Spark), DAC (OuteTTS)
-"""
+"""Loads and decodes TTS audio codecs: SNAC (Orpheus), CSM (Sesame), BiCodec (Spark), DAC (OuteTTS)."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_backend.py b/studio/backend/core/inference/audio_cpp_backend.py
index 07c8af80a65..807f4e360dd 100644
--- a/studio/backend/core/inference/audio_cpp_backend.py
+++ b/studio/backend/core/inference/audio_cpp_backend.py
@@ -1,18 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Worker backend for audio.cpp speech, music and separation models in the main audio slot.
-
-Selected by the inference worker in place of ``NativeAudioBackend`` when the model
-is an audio.cpp TTS or music GGUF, so loading, auto-switching, idle eviction,
-cancellation and the Audio page, read-aloud and ``/v1/audio/speech`` all work
-through the machinery every other main-slot audio model uses. The weights run in
-an ``audiocpp_server`` child; this class only downloads, starts, proxies and stops.
-
-A cancelled request cannot interrupt GPU work already queued inside the server, and
-the server would make the next request wait for it (minutes, for music). So a cancel
-stops the server and the next request starts it again from the warm file cache.
-"""
+"""Worker backend for audio.cpp speech, music and separation models in the main audio slot, used in
+place of NativeAudioBackend; weights run in an audiocpp_server child. A cancel stops that server
+(queued GPU work cannot be interrupted); the next request restarts it from the warm file cache."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_catalog.py b/studio/backend/core/inference/audio_cpp_catalog.py
index ac31e2eff76..c11a1e5bd10 100644
--- a/studio/backend/core/inference/audio_cpp_catalog.py
+++ b/studio/backend/core/inference/audio_cpp_catalog.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The audio.cpp models Unsloth Studio can offer and the Audio pages each runs on: every umbrella
-folder, plus the Community repos the runtime's ``model_specs/`` download from. Public data only.
-"""
+"""audio.cpp models Studio offers and the Audio pages each runs on: umbrella folders plus Community
+repos the runtime's model_specs/ pulls from; public data only."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_failures.py b/studio/backend/core/inference/audio_cpp_failures.py
index 39c93a92ed9..45d2c1c8658 100644
--- a/studio/backend/core/inference/audio_cpp_failures.py
+++ b/studio/backend/core/inference/audio_cpp_failures.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Known audio.cpp failures, named so a client can offer the fix. Raw runtime text is only
-classified, never returned: any runtime detail in a message goes through ``sanitize_runtime_tail``."""
+"""Known audio.cpp failures, named so clients can offer a fix; raw runtime text is only classified,
+never returned, and details go through sanitize_runtime_tail."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_files.py b/studio/backend/core/inference/audio_cpp_files.py
index 148241b6063..30cc3c653ea 100644
--- a/studio/backend/core/inference/audio_cpp_files.py
+++ b/studio/backend/core/inference/audio_cpp_files.py
@@ -1,18 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Where an audio.cpp model's files live, and how audio.cpp is shown them.
-
-The weights are ordinary Hub files in the shared HF cache, downloaded like any GGUF
-variant, so the Model Hub, Download Manager and deletion all see them. audio.cpp,
-however, picks a loader by file extension after resolving symlinks, and an HF cache
-snapshot entry is a symlink to an extension-less blob, so it cannot be handed the
-snapshot path. ``materialize`` hardlinks the variant's files under their real names
-into a small link farm beside the hub cache (same volume, so no copy and no extra
-disk). A cache without symlinks already stores real files and is used as is, except
-on Windows, where every model goes through the farm's short per-model path: the
-Windows server cannot open a path of 260 characters or more.
-"""
+"""Weights are HF cache files (Model Hub and deletion see them); materialize hardlinks them by real
+name into a farm beside the cache, since audio.cpp picks loaders by extension after resolving
+symlinks. Real-file caches skip it, except on Windows, where the short farm path avoids the
+260-char limit."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_models.py b/studio/backend/core/inference/audio_cpp_models.py
index e586f4ec563..c46669ce007 100644
--- a/studio/backend/core/inference/audio_cpp_models.py
+++ b/studio/backend/core/inference/audio_cpp_models.py
@@ -1,24 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Recognise a GGUF that audio.cpp runs, and work out what Studio needs to run it.
-
-Every GGUF audio.cpp writes declares ``general.architecture = "audiocpp"`` and, in
-most cases, names its loader in ``audiocpp.model_spec.family`` and embeds the full
-model spec in ``audiocpp.model_spec.json``. The server has no auto-detection, so
-Studio reads the family itself and hands it over together with a runtime task token.
-
-A model is any Hub repo (or local file) holding such GGUFs. The ``audio-cpp/audio.cpp-gguf``
-repo publishes many models side by side, one per top-level folder, so a model there is
-named by three segments (``audio-cpp/audio.cpp-gguf/Kokoro-82M-GGUF``); three segments
-cannot collide with a real ``owner/name`` repo id. Variants are the quants in that repo
-or folder, like any llama.cpp GGUF repo. A few families (MiniMax Music 3, YuE2) are
-packages of several GGUFs plus config files that load as one directory; their variants
-are the component mixes the package defines.
-
-Everything that needs the repo, the files, the family or the variant goes through
-``resolve``; nothing else parses the id.
-"""
+"""Models are Hub repos or local files of audiocpp GGUFs (general.architecture); variants are
+quants, or component mixes for packages like YuE2. audio-cpp/audio.cpp-gguf models take three-
+segment ids. Studio reads audiocpp.model_spec.family (the server cannot detect it). Only
+resolve() parses ids."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_music.py b/studio/backend/core/inference/audio_cpp_music.py
index db6e5a18a09..723ca3941d2 100644
--- a/studio/backend/core/inference/audio_cpp_music.py
+++ b/studio/backend/core/inference/audio_cpp_music.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""audio.cpp music request bodies for ``/audio/generate`` and ``/audio/run``.
-
-A strict spec (``schema_version``) refuses undeclared options, so the CLI's top-level shortcuts
-(``duration_seconds``, ``lyrics``) are sent to it only as declared options. MiniMax keeps its old
-body: its session reads both duration keys.
-"""
+"""audio.cpp music request bodies for /audio/generate and /audio/run. A strict schema_version spec
+refuses undeclared options, so duration_seconds and lyrics go only as declared options; MiniMax
+keeps its old body, since its session reads both duration keys."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_option_table.py b/studio/backend/core/inference/audio_cpp_option_table.py
index 7a46025486c..89defab3561 100644
--- a/studio/backend/core/inference/audio_cpp_option_table.py
+++ b/studio/backend/core/inference/audio_cpp_option_table.py
@@ -1,19 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-model request options and recommended values for the pinned audio.cpp runtime.
-
-The published GGUFs often embed a spec older than the runtime, and some families declare no request
-options at all even though their loaders read them. ``STUDIO_OPTION_LISTS`` names the options such a
-family reads; it is used only when neither the runtime nor the GGUF declares any. ``OPTION_RULES`` then
-adjusts whichever list a model ends up with: the value Unsloth Studio recommends (shown in Advanced
-and sent when the user leaves it alone), tighter bounds, and options a workflow has no use for.
-
-Recommended values come from audio.cpp's own web UI table (``webui/configs/model_params.json``),
-else the runtime's default in the C++ loader, else the upstream model card; each one names its source.
-A default of ``None`` sends nothing, for options the runtime works out per request. The table holds
-only for the tags it was checked against.
-"""
+"""STUDIO_OPTION_LISTS: options a family's loader reads, used only if neither runtime nor GGUF
+declares any. OPTION_RULES: recommended values (a None default sends nothing), bounds, unused
+options; from webui/configs/model_params.json, else C++ loader default, else model card. Only for
+checked tags."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_outputs.py b/studio/backend/core/inference/audio_cpp_outputs.py
index 46aefbfbe7a..e21c15efc8e 100644
--- a/studio/backend/core/inference/audio_cpp_outputs.py
+++ b/studio/backend/core/inference/audio_cpp_outputs.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Stems out of a saved separation answer, decoded in chunks from an mmap.
-
-Not ``json.loads``: ~42 MB of base64 per stem for a 180 s track would be held three times over.
-"""
+"""Stems from a saved separation answer, base64-decoded in chunks from an mmap; json.loads would
+hold ~42 MB of base64 per 180 s stem three times over."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_cpp_server.py b/studio/backend/core/inference/audio_cpp_server.py
index 47c3303d2a7..2473f3bc2a3 100644
--- a/studio/backend/core/inference/audio_cpp_server.py
+++ b/studio/backend/core/inference/audio_cpp_server.py
@@ -1,18 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One ``audiocpp_server`` child process serving one audio.cpp model.
-
-Shared by the dictation sidecar (speech to text) and the audio worker (speech and
-music), which each own an instance. The server is bound to 127.0.0.1 on an
-ephemeral port and configured with exactly one model under a per-launch random id,
-so the readiness probe can tell our child from any other process that won the bind
-race: it must answer ``/health`` and list that id in ``/v1/models``.
-
-Binary discovery mirrors whisper.cpp's: ``AUDIOCPP_SERVER_PATH`` (the binary),
-``UNSLOTH_AUDIO_CPP_PATH`` (an install dir), the managed ``<UNSLOTH_HOME>/audio.cpp``
-tree ``install_audio_cpp_prebuilt.py`` writes, then PATH.
-"""
+"""One audiocpp_server child per model on 127.0.0.1 with a random per-launch id; ready only if
+/health answers and /v1/models lists that id (so a bind-race rival fails). Binary:
+AUDIOCPP_SERVER_PATH, UNSLOTH_AUDIO_CPP_PATH, <UNSLOTH_HOME>/audio.cpp (from
+install_audio_cpp_prebuilt.py), then PATH."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_device.py b/studio/backend/core/inference/audio_device.py
index 5e449328a0c..8bc831fbfe4 100644
--- a/studio/backend/core/inference/audio_device.py
+++ b/studio/backend/core/inference/audio_device.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Where an audio model's weights go: the accelerator, or plain CPU RAM.
-
-Audio loads take an accelerator whenever one exists. That is right until the GPU
-is the scarce resource (a resident chat model, a training run, a card too small
-for the checkpoint), and Whisper and the smaller TTS models run fine on CPU.
-
-Values match ``RAG_EMBED_DEVICE`` (``core/rag/config.py``):
-
-``auto`` detect as before.
-``cpu`` force CPU RAM, even with a working accelerator.
-``gpu`` prefer the accelerator. The existing CPU retry after a failed load
- still applies, so this is a preference and not a guarantee.
-
-``UNSLOTH_AUDIO_DEVICE`` supplies the default for a request that names none.
-"""
+"""Audio weights go to the accelerator or CPU RAM: auto detects, cpu forces RAM, gpu prefers the
+accelerator (a failed load still retries on CPU). Values match RAG_EMBED_DEVICE
+(core/rag/config.py); UNSLOTH_AUDIO_DEVICE sets the default."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_edit.py b/studio/backend/core/inference/audio_edit.py
index 08cf2fdbc15..ccec156e682 100644
--- a/studio/backend/core/inference/audio_edit.py
+++ b/studio/backend/core/inference/audio_edit.py
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Checks for an Edit speech request, and the source clip an edit keeps in history.
-
-The client renders the word diff (DotTTS markup or FireRedAudio instructions); each check holds it
-against both transcripts, so a malformed or injected value never reaches the runtime.
-"""
+"""Checks for Edit speech requests (DotTTS markup or FireRedAudio word diffs, verified against both
+transcripts) and the source clip an edit keeps in history, so malformed or injected values never
+reach the runtime."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_errors.py b/studio/backend/core/inference/audio_errors.py
index 18be1c1c684..92cee611fb3 100644
--- a/studio/backend/core/inference/audio_errors.py
+++ b/studio/backend/core/inference/audio_errors.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Audio errors that are safe to show a client verbatim.
-
-``safe_error_detail`` flattens everything to "An internal error occurred", right for a
-failure but wrong for a capability answer, where the reason is the whole reply. These
-carry no path or user input, so the route passes them straight through.
-"""
+"""Audio errors safe to show clients verbatim, which safe_error_detail would flatten; they hold no
+path or user input, so the route passes them through."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_gallery.py b/studio/backend/core/inference/audio_gallery.py
index 64203811e4e..d1d2d885286 100644
--- a/studio/backend/core/inference/audio_gallery.py
+++ b/studio/backend/core/inference/audio_gallery.py
@@ -1,13 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Disk-backed persistence for generated TTS audio clips.
-
-Each clip is a pair under ``workspace_root()/audio``: ``{id}.wav`` holds the bytes and
-``{id}.json`` the recipe (a WAV has no portable text chunk). A lone file is not a
-valid record. A converted upload is kept as ``{id}.source.wav`` and goes with its clip.
-Dumb storage: the route owns the schema, this reads, writes and sorts.
-"""
+"""Disk-backed storage of generated TTS clips as {id}.wav + {id}.json pair under
+workspace_root()/audio (recipe in JSON, since WAV has no portable text chunk); a lone file is not
+a valid record; {id}.source.wav for converted uploads goes with its clip; the route owns the
+schema."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_inputs.py b/studio/backend/core/inference/audio_inputs.py
index d7aa9f5e21e..ef598fb31d4 100644
--- a/studio/backend/core/inference/audio_inputs.py
+++ b/studio/backend/core/inference/audio_inputs.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Audio the user gives the Audio page, kept for a day under the account's ``<gallery_dir>/inputs``.
-
-Requests name an input, a gallery clip or a saved voice by id only; this module resolves the id
-inside the current account, so no client ever names a file."""
+"""Audio page inputs kept a day under <gallery_dir>/inputs; requests name an input, clip or voice by
+id, resolved in the current account, never a file path."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_task_outputs.py b/studio/backend/core/inference/audio_task_outputs.py
index 7f81c84f8db..0c9a2c02513 100644
--- a/studio/backend/core/inference/audio_task_outputs.py
+++ b/studio/backend/core/inference/audio_task_outputs.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Every WAV a ``/v1/tasks/run`` reply carries. With ``named_audio_outputs`` present the
-top-level ``audio`` repeats the first one, so it is not counted twice."""
+"""Every WAV in a /v1/tasks/run reply; when named_audio_outputs is present, top-level audio repeats
+its first entry, so it is not counted twice."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_voices.py b/studio/backend/core/inference/audio_voices.py
index 6e11f962e4c..68f627fc028 100644
--- a/studio/backend/core/inference/audio_voices.py
+++ b/studio/backend/core/inference/audio_voices.py
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Saved voices: ``{id}.wav`` (24 kHz mono, at most 30 s) plus ``{id}.json`` under the account's
-``<gallery_dir>/voices``, kept until deleted. As in the gallery the sidecar is written last and is
-what makes a pair a voice, so a lone WAV is never listed, served or deleted."""
+"""Saved voices: {id}.wav (24 kHz mono, at most 30 s) plus {id}.json under <gallery_dir>/voices,
+kept until deleted; the sidecar is written last and is what makes a pair a voice, so a lone WAV
+is never listed, served or deleted."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/audio_workflows.py b/studio/backend/core/inference/audio_workflows.py
index e68c6d54c59..e999541d393 100644
--- a/studio/backend/core/inference/audio_workflows.py
+++ b/studio/backend/core/inference/audio_workflows.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which Audio page workflows (Speak, Clone, Edit, Convert, Music, Separate, Transcribe) a model
-or a clip belongs to.
-
-Mirrors ``studio/frontend/src/features/audio/workflows.ts``. This module reads the audio.cpp
-constants; ``audio_cpp_models`` never imports it.
-"""
+"""Which Audio page workflows (Speak, Clone, Edit, Convert, Music, Separate, Transcribe) a model or
+clip belongs to; mirrors studio/frontend/src/features/audio/workflows.ts. Reads audio.cpp
+constants; audio_cpp_models never imports it."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/browser_agent.py b/studio/backend/core/inference/browser_agent.py
index 7e472673afb..d05dbf99ca4 100644
--- a/studio/backend/core/inference/browser_agent.py
+++ b/studio/backend/core/inference/browser_agent.py
@@ -1,18 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Browser use: tools that let the model drive the browser panel the user is looking at.
-
-Every tool loop (GGUF, safetensors/MLX, external providers) runs these like any other tool; the
-page itself is driven by the chat tab, which runs each action in the agent's own browser tab and
-posts the result back (``state.browser_actions``). The tab is where the user can watch, stop and
-take over, and it gates the risky actions (submitting forms, buying, signing in, new sites) with a
-prompt this side cannot classify: only the live page knows what ``r12`` is.
-
-What this side enforces: argument shapes, http(s) only, public hosts or this machine off Studio's own
-ports, the request's website policy before and after a navigation, and that page text reaches the model
-fenced as untrusted.
-"""
+"""Lets the model drive the chat tab browser panel (user can watch, stop, take over; tab gates risky
+actions). Enforces argument shapes, http(s) only, public or this-machine hosts off Studio ports,
+website policy before and after navigation, and fenced untrusted page text."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/chat_eos.py b/studio/backend/core/inference/chat_eos.py
index 4bcc699b5cc..caa5641d338 100644
--- a/studio/backend/core/inference/chat_eos.py
+++ b/studio/backend/core/inference/chat_eos.py
@@ -1,19 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Resolve a chat model's assistant-turn-end stop tokens.
-
-Some checkpoints set eos_token_id to a bare document terminator (Qwen3.5 ships
-config eos ``<|endoftext|>`` though chat turns end with ``<|im_end|>``, and its
-small chat variants ship no generation_config), so generation runs past the turn
-and loops -- re-emitting tool calls or hallucinating ``<|im_start|>`` turns.
-
-Turn-end markers are derived from the tokenizer's ``chat_template`` (the tokens it
-actually uses to end a turn), not raw vocab membership: a base/coder model can
-carry ChatML control tokens in a shared vocab without using them, and a loader
-may have synced ``eos_token`` to the document terminator. Dependency-light (no
-torch / unsloth) so it is unit-testable without the full inference stack.
-"""
+"""Turn-end stop tokens for chat models: some checkpoints set eos to a bare document terminator
+while chat turns end with <|im_end|>, so generation runs on. Markers come from the chat_template,
+not vocab membership, since base models may carry unused ChatML tokens. Dependency-light for unit
+tests."""
from typing import Optional
diff --git a/studio/backend/core/inference/chat_template_helpers.py b/studio/backend/core/inference/chat_template_helpers.py
index d0f9b080c07..115f6dc2dd3 100644
--- a/studio/backend/core/inference/chat_template_helpers.py
+++ b/studio/backend/core/inference/chat_template_helpers.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Dependency-light wrapper around tokenizer.apply_chat_template with a kwarg fallback for templates
-that reject reasoning/tools args, plus the shared native-chat-template fallback used by the
-transformers and MLX backends."""
+"""Dependency-light wrapper around tokenizer.apply_chat_template, dropping reasoning/tools kwargs
+for templates that reject them; shared native fallback for transformers and MLX."""
import copy
import functools
diff --git a/studio/backend/core/inference/chat_templates.py b/studio/backend/core/inference/chat_templates.py
index 91da20384ea..070efa9e625 100644
--- a/studio/backend/core/inference/chat_templates.py
+++ b/studio/backend/core/inference/chat_templates.py
@@ -1,18 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Bundled chat-template selection for GGUF inference.
-
-Some shipped GGUF quants embed an older chat template. Rather than re-cutting and
-asking users to re-download every quant, Unsloth can override the embedded template
-at llama-server launch time with a bundled, up-to-date Jinja template for known
-model families. The override is wired through the existing ``chat_template_override``
--> ``--chat-template-file`` path in ``LlamaCppBackend.load_model``.
-
-Currently this covers ``unsloth/gemma-4-*-GGUF``, which gains the upstream PR #118
-``preserve_thinking`` flag (defaulted OFF here) so the Unsloth "Preserve thinking"
-toggle appears while staying disabled by default.
-"""
+"""Overrides embedded GGUF chat templates at llama-server launch (chat_template_override to --chat-
+template-file in LlamaCppBackend.load_model) for known families; currently covers
+unsloth/gemma-4-*-GGUF, whose preserve_thinking flag is OFF by default."""
import re
from functools import lru_cache
diff --git a/studio/backend/core/inference/context_refusal.py b/studio/backend/core/inference/context_refusal.py
index 37a241f05c2..f92ea7442cc 100644
--- a/studio/backend/core/inference/context_refusal.py
+++ b/studio/backend/core/inference/context_refusal.py
@@ -1,16 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Why a prompt did not fit, carried from the context fit to the message the user reads.
-
-The fit knows the SHAPE of a refusal (how much is the turn just sent vs the floor
-eviction could not reduce); `_friendly_error` builds the message much later from
-llama-server's text, which knows only a total, and so tells a two-message thread to
-"shorten the conversation". Threading the diagnosis through `_friendly_error`'s
-forty-odd call sites would be worse than the disease, so it rides the request in a
-ContextVar: per-task, and asyncio copies the context per request, so one request's
-refusal cannot describe another's.
-"""
+"""Carries the context fit's refusal diagnosis to the user-facing message via a ContextVar;
+_friendly_error sees only llama-server's total, so a two-message thread would be told to shorten
+the conversation; asyncio copies the context per request, so one refusal cannot describe another."""
from contextvars import ContextVar
from typing import Optional
diff --git a/studio/backend/core/inference/decode_layers.py b/studio/backend/core/inference/decode_layers.py
index ed2a78d6a36..90632f52d63 100644
--- a/studio/backend/core/inference/decode_layers.py
+++ b/studio/backend/core/inference/decode_layers.py
@@ -1,13 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Install and remove one wrapper layer on an object's method slot (a VAE's ``decode`` / ``_decode``), exactly.
-
-``wrap`` records what the slot held on that object (an instance-dict entry, possibly an instance-bound override, or
-nothing, so the class method showed through) and puts the layer in the instance dict. ``unwrap`` puts back exactly
-that when the layer is still outermost. When later wrappers captured it (they hold it in their closures), the layer
-cannot be cut out: it turns into a pass-through to what it wrapped, and the ``__wrapped__`` chain skips it.
-"""
+"""Installs and removes one wrapper on an instance's method slot (e.g. VAE decode) exactly: wrap
+records the prior instance-dict entry or none, unwrap restores it if still outermost; if a later
+wrapper captured it, it becomes a pass-through skipped by __wrapped__."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_aot_cache.py b/studio/backend/core/inference/diffusion_aot_cache.py
index bc4061ee11e..2e61e607ac8 100644
--- a/studio/backend/core/inference/diffusion_aot_cache.py
+++ b/studio/backend/core/inference/diffusion_aot_cache.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Let AOTAutogradCache store the denoiser graphs that hold an ``sdpa_kernel`` block.
-
-Dynamo bakes ``sdpa_kernel`` into the graph as ``_backend_from_string`` / ``_sdpa_kernel`` calls, which are not on
-AOTAutogradCache's allowlist, so every regional block of FLUX.1, Z-Image and Qwen-Image re-ran AOT tracing on each
-process start (pytorch/pytorch#194007; 2.6 / 4.7 / 1.8 s of a B200 restart's first render). Their arguments are graph
-constants, so the graph keys them apart; the one ambient input, SDPA's backend priority order, goes into the marked
-value torch folds into the cache key. UNSLOTH_DIFFUSION_SDPA_AOT_CACHE=0 disables it.
-"""
+"""Lets AOTAutogradCache store denoiser graphs with an sdpa_kernel block (FLUX.1, Z-Image, Qwen-
+Image), whose Dynamo-baked calls are not on AOTAutogradCache's allowlist; the SDPA backend
+priority order is keyed into the cache. UNSLOTH_DIFFUSION_SDPA_AOT_CACHE=0 disables it."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_arch_patches.py b/studio/backend/core/inference/diffusion_arch_patches.py
index 9bd5ac8cd7b..278848e1f3b 100644
--- a/studio/backend/core/inference/diffusion_arch_patches.py
+++ b/studio/backend/core/inference/diffusion_arch_patches.py
@@ -1,24 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-architecture eager fusions for the diffusion DiT blocks.
-
-``diffusion_eager_patches.py`` covers the SHARED classes (RMSNorm, AdaLayerNorm*). The remaining
-fusible ops -- the gated residual ``x = x + gate * out`` and the inline modulation
-``norm * (1 + scale) + shift`` -- are written longhand in each family's PER-MODEL block forward,
-so they need per-arch patches. One small patch function per target, applied through the shared,
-reversible backend.
-
-The fused op is ``torch.addcmul(a, b, c) == a + b * c`` (one FMA kernel, 1-ULP, MORE accurate).
-Only the out-of-place form is used: COMPILE-SAFE (lowers to plain ops, neutral under
-torch.compile), it captures the eager win (fewer launches) but not the output allocation. The
-in-place ``addcmul_`` would save the allocation, but that measured NEUTRAL here (CUDA allocator
-recycles) and is compile-unsafe + aliasing-risky.
-
-Each patch is guarded TWICE: ``can_safely_patch`` checks the SIGNATURE, and ``_body_has`` confirms
-the exact rewritten lines are still present, so a changed diffusers block is left UNPATCHED.
-Kill-switch: ``UNSLOTH_DIFFUSION_ARCH_PATCHES=0``. Implemented for all five families (see ``_SPECS``).
-"""
+"""Per-arch eager fusions of DiT gated residuals and modulation via out-of-place torch.addcmul
+(compile-safe; in-place measured neutral and compile-unsafe); patches check signature and exact
+body lines, so a changed diffusers block stays unpatched. UNSLOTH_DIFFUSION_ARCH_PATCHES=0
+disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_attention.py b/studio/backend/core/inference/diffusion_attention.py
index 5b93ad9056c..8d0ece10061 100644
--- a/studio/backend/core/inference/diffusion_attention.py
+++ b/studio/backend/core/inference/diffusion_attention.py
@@ -1,37 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Select the diffusion transformer's attention backend.
-
-diffusers' ``transformer.set_attention_backend(name)`` dispatcher swaps the SDPA kernel,
-validating hardware/package at set time (default ``native`` = ``F.scaled_dot_product_attention``).
-Attention is bandwidth-bound, so a better kernel is a real win orthogonal to weight quantisation
-(it speeds the QK/PV matmuls torchao never touches) and composes with torch.compile.
-
- auto - the best *exact* backend for the device. On NVIDIA CUDA that is cuDNN fused attention
- (``_native_cudnn``). Torch's SDPA dispatch is a HEURISTIC, not a guarantee, and that is
- the reason to pin it: re-measured on torch 2.12 / B200 at Qwen-Image's 1024px shape
- (B=1 H=24 N=4352 D=128 bf16) the default ALREADY lands on cuDNN, so pinning is
- bitwise-identical and near free (compiled 1.599s -> 1.572s, 1.02x; eager 0.93x, the
- per-call sdpa_kernel wrapper cost, which compile folds away) -- but FLASH and EFFICIENT
- at that same shape run 3.9x and 9.0x slower. Pinning is insurance against the heuristic
- picking one of those on another card, head_dim or torch build. On Blackwell (SM100+) auto
- leaves native when torch's own dispatch picks cuDNN at every DiT head dim and the run dtype
- (same kernel, no per-call wrapper; ``UNSLOTH_DIFFUSION_BLACKWELL_NATIVE_ATTN=0`` keeps the
- pin). Elsewhere stays ``native``. Only upgrades when a speed profile is active, so ``speed_mode=off`` stays
- bit-identical.
- native - force the default SDPA (bit-identical reference).
- cudnn - cuDNN fused attention (exact; NVIDIA).
- flash / flash3 / flash4 - FlashAttention 2 / 3 (Hopper) / 4 (SM100); exact, kernel-gated.
- sage - SageAttention 2 (INT8 QK); quantized, small quality cost. A pip SageAttention 2 when installed, else the
- kernels-community build from the Hugging Face kernels hub (``sage_hub``, Ampere / Ada / Hopper).
- xformers / aiter - memory-efficient (NVIDIA) / AITER (AMD ROCm).
- flash on ROCm - only when the DAO-AILab ROCm build passes an on-card check; ``auto`` also needs a block timing win
- (``UNSLOTH_DIFFUSION_ROCM_FLASH``: auto | 0 | 1). The timing persists per toolchain and geometry under
- the Studio cache (``UNSLOTH_DIFFUSION_ROCM_FLASH_CACHE_DIR``), so a restart reads it instead of re-timing.
-
-Best-effort: an unavailable backend falls back to the diffusers default. torch/diffusers lazy.
-"""
+"""Attention backend: auto picks cuDNN on NVIDIA with a speed profile (Blackwell stays native if
+torch picks cuDNN, unless UNSLOTH_DIFFUSION_BLACKWELL_NATIVE_ATTN=0); native, cudnn,
+flash/flash3/flash4, sage, xformers, aiter; unavailable falls back to native; torch/diffusers
+lazy."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_auto_policy.py b/studio/backend/core/inference/diffusion_auto_policy.py
index 8c5e4af114d..0c505f80e12 100644
--- a/studio/backend/core/inference/diffusion_auto_policy.py
+++ b/studio/backend/core/inference/diffusion_auto_policy.py
@@ -1,22 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Hardware-aware auto-policy for the diffusion loader: a pure decision layer.
-
-The loader historically planned memory from the GGUF file size BEFORE considering the dense
-transformer-quant fast path, which hid the fast path where it matters: where the GGUF-size plan
-picks offload, a dense int8/fp8 transformer (~half the bf16 bytes) often fits resident and beats
-the offloaded GGUF. This module supplies the pieces to fix that:
-
- * a per-family bf16 component-size table (transformer / text encoders / VAE) with per-scheme
- scaling, so a candidate's footprint is estimated BEFORE anything is downloaded; and
- * ``resolve_dense_quant_candidate``, which turns a request + device into a concrete estimate the
- loader re-plans memory against.
-
-It also builds the ``resolved`` record for status: per Advanced control, the engaged value plus
-its provenance (explicit / auto) and a short reason. Pure: no torch import at module import, so the
-decision logic unit-tests on CPU-only hosts.
-"""
+"""Decision layer for the diffusion loader: estimates dense int8/fp8 transformer footprints from a
+per-family bf16 size table before download, so the dense fast path is weighed before GGUF-size
+planning. Builds the resolved record (engaged value, provenance, reason); no torch import."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_autoopt/__init__.py b/studio/backend/core/inference/diffusion_autoopt/__init__.py
index c77c75eb87b..2e491f02c65 100644
--- a/studio/backend/core/inference/diffusion_autoopt/__init__.py
+++ b/studio/backend/core/inference/diffusion_autoopt/__init__.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Diffusion / video auto-optimizer: one orchestrator over Studio's speed primitives.
-
-* ``targets`` denoiser and runner resolution (attribute contracts + by-type discovery).
-* ``profile`` static introspection of a denoiser class (repeated blocks, graph-break screen), cached by digest.
-* ``patches`` the PatchSpec registry: one install / uninstall lifecycle and one fingerprint util for every
- per-architecture source / forward patch.
-* ``plan`` the ordered steps, their predicted decision + reason, the canonical compile-cache kwargs.
-* ``apply`` ``run_speed_layer``: the single image + video entry, per-step audit.
-* ``runtime`` call-time checks against the runner that actually executes a request.
-
-Import is torch-free; every submodule imports torch / diffusers lazily.
-"""
+"""Diffusion/video auto-optimizer orchestrator; import is torch-free, submodules load torch lazily."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_autoopt/apply.py b/studio/backend/core/inference/diffusion_autoopt/apply.py
index 13a53ebb0fb..24a8f13ee04 100644
--- a/studio/backend/core/inference/diffusion_autoopt/apply.py
+++ b/studio/backend/core/inference/diffusion_autoopt/apply.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Execute the optimization plan: the ONE speed-layer entry for the image and video backends.
-
-``run_speed_layer`` runs the registered patch stages, the family hooks (data, not branches in the backends) and the
-existing ``apply_speed_optims`` primitive for one pipe / view, and records every step into the load's
-:class:`Audit` (engaged / declined + reason / failed + error). Failures inside the primitives are captured from the
-warnings they already log (a logger proxy), so their internals stay untouched. The audit surfaces in status as
-``resolved["speed_mode"]["steps"]``.
-"""
+"""run_speed_layer, the one image/video speed-layer entry: runs patch stages, family hooks and
+apply_speed_optims per pipe or view, recording each step in the load Audit; failures caught from
+logged warnings; audit surfaces in status as resolved[speed_mode][steps]."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_autoopt/patches.py b/studio/backend/core/inference/diffusion_autoopt/patches.py
index 8ce1def0378..0fa50db4063 100644
--- a/studio/backend/core/inference/diffusion_autoopt/patches.py
+++ b/studio/backend/core/inference/diffusion_autoopt/patches.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One registry and one lifecycle for every diffusion source / forward patch.
-
-Each per-architecture module (eager fusions, arch ``_SPECS``, Qwen RoPE, Q2.1 fast step / RoPE / fused, FLUX.2 RoPE,
-ROCm fused, Z-Image fused, Wan fused) used to be installed from its own call site with its own teardown list. They now
-register a :class:`PatchSpec` here and are installed by stage, uninstalled by group, and report one outcome each into
-the load's audit record. The modules keep their internals (fingerprints, eligibility, stashes); the registry owns
-WHEN they run, the kill switches, and the record.
-
-Fingerprints share one helper, :func:`source_digest` (the two identical ``_digest`` copies it replaces stay importable
-as aliases), plus :func:`body_has` / :func:`body_has_once` for needle guards. :func:`splice_source` is the safe in-memory
-source rewrite of unsloth-zoo's ``fused_losses/forward_install.py``: exactly-once needles, an unresolved-globals check,
-exec in the original module globals, a digest gate, and the original kept for an exact uninstall.
-"""
+"""PatchSpec registry for source/forward patches; splice_source keeps originals for exact uninstall."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_autoopt/plan.py b/studio/backend/core/inference/diffusion_autoopt/plan.py
index e8b839f485a..9ead0d04ef7 100644
--- a/studio/backend/core/inference/diffusion_autoopt/plan.py
+++ b/studio/backend/core/inference/diffusion_autoopt/plan.py
@@ -1,17 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The optimization plan: which steps a load will try, in what order, and why a step is declined.
-
-Every decision here is the SAME predicate the primitives apply (compile_eligible, the fp16 U-Net offload rule,
-family flags, the graph layer's eligibility), evaluated up front so the audit can name the reason. The primitives
-still decide at apply time; the plan never overrides a registered family. For a family with no data the plan uses
-the denoiser profile to decline a compile up front (no repeated blocks, graph-break suspects in a discovered block)
-rather than letting it fail inside the load.
-
-:func:`compile_cache_kwargs` is the one resolver for the compile-cache fingerprint kwargs (load-time and deferred
-image compile, and the opt-in video compile cache), so the bundle keys on what the compile will actually use.
-"""
+"""Ordered optimizer steps and decline reasons, using the same predicates the primitives apply;
+primitives still decide at apply time and the plan never overrides a registered family"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_autoopt/profile.py b/studio/backend/core/inference/diffusion_autoopt/profile.py
index f9dbabf929b..32e740d2557 100644
--- a/studio/backend/core/inference/diffusion_autoopt/profile.py
+++ b/studio/backend/core/inference/diffusion_autoopt/profile.py
@@ -1,18 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Static introspection of a denoiser class, the input the optimizer plans from.
-
-A :class:`ModelProfile` answers, without running the model: which blocks repeat (declared ``_repeated_blocks``,
-Studio's verified list, or discovered via ``_no_split_modules`` + a ModuleList holding >= 2), whether the attention
-goes through diffusers' dispatcher, whether a repeated block merges the text and image streams (static compile on old
-inductors), and a static graph-break screen of each repeated block's ``forward`` source (host syncs, data-dependent
-shapes). Profiles are cached by (class qualname, forward source digest, diffusers version), so a diffusers upgrade or
-a patched forward re-profiles.
-
-The profile only DESCRIBES. Registered families keep the decisions they always had; the plan uses the profile to
-explain a decline and, for a family with no data, to decline a step up front with the reason instead of failing.
-"""
+"""Static denoiser profile (repeated blocks, graph-break screen) that only describes; registered
+families keep their decisions; cached by class, forward digest and diffusers version"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_autoopt/runtime.py b/studio/backend/core/inference/diffusion_autoopt/runtime.py
index 1388d797f78..2ae10b73b90 100644
--- a/studio/backend/core/inference/diffusion_autoopt/runtime.py
+++ b/studio/backend/core/inference/diffusion_autoopt/runtime.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Call-time checks against the pipeline that actually runs a request.
-
-Load-time eligibility is judged on the base pipe, but a request may run a DIFFERENT pipeline over the same denoiser:
-an image workflow built with ``from_pipe`` (FLUX.1 img2img / inpaint), the video I2V class swap, LTX-2.5's condition
-pipe. First-Block-Cache hooks live on the shared denoiser and need the RUNNER to open ``cache_context``; FLUX.1's
-``FluxPipeline`` does, ``FluxImg2ImgPipeline`` / ``FluxInpaintPipeline`` (diffusers 0.41) do not, so an engaged cache
-raised "No cache context is set" on the first img2img step. These helpers answer for the runner.
-"""
+"""Call-time checks on the request's runner; FBCache needs that runner to open cache_context."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_autoopt/targets.py b/studio/backend/core/inference/diffusion_autoopt/targets.py
index c0f80b72499..b38e08e008a 100644
--- a/studio/backend/core/inference/diffusion_autoopt/targets.py
+++ b/studio/backend/core/inference/diffusion_autoopt/targets.py
@@ -1,21 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which modules of a pipeline are denoisers, and which pipeline actually runs a request.
-
-Two resolvers with different contracts:
-
-* :func:`denoiser_dits` / :func:`denoiser_unet` / :func:`guarded_dits` / :func:`hooked_denoisers` are the exact
- attribute contracts the speed, attention, graph and offload layers have always used (one copy here instead of one
- per module). Every primitive keeps reaching precisely the modules it reached before.
-* :func:`denoisers` resolves BY TYPE for the optimizer's profile / audit and for a family with no data: diffusers
- ``ModelMixin`` components that declare or expose repeated transformer blocks, honouring ``family.denoiser_attr``,
- an MoE ``transformer_2`` and named partitions (``transformer_ref``). It never feeds a primitive of a registered
- family, so it cannot widen what a known load touches.
-
-:func:`runner_for` names the pipeline that executes a call (from_pipe workflows, the I2V class swap, LTX-2.5's
-condition pipe) so call-time checks (``runtime.py``) judge the runner, not the base pipe.
-"""
+"""Exact attribute resolvers feed primitives; by-type denoisers() serves profile, audit and no-data
+families, and never feeds a primitive of a registered family"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_batched.py b/studio/backend/core/inference/diffusion_batched.py
index 9e8fcd65c96..996b4f9c78d 100644
--- a/studio/backend/core/inference/diffusion_batched.py
+++ b/studio/backend/core/inference/diffusion_batched.py
@@ -1,30 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Batched multi-image planning for the local diffusion backend.
-
-One generation call can produce N images three ways: a prompt LIST (one image per
-prompt), one prompt x a seed LIST, or the legacy single prompt + ``batch_size``
-(whose per-image seeds derive as base..base+batch_size-1, matching the native
-sd.cpp engine and the gallery recipe replay). These helpers turn the request into
-an explicit per-image ``(prompt, seed)`` job list, chunk it into per-forward
-batches, and support OOM backoff by splitting a failed chunk in half.
-
-Measured on the 32-image eval suites (diffusers 0.39 / torch 2.10): one batched
-forward with per-image ``torch.Generator``s is numerics-safe (LPIPS deltas within
-0.002 of serial) and 10-22x faster end-to-end than serial per-image engines --
-batch 32 fits 4-step 12B-class models on one GPU, batch 8 fits a 20B model at
-1024px with CFG batching. Per-image generators keep every image individually
-reproducible: same-seed images within the same batch shape are bit-identical
-once the compiled graph is settled (the very first generation during an
-in-flight deferred compile can deviate transiently by a few ulps);
-regenerating an image alone with its recorded seed reproduces it up to
-batch-size-dependent kernel numerics (measured mean abs pixel delta ~2.5/255,
-LPIPS delta under 0.002), not bit-exactly.
-
-Pure and torch-free so the CPU unit tests stay light; the engine owns the
-torch.Generator construction and the actual pipeline calls.
-"""
+"""Explicit per-image (prompt, seed) jobs for batched generation; OOM backoff splits a chunk in half."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_bg_compile.py b/studio/backend/core/inference/diffusion_bg_compile.py
index 8de5b8b5232..74d0f26af91 100644
--- a/studio/backend/core/inference/diffusion_bg_compile.py
+++ b/studio/backend/core/inference/diffusion_bg_compile.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Compile a dense denoiser in the background while the user's renders keep running eager.
-
-``arm`` records the first few distinct denoiser inputs of a render run under ``force_eager`` (read by every compile
-guard and CUDA-graph wrapper); ``kick`` replays them through the compiled callable on a daemon thread with CUDA-graph
-capture suppressed, so the next render pays only the capture. A render arriving mid-compile waits for it: a render
-beside the compile was starved to 49-62 s on a B200. Any failure ends the attempt and the next render compiles inline.
-
-Dense denoisers only: torchao ones are ~30x slower eager. Offloaded ones too: no render runs beside the compile,
-so offload hooks see one forward at a time (UNSLOTH_DIFFUSION_BG_COMPILE_OFFLOADED=0 opts out). By default only the deferred
-profile (generation 3, already eager -> compiled) uses it; UNSLOTH_DIFFUSION_BG_COMPILE=1 also moves a load's
-first-render compile (render 1 then differs from render 2 for one seed), =0 disables it.
-
-``dynamic=True`` SymFloats dynamo cannot tensorify (norm ``eps``) cost a restart per block type; their names are
-saved in the load's compile-cache dir and pre-seeded next load (UNSLOTH_DIFFUSION_BG_COMPILE_FLOAT_SEEDS=0 opts out).
-"""
+"""Dense denoisers (offloaded too) compile in background while renders run eager; a render mid-
+compile waits for it; any failure ends the attempt and the next render compiles inline;
+UNSLOTH_DIFFUSION_BG_COMPILE=0 disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_block_graph.py b/studio/backend/core/inference/diffusion_block_graph.py
index b41d0d08c31..2789498ae96 100644
--- a/studio/backend/core/inference/diffusion_block_graph.py
+++ b/studio/backend/core/inference/diffusion_block_graph.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""CUDA graphs per denoiser block, for denoisers whose weights an offload tier moves.
-
-A whole-forward graph only holds while every weight stays at one address. Here each repeated block records on its
-own, keyed by its inputs AND the device addresses of its weights: moved weights run eagerly once, then record again.
-Streamed blocks get fixed addresses from the prefetcher's slot ring (``GroupPrefetcher.enable_slots``). The offload
-hooks stay eager around the recorded compute. Static inputs are shared per (block class, layout) since replays never
-overlap, and all recordings share one pool per denoiser.
-"""
+"""Per-block CUDA graphs keyed by inputs and weight addresses; moved weights re-record once; offload
+hooks stay eager; static inputs shared since replays never overlap"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_block_restride.py b/studio/backend/core/inference/diffusion_block_restride.py
index 2a309bf6885..5c2e375b8be 100644
--- a/studio/backend/core/inference/diffusion_block_restride.py
+++ b/studio/backend/core/inference/diffusion_block_restride.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Give FLUX.1's first single block the slice layout of blocks 1..37 so all 38 share one compiled graph.
-
-Block 0 gets two separate tensors; the rest get two slices of one ``[B, text + image, D]`` buffer. Dynamo guards on
-strides, so block 0 otherwise compiles a second graph ("stride mismatch at index 0"). The block concatenates its
-inputs first, so copying them into one buffer is value-identical. ``UNSLOTH_DIFFUSION_BLOCK_RESTRIDE=0`` disables it.
-"""
+"""FLUX.1 block 0 takes the slice layout of blocks 1..37 so one compiled graph serves all 38;
+copying its inputs into one buffer is value-identical; UNSLOTH_DIFFUSION_BLOCK_RESTRIDE=0
+disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_cache.py b/studio/backend/core/inference/diffusion_cache.py
index 71432b52d68..cb72d21b42c 100644
--- a/studio/backend/core/inference/diffusion_cache.py
+++ b/studio/backend/core/inference/diffusion_cache.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in step caching for the diffusion transformer (First-Block-Cache).
-
-Once a DiT's trajectory settles its output changes little across steps, so most of the
-transformer can be reused. FBCache computes the first block and, if its residual barely changed
-from the previous step (within ``threshold``), skips the rest and reuses their cached output.
-diffusers ships it natively (``transformer.enable_cache(FirstBlockCacheConfig(...))``).
-
-Measured on Flux.1-dev (28 steps, 1024px, B200): ~1.4x on top of torch.compile (2.83 -> 2.03 s)
-at LPIPS ~0.08 -- deep inside the speed-for-quality bar.
-
-Explicit ``fbcache`` works on every tier; unset / ``auto`` engages only on ``max`` with 20+ steps.
-It composes with torch.compile only at ``fullgraph=False`` (the cache's compiler-disabled decision
-is a graph break), which the speed layer switches to automatically. Best-effort: an incompatible
-model is caught and the load proceeds uncached. torch / diffusers imported lazily.
-"""
+"""Opt-in FBCache step reuse; unset or auto only on max tier with 20+ steps; needs fullgraph=False
+under torch.compile; best-effort, an incompatible model loads uncached; torch and diffusers
+imported lazily"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_cfg_batch.py b/studio/backend/core/inference/diffusion_cfg_batch.py
index bd4666bc42a..6e3176639fc 100644
--- a/studio/backend/core/inference/diffusion_cfg_batch.py
+++ b/studio/backend/core/inference/diffusion_cfg_batch.py
@@ -1,42 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""CFG batching: both guidance branches of a step through ONE forward of the denoiser.
-
-A guided step calls the denoiser twice (conditional, then unconditional). ComfyUI batches the two branches into one
-call by default whenever memory allows (``comfy/samplers.py`` ``calc_cond_batch``), resident or not; diffusers pipelines
-call the transformer once per branch. A denoiser streamed from host memory pays its weight upload once instead of
-twice; a resident one gains where one doubled call keeps the GPU busier than two (small images). This router batches
-them for the classes whose forward keeps no state between calls:
-
-- the first branch of a step builds the second branch's arguments from the previous step's second call (same latent
- object, the first branch's per-step tensors, the second branch's constants), runs both as one call of twice the
- batch, returns the first half and keeps the second;
-- the second call is verified against what was batched (every argument bitwise) and gets the kept half; anything
- else (a changed argument, no second call, a third call) reruns that branch plain and counts as a miss.
-
-Priced once per request shape, before any batched result is used: steps 1-2 run plain (step 2 is timed); a resident
-pair >= ``_RESIDENT_MAX_PAIR_S`` stays plain untried. Otherwise a discarded trial (plain pairs interleaved with doubled
-calls) batches steps 3+ only if the fastest batched step (predict, merge, snapshot, doubled call, split, verify) beats the
-fastest plain pair by ``_MEASURED_FRACTION``, so every render of a shape takes one path (same seed, same image). The
-verdict is latched for the load (memory pressure never re-times it) and stored per (model, weight tensor classes and
-quant scheme, speed tier, offload policy, card, compiled or eager, request shape, runtimes) next to the learned peaks,
-first writer wins: a borderline shape
-cannot land on a different path in another process (``UNSLOTH_DIFFUSION_CFG_BATCH_VERDICTS=0`` keeps it per load;
-``UNSLOTH_DIFFUSION_CFG_BATCH_VERDICTS_FILE`` names the file). The doubled call needs room for twice a plain call's
-activations; no room, or an OOM, turns the shape plain for the rest of that render.
-
-Not always bit-exact (other GEMM / attention tiles): B200 bf16 resident FLUX.2-klein-base-4B is bitwise equal,
-Wan2.1-T2V-1.3B LPIPS 0.019 mean; offloaded FLUX.2-klein-base LPIPS ~0.01. ``UNSLOTH_DIFFUSION_CFG_BATCH=0`` keeps the exact
-one-branch-per-call path, as does a request with ``speed_mode="off"``; ``force`` batches anyway, an unlisted class too
-(the trial's discarded calls must be side-effect free). Declined for per-call activation scaling (NVFP4 without frozen
-global scales), whose scale would change with the doubled batch, and for denoisers already wrapped by another forward
-layer.
-
-Compiled denoisers: the doubled shape compiles a second graph per block, allowed only in a shape's trial render.
-Offloaded compiled denoisers batch; resident compiled ones and shapes judged before a later compile stay plain. A
-follow-up-render compile ends batching for the load; under Dynamo tracing the router passes straight through.
-"""
+"""Batches CFG branches into one forward for stateless denoisers only; a second call differing from
+the batched inputs reruns that branch plain; not always bit-exact; UNSLOTH_DIFFUSION_CFG_BATCH=0
+keeps one branch per call"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_comfy_block.py b/studio/backend/core/inference/diffusion_comfy_block.py
index c7c7f15d249..976fca07a06 100644
--- a/studio/backend/core/inference/diffusion_comfy_block.py
+++ b/studio/backend/core/inference/diffusion_comfy_block.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""ComfyUI ``nvfp4`` / ``mxfp8`` layers: decode, dequantize, and the runtimes that keep them.
-
-Layout measured on Comfy-Org's files: nvfp4 ``.weight`` uint8 ``[N, K/2]`` with the EVEN column in the HIGH nibble,
-e4m3 block scales (per 16 columns) in the cuBLAS 128x4 tiled layout, ``.weight_scale_2`` per-tensor,
-``.input_scale`` = activation ``amax / (448 * 6)``, optional ``.pre_quant_scale`` input smoothing. mxfp8 ``.weight``
-e4m3 ``[N, K]`` with e8m0 exponents (per 32 columns) in the same tiled layout. Decoded layers are row-major so the
-row-tag mapping in ``diffusion_comfy_quant`` splits and concatenates them as for int8 / fp8.
-"""
+"""ComfyUI nvfp4/mxfp8 layer decode; nvfp4 stores the EVEN column in the HIGH nibble."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_comfy_components.py b/studio/backend/core/inference/diffusion_comfy_components.py
index 84b2eb6654c..71342da8942 100644
--- a/studio/backend/core/inference/diffusion_comfy_components.py
+++ b/studio/backend/core/inference/diffusion_comfy_components.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Separate text-encoder / VAE files (ComfyUI ``models/text_encoders``, ``models/vae``) beside a single-file DiT.
-
-Each file is classified from its header, assigned to the base pipeline slot whose class it fits, renamed under a
-rule that loads strictly, and built from the base repo's config (which still supplies configs and tokenizers).
-fp8, nvfp4 and mxfp8 dequantize, int8 ConvRot stays int8, every other ComfyUI quant format is refused by name.
-"""
+"""ComfyUI text-encoder and VAE files beside a single-file DiT; fp8, nvfp4 and mxfp8 dequantize,
+int8 ConvRot stays int8, other ComfyUI quant formats are refused by name"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_comfy_quant.py b/studio/backend/core/inference/diffusion_comfy_quant.py
index b90881f2c66..c98d7cbe3ff 100644
--- a/studio/backend/core/inference/diffusion_comfy_quant.py
+++ b/studio/backend/core/inference/diffusion_comfy_quant.py
@@ -1,24 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Load a ComfyUI-format quantized single-file DiT, or refuse it by name.
-
-ComfyUI keeps quantized codes under each layer's ``.weight`` with ``.weight_scale`` (some formats also
-``.input_scale``, ...) beside it, the format declared per layer (``<layer>.comfy_quant`` JSON tensor), in
-the header's ``_quantization_metadata`` table, or by the legacy ``scaled_fp8`` marker + ``.scale_weight``.
-Stock ``from_single_file`` casts the codes as weights and drops the scales: the load succeeds and renders noise.
-
-From the header alone: int8_tensorwise (optionally ConvRot) maps into Studio's int8 runtime with codes and
-per-row scales unchanged; float8_e4m3fn into Studio's per-row fp8 runtime (scalar scale repeated per row);
-nvfp4 into Studio's FlashInfer NVFP4 Linear and mxfp8 into a ``torch._scaled_mm`` block-scaled Linear
-(``diffusion_comfy_block``); where none runs, or for layers Studio keeps in bf16 and float8_e5m2, layers
-dequantize. Any other format is refused by name, never mis-loaded.
-
-Row mapping: the family's converter runs once on float64 row tags ``(source key, row)``; the tags that
-come out say which source rows each diffusers weight holds. A converter that splices columns, changes
-the column count or transforms values leaves undecodable tags and is refused. (Tags are constant along a
-row: a pure input-column reorder would go unseen; no diffusers converter does one.)
-"""
+"""ComfyUI quantized single-file DiTs: stock loader drops scales and renders noise; others refused."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_compile_cache.py b/studio/backend/core/inference/diffusion_compile_cache.py
index d2b4fde7b84..ac823469d82 100644
--- a/studio/backend/core/inference/diffusion_compile_cache.py
+++ b/studio/backend/core/inference/diffusion_compile_cache.py
@@ -1,58 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pre-warmed ``torch.compile`` cache for the diffusion denoiser (Mega-cache).
-
-The regional compile of the repeated denoiser block pays a one-time 25-58s compile on
-the FIRST image after a load. This lets that cost be paid ONCE (by the distributor ahead
-of time or the user on first run) and reused on every later load via torch's portable
-Mega-cache (``save_cache_artifacts`` / ``load_cache_artifacts``, torch >= 2.7).
-
-PORTABILITY IS NOT UNIVERSAL: an artifact is only valid for the SAME torch/Triton/CUDA
-build, GPU arch, and model graph (family, dtype, quant, attention backend, compile
-kwargs, shape bucket, quant variant, graph kill switches). torch validates these on load;
-a mismatch yields no hit, not an error. Hence
-an EXACT-MATCH fingerprint with SILENT FALLBACK to local compile (a miss is normal), and
-per-arch bundles keyed by the full fingerprint. See
-``outputs/compile_cache/DISTRIBUTION.md``.
-
-GGUF loads participate too (fingerprinted ``quant="gguf"``, a different compiled graph
-than the dense family): ``torch.compile`` mode="default" runs clean over diffusers'
-GGUF dequant path (measured on torch 2.10 / diffusers 0.39), but the cold warmup is
-HEAVY at batched shapes -- ~159 s first-pass wall on a 12B-class 4-step model at
-batch 32, up to ~655 s on a 20B CFG-batched model at 1024px -- which is exactly the
-cost this bundle amortises to once-ever. Batched generation registers every distinct
-(width, height, batch) chunk shape it runs via ``register_shape`` so a static-compile
-bundle grows to cover the batch sizes actually used, OOM-backoff halves included.
-
-Lifecycle (around ``_compile_repeated_blocks``): ``begin`` builds the fingerprint, points
-``TORCHINDUCTOR_CACHE_DIR`` at a per-key dir, and loads a matching bundle (before the
-first compiled forward); ``save`` writes the bundle + manifest after the warmup forward
-(on by default, a hit skips the rewrite); ``restore`` resets the inductor dir on unload.
-All env-gated and best-effort; torch imported lazily.
-
-DISK: LRU keys are evicted past ``UNSLOTH_DIFFUSION_COMPILE_CACHE_MAX_GB``, never one open here or used in the last hour.
-
-The generate path calls ``save_async``, not ``save``: the write is pure bookkeeping for
-the NEXT process, so making a user wait on it buys them nothing. Measured on a B200
-(Z-Image-Turbo, speed=max, torch 2.11): a 42.7 MB bundle costs 0.088 s to serialise plus
-0.033 s to write, a 71.1 MB one 0.130 s plus 0.057 s, so roughly 2.6 ms per MB, and the
-docstring's batched-GGUF bundles are far larger than either. ``save`` itself is unchanged
-and still synchronous, for tests and for anyone who needs the write to have happened by
-the time the call returns.
-
-ON-DISK LAYOUT, per key dir: ``manifest.json`` plus one or more ``bundle-<sha16>.bin``.
-The bundle is CONTENT-ADDRESSED and the manifest names the one it is paired with, so the
-manifest is the single commit point: a save writes a file no reader is using, then
-publishes the manifest naming it, then collects the bundles no manifest names. Killed
-anywhere in between, what is on disk is still a matching pair, either the old one (the
-new bundle is an orphan) or the new one. That matters because a save runs on a daemon
-thread that interpreter exit can kill mid-write: writing one fixed ``cache.bin`` in place
-would leave the old manifest paired with a new bundle, and the sha256 check on load would
-then throw away a warm start that was perfectly good. Manifests without a ``bundle`` key
-are pre-content-addressing and name ``cache.bin``, so old bundles keep hitting; the format
-version is deliberately NOT bumped, since bumping it is what would invalidate them.
-"""
+"""Torch Mega-cache of denoiser compile; exact-match fingerprint, a mismatch yields a miss not an
+error; best-effort; manifest is the commit point over content-addressed bundles; old cache.bin
+manifests stay valid, format version not bumped; LRU never evicts open or last-hour keys"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_compile_config.py b/studio/backend/core/inference/diffusion_compile_config.py
index 6099ae005b5..f801955ecd6 100644
--- a/studio/backend/core/inference/diffusion_compile_config.py
+++ b/studio/backend/core/inference/diffusion_compile_config.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""torch 2.12+ keeps dynamo / inductor config writes in a ContextVar, so knobs set on the load thread are invisible on
-the render thread that compiles. Knobs are recorded here and ``apply()`` re-writes them into the current context."""
+"""torch 2.12+ stores dynamo/inductor config in a ContextVar; apply() re-sets knobs per thread."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_cond_blocks.py b/studio/backend/core/inference/diffusion_cond_blocks.py
index 6fe4d89d01b..78c7cc327cc 100644
--- a/studio/backend/core/inference/diffusion_cond_blocks.py
+++ b/studio/backend/core/inference/diffusion_cond_blocks.py
@@ -1,16 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Run FLUX.3 Klein Base's conditioning-only work (text and reference-image mode blocks at timestep 0) once per render.
-
-Nothing there reads the latent or the step's timestep, so ComfyUI also runs it once (``comfy/ldm/flux3/model.py``
-``preprocess_conds``). A flow-map checkpoint (distilled Klein) feeds the target time into those modulations, so it
-keeps the per-step path. A forward pre-hook caches the states per branch, keyed by the identity of the pipeline's
-conditioning tensors; it runs before the forward, so a whole-step CUDA graph copies them into its static buffers on
-every replay and never bakes a stale tensor. The cache is cleared at the start and end of every pipeline call, so a
-LoRA or weight change never meets an old entry. Bit-identical output. Kill switch ``UNSLOTH_DIFFUSION_COND_BLOCKS=0``;
-installed only when the diffusers forward source hash matches, else the stock forward.
-"""
+"""FLUX.3 Klein Base conditioning blocks run once per render, bit-identical; cache cleared at start
+and end of each pipeline call; installed only on matching diffusers forward hash, else stock;
+UNSLOTH_DIFFUSION_COND_BLOCKS=0 disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_cond_cache.py b/studio/backend/core/inference/diffusion_cond_cache.py
index b297d83aa5e..562de26079f 100644
--- a/studio/backend/core/inference/diffusion_cond_cache.py
+++ b/studio/backend/core/inference/diffusion_cond_cache.py
@@ -1,34 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Persistent prompt-conditioning cache for the diffusion INFERENCE path.
-
-The inference sibling of the trainers' ``cond_cache_dir`` (see
-``diffusion_train_common.DiffusionLoraConfig``), reusing the SAME on-disk store
-(``diffusion_train_extras.PersistentConditioningCache``): one safetensors file
-per encoded prompt, keyed by content hash + family. Enabled by pointing
-``UNSLOTH_DIFFUSION_COND_CACHE_DIR`` at a directory -- unset/blank means off,
-exactly like the trainer knob, so the default render path stays untouched.
-
-When enabled, the loaded pipeline's ``encode_prompt`` is wrapped per-instance:
-a repeated prompt returns the stored embeddings and never runs the text-encoder
-forward, so under an offload policy the multi-GB encoders stay OFF the GPU for
-warm prompts entirely. Verified bit-identical on the 32-image eval suites
-(FLUX.1-schnell / FLUX.2-klein / Qwen-Image-2512): renders from cached
-embeddings match inline-encoded renders exactly, and warm runs load the whole
-pipeline with no text encoder resident (8-18s load, ~7B-VL VRAM saved on
-Qwen-Image).
-
-Safety gates: the wrapper only caches calls whose arguments are all plain
-JSON-safe values (a tensor argument such as pre-supplied ``prompt_embeds``
-passes straight through), keys on everything that changes the embedding
-numerics (family, checkpoint repo, the companion base repo that supplies the
-text encoders, dtype, text-encoder quant, diffusers version, and the full
-argument set minus device/generator), and bypasses entirely while LoRA
-adapters are attached (an adapter may target the text encoders). Best-effort
-throughout: any cache failure falls back to the real encode. torch is imported
-lazily so this stays importable in a no-torch runtime.
-"""
+"""Prompt-embedding cache, off unless UNSLOTH_DIFFUSION_COND_CACHE_DIR is set; bypassed while LoRA
+adapters are attached; best-effort, any cache failure falls back to the real encode; torch
+imported lazily"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_conditioning.py b/studio/backend/core/inference/diffusion_conditioning.py
index 5f8698d2071..6a11b967290 100644
--- a/studio/backend/core/inference/diffusion_conditioning.py
+++ b/studio/backend/core/inference/diffusion_conditioning.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Condition images and output geometry for the reference and unified-edit workflows, shared by
-the diffusers and sd.cpp engines.
-
-Localized editing follows the official Qwen-Image-2.1 demo conventions, which are generative
-guides rather than inpainting masks: nothing here keeps pixels outside the region.
-
-- ``annotate``: coloured marks (outlines, arrows) drawn ON the source. The instruction names the
- colours and asks for the marks to be left out of the result.
-- ``paint``: an opaque white region painted ON the source. The instruction refers to the white
- area.
-- ``mask``: a separate white-on-black mask at the source's geometry, sent as Image 2 right after
- the source. The instruction refers to the marked area.
-"""
+"""Reference/edit image modes (annotate, paint, mask) are generative guides, not inpainting masks."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_content.py b/studio/backend/core/inference/diffusion_content.py
index 4293ced60c4..83cf4c5b847 100644
--- a/studio/backend/core/inference/diffusion_content.py
+++ b/studio/backend/core/inference/diffusion_content.py
@@ -1,15 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""What a single-file diffusion checkpoint IS (DiT of which family / text encoder / VAE / LoRA /
-ControlNet), from the safetensors or GGUF header only: no torch, no weight bytes, cached per
-(path, size, mtime). ComfyUI and diffusers layouts, bare or under a container prefix.
-
-Same-architecture variants (FLUX.1 dev / Krea / Kontext, Qwen-Image / 2512 / Edit / Edit-2509,
-klein distilled / base, Z-Image base / Turbo, HiDream full / dev / fast, LTX-2 / 2.3,
-HunyuanVideo-1.5 480p / 720p, Wan A14B high / low noise, Wan2.1-T2V-14B vs an A14B expert) have identical keys: the
-file name decides.
-"""
+"""Checkpoint parts from the header alone (no torch, no weight bytes); same-arch variants share
+keys, so the file name decides"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_controlnet.py b/studio/backend/core/inference/diffusion_controlnet.py
index b6407c5aced..c1565199296 100644
--- a/studio/backend/core/inference/diffusion_controlnet.py
+++ b/studio/backend/core/inference/diffusion_controlnet.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Diffusion ControlNet support: family-gated discovery, resolution to a loadable diffusers
-repo/dir, control-image preprocessing, and a capability gate.
-
-Mirrors ``diffusion_lora.py``. Two differences: (1) a ControlNet is a full diffusers repo (loaded
-via ``from_pretrained``), so resolution yields a repo id / local dir, not a file; (2) it needs a
-spatial *control image*, either supplied already-preprocessed ("passthrough") or derived here
-("canny", a dependency-free edge map).
-
-ControlNets are architecture-specific, so discovery is family-gated like the LoRA picker. The
-request never carries a path (only a discovery id or ``owner/name`` repo id), so a client cannot
-make the backend read an arbitrary location.
-"""
+"""Family-gated ControlNet discovery; requests carry only a discovery id or owner/name, never a path."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_convrot_quant.py b/studio/backend/core/inference/diffusion_convrot_quant.py
index 919067b107e..0604a9e9a17 100644
--- a/studio/backend/core/inference/diffusion_convrot_quant.py
+++ b/studio/backend/core/inference/diffusion_convrot_quant.py
@@ -1,40 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""ConvRot rotation and the int8 per-row activation quant as ONE kernel (``rotq_i8``), for every int8 ConvRot Linear.
-
-The stock path is two kernels: ``ConvRotLinear.forward``'s block-Hadamard rotation as a bf16 GEMM (writes the rotated
-activation to HBM), then torchao's per-row act quant (reads it back, writes int8 + one scale per row). ``rotq_i8`` holds
-whole activation rows of the ``[M * K / G, G]`` group view per tile, runs the rotation GEMM in the stock K order with
-the stock bf16 rounding, closes the per-row amax in the epilogue and writes the int8 codes and the row scale: one read
-of x, no rotated intermediate.
-
-NUMERICS: codes and scales are bit-identical to the stock rotation + torchao quant (v1
-``_int8_symm_per_token_reduced_range_quant``; v2 ``Int8Tensor.from_hp(PerRow)``: bf16 scale, reciprocal and product on
-torchao <= 0.17, fp32 on >= 0.18). Every device is probed against that path before use (outliers, a zero row, ragged
-M, every K the tile admits); a miss keeps the stock path on that device.
-
-One home for the kernel: ``diffusion_int8_gemm`` uses it for every ConvRot Linear it swaps (fused-dequant GEMM on
-sm80 / sm89 / sm120, cuBLAS ``_int_mm`` + torchao's epilogue on the other measured archs), and ``convrot_act_quant``
-gives any other int8 consumer of a rotated activation the same codes.
-
-Per-arch gate (``_ROTQ_CONFIG``): measured archs only; ``UNSLOTH_DIFFUSION_INT8_ROTQUANT=1`` (or
-``UNSLOTH_DIFFUSION_INT8_GEMM=1``) also enables it on an unmeasured sm80+ part, still probe-gated. Kill switch
-``UNSLOTH_DIFFUSION_INT8_ROTQUANT=0``; ``UNSLOTH_DIFFUSION_INT8_GEMM=0`` turns off the whole int8 Linear swap.
-
-H16 ROTATION (``rotq_h16``, default where ``rotq_i8`` passed): ``H256 = H16 (x) H16``, so a group rotates as
-``H16 . X . H16`` (one bf16 tensor-core dot, one fp32 dot): 32 multiply-adds per element instead of 256, bandwidth-bound
-everywhere. A different fp32 summation order: ~1 code in 10^6 differs by one step, scales equal; the probe gates it per
-device at that tolerance (``codes_close``). ``UNSLOTH_DIFFUSION_INT8_ROTQUANT_H16=0`` keeps the bit-identical dense kernel.
-
-UNLISTED ARCHS (sm86, sm87, sm90, sm100, sm103, sm121, ...: no ``_ROTQ_CONFIG`` entry, so no dense tile to probe):
-``rotq_h16`` needs no tile, so ``unlisted_device_ok`` probes it there directly, then a latency check against the two
-kernels it replaces (see below). Kill switch ``UNSLOTH_DIFFUSION_INT8_ROTQUANT_UNLISTED=0``.
-
-SwiGLU PROLOGUE (``rotq_h16`` only): the down projection's codes come straight from the gate / value halves, the
-product computed in-kernel like the compiled stock MLP; the [M, hidden] HBM round trip was ConvRot's largest cost over
-plain int8 at Qwen-Image-2.1 1024px. Kill switch ``UNSLOTH_DIFFUSION_INT8_ROTQUANT_SWIGLU=0``.
-"""
+"""Fused ConvRot rotation and int8 per-row quant (rotq_i8), bit-identical to stock; each device is
+probed first and a miss keeps the stock path; H16 variant not bit-exact;
+UNSLOTH_DIFFUSION_INT8_ROTQUANT=0 disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_cuda_graph.py b/studio/backend/core/inference/diffusion_cuda_graph.py
index 7bf5d25c180..d3bd71a271e 100644
--- a/studio/backend/core/inference/diffusion_cuda_graph.py
+++ b/studio/backend/core/inference/diffusion_cuda_graph.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Static-buffer CUDA-graph capture of ONE denoiser forward, for the diffusion backends.
-
-Each denoiser module gets a ``GraphedForward`` in its INSTANCE ``__dict__`` under ``forward``.
-Not a proxy: the pipelines read ``.dtype`` / ``.config`` / ``.cache_context`` off the transformer.
-Not a hook: hooks move ``nn.Module._call_impl`` off its fast path and offload owns the hook list.
-"""
+"""Static-buffer CUDA graph of a denoiser forward, kept in instance __dict__; not a proxy or hook."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_denoiser_prequant.py b/studio/backend/core/inference/diffusion_denoiser_prequant.py
index 9bf5a4498df..d755868586f 100644
--- a/studio/backend/core/inference/diffusion_denoiser_prequant.py
+++ b/studio/backend/core/inference/diffusion_denoiser_prequant.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Seed an official image PIPELINE pick with its hosted pre-quantized denoiser.
-
-A ``kind == "pipeline"`` pick assembles every component from one repo, so the only way to run a
-quantised denoiser without materialising the bf16 shards is handing ``from_pretrained`` an
-already-quantised ``transformer=``. Torch-free at import."""
+"""Seeds an official pipeline pick with its hosted pre-quantized transformer to avoid bf16 shards;
+torch-free at import"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_device.py b/studio/backend/core/inference/diffusion_device.py
index 9937bb8d713..127b041a0eb 100644
--- a/studio/backend/core/inference/diffusion_device.py
+++ b/studio/backend/core/inference/diffusion_device.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Device + dtype policy for the local diffusion backend.
-
-torch imported lazily so this stays importable in a no-torch runtime. Unsloth's hardware layer
-reports product backends (CUDA, XPU, MLX, CPU); diffusers runs on PyTorch devices, so Apple
-Silicon maps to MPS and ROCm to ``cuda``. Centralises that mapping plus the per-backend dtype and
-the capability flags optimisation paths key off.
-"""
+"""Device/dtype policy: Apple Silicon maps to MPS and ROCm to cuda; torch imported lazily."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_dynamic_text.py b/studio/backend/core/inference/diffusion_dynamic_text.py
index fef6a368688..773bb3ef26e 100644
--- a/studio/backend/core/inference/diffusion_dynamic_text.py
+++ b/studio/backend/core/inference/diffusion_dynamic_text.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Mark a DiT's prompt-length inputs dynamic (``dynamic_sources``, scoped to its forward) so a new prompt length
-never recompiles; blanket ``dynamic=True`` hits torchao CantSplit.
-
-torch 2.13+ guards symbolic slice bounds on ``s is None`` (Qwen-Image-2.1 ``cache_write_slice``), recompiling per
-prompt length; ``install`` restores 2.12's answer. Probe-gated; kill switch ``UNSLOTH_DIFFUSION_SLICE_IDENTITY_FIX=0``."""
+"""Prompt-length inputs dynamic so new lengths never recompile; blanket dynamic=True hits torchao."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_eager_patches.py b/studio/backend/core/inference/diffusion_eager_patches.py
index cfd4d096e32..7607d049c86 100644
--- a/studio/backend/core/inference/diffusion_eager_patches.py
+++ b/studio/backend/core/inference/diffusion_eager_patches.py
@@ -1,30 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Reversible, failure-safe monkey-patches that speed up the diffusion denoiser.
-
-These patch a couple of SHARED diffusers classes (a tiny surface covering all families) to make
-inference faster WITHOUT reducing accuracy or regressing ``torch.compile``. Both are compile-safe:
-they lower to plain ops, are bit-identical or FMA-1-ULP (equal-or-MORE accurate) vs stock, and
-torch.compile fuses either form to the same kernel -- so they help EAGER and are compile-neutral.
-
-Patched (measured B200, bf16, DiT shapes):
-* ``RMSNorm.forward`` -> fused ``F.rms_norm`` on the common path (non-NPU, no bias, weight
- None/fp16/bf16; else the exact original). The standout win (~6-12x per call, QK-norm runs every
- attention block on Qwen-Image + Z-Image). bf16: one rounding instead of two (~1 ULP off stock, nearer fp64).
-* ``AdaLayerNormContinuous`` / ``AdaLayerNormZero`` / ``AdaLayerNormZeroSingle`` -> the
- ``norm(x)*(1+scale)+shift`` modulation fused via ``torch.addcmul`` (~1.2x, fp32 exact, bf16 1
- ULP). Covers flux.1 / flux.2-klein / qwen-image.
-
-NOT patched (evidence-based): ``FeedForward`` Dropout skip (measured a REGRESSION, the isinstance
-check costs more); GEGLU/SwiGLU/GELU (mul-bound, need a custom kernel); per-family custom classes
-and attention (not shared; attention already routes through the set_attention_backend dispatcher).
-
-Lifecycle: ``install_compile_safe_patches()`` is idempotent, class-level. Install for any active
-speed tier; the bit-identical ``off`` path runs UNINSTALLED, so the caller uninstalls on an ``off``
-load and on unload. The chat<->diffusion arbiter guarantees a single active pipe, so class-level
-state is safe.
-"""
+"""Reversible, failure-safe, compile-safe accuracy-neutral patches of shared diffusers classes;
+uninstall on off-tier loads and on unload; the chat/diffusion arbiter ensures one active pipe, so
+class-level state is safe"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_embeddings.py b/studio/backend/core/inference/diffusion_embeddings.py
index c2a0fde9267..c1a25defaae 100644
--- a/studio/backend/core/inference/diffusion_embeddings.py
+++ b/studio/backend/core/inference/diffusion_embeddings.py
@@ -1,23 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Textual-inversion embeddings (EasyNegative and friends) for the CLIP-conditioned image families.
-
-Files live in ``<studio_home>/embeddings/diffusion`` (beside ``loras/diffusion``). As in AUTOMATIC1111 the
-filename stem is the trigger: a prompt or negative prompt naming it (any case, as a whole word, or ComfyUI's
-``embedding:NAME``) uses the embedding for that generation. safetensors only (``.pt`` is pickled).
-
-Formats, as diffusers' ``load_textual_inversion`` reads them (docs: "Textual inversion", SDXL section):
- * SD 1.x: one tensor ``[n, 768]`` (A1111 ``emb_params`` or a single diffusers ``<token>`` key);
- * SDXL: ``clip_l [n, 768]`` for ``text_encoder`` / ``tokenizer`` and ``clip_g [n, 1280]`` for
- ``text_encoder_2`` / ``tokenizer_2``.
-
-Applying one never reloads the pipeline and never mutates a loaded component: each tokenizer is swapped for
-a copy carrying the added tokens (``tok``, ``tok_1``, ... as diffusers names multi-vector embeddings, so the
-pipeline's own ``maybe_convert_prompt`` expands them), and each text encoder's input embedding is wrapped by a
-module that serves the new ids and calls the original for every other id. ``restore`` puts the original
-objects back, so a generation that names no embedding runs the unchanged modules. The denoiser is untouched.
-"""
+"""Textual-inversion embeddings, safetensors only (.pt is pickled); filename stem is the trigger;
+applying one never reloads or mutates a loaded component, denoiser untouched"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_engine_router.py b/studio/backend/core/inference/diffusion_engine_router.py
index e0ec7a78f9a..a309e013e26 100644
--- a/studio/backend/core/inference/diffusion_engine_router.py
+++ b/studio/backend/core/inference/diffusion_engine_router.py
@@ -1,37 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Selects the diffusion engine (diffusers vs native sd.cpp) for the live route.
-
-One engine at a time. On a CUDA/ROCm/XPU GPU it is the diffusers ``DiffusionBackend`` (the default,
-the only path with the torchao fast-quant / compile stack); with no usable GPU (CPU, or MPS when
-enabled) the native ``SdCppDiffusionBackend`` (faster, lighter on RAM there). Chosen once at load
-and remembered, so ``generate`` / ``unload`` / ``status`` / progress all act on the same engine.
-
-Built on the pure ``select_diffusion_engine`` decision; this module adds the policy (env opt-out,
-MPS gating, per-family native-asset support, lazy binary availability) and records fallbacks.
-
-Per load, ``/images/load``'s ``engine`` field (auto | diffusers | sd_cpp) asks for an engine; the env override below
-wins over it. An explicit pick the engine cannot serve is refused, never silently swapped for the other engine.
-
-Env knobs:
- UNSLOTH_DIFFUSION_ENGINE=auto|diffusers|sd_cpp force an engine (auto = decide); wins over a per-load pick
- UNSLOTH_DIFFUSION_SD_CPP=auto|0|1 enable/disable the native route
- UNSLOTH_DIFFUSION_SD_CPP_MPS=0|1 allow native on Apple MPS (default off)
- UNSLOTH_DIFFUSION_SD_CPP_INSTALL=auto|0|1 allow lazy binary install (in sd_cpp_backend)
- UNSLOTH_DIFFUSION_SD_CPP_DEVICE=nvidia[:N] run native on a card torch cannot see
- UNSLOTH_DIFFUSION_MLX=auto|0|1 the Apple Silicon MLX engine: auto (default) routes each request,
- 1 forces MLX alone, 0 turns it off (diffusers MPS as before)
-
-The MLX engine (``mlx_diffusion_backend``) is considered on macOS 14+ on Apple Silicon, for a GGUF of a family that
-declares ``mlx_model_config`` in a quant the converter handles (Q4_0 / Q4_1 / Q5_0 / Q5_1 / Q8_0, the Q4_K / Q5_K /
-Q6_K mixes, BF16 / F16), with ``mlx`` and ``mflux`` installed. With ``auto`` the load goes to the routed engine
-(``mlx_diffusion_routing``): plain text-to-image runs on MLX, and a request that needs a feature MLX lacks is served
-by diffusers on MPS, loaded on demand. A load that itself needs such a feature (LoRA, separate component files, an
-explicit precision) stays on diffusers. With ``1`` the MLX engine runs alone and refuses those requests. Every refusal
-is recorded (``mlx_fallback_reason`` in the status) and falls through to the choice this module makes without it; on
-a host that is not an Apple Silicon Mac ``auto`` records nothing.
-"""
+"""One engine per load: diffusers on CUDA/ROCm/XPU, native sd.cpp on CPU or MPS when enabled; MLX
+auto takes plain text-to-image on Apple Silicon, else diffusers MPS; explicit picks refused,
+never swapped; env override wins over a per-load pick."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_families.py b/studio/backend/core/inference/diffusion_families.py
index 934ae12139b..766c755d9a7 100644
--- a/studio/backend/core/inference/diffusion_families.py
+++ b/studio/backend/core/inference/diffusion_families.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pure helpers for diffusion model identification. No torch/diffusers imports: everything here is a
-pure function of its string/path arguments, so it can be unit-tested without the heavy runtime. A
-diffusion checkpoint published as a single-file GGUF only carries the transformer weights; the
-matching VAE / text encoders / scheduler come from a companion ``diffusers`` base repo, and
-``DiffusionFamily`` maps a checkpoint to the diffusers classes and base repo needed to assemble
-the full pipeline."""
+"""Pure torch-free helpers; a GGUF holds only the transformer, so DiffusionFamily names the base repo."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_fast_load.py b/studio/backend/core/inference/diffusion_fast_load.py
index 3caa69bc0de..78f4c60331c 100644
--- a/studio/backend/core/inference/diffusion_fast_load.py
+++ b/studio/backend/core/inference/diffusion_fast_load.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Cold-start I/O for the image load path, byte-for-byte neutral: ``start_load_prefetch`` warms the page
-cache with the files the load reads next (parallel slice reads beat mmap page faults); ``fast_upload``
-moves plain host tensors (and the inner tensors of torchao-style wrapper subclasses) through a pinned
-ring and hands them to the existing ``.to`` via a ``TorchFunctionMode``, so placement semantics stay
-the module's own. Kill switches
-``UNSLOTH_DIFFUSION_PREFETCH=0`` / ``UNSLOTH_DIFFUSION_FAST_UPLOAD=0``.
-"""
+"""Byte-neutral image-load I/O. Off: UNSLOTH_DIFFUSION_PREFETCH=0, UNSLOTH_DIFFUSION_FAST_UPLOAD=0."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_flow_shift.py b/studio/backend/core/inference/diffusion_flow_shift.py
index 58582182838..30b13c11a2c 100644
--- a/studio/backend/core/inference/diffusion_flow_shift.py
+++ b/studio/backend/core/inference/diffusion_flow_shift.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Rebuild the loaded scheduler at ComfyUI's static sigma shift (shipped schedulers differ, e.g.
-Qwen-Image dynamic ~2.0 + terminal stretch vs 3.1), unless the checkpoint ships its own sampling
-grid. No torch/diffusers imports."""
+"""Rebuilds the loaded scheduler at ComfyUI static sigma shift unless the checkpoint ships its own
+grid; no torch or diffusers imports."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_flux2_rope.py b/studio/backend/core/inference/diffusion_flux2_rope.py
index c25280bb90b..1c91a2bbab5 100644
--- a/studio/backend/core/inference/diffusion_flux2_rope.py
+++ b/studio/backend/core/inference/diffusion_flux2_rope.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""FLUX.2 RoPE as one Triton kernel on fp16 GPUs (T4 and other pre-Ampere cards).
-
-Same fp32 arithmetic and rounding order as stock ``apply_rotary_emb`` (FMA contraction off), so the output is
-bit-identical. Patches only ``transformer_flux2``'s global for fp16 CUDA loads; any other call falls through to stock.
-Kill switch: ``UNSLOTH_DIFFUSION_FLUX2_FUSED_ROPE=0``.
-"""
+"""Bit-identical FLUX.2 RoPE Triton kernel for fp16 GPUs; off via UNSLOTH_DIFFUSION_FLUX2_FUSED_ROPE=0."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_flux3.py b/studio/backend/core/inference/diffusion_flux3.py
index 0eace8066db..a25723aaa6f 100644
--- a/studio/backend/core/inference/diffusion_flux3.py
+++ b/studio/backend/core/inference/diffusion_flux3.py
@@ -1,22 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""FLUX.3 Image Klein: a classic pipeline face over Diffusers' modular FLUX.3 blocks.
-
-Diffusers ships FLUX.3 only as a Modular Diffusers workflow (``Flux3DistilledAutoBlocks`` for the
-16-step flow-map checkpoint, ``Flux3AutoBlocks`` for the undistilled base), and the repos carry a
-``modular_model_index.json`` instead of a ``model_index.json``. The image backend drives every
-other family through a ``DiffusionPipeline``: placement (``to`` / model and group offload), the
-step callback (progress, cancel), the decode-phase hook and the scheduler swap all address
-``pipe.<component>``. ``Flux3KleinPipeline`` is that face: it registers the same component
-objects the blocks run, so offload hooks, compiled or quantised replacements and a swapped
-scheduler reach the blocks unchanged, and its ``__call__`` takes the keywords the generate path
-passes.
-
-The component objects are loaded per subfolder (``text_encoder`` also carries the Qwen3-VL
-processor), so only ``transformer/``, ``text_encoder/`` and ``vae/`` are ever read; the repo-root
-BFL single file and ``ae.safetensors`` and the ``variants/`` quantised packages are not.
-"""
+"""FLUX.3 pipeline facade over Modular Diffusers blocks; reads only transformer/, text_encoder/, vae/."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_fp16_guard.py b/studio/backend/core/inference/diffusion_fp16_guard.py
index e27cc9b3f02..c0f20863213 100644
--- a/studio/backend/core/inference/diffusion_fp16_guard.py
+++ b/studio/backend/core/inference/diffusion_fp16_guard.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep bf16-native DiTs in float16 on fp16-only cards (T4 / sm75) instead of promoting them to float32.
-
-``rescale_post_norm``: a branch that overflows float16 but feeds an RMSNorm is divided by a power of two s before the
-overflow point and that norm's eps by s**2, since ``rms_norm(y / s, eps / s**2) == rms_norm(y, eps)`` (no clamping).
-Attention scales its input (q / k RMSNorm eps scaled too; v and the bias-free out projection are linear); the FFN scales
-the ``w3`` half of the gate. Hooks sit on the parents and call ``to_q`` / ``w1`` / ... at run time, so a later LoRA or
-quantized Linear sees the same rescale. Kill switch: ``UNSLOTH_STUDIO_FP16_GUARD=0`` restores the float32 promotion.
-"""
+"""Keeps bf16 DiTs in float16 on fp16-only cards by pre-scaling; hooks run at call time so a later
+LoRA or quantized Linear sees the same rescale; UNSLOTH_STUDIO_FP16_GUARD=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_fp16_variant.py b/studio/backend/core/inference/diffusion_fp16_variant.py
index 0ad479f597f..97a25a7ca42 100644
--- a/studio/backend/core/inference/diffusion_fp16_variant.py
+++ b/studio/backend/core/inference/diffusion_fp16_variant.py
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Read ``.fp16`` weight twins instead of fp32 defaults on fp16 loads (bit-identical after the cast).
-
-fp16 targets only (fp16 -> bf16 rounds differently); needs a single-file twin for EVERY component and no class
-pinning fp32 modules. Kill switch: ``UNSLOTH_DIFFUSION_FP16_VARIANT=0``.
-"""
+"""Reads .fp16 weight twins on fp16 loads only, and only when every component has a single-file twin
+and no class pins fp32 modules; bit-identical after cast; UNSLOTH_DIFFUSION_FP16_VARIANT=0
+disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_fp8_unit_scale.py b/studio/backend/core/inference/diffusion_fp8_unit_scale.py
index 919f0db5add..0b2c552198a 100644
--- a/studio/backend/core/inference/diffusion_fp8_unit_scale.py
+++ b/studio/backend/core/inference/diffusion_fp8_unit_scale.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""sm_89 precise-accumulate fp8 GEMM: unit-scale ``torch._scaled_mm`` + fp32 row x column scale epilogue.
-
-On sm_89 torchao's row-wise ``_scaled_mm`` hits a slow CUTLASS stream-K kernel. L4, torch 2.14.1, 1024 px linears:
-* precise accumulate: row-wise 29-32 TFLOP/s, per-tensor 102-134 TFLOP/s; end to end klein-4B 1.034 -> 0.480 s/step,
- Z-Image-Turbo 1.708 -> 0.772 s/step.
-* fast accumulate: row-wise 85-108, per-tensor 91-127 TFLOP/s, no end-to-end gain, so left on torchao (bit-identical).
-Only difference vs row-wise: one bf16 rounding of the unscaled accumulator (relative error <= 2^-9).
-
-``UNSLOTH_DIFFUSION_FP8_UNIT_SCALE``: ``0`` off, ``1`` every arch + both accumulate modes (testing), else auto.
-"""
+"""sm_89 precise-accumulate fp8: unit-scale _scaled_mm beats torchao row-wise (fast accumulate stays
+on torchao, no gain); UNSLOTH_DIFFUSION_FP8_UNIT_SCALE=0 off."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_gguf_compile.py b/studio/backend/core/inference/diffusion_gguf_compile.py
index 5635966fc0d..a04aa8d9728 100644
--- a/studio/backend/core/inference/diffusion_gguf_compile.py
+++ b/studio/backend/core/inference/diffusion_gguf_compile.py
@@ -1,29 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GGUF dequant accelerator for the light-compile (``default``) diffusion path.
-
-Profiling showed ~70-80% of EAGER GGUF denoise CUDA time is the per-forward weight dequant:
-every ``GGUFLinear.forward`` calls ``dequantize_gguf_tensor`` -> ``dequantize_blocks_Q4_K``, a
-~20-op pure-PyTorch chain, once per linear per step.
-
-``install_compiled_dequant`` swaps ``dequantize_gguf_tensor`` for ``torch.compile(orig,
-dynamic=True)``, which Inductor fuses into a few kernels. Measured 1.24-1.64x warm at a small
-compile (~7.5-10.4s), zero extra VRAM (weights stay quantized). ``dynamic=True`` is key: the
-dequant inputs are the fixed-shape WEIGHT tensors, so it compiles once and never recompiles on a
-resolution change. ``forward_native`` resolves the function as a module global, so replacing the
-module attribute reroutes every linear.
-
-The ``default`` tier's lever (block stays eager), and ``max``'s where the block cannot compile (ROCm). NOT used
-when ``max`` compiles the block: that graph fuses the dequant inline, and a separate compiled dequant would break it.
-
-The swap goes through the shared reversible patch backend; ``uninstall_*`` restores the exact
-original so a later bit-identical ``off`` load runs stock dequant. Kill-switch:
-``UNSLOTH_DIFFUSION_GGUF_COMPILE_DEQUANT=0``. torch / diffusers imported lazily.
-
-(A weight-buffer accelerator was removed: neutral end-to-end, since the CUDA caching allocator
-already serves the per-forward cast from its pool. See outputs/arch_patch/SUMMARY.md.)
-"""
+"""Compiles GGUF dequant with dynamic=True for the default tier and for max where the block cannot
+compile; never where max compiles the block (would break it); torch and diffusers imported
+lazily; UNSLOTH_DIFFUSION_GGUF_COMPILE_DEQUANT=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_gguf_pipeline.py b/studio/backend/core/inference/diffusion_gguf_pipeline.py
index 1db08b17bf8..2a9d60b77a7 100644
--- a/studio/backend/core/inference/diffusion_gguf_pipeline.py
+++ b/studio/backend/core/inference/diffusion_gguf_pipeline.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Load a whole-pipeline GGUF (stable-diffusion.cpp ``convert`` of an SDXL checkpoint) through diffusers.
-
-Pipeline-level ``from_single_file`` treats every component as packed GGUF bytes (text encoders fail 816 vs 768), so
-only the denoiser loads quantized; the rest is dequantized once and fed to the pipeline loader in place of the read.
-"""
+"""Loads whole-pipeline GGUFs via diffusers: only the denoiser stays quantized, rest is dequantized."""
import threading
from typing import Any, Optional
diff --git a/studio/backend/core/inference/diffusion_gguf_route.py b/studio/backend/core/inference/diffusion_gguf_route.py
index 90b9d9e52bf..f97944cce2a 100644
--- a/studio/backend/core/inference/diffusion_gguf_route.py
+++ b/studio/backend/core/inference/diffusion_gguf_route.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Let a GGUF pick whose memory plan offloads load the cached hosted int8 / fp8 checkpoint under that offload.
-
-Only a pre-quantised checkpoint, never a dense bf16 build; ``auto`` takes it only when cached and only for GGUFs less
-accurate than it. Device eligibility (CUDA bf16) is the caller's.
-"""
+"""Under offload, auto uses a cached pre-quantised int8/fp8 checkpoint only for GGUFs less accurate
+than it; never a dense bf16 build; device eligibility is the caller's."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_hidream.py b/studio/backend/core/inference/diffusion_hidream.py
index 51b9f5d1475..d7f37ed6541 100644
--- a/studio/backend/core/inference/diffusion_hidream.py
+++ b/studio/backend/core/inference/diffusion_hidream.py
@@ -1,17 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""HiDream-I1 Llama text-encoder assembly.
-
-The HiDream-ai/HiDream-I1-* repos name ``text_encoder_4`` (LlamaForCausalLM) and
-``tokenizer_4`` in their model_index but do NOT ship the weights: the official example
-loads meta-llama/Meta-Llama-3.1-8B-Instruct separately and passes both components into
-``HiDreamImagePipeline.from_pretrained``. That upstream repo is Hub-gated (manual
-approval), so Unsloth loads the open unsloth mirror instead -- byte-identical weights,
-no license wall at load time, and the unsloth org is already inside the loader's
-non-GGUF trust gate. ``output_hidden_states=True`` matches the official example: the
-pipeline's prompt encoder consumes the Llama hidden states, not the logits.
-"""
+"""HiDream Llama encoder loads the byte-identical unsloth mirror since upstream is gated; the
+unsloth org is inside the non-GGUF trust gate; output_hidden_states=True, as the pipeline
+consumes hidden states."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_hires.py b/studio/backend/core/inference/diffusion_hires.py
index ec10590b1bd..f396bd02746 100644
--- a/studio/backend/core/inference/diffusion_hires.py
+++ b/studio/backend/core/inference/diffusion_hires.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Hires fix: txt2img, upscale, then refine (img2img at a denoise) in one request.
-
-Defaults follow ComfyUI's 2_pass_txt2img example (1.5x, denoise 0.5, 14 steps). Hires steps is the exact refine
-count, as in ComfyUI (``new_steps = int(steps / denoise)``) and A1111 (``hr_second_pass_steps or steps``).
-"""
+"""Hires fix (txt2img, upscale, img2img refine); hires steps is the exact refine count, as in ComfyUI."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_hosted_vae.py b/studio/backend/core/inference/diffusion_hosted_vae.py
index 65ea65c336e..d3e35f8cb66 100644
--- a/studio/backend/core/inference/diffusion_hosted_vae.py
+++ b/studio/backend/core/inference/diffusion_hosted_vae.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Hosted bf16 VAE for a bf16 diffusers pipeline load whose base repo stores its VAE in fp32.
-
-Same module as bf16 ``from_pretrained`` of the fp32 ``vae/``, half the bytes. Any load failure falls back to the
-base ``vae/``, fetching it when the plan dropped it. ``UNSLOTH_DIFFUSION_HOSTED_VAE=0`` disables.
-"""
+"""bf16 VAE for fp32-VAE base repos (fallback: base vae/); UNSLOTH_DIFFUSION_HOSTED_VAE=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_hub_evidence.py b/studio/backend/core/inference/diffusion_hub_evidence.py
index a462cf2b1eb..0e71eab93e1 100644
--- a/studio/backend/core/inference/diffusion_hub_evidence.py
+++ b/studio/backend/core/inference/diffusion_hub_evidence.py
@@ -1,22 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Family evidence for a Hub single-file pick whose id and filename name no family.
-
-Fine-tunes ship under their own names (``Laxhar/noobai-XL-Vpred-1.0``,
-``OnomaAIResearch/Illustrious-xl-early-release-v0``), so the name matcher answers None and the pick
-is refused as an unknown family although the checkpoint states what it is: its safetensors header
-holds a whole SDXL checkpoint (UNet, both text encoders, VAE). Only that is read: the picked file's
-header, and only for whole-pipeline families (SDXL), whose checkpoint is self-contained; a
-transformer-only family resolves its base and defaults from the name. A pipeline pick needs no
-evidence here: a remote one loads only from trusted (named) repos, and a local folder is already
-read through its ``model_index.json``.
-
-Evidence is advisory. ``prefetch_for_pick`` (the routes, user-initiated requests only) re-reads the
-header off the Hub on every request; ``cached_family`` hands that verdict, or a cached copy's header,
-to the network-free ``detect_family_for_pick``. The load opens the downloaded file itself, and that
-stays the authoritative check.
-"""
+"""Family evidence from a Hub safetensors header (SDXL only); advisory, the load check stays final;
+remote pipeline picks need no evidence (trusted repos); detect_family_for_pick is network-free;
+prefetch_for_pick only for user requests."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_ideogram4.py b/studio/backend/core/inference/diffusion_ideogram4.py
index 4818f9d4a64..c31478dbf23 100644
--- a/studio/backend/core/inference/diffusion_ideogram4.py
+++ b/studio/backend/core/inference/diffusion_ideogram4.py
@@ -1,31 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Ideogram 4 pipeline assembly for a transformers-4.x runtime.
-
-The ideogram-ai repos ship the transformers-5.x Qwen text stack (like the krea repos), breaking
-``Ideogram4Pipeline.from_pretrained`` on 4.x twice: (1) ``text_encoder/config.json`` keeps rope
-under ``rope_parameters`` (5.x), which 4.x Qwen3-VL crashes on -- fixed by the shared krea remap
-shim; (2) ``model_index.json`` pins the SLOW ``Qwen2Tokenizer`` but the repo ships only
-``tokenizer.json``, so neither the slow class (can't construct) nor the fast class (type-gate
-rejected) loads. So the pipeline is assembled per-component (no from_pretrained type gate).
-
-The two DiTs need one more fix on the ``-fp8`` base repo, whose shards store the vendor's float8
-layout diffusers can't read: attention is FUSED as ``attention.qkv.weight`` [3*hidden, hidden]
-(Q/K/V stacked) + ``attention.o.weight``, vs diffusers' SPLIT ``to_q``/``to_k``/``to_v`` +
-``to_out.0`` (from_pretrained maps neither -> random weights on meta); and each ``*.weight`` is
-float8_e4m3 with a per-channel ``*.weight_scale`` (real weight = ``fp8.float() * scale[:, None]``)
-that diffusers drops. So ``load_ideogram4_transformer`` reads the shards, dequantizes, splits qkv
-and renames o -> to_out.0, then loads into a config-constructed model (verified vs the split
-``-nf4`` repo: cosine ~0.997, quant noise apart). The already-split ``-nf4`` repos carry a
-``quantization_config`` and use the stock path, so the conversion is gated on the ``*.weight_scale``
-marker. VAE via ``AutoencoderKLFlux2``, scheduler ``FlowMatchEulerDiscreteScheduler``.
-
-One last incompat is in the diffusers pipeline: it calls ``create_causal_mask(inputs_embeds=...)``
-with no ``cache_position``, but 4.x/5.0 spell it ``input_embeds`` and require ``cache_position``.
-``_patch_create_causal_mask`` installs a signature-aware wrapper that renames the kwarg and derives
-``cache_position``; self-disabling where the installed function already accepts the exact kwargs.
-"""
+"""Ideogram 4 assembled per component for transformers 4.x; -fp8 DiTs need fp8 dequant and qkv
+split, gated on weight_scale (-nf4 keeps stock path); create_causal_mask kwarg patch self-
+disables where supported."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_inductor_backports.py b/studio/backend/core/inference/diffusion_inductor_backports.py
index e4c3c060ae1..fb38e873adf 100644
--- a/studio/backend/core/inference/diffusion_inductor_backports.py
+++ b/studio/backend/core/inference/diffusion_inductor_backports.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Backport of torch 2.14's polynomial-gcd proof in ``SizeVarAllocator.statically_known_multiple_of``.
-
-torch 2.12 / 2.13 cannot prove ``(k*a - k*b) % (a - b) == 0`` and raise inductor ``CantSplit`` under
-``torch.compile(dynamic=True)`` (Qwen-Image-2.1 torchao fp8 / int8, FLUX.1 single-stream blocks). Probe-gated, not
-version-gated; only turns False into True when the gcd equals the denominator up to sign.
-Kill switch: ``UNSLOTH_DIFFUSION_INDUCTOR_BACKPORTS=0``."""
+"""Backport of torch 2.14 gcd multiple-of proof; probe-gated, not version-gated, and only turns
+False into True; UNSLOTH_DIFFUSION_INDUCTOR_BACKPORTS=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_inference_info.py b/studio/backend/core/inference/diffusion_inference_info.py
index f2ab6352ac8..d515cab3db4 100644
--- a/studio/backend/core/inference/diffusion_inference_info.py
+++ b/studio/backend/core/inference/diffusion_inference_info.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pure, torch-free per-family footprint summary for the inference info endpoint.
-
-Turns the auto-policy's per-family bf16 component table plus its per-scheme steady factors into a
-static "what would this cost resident" summary the frontend shows BEFORE loading, so a user can
-size the int8/fp8/nvfp4/mxfp8 tradeoff. Estimates are the STEADY resident footprint (transformer *
-factor + companions), matching ``estimate_dense_quant``'s ``steady_total``. Pure: torch-free, no
-GPU probing, unit-tests on CPU-only hosts.
-"""
+"""Pure torch-free per-family steady footprint (transformer * factor + companions) for info endpoint."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_int8_fused.py b/studio/backend/core/inference/diffusion_int8_fused.py
index 52f68e50f02..1a0057b8d73 100644
--- a/studio/backend/core/inference/diffusion_int8_fused.py
+++ b/studio/backend/core/inference/diffusion_int8_fused.py
@@ -1,31 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Fused int8 activation path between two torchao int8 GEMMs of a DiT feed-forward: one Triton kernel
-reads the int32 ``_int_mm`` output, applies dequant + GELU(tanh) / SwiGLU and writes int8 + the fp32 row scale.
-
-NUMERICS: bit-identical to EAGER torchao + ATen (every bf16 rounding kept, ATen's GELU(tanh) formula op for op (equal
-on every bf16 input), fp contraction off so
-``y * w_scale + bias`` rounds twice, row scale ``bf16(amax / 127.5)`` clamped at fp32 eps, quantizer multiplies by
-the correctly rounded reciprocal). The compiled stock path is NOT eager-exact (Inductor keeps fp32 chains).
-Activation-scale contract follows the incoming scale's dtype: fp32 on torchao >= 0.18; bf16 on <= 0.17, where
-``int32 * bf16`` rounds twice (int32 -> fp32 -> bf16) and ``1 / s`` and ``x * (1 / s)`` round to bf16.
-
-Anything but a plain dynamic symmetric per-row ``Int8Tensor`` on CUDA + Triton >= 3.2 keeps the stock path.
-
-ConvRot (Z-Image int8 default): w1 and w3 rotate the same input, so the SwiGLU's fused in-projection is a ConvRotLinear
-(one rotation + one activation quant for both halves). A rotated w2 needs its input rotated BEFORE the quant, which the
-kernel's fused quant cannot do, so that MLP computes the bf16 SiLU product with the stock epilogue ops and hands it to
-w2's own (rotating) forward. Same ops on the same values as the three stock rotated Linears.
-
-``int8_linear`` (also used by Z-Image's fused attention) runs a plain or rotated Int8Tensor Linear as torchao's act
-quant + ``_int_mm`` + epilogue without torchao 0.17's always-on zero-point pass, and the act quant itself as one probed
-Triton kernel (``int8_act_quant_rows``, bit-identical to torchao 0.17 and 0.18): Inductor's codegen of the same per-row
-quant ran 2-3x slower on B200 (Z-Image shapes, M 4224: K 3840 24-32 -> 11 us, K 10240 53-70 -> 32 us).
-A rotated input (ConvRot) is rotated and quantized by one kernel (``_rotated_act_quant``: ``rotq_h16`` of
-``diffusion_convrot_quant``) on an unlisted-arch card it was armed for, else rotation GEMM + act quant.
-Kill switch: ``UNSLOTH_DIFFUSION_INT8_FUSED=0`` (all of the above).
-"""
+"""Fused int8 FFN activation kernel, bit-identical to eager; only a plain dynamic symmetric per-row
+Int8Tensor on CUDA with Triton 3.2 or newer takes it, else stock path;
+UNSLOTH_DIFFUSION_INT8_FUSED=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_int8_gemm.py b/studio/backend/core/inference/diffusion_int8_gemm.py
index 7992150062f..109cdb29b33 100644
--- a/studio/backend/core/inference/diffusion_int8_gemm.py
+++ b/studio/backend/core/inference/diffusion_int8_gemm.py
@@ -1,51 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""int8 x int8 GEMM with torchao's dequant epilogue in the kernel: bf16 out instead of an int32 ``_int_mm`` output.
-
-The stock torchao W8A8 linear writes the int32 accumulator to HBM (4 bytes per output element) and the next compiled
-kernel reads it back to apply ``(c * x_scale) * w_scale``. Here one Triton kernel does the GEMM and the epilogue and
-writes bf16, so every int8 Linear writes half the bytes and its consumer (norm, RoPE, SwiGLU, act quant) reads half.
-
-NUMERICS: the Linear output is bit-identical to torchao's epilogue, eager and compiled under Studio's
-``emulate_precision_casts``: ``bf16(bf16(r(c) * xs) * ws)`` (+ bias as a bf16 add), where ``r`` rounds the int32
-accumulator to bf16 when the activation scale is bf16 (int32 * bf16 promotes to bf16, via fp32: two roundings) and to
-fp32 when it is fp32.
-The activation quant is torchao's own math, so Inductor still fuses it into the producer. A compiled block is NOT
-bit-identical end to end: the consumer reductions (LayerNorm / RMSNorm Welford) that used to fuse the epilogue now
-read bf16 and Inductor re-tiles them, a rounding-order change smaller than compiled-vs-eager (LPIPS-gated).
-
-Per-arch gate: sm80 / sm89 / sm120 on (measured), everything else stock. sm75: Triton cannot lower the int8 dot;
-sm100: Triton int8 is slower than cuBLAS. ROCm (weight-only int8 there) and CPU never reach it.
-Tiles: one default per arch plus a per-shape table (``_SHAPE_TILES``) for the shapes where another tile measured
-faster; every tile is probed bit-exact per device, and a tile that fails falls back to the arch default. All tiles
-accumulate in int32, so the output does not depend on the tile.
-
-Kill switch: ``UNSLOTH_DIFFUSION_INT8_GEMM=0``; ``=1`` also enables it on an unmeasured arch (still probe-gated).
-``UNSLOTH_DIFFUSION_INT8_GEMM_TILES=0`` keeps the arch default tile for every shape.
-
-ConvRot Linears (MiniMax-H3, Qwen-Image-2.1 ConvRot) run ``ConvRotLinear.forward``'s own rotation first, so eager
-output stays bit-identical; kill switch ``UNSLOTH_DIFFUSION_INT8_GEMM_CONVROT=0``.
-
-Rotated Linears on the archs ``diffusion_convrot_quant`` covers run the rotation and the act quant as ONE kernel
-(``rotq_h16`` / ``rotq_i8``, probed per device). Where the fused GEMM is off but that kernel is on (sm100), only the
-rotated Linears are swapped and their GEMM is cuBLAS ``_int_mm`` with torchao's epilogue, op for op. Kill switch
-``UNSLOTH_DIFFUSION_INT8_ROTQUANT=0``.
-
-Rotated Linears that read the SAME activation (Q / K / V, a SwiGLU's gate / value) share one rotation + act quant
-(``shared_rotq_linears``): Inductor does not merge identical opaque custom-op calls in an inference graph (7 kernels
-per Qwen-Image-2.1 block for 4 distinct inputs). Outputs are bit-identical to the separate calls.
-
-A fully swapped Qwen-Image-2.1 SwiGLU MLP takes its down projection's codes straight from the gate / value halves
-(``convrot_swiglu_act_quant``); kill switch ``UNSLOTH_DIFFUSION_INT8_ROTQUANT_SWIGLU=0``.
-
-A block-streamed denoiser installs against its onload device (``install(..., device = ...)``): group offload's
-``swap_tensors`` keeps each Parameter's identity and the forward reads the payload off the live Parameter, so every
-call sees the onloaded copy. Kill switch ``UNSLOTH_DIFFUSION_INT8_GEMM_STREAMED=0``.
-
-It also patches host-resident SwiGLU MLPs (the group hook onloads the block first; off-device weights fall back to
-stock). Kill switch ``UNSLOTH_DIFFUSION_INT8_SWIGLU_STREAMED=0``.
-"""
+"""int8 GEMM with torchao dequant epilogue in Triton, bf16 out; sm80/sm89/sm120 only, else stock
+(ROCm and CPU never reach it); Linear output bit-identical, compiled block not end to end;
+UNSLOTH_DIFFUSION_INT8_GEMM=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_krea2.py b/studio/backend/core/inference/diffusion_krea2.py
index 5d71b0570f4..3559a0c358b 100644
--- a/studio/backend/core/inference/diffusion_krea2.py
+++ b/studio/backend/core/inference/diffusion_krea2.py
@@ -1,27 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Krea 2 pipeline loader: assembles ``Krea2Pipeline`` from per-component loads.
-
-Why not ``from_pretrained``: the ``krea/Krea-2-Turbo`` repo was exported with transformers 5.2 and
-two configs use 5.x-only conventions 4.x can't parse:
-
-- ``tokenizer_config.json`` declares slow ``Qwen2Tokenizer`` but ships only ``tokenizer.json``.
- 4.x's slow class needs vocab.json/merges.txt (absent), and its fast class trips over
- ``extra_special_tokens`` stored as a LIST. Loading the fast class with ``extra_special_tokens={}``
- is id-identical (every token is already an added special token, and the pipeline templates prompts
- manually).
-- ``text_encoder/config.json`` keeps rope under ``rope_parameters`` (5.x); 4.x reads
- ``rope_scaling`` + ``rope_theta`` and crashes. The values are copied verbatim and equal 4.x's
- Qwen3-VL defaults, so the rotary embedding is numerically identical.
-
-``from_pretrained`` also type-checks a passed ``tokenizer`` against the SLOW class, so the pipeline
-is built through its constructor, forwarding the ``is_distilled`` / ``text_encoder_select_layers`` /
-``patch_size`` init config (Turbo's mu=1.15 shift rides on ``is_distilled``).
-
-Both workarounds self-disable on transformers 5.x (the plain tokenizer load succeeds, rope_scaling
-parses non-None).
-"""
+"""Krea2Pipeline built through its constructor, forwarding is_distilled, text_encoder_select_layers
+and patch_size (Turbo shift rides on is_distilled); both workarounds self-disable on transformers
+5.x."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_layer_split.py b/studio/backend/core/inference/diffusion_layer_split.py
index 767b99565e0..4af8bec252e 100644
--- a/studio/backend/core/inference/diffusion_layer_split.py
+++ b/studio/backend/core/inference/diffusion_layer_split.py
@@ -1,30 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One denoiser split across several CUDA cards by contiguous ranges of its repeated blocks (layer split).
-
-For a DiT that does not fit one selected card: each repeated block lives whole on one card, everything else of the
-denoiser (embedders, modulation, final norm and projection) stays on the primary. Blocks run one after another, so
-this buys memory, not speed; the weights never move after placement and only activations cross a card boundary.
-
-The boundary is a same-named subclass of each block's class whose ``__call__`` moves tensor arguments to the block's
-card before ``nn.Module.__call__`` runs. It runs outside ``_compiled_call_impl``, so a regional compile only ever sees
-tensors on the block's own card (no graph break; the shared block code compiles once per card). Tensors computed once
-per forward on the primary (rotary tables, modulation, masks) are copied once per card per forward, not per block.
-
-Outputs: in lazy mode a block's outputs move only where the next block of its list sits on another card, and home at
-the end of the list. That is only correct when the denoiser's loop does no tensor op of its own between blocks, so it
-is limited to the classes below and to calls without a residual input (ControlNet, VACE hints); every other call is
-eager: outputs return to the primary after every off-primary block. Both are exact copies, so the image matches a
-one-card run bit for bit.
-
-Every route reads where the block's weights and the denoiser's own weights are NOW, per call, so a later ``.to()`` of
-the pipeline or of the denoiser (eviction to the CPU, a move onto one card) keeps the forward on one device, as the
-component boundary does.
-
-Kill switch ``UNSLOTH_DIFFUSION_LAYER_SPLIT=0`` (never split a denoiser; the planner offloads as before); ``force``
-splits across the selected cards even when one card would hold the denoiser (for proving bit-identity).
-"""
+"""Splits repeated denoiser blocks over CUDA cards for memory, not speed; lazy output hand-off only
+for listed classes without residual inputs, else eager; UNSLOTH_DIFFUSION_LAYER_SPLIT=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_layer_split_plan.py b/studio/backend/core/inference/diffusion_layer_split_plan.py
index 886540404fc..0ef16a29ea4 100644
--- a/studio/backend/core/inference/diffusion_layer_split_plan.py
+++ b/studio/backend/core/inference/diffusion_layer_split_plan.py
@@ -1,23 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Layer split planner: a denoiser too big for one card, cut into contiguous block ranges across the selected cards.
-
-Order of preference on a multi-card selection: companion split (diffusion_multigpu), then a layer split, then the
-one-card offload plan. A layer split is only considered when the one-card plan offloads the DENOISER itself and the
-companion assignment found nothing; it is priced with the same per-card reserves as the companion split. The VAE and
-every non-text-encoder companion stay on the primary (the decode and its tile verdict stay where today's guard reads
-them); the text encoders may move to any used card. One card, Keep multiple models loaded and the kill switches keep
-today's plan unchanged. ROCm splits across discrete cards only (an APU's memory is the host's: a split across "cards"
-sharing one pool frees nothing), and a per-gfx-target attention kernel keeps blocks on cards of the primary's target.
-
-The engine (block placement + device-crossing hooks) is a separate piece; this module only defines the interface it
-must provide (``split_blocks``, ``engine_available``, ``place_layer_split``, ``undo_layer_split``) with stubs that keep
-production behaviour unchanged until it lands.
-
-``UNSLOTH_DIFFUSION_LAYER_SPLIT=0`` turns only this off; ``force`` also cuts a denoiser one card would hold resident
-(for proving the engine on cards that are too big to need it).
-"""
+"""Layer split tried after companion split, only when the one-card plan offloads the denoiser; one
+card, Keep multiple models loaded and kill switches keep the current plan unchanged; engine is
+stubbed until it lands."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_lora.py b/studio/backend/core/inference/diffusion_lora.py
index 939a6e26f81..05b9e396014 100644
--- a/studio/backend/core/inference/diffusion_lora.py
+++ b/studio/backend/core/inference/diffusion_lora.py
@@ -1,17 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Shared LoRA support for the Unsloth diffusion backends.
-
-The native sd-cli engine selects adapters by `<lora:NAME:WEIGHT>` prompt tags resolved against a
-`--lora-model-dir`; diffusers loads them with `load_lora_weights()` + `set_adapters()`. This
-module holds the shared parts: a curated + local catalog, id->file resolution (with HF download),
-a managed directory materialiser, native alias naming, and the single `supports_lora()` gate.
-
-The request layer only passes a LoRA *id* (discovery id, local stem, or HF repo id) plus a
-weight, never a raw path, so a client cannot make the backend read an arbitrary file. Resolution
-validates the id against the catalog / local dir / HF hub before loading.
-"""
+"""Shared LoRA catalog and id resolution; requests pass only an id, never a path (no arbitrary reads)."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_mask.py b/studio/backend/core/inference/diffusion_mask.py
index d9236b6f6a0..1482dc00fa5 100644
--- a/studio/backend/core/inference/diffusion_mask.py
+++ b/studio/backend/core/inference/diffusion_mask.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Inpaint mask settings: AUTOMATIC1111's "Mask blur" and "Inpaint area: Only masked" (diffusers padding_mask_crop).
-
-Unset / 0 / False leave the request exactly as before."""
+"""Inpaint mask blur and only-masked crop (padding_mask_crop); unset, 0 or False is a no-op."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_measured_peaks.py b/studio/backend/core/inference/diffusion_measured_peaks.py
index 4c48cee0536..549a5a196e5 100644
--- a/studio/backend/core/inference/diffusion_measured_peaks.py
+++ b/studio/backend/core/inference/diffusion_measured_peaks.py
@@ -1,23 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Learned activation peaks: the real CUDA peak above the resident weights, recorded per
-(family, denoiser quant, speed tier, resolution bucket, frames, GPU name) at a successful render and persisted under
-the Studio cache dir, so later loads of the same model place it from a measurement instead of the flat
-8192 MiB/MP estimate.
-
-The static tables in ``diffusion_memory`` stay the seed: a learned value only RAISES a seeded peak (a local
-measurement above the seed means this machine needs more) and supplies one where no seed exists. It never lowers a
-seed, because one render does not exercise every phase (a prompt-cache hit skips the encoder, a smaller request
-decodes less), and the seed was measured on the worst phase.
-
-Phases: ``pre_decode`` / ``decode`` on the whole-render scale (prefetch window pad included), ``decode_unpadded`` /
-``unpadded`` without it (only the VAE runs at decode; resident weights hold no window). Pre-phase stores place from the
-whole-render peak. ``UNSLOTH_DIFFUSION_PHASE_PEAKS=0`` ignores the phases.
-
-``UNSLOTH_DIFFUSION_LEARNED_PEAKS=0`` turns lookups and recording off; ``UNSLOTH_DIFFUSION_LEARNED_PEAKS_FILE``
-names the JSON file (default ``<studio cache>/diffusion_measured_peaks.json``).
-"""
+"""Learned CUDA activation peaks per render setup; they can raise the static seed but never lower it."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_moss_fused.py b/studio/backend/core/inference/diffusion_moss_fused.py
index 62a01c59322..0ef8633c155 100644
--- a/studio/backend/core/inference/diffusion_moss_fused.py
+++ b/studio/backend/core/inference/diffusion_moss_fused.py
@@ -1,29 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""MOSS-Image blocks inside the regional compile: one q/k/v GEMM, and int8 Linears through ``int8_linear``.
-
-ComfyUI's repacked MOSS files fuse ``proj.q/k/v`` into one ``proj.qkv`` Linear ("one GEMM and one activation
-quantization instead of three"). Here the three bias-free int8 projections become one Linear over the concatenated
-output rows, built at load from the checkpoint's own tensors: codes and per-row scales concatenate; ConvRot parts
-rotate the SAME input at one group, and the rotation acts on the shared input axis, so the fused Linear is itself a
-ConvRotLinear (one rotation + one act quant + one GEMM for q, k and v). Per-row scales make the fused output equal the
-three separate ones. The parts' weights become views of the fused one, so no memory is added. The block reads the
-fused Linear only inside the compiled forward and only while ``proj.q/k/v`` are still the modules it was built from
-(a LoRA wrapper keeps stock). bf16 keeps three GEMMs: one fused GEMM measured neutral there.
-
-int8 (plain or ConvRot) Linears also run through ``diffusion_int8_fused.int8_linear``: the module's own rotation, the
-probed Triton act quant (bit-identical to torchao's) and ``_int_mm`` with torchao's epilogue, i.e. torchao's eager math
-where the stock compiled path is Inductor's fp32 chain.
-
-Measured on an exclusive B200 (1024x1024, 30 steps, CFG 3, CUDA graphs, s/step): INT8-ConvRot 0.0769-0.0778 ->
-0.0752 with the runner -> 0.0722-0.0726 with the fused QKV too; plain INT8 0.0700 -> 0.0673-0.0678. Peak unchanged.
-
-``UNSLOTH_DIFFUSION_MOSS_QK_ROPE=1`` (opt-in) also runs the q/k RMSNorm + split-half RoPE + [B, H, S, D] relayout as
-one kernel below; it bought 0.7% on bf16 and nothing on int8, so it stays off.
-
-Kill switch: ``UNSLOTH_DIFFUSION_MOSS_FUSED=0`` (``UNSLOTH_DIFFUSION_MOSS_FUSED_QKV=0`` keeps only the int8 runner).
-"""
+"""MOSS-Image fused q/k/v GEMM and int8 Linears; falls back to stock under LoRA on proj.q/k/v."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_moss_image.py b/studio/backend/core/inference/diffusion_moss_image.py
index 21de8c3372f..46e796870f4 100644
--- a/studio/backend/core/inference/diffusion_moss_image.py
+++ b/studio/backend/core/inference/diffusion_moss_image.py
@@ -4,33 +4,8 @@
# The transformer, scheduler and pipeline below are a port of OpenMOSS-Team's ``pipeline_moss_image.py``
# (Apache-2.0, https://huggingface.co/OpenMOSS-Team/MOSS-Image-SFT), keeping its state-dict names and numerics.
-"""MOSS-Image (OpenMOSS-Team/MOSS-Image-SFT and -Base) as an in-tree diffusers pipeline.
-
-The official repos ship the transformer and scheduler as remote code (``model_index.json`` points both at the repo's
-``pipeline_moss_image.py``), and Studio never runs repo code: no ``trust_remote_code``, no ``custom_pipeline``. So the
-model lives here and the pipeline is assembled per component from safetensors and JSON only: ``MOSSImageTransformer``
-(this file) from ``transformer/``, the Qwen3.5 text encoder (``transformers.Qwen3_5Model``, transformers >= 5.3) from
-``text_encoder/``, the FLUX.2 small-decoder VAE (``diffusers.AutoencoderKLFlux2``) from ``vae/`` and the tokenizer.
-
-Numerics follow the reference op for op (fp32 RMSNorm with the weight applied after the cast, fp64 timestep sinusoid,
-fp32 RoPE phases cast to the activation dtype, fp32 noise, CFG and Euler update, fp32 VAE decode); the tests check the
-port bit for bit against the reference file on a tiny random model. What differs is only how the same values are
-reached:
-
-- RoPE tables are built once per (height, width, text length) and reused (the reference rebuilt them per forward).
-- The text refiner (two unmodulated text blocks) does not read the latent or the timestep, so the pipeline runs it
- once per prompt per render (``refine_text``) and hands the refined tokens to every step (``refined_text``), unless
- the transformer carries offload hooks (then every step refines, as the reference does).
-- One sample at its full text length takes no boolean-mask indexing and no ``torch.all`` mask check, so the forward
- is free of host syncs (CUDA-graph capturable); the pipeline passes no mask when every row has the same length.
-- Attention goes through diffusers' dispatcher (``set_attention_backend`` reaches it), whose native backend is the
- same ``scaled_dot_product_attention`` call.
-
-Sampling defaults follow ComfyUI's MOSS-Image workflow (the baseline): 1024x1024, 50 steps, CFG 3, shift 5, Euler
-over ``sgm_uniform`` sigmas, skip-layer guidance on block 22 for the negative pass, empty negative prompt. The
-reference pipeline snaps its sigmas to the 1000-point training grid instead; ``sigma_schedule = "training_grid"`` on
-the scheduler (or ``UNSLOTH_MOSS_SIGMAS=training_grid``) selects that.
-"""
+"""MOSS-Image in-tree diffusers pipeline, no remote code; numerics bit-identical to reference, only
+default sigmas differ"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_mps_fp16.py b/studio/backend/core/inference/diffusion_mps_fp16.py
index 0db3ab57763..b67e75d10e5 100644
--- a/studio/backend/core/inference/diffusion_mps_fp16.py
+++ b/studio/backend/core/inference/diffusion_mps_fp16.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in (``UNSLOTH_DIFFUSION_MPS_FP16=1``) fp16 compute for Z-Image attention / FFN internals on MPS.
-
-Plain fp16 NaNs (FFN output reaches ~5e5), so the two overflowing sites run at power-of-two headroom (exact, as the
-projections are bias-free and attention is linear in v), then are clamped to the fp16 range and rescaled in bf16:
-
- feed-forward: w2(silu(w1 x) * (w3 x / 32)) * 32
- attention: to_out(sdpa(q, k, v / 4)) * 4
-
-Patched per instance, never class-level, so other pipes / models are untouched.
-"""
+"""UNSLOTH_DIFFUSION_MPS_FP16=1 opt-in: Z-Image fp16 on MPS; plain fp16 NaNs, so overflow sites are
+power-of-two scaled, clamped and rescaled in bf16; patched per instance, never class-level"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_multigpu.py b/studio/backend/core/inference/diffusion_multigpu.py
index e0bf0df10b9..4ab7e593fd2 100644
--- a/studio/backend/core/inference/diffusion_multigpu.py
+++ b/studio/backend/core/inference/diffusion_multigpu.py
@@ -1,32 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Several selected CUDA / ROCm cards for one image or video pipeline, without NCCL.
-
-Three levers, all at a component or denoiser-call boundary, never inside a model forward:
-
-* Component split (planner): the DiT stays whole and resident on the primary card while the text encoders, VAE and
- other companions sit on a secondary card, when that removes offload on the primary. Inputs move to a module's own
- card at its entry points and outputs come back to the primary, so the pipeline still sees one device. Copies are
- exact, so the output is bit-identical to a single-card resident run.
-* Layer split (``diffusion_layer_split``): a DiT that fits no single selected card is split by contiguous ranges of
- its repeated blocks, the rest of it on the primary. Activations cross at the range boundaries only; outputs are
- bit-identical to a one-card run.
-* Second denoiser (after load): a two-DiT pipeline (an MoE ``transformer_2``) keeps one expert per card when both
- experts do not fit one card.
-* CFG-parallel (generate): when guidance runs separate cond / uncond denoiser calls on the same latents, every odd
- branch of a step runs on a replica of the denoiser on the secondary card, launched from a worker thread bound to
- that card, while the primary computes the even branch. One output is copied per step; guidance and the scheduler
- step stay on the primary. Branches are recognised from the call boundary alone (same latent tensor object in
- consecutive calls), so true CFG, rescale and multi-branch guidance work unchanged and a guidance-distilled model
- (one call per step) never builds a replica.
-* Layer split (after load, diffusion_layer_split_plan): when one card would offload the denoiser itself and no
- component assignment fits, the denoiser's blocks are cut across the cards. Excludes CFG-parallel.
-
-Kill switches: ``UNSLOTH_DIFFUSION_MULTIGPU=0`` (everything here; one card as before), ``UNSLOTH_DIFFUSION_CFG_PARALLEL=0``
-(only the replica). ``UNSLOTH_DIFFUSION_MULTIGPU=force`` splits the companions even when one card would hold
-everything (for proving bit-identity). With one selected card nothing here engages.
-"""
+"""Several CUDA/ROCm cards per pipeline without NCCL, split only at component or denoiser-call
+boundaries, never inside a forward; outputs bit-identical; UNSLOTH_DIFFUSION_MULTIGPU=0 disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_multistage.py b/studio/backend/core/inference/diffusion_multistage.py
index edd5c1db7fb..79e7c0b7a68 100644
--- a/studio/backend/core/inference/diffusion_multistage.py
+++ b/studio/backend/core/inference/diffusion_multistage.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Family-agnostic helpers for a render that calls its pipeline more than once per request (a multi-stage recipe:
-LTX-2.5's half-size stage, latent upsample, full-size stage). Each helper keys on what the pipeline object carries
-(its offload hook list, its denoiser, its ``encode_prompt``), never on a family name, so any multi-stage render can wrap
-its calls in them.
-
-``encode_once``: every stage encodes the same prompt; the later stages take the first one's device tensors.
-``hold_denoiser_between_calls``: under model CPU offload a pipeline call ends by offloading every component, so the
-next stage would upload the whole denoiser again; hold it when the work in between still fits beside it.
-"""
+"""Multi-stage render helpers keyed on pipeline attributes: encode once, hold denoiser under offload."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_native_cache.py b/studio/backend/core/inference/diffusion_native_cache.py
index c1947b123d6..99110cc75e9 100644
--- a/studio/backend/core/inference/diffusion_native_cache.py
+++ b/studio/backend/core/inference/diffusion_native_cache.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Local cache of native (torchao-free) runtime-quantized denoisers, one entry per component.
-
-Shares ``diffusion_prequant_cache``'s root, locks, manifest and eviction; the key adds the native build spec so an
-entry is only served to the identical native build.
-"""
+"""Native torchao-free denoiser cache, sharing diffusion_prequant_cache's root; key adds build spec."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_native_quant.py b/studio/backend/core/inference/diffusion_native_quant.py
index 2cea276d047..05bc71ac261 100644
--- a/studio/backend/core/inference/diffusion_native_quant.py
+++ b/studio/backend/core/inference/diffusion_native_quant.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Torchao-free weight-only int8 / fp8 for the diffusion transformer (ROCm, Windows torchao stub).
-
-Plain buffers, unlike torchao tensors, survive the offload hooks' ``Module.to()``; torch imported lazily.
-"""
+"""Torchao-free int8/fp8 weight-only quant for ROCm and Windows; plain buffers survive offload
+hooks' Module.to(); torch imported lazily"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_nvfp4_act_quant.py b/studio/backend/core/inference/diffusion_nvfp4_act_quant.py
index d70497b20d1..102c068a686 100644
--- a/studio/backend/core/inference/diffusion_nvfp4_act_quant.py
+++ b/studio/backend/core/inference/diffusion_nvfp4_act_quant.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One-pass NVFP4 quantiser for torchao's ``NVFP4Tensor.to_nvfp4`` (two-level scales, swizzled block scales).
-
-Under Inductor torchao's version is three kernels (quantise, pack, swizzle); this ``triton_op`` does all three in
-one pass.
-
-Arithmetic is torchao's, in torchao's order (block max / 6, divide by the per-tensor scale, clamp to
-[2^-6, 448], e4m3, then ``x * ((1 / s) / scale_fp8)``, clamp to +-6, round-to-nearest-even onto e2m1 by the
-same bit trick), so the packed bytes and scales are bit-identical to torchao's own path; ``verify()`` checks
-that on the device before the patch engages. ``UNSLOTH_NVFP4_FAST_ACT_QUANT=0`` restores torchao.
-"""
+"""One-pass NVFP4 quantiser, bit-identical to torchao's to_nvfp4; verify() checks it before the patch."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_nvfp4_dispatch.py b/studio/backend/core/inference/diffusion_nvfp4_dispatch.py
index 4f9b59300a1..b5dd11eb36f 100644
--- a/studio/backend/core/inference/diffusion_nvfp4_dispatch.py
+++ b/studio/backend/core/inference/diffusion_nvfp4_dispatch.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""FlashInfer's per-call dispatch work, cached. Every private import is HERE, fenced by an EXACT version
-allowlist, ONE all-or-nothing try, and a per-device bit-identity ``verify()`` (a symbol can change meaning)."""
+"""FlashInfer dispatch: every private import lives here, behind an exact-version allowlist in one
+all-or-nothing try, plus per-device verify()"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_nvfp4_install.py b/studio/backend/core/inference/diffusion_nvfp4_install.py
index a72b3fef76d..70e364ff19a 100644
--- a/studio/backend/core/inference/diffusion_nvfp4_install.py
+++ b/studio/backend/core/inference/diffusion_nvfp4_install.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Install FlashInfer on demand for an NVFP4 load, without ever moving the resident torch stack.
-
-Pinned flashinfer-python plus the CUDA-matched jit-cache; every installed distribution is constrained to its
-exact version, verified in a fresh interpreter, and rolled back on any drift.
-"""
+"""On-demand FlashInfer install for NVFP4 loads; pins exact versions, never moves torch, rolls back."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_nvfp4_linear.py b/studio/backend/core/inference/diffusion_nvfp4_linear.py
index 2b1626c5166..b1af17000b8 100644
--- a/studio/backend/core/inference/diffusion_nvfp4_linear.py
+++ b/studio/backend/core/inference/diffusion_nvfp4_linear.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The FlashInfer NVFP4 Linear, and the conversion that puts a hosted checkpoint onto it.
-
-ONE artifact, two backends. Nothing here requantizes: torchao's payload IS FlashInfer's, byte for
-byte. The activation global scale is BAKED, never calibrated (not capture-safe, and the cause of the
-flux black-frame latch), so a layer without one is NOT converted.
-"""
+"""FlashInfer NVFP4 Linear conversion (no requantize); layers without a baked act scale are skipped."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_nvfp4_policy.py b/studio/backend/core/inference/diffusion_nvfp4_policy.py
index ddb643a574b..4779b648907 100644
--- a/studio/backend/core/inference/diffusion_nvfp4_policy.py
+++ b/studio/backend/core/inference/diffusion_nvfp4_policy.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-layer NVFP4 policies for the image DiTs: a named set of layers at 4 bits over an fp8 model.
-
-A policy puts a named set of layers at 4 bits over fp8: a memory lever, not a speed win, so nvfp4
-sits BELOW fp8 in the image auto order. FAILS CLOSED: exact suffixes and asserted counts per rule.
-"""
+"""Per-layer NVFP4 policies for image DiTs: 4-bit layer sets over fp8, a memory lever not a speed
+win, so the image auto order puts nvfp4 below fp8; fails closed"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_nvfp4_protect.py b/studio/backend/core/inference/diffusion_nvfp4_protect.py
index 472a24053c0..d4d8aa4105b 100644
--- a/studio/backend/core/inference/diffusion_nvfp4_protect.py
+++ b/studio/backend/core/inference/diffusion_nvfp4_protect.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-step precision for the NVFP4 backend: which denoising steps run W4A16 instead of W4A4.
-
-A protected step dequantises to a transient bf16 weight; the counter wraps ``pipe.scheduler.step``.
-The set must be MEASURED per model (a copied set did worse than none), so it is off unless named.
-"""
+"""Denoise steps that run W4A16 instead of W4A4; set must be measured per model, so off unless named."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_offline_source.py b/studio/backend/core/inference/diffusion_offline_source.py
index ffa9b15d9a5..9fe67095c2d 100644
--- a/studio/backend/core/inference/diffusion_offline_source.py
+++ b/studio/backend/core/inference/diffusion_offline_source.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Offline tokenizer / processor loads open the cached snapshot folder, not the Hub repo id.
-
-transformers 5.x asks for ``<subfolder>/config.json`` first; offline by repo id it ignores the
-``.no_exist`` marker and raises, while a local folder just skips the missing file.
-"""
+"""Offline tokenizer loads must open the snapshot folder: transformers 5.x raises on repo ids offline."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_offload_prefetch.py b/studio/backend/core/inference/diffusion_offload_prefetch.py
index 895f2760cee..c6ca53ee304 100644
--- a/studio/backend/core/inference/diffusion_offload_prefetch.py
+++ b/studio/backend/core/inference/diffusion_offload_prefetch.py
@@ -1,24 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Event-fenced prefetch for a block-streamed denoiser's diffusers offload groups.
-
-diffusers fences its stream prefetch on the host (``stream.synchronize()`` per onload) and copies one group ahead.
-Here the compute stream waits on a per-group CUDA event instead, and up to ``depth`` streamed groups are copied ahead
-in the order the first forward recorded.
-
-A forward's first copies are queued at the first block's onload (behind a compute-stream event when the top-level
-group uploads on the compute stream): queued earlier they hold that upload back on the copy engine.
-
-Memory stays bounded without a host wait: each offload records a compute-stream event the copy stream waits on, so a
-freed block goes to the next prefetch only after the compute that read it. Bytes in flight never pass ``window``.
-Unpinned copies' temporary pinned staging is capped at ``window`` (else T4 Z-Image pinned the whole denoiser).
-Hooks are per-group / per-module instance attributes; diffusers' classes are untouched.
-
-Cross-forward carry: past the last recorded group, the NEXT forward's first groups are copied into free window
-bytes. Only while a render arms it (never into the last step's decode); held off under a slot ring, step graph,
-capture, or another prefetcher's forward in between (its copies would not be read next).
-"""
+"""Event-fenced prefetch of streamed offload groups, no host sync; a freed block is reused only
+after the compute that read it; bytes in flight never pass window; carry held off under slot
+ring, step graph or capture"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_patch_backend.py b/studio/backend/core/inference/diffusion_patch_backend.py
index 648f61bdf89..f98dbed4727 100644
--- a/studio/backend/core/inference/diffusion_patch_backend.py
+++ b/studio/backend/core/inference/diffusion_patch_backend.py
@@ -1,22 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One vetted path for every diffusion monkey-patch.
-
-Thin wrappers over ``unsloth_zoo.temporary_patches.utils`` ``patch_function`` /
-``restore_original`` so all runtime patching (eager fusions, GGUF accelerators, per-arch rewrites)
-goes through the SAME fingerprint-checked, reversible mechanism:
-
-* ``patch_function`` stashes the live original and, unless ``force=True``, runs
- ``can_safely_patch`` (a param-name/kind/required fingerprint; ``relaxed`` ignores annotation
- drift but rejects a real signature change) -- so a changed forward is left unpatched, not
- miscompiled.
-* ``restore_original`` restores the original -- exact, idempotent uninstall.
-
-``unsloth_zoo`` is imported LAZILY per call: it runs GPU detection at import and raises without an
-accelerator (``UNSLOTH_ALLOW_CPU=1`` bypasses), and the backend must stay importable on CPU-only
-hosts. If the import fails, patching is a best-effort no-op (stock forward runs, correctness kept).
-"""
+"""Diffusion patches via unsloth_zoo patch_function; unsloth_zoo imported lazily, and if that import
+fails patching is a best-effort no-op; changed forward stays unpatched"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_pinned_arena.py b/studio/backend/core/inference/diffusion_pinned_arena.py
index 18445c961b2..297359b1180 100644
--- a/studio/backend/core/inference/diffusion_pinned_arena.py
+++ b/studio/backend/core/inference/diffusion_pinned_arena.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One pinned host copy of a streamed module, packed into power-of-two slabs instead of one pin per tensor.
-
-torch's host allocator rounds each pin up to a power of two (H3's 19.45 GB int8 denoiser held 33.8 GB pinned), and the
-pageable source survived until each group's first onload. The slab copy replaces the parameter's storage on the spot.
-
-Used by every up-front group-offload pin (image streaming / group / resident tiers, streamed encoders, prequant, H3):
-a 23.8 GB bf16 Flux DiT held 37.2 GB pinned per tensor, 24.3 GB packed.
-
-Kill switch: ``UNSLOTH_DIFFUSION_PIN_ARENA=0`` restores per-tensor ``pin_memory()``.
-"""
+"""Streamed weights pinned in packed power-of-two slabs, since torch rounds each per-tensor pin up."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_postprocess.py b/studio/backend/core/inference/diffusion_postprocess.py
index 70fcc80c767..a8c7be26abb 100644
--- a/studio/backend/core/inference/diffusion_postprocess.py
+++ b/studio/backend/core/inference/diffusion_postprocess.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""diffusers' ``postprocess(output_type="pil")`` uint8 conversion on the device instead of numpy on the host.
-
-Stock runs ``(x * 255).round().astype("uint8")`` over host float32 copies, which stalls under host load. Same IEEE ops
-on clamped [0, 1] values, so bit-identical; anything else takes the stock path. A decoded image with NaN raises instead
-of saving blank. Kill switch: ``UNSLOTH_DIFFUSION_DEVICE_POSTPROCESS=0``.
-"""
+"""Device-side uint8 postprocess for output_type pil, bit-identical to stock numpy; other cases take
+the stock path; NaN raises instead of saving blank"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_precision.py b/studio/backend/core/inference/diffusion_precision.py
index 99c11459e6c..201c54b50b1 100644
--- a/studio/backend/core/inference/diffusion_precision.py
+++ b/studio/backend/core/inference/diffusion_precision.py
@@ -1,28 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in low-precision casting of the diffusion pipeline's text encoder(s).
-
-The transformer arrives quantised in the GGUF, but the companion text encoder loads dense
-(bf16) and is often the largest resident component (Qwen3 / T5-XXL / Mistral run to many GB).
-This shrinks it in place, with four backends:
-
- fp8 - diffusers layerwise casting: 8-bit (e4m3) storage, upcast per layer. ~2x
- smaller. Any fp8-capable CUDA card (cc >= 8.9).
- fp8_dynamic - torchao dynamic fp8 COMPUTE (per-row): keeps the matmul in fp8 on the tensor
- cores (torch._scaled_mm) instead of upcasting. ~2x smaller + speedup; cc >= 8.9.
- int8 - torchao dynamic int8 COMPUTE (per-token act + per-channel weight, _int_mm),
- with per-layer keep-bf16 selection. Degrades on large encoders unless the
- sensitive decoder blocks stay bf16, so applied only for families with a
- measured schedule (else falls back to fp8). ~2x smaller; cc >= 8.0.
- nvfp4 - torchao NVFP4 weight-only: 4-bit float storage, two-level microscaling, each
- weight dequantised to bf16 per forward (no FP4 GEMM). ~3.5x smaller (lowest
- VRAM) but a steeper quality cost and a slower prompt encode; cc >= 8.0.
-
-All keep norms / embeddings full precision, are a memory-vs-quality tradeoff (off by default),
-and pair well with streamed (group) offload where the text encoder stays resident. Quantify
-the quality cost with scripts/diffusion_quality.py. torch / diffusers / torchao imported lazily.
-"""
+"""Opt-in text-encoder casting: fp8, fp8_dynamic, int8 or nvfp4, norms kept full precision; int8
+falls back to fp8 unless measured; torch, diffusers, torchao imported lazily; off by default"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_prefix_kv.py b/studio/backend/core/inference/diffusion_prefix_kv.py
index 4acb7eaef7a..5754e7d8c57 100644
--- a/studio/backend/core/inference/diffusion_prefix_kv.py
+++ b/studio/backend/core/inference/diffusion_prefix_kv.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Inductor lowers a prefix KV cache's ``k[:, :prefix].clone()`` to a view of the full K/V buffer, pinning
-it for the render; a hook copies the cached tensors out after the prefill forward."""
+"""Prefix KV clone is copied out after prefill: Inductor makes it a view that pins the K/V buffer."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_prequant.py b/studio/backend/core/inference/diffusion_prequant.py
index b2edccf9ebe..6686bc6313b 100644
--- a/studio/backend/core/inference/diffusion_prequant.py
+++ b/studio/backend/core/inference/diffusion_prequant.py
@@ -1,31 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Load a *pre-quantized* transformer instead of quantising a dense one on the GPU.
-
-The runtime transformer_quant path loads the dense bf16 transformer and ``quantize_``s it in place,
-materialising the full bf16 weights on the GPU first (~2x the GGUF peak, plus the full bf16
-download). When a transformer was already quantised and saved
-(``scripts/build_prequant_checkpoint.py``), this loads those weights directly: build the skeleton on
-``meta`` (``init_empty_weights`` + ``from_config``), ``load_state_dict(assign=True)`` the quantized
-state dict (subclass tensors assigned, not copied, so dense bf16 never touches the GPU), then move
-to device. Measured (B200, Z-Image fp8): GPU load peak 12.9 -> 6.3 GB, download 12 -> 6.28 GB,
-output bit-identical (LPIPS 0.0). The checkpoint carries the same scheme + ``min_features`` as the
-runtime path, so the result matches quantising on the fly.
-
-Two containers, one dict. Historically the artifact could only be a ``torch.save`` pickle, because
-torchao's weight subclasses are wrapper tensors and safetensors stores flat ones; that pickle is read
-under ``weights_only`` plus the constructor ALLOWLIST below, never as a free one, since it is a
-mutable remote file reached by loads that never asked for a scheme (auto resolves an unset precision
-to a hosted checkpoint) and "first-party repo" cannot stand in for that restriction. torchao >= 0.16
-can flatten those subclasses, so an artifact may now also be ``.safetensors`` (see
-``prequant_safetensors``), which needs no allowlist at all and answers the validation questions from
-its header. ``_load_prequant_checkpoint`` returns the same ``{"format", "state_dict", "metadata"}``
-for both, so every check in this module applies to them identically and the two cannot drift apart.
-
-Best-effort and lazily imported: a missing / mismatched / unreadable checkpoint returns None and the
-caller falls back to dense-quantise (then GGUF). Inert with nothing configured.
-"""
+"""Pre-quantized transformer load, lazily imported; pickles use weights_only plus allowlist; bad
+files return None so the caller falls back to dense quantise"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_prequant_cache.py b/studio/backend/core/inference/diffusion_prequant_cache.py
index 1fa443a4b4d..22edf9d11e2 100644
--- a/studio/backend/core/inference/diffusion_prequant_cache.py
+++ b/studio/backend/core/inference/diffusion_prequant_cache.py
@@ -1,24 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Local cache of runtime-quantized denoisers for families with no hosted pre-quant, written in the hosted
-artifacts' exact container + metadata so the next load takes the hosted path from a local file.
-
-KEY: sha256 of every source shard's safetensors header plus content identity (Hub blob name, else stat; two uploads
-of one architecture share a header), component, scheme, POLICY_VERSION, class, Linear filter, ConvRot, fp8
-fast-accum and torch / torchao minors. The multi-GB payload is never read for the key.
-
-TRUST: only Studio writes the root (safetensors, no pickle), so files under its exact realpath count as allowlisted.
-
-COMMIT: artifact then manifest, each via temp + os.replace; the manifest is the commit point.
-
-ENV:
- UNSLOTH_DIFFUSION_PREQUANT_CACHE 0 disables lookups and saves (default on)
- UNSLOTH_DIFFUSION_PREQUANT_CACHE_DIR cache root (default <studio cache>/diffusion_prequant_cache)
- UNSLOTH_DIFFUSION_PREQUANT_CACHE_MAX_GB LRU budget in GB (default 40; 0 disables eviction)
- UNSLOTH_DIFFUSION_PREQUANT_CACHE_ASYNC 0 writes a pipeline load's build before the load returns (default: on a
- background thread once the load is published)
-"""
+"""Runtime-quantized denoiser cache, hosted artifact format; only Studio writes it (safetensors, no
+pickle), so files under its exact realpath are allowlisted; manifest is commit point"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_preview.py b/studio/backend/core/inference/diffusion_preview.py
index 70f052bd1af..56272c2a147 100644
--- a/studio/backend/core/inference/diffusion_preview.py
+++ b/studio/backend/core/inference/diffusion_preview.py
@@ -1,17 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Live latent previews for the image and video denoise loops.
-
-Each snapshot projects the latent to a small RGB picture with a fitted per-family linear map
-(``diffusion_preview_factors``), copies it into a pinned slot with ``non_blocking=True`` plus a CUDA
-event, and a worker thread JPEG-encodes it once ``Event.query()`` says it landed. The denoise thread
-never syncs or reads host memory the GPU is writing, every CUDA call sits inside the CUDA-graph capture
-hold-off, and the latent is only read, so the final image is identical with previews on or off.
-
-Snapshots are planned by STEP, not host time: under CUDA graphs the host enqueues every step long
-before the GPU runs it. Kill switch: ``UNSLOTH_DIFFUSION_PREVIEW=0``.
-"""
+"""Live denoise previews: async pinned copies, JPEG off-thread, planned per step; denoise thread
+never syncs; latent only read, so final image unchanged; UNSLOTH_DIFFUSION_PREVIEW=0 disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_preview_factors.py b/studio/backend/core/inference/diffusion_preview_factors.py
index 72ddc502e03..29db5966655 100644
--- a/studio/backend/core/inference/diffusion_preview_factors.py
+++ b/studio/backend/core/inference/diffusion_preview_factors.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Latent -> RGB maps for the live denoise preview (diffusion_preview). GENERATED, do not edit by hand.
-
-Each map was fitted by least squares from the final denoised latent of real renders to the same renders' VAE
-decode, box-averaged onto the latent grid. Families without an entry get no preview."""
+"""Generated, do not edit: RGB preview maps fitted to VAE decodes; no entry means no preview."""
# family name (lower case) -> map key: ``FamilyProfile.preview_factors`` on the registry rows (not generated).
from .family_profile import profile_table as _profile_table # noqa: E402
diff --git a/studio/backend/core/inference/diffusion_probe_cache.py b/studio/backend/core/inference/diffusion_probe_cache.py
index 4dac266e73a..12cbf85df65 100644
--- a/studio/backend/core/inference/diffusion_probe_cache.py
+++ b/studio/backend/core/inference/diffusion_probe_cache.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Persist the transformer-quant smoke-probe verdicts across processes (4-5 s of every cold quantised load).
-
-Only a clean child table is stored, keyed by everything a verdict depends on (torch / CUDA / torchao / triton, driver,
-card UUID + capability, the probe sources, the quant env). Any difference, or a torn file, is a miss that runs the
-child as before. UNSLOTH_DIFFUSION_PROBE_CACHE=0 disables read and write.
-"""
+"""Cross-process cache of quant probe verdicts, keyed by torch/CUDA/driver/card; mismatch is a miss."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_prompt_cache.py b/studio/backend/core/inference/diffusion_prompt_cache.py
index d023ef662fb..204cb0995ef 100644
--- a/studio/backend/core/inference/diffusion_prompt_cache.py
+++ b/studio/backend/core/inference/diffusion_prompt_cache.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""In-memory, host-RAM LRU of text-encoder outputs for diffusion/video pipes.
-
-``UNSLOTH_DIFFUSION_PROMPT_CACHE=0`` disables; ``UNSLOTH_DIFFUSION_PROMPT_CACHE_MB`` (default 256, capped on
-small hosts) bounds it. Hits return fresh copies so in-place edits cannot poison later renders.
-"""
+"""Host-RAM LRU of text-encoder outputs; hits return copies so in-place edits cannot poison renders."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_prompt_weighting.py b/studio/backend/core/inference/diffusion_prompt_weighting.py
index 8484eeb8a2c..3b30ca50437 100644
--- a/studio/backend/core/inference/diffusion_prompt_weighting.py
+++ b/studio/backend/core/inference/diffusion_prompt_weighting.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""AUTOMATIC1111 prompt weighting for the CLIP-conditioned (SD 1.x / SDXL) diffusers pipelines.
-
-Follows stable-diffusion-webui (commit 82a973c) prompt_parser / sd_hijack_clip / sd_emphasis, rewritten not copied.
-Layer selection is diffusers' own, so at weight 1 a single-chunk prompt matches the pipeline bit for bit.
-"""
+"""AUTOMATIC1111 prompt weighting for CLIP SD/SDXL pipelines; single-chunk weight 1 matches diffusers."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_quant_pad.py b/studio/backend/core/inference/diffusion_quant_pad.py
index ec6284d98e4..91ec0a6463b 100644
--- a/studio/backend/core/inference/diffusion_quant_pad.py
+++ b/studio/backend/core/inference/diffusion_quant_pad.py
@@ -1,26 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pad an int8 Linear's activation rows up to ``torch._int_mm``'s floor, instead of skipping it.
-
-``aten::_int_mm`` asserts ``self.size(0) > 16``. torchao's EAGER path never trips this, because
-``safe_int_mm`` checks the cuBLAS dimension constraints at runtime and falls back to a widened
-``torch.matmul``; inductor lowers the same quantized linear straight to ``_int_mm``, so under
-``torch.compile`` any quantized Linear invoked with a small activation row count raises
-
- RuntimeError: self.size(0) needs to be greater than 16, but got 10
-
-Until now the fix was to leave those Linears dense bf16 (``_INT8_FAMILY_EXCLUDE_NAME_TOKENS`` in
-``diffusion_transformer_quant``). That works, but it forfeits the weight-memory saving on a DiT's
-whole conditioning front end. This is the alternative: pad the flattened row count up to
-``pad_to``, run the GEMM, slice the result back. The module becomes compilable with no change to
-the quantization config, and the rows the caller asked for are returned BITWISE unchanged.
-
-Exact because pad rows REPLICATE row 0 (a zero row gives scale 0 and NaN) and the activation scale
-is PER ROW; ``wrap_small_m_linears`` RAISES on a granularity it cannot prove per row, since a
-half-padded transformer crashes. ``ZeroRowSafeLinear`` answers an EMPTY activation itself (nvfp4).
-Wrapping reparents the Linear, so do it AFTER loading; ``PadToMinM`` is state-dict transparent.
-"""
+"""Pads int8 Linear rows up to torch._int_mm's >16 floor, pad rows repeat row 0 (zero row gives
+NaN); wrap after loading, since it reparents the Linear; wrap raises on non-per-row granularity"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_qwenimage21.py b/studio/backend/core/inference/diffusion_qwenimage21.py
index 9afc39668b8..fe6833c153e 100644
--- a/studio/backend/core/inference/diffusion_qwenimage21.py
+++ b/studio/backend/core/inference/diffusion_qwenimage21.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Qwen-Image-2.1 denoiser forward with the per-step token layout built once (bit-identical).
-
-Kill switch: ``UNSLOTH_DIFFUSION_Q21_FAST_STEP=0``."""
+"""Qwen-Image-2.1 denoiser forward with per-step token layout built once, bit-identical; kill switch
+UNSLOTH_DIFFUSION_Q21_FAST_STEP=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_qwenimage21_fused.py b/studio/backend/core/inference/diffusion_qwenimage21_fused.py
index 2da69b7315b..272e420fc14 100644
--- a/studio/backend/core/inference/diffusion_qwenimage21_fused.py
+++ b/studio/backend/core/inference/diffusion_qwenimage21_fused.py
@@ -1,16 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Qwen-Image-2.1 ConvRot int8: one rotation + one act quant per shared input (QKV, SwiGLU gate/value) in the compile.
-
-Rotation is on the shared input axis and int8 scales are per row, so fused outputs equal the separate rotated ones bit
-for bit. The fused QKV Linear: only where ``diffusion_int8_gemm`` leaves rotated Linears on the stock path (e.g. sm86,
-sm90, sm100), resident only; there the rotation and the act quant run as one ``rotq_h16`` kernel on a card that passed
-``diffusion_convrot_quant.unlisted_device_ok``, else as the rotation GEMM + act quant. Where it swaps them, the
-patched helper routes Q / K / V through ``diffusion_int8_gemm.shared_rotq_linears`` (Inductor does not merge the
-opaque kernel); resident or streamed.
-Kill switch: ``UNSLOTH_DIFFUSION_Q21_CONVROT_FUSED=0``.
-"""
+"""Fused ConvRot rotation and act quant per shared input, bit-identical to separate ops; fused QKV
+Linear only where diffusion_int8_gemm leaves rotated Linears on stock path, resident only; kill
+UNSLOTH_DIFFUSION_Q21_CONVROT_FUSED=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_qwenimage21_rocm.py b/studio/backend/core/inference/diffusion_qwenimage21_rocm.py
index 78d8b780957..6412b5da830 100644
--- a/studio/backend/core/inference/diffusion_qwenimage21_rocm.py
+++ b/studio/backend/core/inference/diffusion_qwenimage21_rocm.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Speed up large Qwen-Image-2.1 ROCm attention with query chunks.
-
-Unmasked, noncausal queries are independent; each chunk keeps all keys and values.
-"""
+"""Query-chunked Qwen-Image-2.1 ROCm attention; chunks keep all keys and values (unmasked, noncausal)."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_qwenimage21_rope.py b/studio/backend/core/inference/diffusion_qwenimage21_rope.py
index caf813c3a92..4401377a5eb 100644
--- a/studio/backend/core/inference/diffusion_qwenimage21_rope.py
+++ b/studio/backend/core/inference/diffusion_qwenimage21_rope.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Qwen-Image-2.1 RoPE in real arithmetic under ``torch.compile``, bit-identical to the complex form.
-
-Inductor cannot fuse complex multiply; ATen's fma placement differs per card (B200 vs A100), so
-``install`` probes the card and mirrors it via ``addcmul`` (one ``fma``). Kill switch:
-``UNSLOTH_DIFFUSION_Q21_REAL_ROPE=0``.
-"""
+"""Real-arithmetic Qwen-Image-2.1 RoPE, bit-identical to the complex form (Inductor cannot fuse
+complex mul); kill UNSLOTH_DIFFUSION_Q21_REAL_ROPE=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_qwenimage21_vision.py b/studio/backend/core/inference/diffusion_qwenimage21_vision.py
index 1860f2adc1b..29f95b32b15 100644
--- a/studio/backend/core/inference/diffusion_qwenimage21_vision.py
+++ b/studio/backend/core/inference/diffusion_qwenimage21_vision.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Qwen-Image-2.1 vision SDPA gives NaN conditioning on gfx1151: use query-chunked eager there.
-
-UNSLOTH_QWEN_IMAGE_ROCM_VISION_EAGER: auto (gfx1151 only), 1 (any ROCm GPU), 0 (off).
-"""
+"""Vision SDPA gives NaN on gfx1151; query-chunked eager there (UNSLOTH_QWEN_IMAGE_ROCM_VISION_EAGER)."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_qwenimage_rope.py b/studio/backend/core/inference/diffusion_qwenimage_rope.py
index 4a97058cb33..3a850cec36f 100644
--- a/studio/backend/core/inference/diffusion_qwenimage_rope.py
+++ b/studio/backend/core/inference/diffusion_qwenimage_rope.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Qwen-Image RoPE in real arithmetic (Inductor cannot lower the complex multiply): points the stock RoPE at
-``diffusion_qwenimage21_rope``'s probed fma wrapper, bit-identical to the complex product. Two stock forms:
-diffusers 0.41.0 routes through ``ROPE_PER_DEVICE["cuda"]`` (its entry is swapped); main d42ebf9c dropped the table
-and the attention processor calls the module global ``apply_rotary_emb_qwen`` (the global is swapped, only while the
-processor matches a known source). Kill switch: ``UNSLOTH_DIFFUSION_QWEN_REAL_ROPE=0``
-(``UNSLOTH_DIFFUSION_Q21_REAL_ROPE=0`` also disables it).
-"""
+"""Real-arithmetic Qwen-Image RoPE, patched into diffusers; kill UNSLOTH_DIFFUSION_QWEN_REAL_ROPE=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_rocm_compile.py b/studio/backend/core/inference/diffusion_rocm_compile.py
index 4f7e2430c50..cb341d5d4b2 100644
--- a/studio/backend/core/inference/diffusion_rocm_compile.py
+++ b/studio/backend/core/inference/diffusion_rocm_compile.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-process probe: can this ROCm install regionally compile a transformer block?
-
-ROCm was refused because inductor's pooled buffers (``memory_planning``) are views AOTAutograd rejects; Studio now
-compiles with it off and no cudagraphs on ROCm. The probe compiles one small block as the default tier does and checks
-it against eager; any failure stays eager.
-
-``UNSLOTH_DIFFUSION_ROCM_COMPILE``: ``0`` never compiles on ROCm, ``1`` skips the probe, unset / ``auto`` probes.
-"""
+"""Per-process probe that a regional block compile matches eager on ROCm; failure stays eager; ROCm
+compiles with memory_planning off and no cudagraphs; UNSLOTH_DIFFUSION_ROCM_COMPILE=0 off, 1
+skips probe"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_rocm_fused.py b/studio/backend/core/inference/diffusion_rocm_fused.py
index 26cd37b0971..5f5b6c44e52 100644
--- a/studio/backend/core/inference/diffusion_rocm_fused.py
+++ b/studio/backend/core/inference/diffusion_rocm_fused.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Fused RoPE and AdaLN modulation Triton kernels for the FLUX DiT on ROCm (bf16 / fp16).
-
-RoPE reuses ``diffusion_flux2_rope``'s kernel (bit-identical to stock). AdaLN keeps stock's rounding chain; only the
-row-reduction order differs. Inference only, never while compiling; any ineligible call runs the forward live at
-install. ``UNSLOTH_DIFFUSION_FUSED_ROPE=auto|0|1`` (auto = ROCm and NVIDIA CUDA on Linux; ComfyUI runs FLUX RoPE
-through comfy-kitchen's fused kernel by default), ``UNSLOTH_DIFFUSION_FUSED_ADALN=auto|0|1`` (auto = off: no gfx1151
-speedup and not bit-identical).
-"""
+"""Triton RoPE (auto on ROCm and NVIDIA CUDA Linux) and AdaLN kernels for FLUX; inference only,
+never while compiling; AdaLN off by default (not bit-identical); UNSLOTH_DIFFUSION_FUSED_ROPE,
+UNSLOTH_DIFFUSION_FUSED_ADALN"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_sampler.py b/studio/backend/core/inference/diffusion_sampler.py
index f5f71e44859..f2603d5c95a 100644
--- a/studio/backend/core/inference/diffusion_sampler.py
+++ b/studio/backend/core/inference/diffusion_sampler.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Sampler (scheduler) choice for the diffusers image engine, plus the v-prediction markers a
-single-file SDXL checkpoint carries. Names follow AUTOMATIC1111; the mapping is the diffusers
-scheduler overview table. No torch/diffusers imports at module level."""
+"""A1111 sampler names mapped to diffusers schedulers; no torch/diffusers imports at module level."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_sd_controls.py b/studio/backend/core/inference/diffusion_sd_controls.py
index 262438d8ebe..99256431c8e 100644
--- a/studio/backend/core/inference/diffusion_sd_controls.py
+++ b/studio/backend/core/inference/diffusion_sd_controls.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""SDXL generation controls (diffusers engine): A1111 prompt weighting, CLIP skip, CFG rescale, variation seeds.
-
-CLIP skip uses A1111 numbering: A1111 N = diffusers N - 1 on SD 1.x and N - 2 on SDXL (diffusers already reads
-the penultimate layer there; matches webui-forge minimal_clip_skip). On SDXL it moves CLIP-L and OpenCLIP-G
-together, as ComfyUI's CLIPSetLastLayer (sdxl_clip.SDXLClipModel.set_clip_options) and Forge's
-StableDiffusionXL.set_clip_skip do. Variation seeds follow webui modules/rng.py;
-the base noise is still drawn by prepare_latents, so the generator advances exactly as before.
-"""
+"""A1111 CLIP skip N = diffusers N-1 on SD 1.x, N-2 on SDXL; variation seeds follow webui rng; base
+noise still drawn in prepare_latents, so generator advances as before"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_segment.py b/studio/backend/core/inference/diffusion_segment.py
index 370d2626ebe..5112e860e51 100644
--- a/studio/backend/core/inference/diffusion_segment.py
+++ b/studio/backend/core/inference/diffusion_segment.py
@@ -1,37 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Text-prompted masks for the Images page: SAM 3 (Segment Anything with Concepts) turns "sofa, red lamp, pillow:2"
-into a white-on-black mask the inpaint and localized-edit painters load and keep editable.
-
-Behaviour follows ComfyUI's ``SAM3_Detect`` node and its "Image Segmentation (SAM3)" blueprint
-(comfy_extras/nodes_sam3.py, comfy/text_encoders/sam3_clip.py): comma-separated concepts, ``:N`` caps a concept's
-detections (default 1), the image is stretched to 1008x1008 with bilinear resampling, a detection is kept when its
-score > 0.5, the best ``N`` per concept are kept, and the union of their masks (mask logits upsampled bilinearly to
-the source size, > 0) is the result. Two departures: the score is sigmoid(logit) * sigmoid(presence), as in Meta's
-SAM 3 and transformers' post-processing (ComfyUI drops the presence term, and then a concept that is not in the
-picture, "elephant" in a living room, masks the sofa at 0.72; with it every absent concept scores below 0.02 and no
-present one changes), and ComfyUI's optional crop-and-refine pass through the tracker's SAM decoder is not run.
-
-Weights come from a small table of variants (SEGMENTER_VARIANTS). The default is SAM 3.1: Meta ships it only as an
-original-format multiplex checkpoint, so it is the SAM 3.1 detector converted with transformers' own SAM 3 converter
-into a BF16 ``Sam3Model`` repository (ungated, SAM License). The official transformers-format ``facebook/sam3``
-(gated: the license is accepted on Hugging Face) stays selectable with ``UNSLOTH_SAM3_VARIANT=sam3``, and is used
-when it is already downloaded and SAM 3.1 is not. ``UNSLOTH_SAM3_PATH`` points at any local transformers-format SAM 3
-directory instead.
-
-SAM 3.1 also ships pre-quantized detector files (FP8, INT8, INT8-ConvRot; diffusion_segment_quant). On a CUDA card
-``UNSLOTH_SAM3_PRECISION`` (auto / bf16 / fp8 / int8) picks one. auto runs bf16, which is faster, while the card has
-room for it, and only when it is short of memory loads a file that passed the accuracy gate (INT8, the ConvRot build
-unless ``UNSLOTH_SAM3_INT8_CONVROT=0``). The download fetches that one weights file with the configs and tokenizer,
-and bf16 when the file is not published; the CPU and Apple's MPS run bf16 weights (a quantized file that is the only
-one on disk is dequantized there).
-
-The model is auxiliary to the image model, like the FLUX.3 prompt upsampler: loaded on the first request, kept for
-a short keep-alive, unloaded right after a call when the accelerator is tight, and dropped whenever the GPU arbiter
-hands the GPU to a load, evicts the image model, or training starts. It runs on the CPU while training holds the GPU
-or when the accelerator has no room.
-"""
+"""Text-prompted SAM 3 masks like ComfyUI SAM3_Detect, score = sigmoid(logit) * sigmoid(presence);
+dropped when the GPU arbiter loads, evicts the image model or training starts; CPU while training"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_segment_quant.py b/studio/backend/core/inference/diffusion_segment_quant.py
index 9e3f5328bad..3dd4d6c850d 100644
--- a/studio/backend/core/inference/diffusion_segment_quant.py
+++ b/studio/backend/core/inference/diffusion_segment_quant.py
@@ -1,25 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pre-quantized SAM 3 / SAM 3.1 detector weights for Mask from text: FP8, INT8 and INT8-ConvRot.
-
-The segmenter is not a diffusion transformer, but its quantization is the diffusion one, imported rather than copied
-so the two cannot drift: the torchao config (``_make_quant_config``: fp8 per-row weight scale with dynamic per-token
-activations, int8 W8A8 dynamic), the Linear filter (``make_filter_fn``: min features, bf16 and alignment rules), the
-ConvRot block-Hadamard rotation and its recorded-fqn contract (``diffusion_convrot``), the safetensors container
-(``prequant_safetensors``, torchao's flatten layout + ``unsloth_format`` / ``unsloth_metadata``) and the
-version-neutral weight fingerprint. What is SAM specific lives here: which Linears are left in bf16, which arms
-``auto`` may pick, the artifact names, and the loader that builds a ``Sam3Model`` around the quantized state dict.
-
-Exclusions come from a per-group sensitivity scan (numbers on the unsloth/sam3.1 model card): one group at a time,
-mask IoU / score / kept-count measured against bf16 over a 53-prompt set. They are baked into every artifact and
-compared at load, like the diffusion families' exclude tokens, so an artifact built under a different rule is refused
-rather than loaded.
-
-Quantized kernels are CUDA only here: on the CPU or Apple's MPS the segmenter runs bf16 / fp32 weights, and a
-quantized file that is the only one downloaded is dequantized for that device (the rotation, when present, stays
-installed, which is exact in floating point).
-"""
+"""SAM 3 pre-quantized FP8/INT8/ConvRot detector weights sharing diffusion quant code; quantized
+kernels CUDA only (CPU/MPS dequantize a lone quantized file); other exclusions refused at load"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_single_file_converters.py b/studio/backend/core/inference/diffusion_single_file_converters.py
index cdb1fff832d..e0f883cd3da 100644
--- a/studio/backend/core/inference/diffusion_single_file_converters.py
+++ b/studio/backend/core/inference/diffusion_single_file_converters.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Original-layout (ComfyUI / reference repo) single files -> diffusers state dicts for Krea 2 and
-HunyuanImage 2.1, which diffusers ships without a single-file converter.
-
-Rules only rename, split rows or reorder whole rows, never columns: ``diffusion_comfy_quant`` traces
-each int8 / fp8 row (and GGUF block) back to its source and refuses anything else. Unknown keys raise.
-No module-level torch import: ``diffusion.py`` imports this on every load.
-"""
+"""Krea 2 / HunyuanImage 2.1 single files to diffusers; row-wise renames and splits only, never
+columns; unknown keys raise; no module-level torch import"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_single_file_trust.py b/studio/backend/core/inference/diffusion_single_file_trust.py
index d9fdaaa7eff..80046c27dbc 100644
--- a/studio/backend/core/inference/diffusion_single_file_trust.py
+++ b/studio/backend/core/inference/diffusion_single_file_trust.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-file trust for single-file diffusion checkpoints from any Hugging Face repo.
-
-The repo allowlists guard ``from_pretrained`` (pickled weights, ``trust_remote_code``). A lone
-``.safetensors`` file has neither risk: only that file is downloaded, it is parsed without
-unpickling, and every config and companion still comes from the family's trusted base repo.
-"""
+"""Per-file trust for a lone .safetensors file from any HF repo (no pickle risk); configs from base."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_small_host.py b/studio/backend/core/inference/diffusion_small_host.py
index 737ec8a7cd8..9acee08907a 100644
--- a/studio/backend/core/inference/diffusion_small_host.py
+++ b/studio/backend/core/inference/diffusion_small_host.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Small-host load route: a bf16 repo loaded at fp16/fp32 materialises every converted weight in anonymous host RAM
-(FLUX.1 at fp16: 35 GB, OOM-killed on a 31 GB host before the planner runs). Engaged only when that dense load would
-not fit: big components load at their stored bf16 (memory-mapped), encoders stream with layerwise casting, a streamed
-denoiser is stored as int8 per-channel weights. ``UNSLOTH_DIFFUSION_SMALL_HOST=0|1`` disables / forces it;
-``UNSLOTH_DIFFUSION_HOST_RAM_CHECK=0`` skips the pre-load refusal.
-"""
+"""Low-RAM load route, used only when a dense load would not fit RAM; UNSLOTH_DIFFUSION_SMALL_HOST=0|1."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_speed.py b/studio/backend/core/inference/diffusion_speed.py
index 60f89c00c34..72a7453feda 100644
--- a/studio/backend/core/inference/diffusion_speed.py
+++ b/studio/backend/core/inference/diffusion_speed.py
@@ -1,36 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in speed optimisations for the local diffusion backend.
-
-Off by default, so the default render path stays bit-identical (the regression harness checks
-this). On opt-in it applies the near-lossless speedups in the diffusers-recommended order
-(channels_last + cudnn.benchmark -> compile, with TF32 / fused-QKV under "max"):
-
- off - nothing (default; bit-identical reference).
- eager - everything lossless EXCEPT torch.compile: channels_last VAE + cudnn.benchmark +
- attention backend + the shared eager monkey-patches (fused RMSNorm / AdaLayerNorm
- + per-arch addcmul, see diffusion_eager_patches.py / diffusion_arch_patches.py). The
- fast first-image / casual path, no compile tax.
- default - LIGHT compile. GGUF: compile ONLY the dequant op chain (~70-80% of eager GGUF time)
- for ~1.24-1.64x at a small one-time compile (~7.5-10.4s), zero extra VRAM,
- resolution-invariant; the block stays eager. Dense: no dequant, so falls back to
- regional compile of the repeated block; a U-Net (SDXL, no repeated-block list) gets a
- whole-module STATIC compile (1.61x at LPIPS 0.034, see ``_UNET_WHOLE_COMPILE``).
- max - FULL compile: regional max-autotune compile of the repeated block (fuses GGUF dequant
- + matmul/norm/elementwise in one graph -- ~3.2x on GGUF Z-Image, PSNR ~36 dB, above
- the Q4 noise floor) plus TF32 matmul and fused QKV.
-
-``default`` is the cheap always-amortising compile; ``max`` pays the larger regional tax for the
-bigger warm speedup. The compiled dequant is skipped under ``max``, which subsumes it.
-
-Knobs, safe unset: ``UNSLOTH_DIFFUSION_COMPILE_VAE=auto|0|1`` (DiT VAE decode compile; ``auto`` = ``max`` only),
-and in their own modules ``UNSLOTH_NVFP4_FAST_BIAS``, ``_FAST_DISPATCH``, ``_ZERO_BUFFER`` and ``_BACKEND``.
-
-The flags this flips (TF32, cudnn.benchmark) are PROCESS-WIDE, so ``snapshot_backend_flags`` /
-``restore_backend_flags`` let the caller restore prior values at unload, keeping a later ``off``
-load bit-identical. torch imported lazily.
-"""
+"""Opt-in speed modes off/eager/default/max (off by default); TF32 and cudnn.benchmark are process-
+wide, restore at unload; torch imported lazily"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_stable_arena.py b/studio/backend/core/inference/diffusion_stable_arena.py
index cd8c7b7f779..7186a74948e 100644
--- a/studio/backend/core/inference/diffusion_stable_arena.py
+++ b/studio/backend/core/inference/diffusion_stable_arena.py
@@ -1,25 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Stable device addresses for a whole-module CPU-offloaded denoiser (``memory_mode=low_vram``).
-
-accelerate's ``CpuOffload`` hook onloads the denoiser with ``module.to(device)`` at the start of every render, so the
-caching allocator hands its weights new addresses each time and a CUDA graph recorded on render 1 cannot replay on
-render 2 (``diffusion_cuda_graph.MODEL_OFFLOAD_REASON``). Here the denoiser's device copy lives in one CUDA virtual
-address range reserved once for the load (driver VMM: ``cuMemAddressReserve``). An onload creates physical memory,
-maps it at that range and copies the kept host weights in; the offload syncs the card, unmaps and releases the
-physical memory, so the text encoder and VAE phases get the VRAM back exactly as with the stock hook. The weights
-land at the same addresses on every render, so the recorded step graph keeps replaying.
-
-ComfyUI does the same for its graph replays over offloaded weights (comfy_aimdo ``model_vbar``).
-
-Plain dense tensors (with their strides) and torchao-style wrapper weights (int8 / fp8: their plain inner tensors,
-rebuilt over the range) are placed; a module holding any other parameter type (GGUF) is left to the stock hook.
-Opt out with ``UNSLOTH_DIFFUSION_MODEL_OFFLOAD_ARENA=0``.
-
-Block offload uses the same ranges per resident group, for the groups a prompt encode streams and pins again
-(``GroupRange``, below; opt out with ``UNSLOTH_DIFFUSION_GROUP_REPIN_RANGE=0``).
-"""
+"""Keeps offloaded denoiser weights at fixed VMM addresses so recorded CUDA graphs replay; GGUF or
+other parameter types left to the stock hook"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_step_skip.py b/studio/backend/core/inference/diffusion_step_skip.py
index 37e688054ce..0505bcb388d 100644
--- a/studio/backend/core/inference/diffusion_step_skip.py
+++ b/studio/backend/core/inference/diffusion_step_skip.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in static step skip (``transformer_cache="static"``): a schedule fixed per generation, decided outside the
-forward, so compile fullgraph and the CUDA graph are kept. A GraphedForward installed later goes under this layer."""
+"""Opt-in static step skip (transformer_cache=static): schedule fixed per generation outside the
+forward, keeps fullgraph compile and CUDA graph; GraphedForward installed later goes under it"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_te_release.py b/studio/backend/core/inference/diffusion_te_release.py
index 32139a81e06..e3a2d926b12 100644
--- a/studio/backend/core/inference/diffusion_te_release.py
+++ b/studio/backend/core/inference/diffusion_te_release.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Release the text encoders during denoise on unified memory, where offloading frees nothing.
-
-The first release snapshots the encoders' large tensors to local disk; a forward pre-hook reloads them bit-exact before
-an encoder runs again. ``UNSLOTH_DIFFUSION_RELEASE_TEXT_ENCODER=1`` / ``=0`` forces it on / off.
-"""
+"""Releases text encoders during denoise on unified memory (disk snapshot, bit-exact reload)."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_te_truncate.py b/studio/backend/core/inference/diffusion_te_truncate.py
index 6c74e936206..531f79b47c6 100644
--- a/studio/backend/core/inference/diffusion_te_truncate.py
+++ b/studio/backend/core/inference/diffusion_te_truncate.py
@@ -1,10 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Drop text-encoder decoder layers (and an unread head) after the last hidden state the pipeline's
-``encode_prompt`` reads. A NaN-taint bisection over weightless passthrough slots finds that layer; kept layers
-are untouched, so outputs are bit-identical. Any surprise keeps the full encoder.
-Kill switch: ``UNSLOTH_DIFFUSION_TE_TRUNCATE=0``."""
+"""Drops text-encoder decoder layers and an unread head after the last hidden state encode_prompt
+reads; outputs bit-identical; any surprise keeps the full encoder; kill
+UNSLOTH_DIFFUSION_TE_TRUNCATE=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_text_encoder_trim.py b/studio/backend/core/inference/diffusion_text_encoder_trim.py
index 25357317236..69e99e5383d 100644
--- a/studio/backend/core/inference/diffusion_text_encoder_trim.py
+++ b/studio/backend/core/inference/diffusion_text_encoder_trim.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Drop the unused ``lm_head`` of a Qwen3-VL text encoder whose pipeline reads only hidden states.
-
-Qwen-Image-2.1 reads ``hidden_states[-1]`` (diffusers ``QwenImage21Pipeline._get_qwen_prompt_embeds``); the untied
-151936 x 4096 head runs after every hidden state, so replacing it with :class:`NoLogitsHead` is bit-identical. The
-vision tower stays: edit requests on the same pipeline run ``model.visual``. Kill switch: ``UNSLOTH_TE_KEEP_LM_HEAD=1``.
-"""
+"""Drops unused lm_head of Qwen3-VL text encoder (bit-identical); vision tower must stay, since edit
+requests run model.visual; kill UNSLOTH_TE_KEEP_LM_HEAD=1"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_torchao_patches.py b/studio/backend/core/inference/diffusion_torchao_patches.py
index b9b9ffcf782..cc1e7a1ad8c 100644
--- a/studio/backend/core/inference/diffusion_torchao_patches.py
+++ b/studio/backend/core/inference/diffusion_torchao_patches.py
@@ -1,15 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Studio's copy of ``unsloth/import_fixes.py::fix_torchao_safe_int_mm_repr_probe``, not an import
-of it: the diffusion process must not execute ``unsloth/__init__``. The two copies are mutually inert.
-
-torchao's int8 GEMM asks whether it is being traced by formatting its input's repr, which on a real
-CUDA tensor calls ``.item()``: a device sync per eager int8 linear, and an outright
-``cudaErrorStreamCaptureUnsupported`` inside ``torch.cuda.graph``. Installed from a meta path finder
-at import time, not at quantise time, because the int8 prequant path only ``torch.load``s torchao
-subclasses and never calls ``quantize_``.
-"""
+"""torchao int8 GEMM repr calls .item() (breaks CUDA graphs); Studio's own copy, not an import:
+diffusion must not execute unsloth/__init__; installed at import time via meta path finder"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_transformer_quant.py b/studio/backend/core/inference/diffusion_transformer_quant.py
index 3a3dd936442..a1ba7dfce5b 100644
--- a/studio/backend/core/inference/diffusion_transformer_quant.py
+++ b/studio/backend/core/inference/diffusion_transformer_quant.py
@@ -1,23 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in low-precision quantisation of the diffusion DiT transformer.
-
-The default GGUF path stores weights 4-bit but DEQUANTISES to bf16 on every matmul, so it runs at
-bf16 tensor-core rate: a memory win that costs speed. The opt-in alternative here loads the DENSE
-bf16 transformer and torchao-quantises it with a DYNAMIC-ACTIVATION scheme, so the matmul runs on
-low-precision tensor cores. Measured on B200 (Z-Image-Turbo, 1024px/8 steps) against GGUF+compile
-(0.802s, LPIPS 0.083): fp8 0.585s (1.37x), int8 0.603s (1.33x), both at LOWER LPIPS, at a
-higher-memory dense load. GGUF stays the low-memory default and fallback.
-
-Scheme by architecture (``auto`` takes the best supported): int8 leads every tier, then fp8 on
-Ada / Hopper / Blackwell (sm_89+) and mxfp8 on Blackwell (sm_100+); Ampere (sm_80+) has int8 alone.
-nvfp4 is explicit opt-in, outside the auto ladder. ``_AUTO_LADDER`` is what ships.
-
-Every scheme needs ``torch.compile`` for the speedup (dynamic quant is ~30x slower eager); the
-loader compiles the repeated block after this. torch / torchao imported lazily; every probe is
-best-effort, yielding None so the caller loads GGUF.
-"""
+"""Opt-in dynamic-activation torchao DiT quant; needs torch.compile (eager ~30x slower); torch and
+torchao imported lazily; probes best-effort, GGUF fallback"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_upscalers.py b/studio/backend/core/inference/diffusion_upscalers.py
index 02de135cf09..51fc82df041 100644
--- a/studio/backend/core/inference/diffusion_upscalers.py
+++ b/studio/backend/core/inference/diffusion_upscalers.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Image upscalers for Hires fix and the Upscale workflow: Lanczos, latent, and ESRGAN-family models via spandrel.
-
-The catalog holds only redistributable weights (Real-ESRGAN, BSD-3-Clause, pinned by size and SHA-256); others
-(4x-UltraSharp is CC BY-NC-SA) stay user-supplied in ``<workspace>/upscale_models``. A request never carries a path.
-"""
+"""Upscaler catalog holds only redistributable weights pinned by SHA-256; others are user-supplied
+in workspace upscale_models; a request never carries a path"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_vae_attn_chunked.py b/studio/backend/core/inference/diffusion_vae_attn_chunked.py
index ea0f91d1ac9..0b6bc7b9034 100644
--- a/studio/backend/core/inference/diffusion_vae_attn_chunked.py
+++ b/studio/backend/core/inference/diffusion_vae_attn_chunked.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Query-chunked VAE attention on ROCm and Apple MPS, where no fused SDPA kernel takes head dim 384 / 512.
-
-AOTriton caps gfx11 at head dim 256, so SDPA falls back to the math kernel and materialises the full fp32 score
-matrix (16 GiB for a 2048x2048 FLUX.1 decode). Unmasked query rows are independent, so chunking them is exact.
-``UNSLOTH_VAE_ATTN_CHUNKED=0`` disables it; ``UNSLOTH_VAE_ATTN_CHUNK_MB`` sets the per-chunk fp32 score budget.
-"""
+"""Query-chunked VAE attention on ROCm/MPS, where no fused SDPA takes head dim 384/512; exact."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_vae_fp16.py b/studio/backend/core/inference/diffusion_vae_fp16.py
index fe3d7c214fe..bc7fb4c5882 100644
--- a/studio/backend/core/inference/diffusion_vae_fp16.py
+++ b/studio/backend/core/inference/diffusion_vae_fp16.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""fp16 VAE decode for U-Net (SDXL) pipelines whose VAE sets ``force_upcast``.
-
-The SDXL VAE overflows fp16 in its last decoder stages, so the pipelines upcast the whole VAE to fp32 on fp16 loads.
-Dividing the residual stream after the first upsampler by 2**8 (and the eps of each GroupNorm reading it by 2**16) is an
-identity, since GroupNorm is scale invariant, and keeps every activation in fp16 range. A non-finite decode still reruns
-in fp32 and hands later decodes back to the pipeline's upcast.
-"""
+"""fp16 SDXL VAE decode: residual scaled 2**-8 (GroupNorm is scale invariant); a non-finite decode
+reruns fp32 and later decodes revert to the pipeline upcast"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_vae_fused.py b/studio/backend/core/inference/diffusion_vae_fused.py
index 7d10d08739a..b378ff155c1 100644
--- a/studio/backend/core/inference/diffusion_vae_fused.py
+++ b/studio/backend/core/inference/diffusion_vae_fused.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Triton-fused GroupNorm / channel RMS norm for eagerly decoded image and video VAEs.
-
-CUDA GroupNorm has no channels-last kernel, so every norm copies NHWC <-> NCHW; these kernels read any layout,
-write channels-last with fp32 statistics. ``install(vae)`` patches instances (never classes), each falling back
-to stock on a new exception. NVIDIA CUDA + Triton >= 3.3 only; ``UNSLOTH_VAE_FUSED=0`` disables.
-"""
+"""Triton GroupNorm/RMS norm for eager VAE decode (NVIDIA CUDA, Triton>=3.3); patches instances
+never classes; falls back to stock on new exception; UNSLOTH_VAE_FUSED=0 off"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_vae_oom.py b/studio/backend/core/inference/diffusion_vae_oom.py
index e8b5ec9702c..b3cda3c55d7 100644
--- a/studio/backend/core/inference/diffusion_vae_oom.py
+++ b/studio/backend/core/inference/diffusion_vae_oom.py
@@ -1,20 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Recover a VAE decode that runs out of memory by offloading, never by shrinking tiles.
-
-Wraps the instance ``_decode`` (under the decode-level wrappers, over the tiled decode). On an OOM, each step runs only
-if the previous one still runs out of memory:
-
-a. Free the decode's device without changing the math: Studio's resident offload groups (text encoders, denoiser
- blocks) stream again, captured CUDA graphs are dropped, and every other pipeline component still whole on the card
- moves to the host. The SAME decode is retried, so an untiled decode stays untiled and the output is unchanged.
-b. An untiled decode retries tiled at the VAE's stock tile sizes: ComfyUI's single tiled retry.
-c. The VAE's own weights stream from the host per layer (diffusers leaf-level group offload), still at stock tiles.
-
-Tile sizes are never touched: tiles under the stock size bring back visible seams. Everything moved goes back where
-it was once the decode returns or fails. Kill switch ``UNSLOTH_VAE_OOM_RETRY=0``.
-"""
+"""VAE decode OOM recovery: offload, never shrink tiles (seams); steps run in order, each only if
+the previous still OOMs; moved parts restored; UNSLOTH_VAE_OOM_RETRY=0 disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_vae_prebuild.py b/studio/backend/core/inference/diffusion_vae_prebuild.py
index a2b35fb25dd..158315b462e 100644
--- a/studio/backend/core/inference/diffusion_vae_prebuild.py
+++ b/studio/backend/core/inference/diffusion_vae_prebuild.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Build the fused VAE's Triton kernels in a child process while a first start compiles its denoiser.
-
-The first decode with an empty Triton cache JIT-compiles every fused VAE kernel (~3 s of render 1 on an RTX PRO 6000).
-On a load with no compile bundle, a spawned child rebuilds the VAE from its config without weights, installs the same
-fused passes and decodes zeros at a small latent (same divisibility classes), filling the shared Triton cache. The
-parent never waits; kernels the child has not finished are compiled by the parent as before.
-``UNSLOTH_DIFFUSION_VAE_PREBUILD=0`` disables it.
-"""
+"""Child process warms Triton cache for fused VAE kernels without weights; parent never waits;
+UNSLOTH_DIFFUSION_VAE_PREBUILD=0 disables"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_vae_single_frame.py b/studio/backend/core/inference/diffusion_vae_single_frame.py
index 8fc540e8ddb..0a474d48a6b 100644
--- a/studio/backend/core/inference/diffusion_vae_single_frame.py
+++ b/studio/backend/core/inference/diffusion_vae_single_frame.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Single-frame fast path for the Qwen-Image causal 3D VAE: one frame with no cache only meets the last
-temporal kernel slice, so each conv is exactly ``conv2d(x[:, :, 0], weight[:, :, -1], bias)``, and the
-first chunk of the cached walk equals ``decoder(x, feat_cache=None)``. Gated to single-frame untiled
-calls (tiled / multi-frame keep 3D convs). PSNR ~60 dB vs 3D (different cuDNN algo), so non-``off``
-tiers only. Kill switch, read at install: ``UNSLOTH_DIFFUSION_VAE_SINGLE_FRAME=0``."""
+"""Qwen-Image VAE single-frame untiled path, non-off tiers only; UNSLOTH_DIFFUSION_VAE_SINGLE_FRAME=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_zimage_cfg_split.py b/studio/backend/core/inference/diffusion_zimage_cfg_split.py
index 3a58a80a4f1..aff77680245 100644
--- a/studio/backend/core/inference/diffusion_zimage_cfg_split.py
+++ b/studio/backend/core/inference/diffusion_zimage_cfg_split.py
@@ -1,35 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Z-Image guidance branches as two calls at the guidance-off batch, so turning CFG on compiles and records nothing.
-
-``ZImagePipeline`` (and its img2img / inpaint variants) batches a guided step into ONE transformer call of twice the
-samples: the latents repeated, the prompt embeddings followed by the negative ones. A session that rendered guidance 0
-first (Turbo's default) compiled the repeated block at one sample with no attention mask; the doubled call is a new
-batch (dynamo specialises size 1) and, whenever the two captions pad to different 32-token buckets, a mask that was None
-before, so the first guided render recompiled the block three times (one graph per block kind: noise refiner, context
-refiner, main layers) and recorded a new whole-step CUDA graph. Later guided prompts kept recompiling as their caption
-lengths moved between "same bucket as the negative" (no mask) and "other bucket" (mask).
-
-Here a guided call of ``2 * B`` samples runs as the conditional ``B`` then the unconditional ``B`` through the module's
-normal call (every forward layer, hook and graph sees an ordinary guidance-off call), and the two output lists are
-joined in the pipeline's order. Same math: the batched call masks the padding, the split one has none to mask. Not
-bit-exact: a single sample with no mask can pick other attention / GEMM tiles than the masked pair.
-
-Engaged per render (``render``: Studio knows the images per call, so ``2 * B`` samples is a guided call, ``B`` is not),
-only on a resident denoiser: a block-streamed one would upload its weights twice per step, which costs more than the
-recompile. Group offload counts as resident (checked per call) while every offload group is pinned. Declined per call under a step cache and a static step skip that cannot key a step's two calls apart.
-Under a CFG-parallel router the halves go to ``run_pair`` (identity pairing never matches fresh tensors). Kill switch: ``UNSLOTH_DIFFUSION_ZIMAGE_CFG_SPLIT=0``.
-
-Studio arms it ``compiled_only``: a render splits only while the denoiser runs compiled code or replays CUDA graphs,
-checked per render since a deferred compile can engage after the load. The eager render that records inputs for a
-pending background compile splits too, so the compile builds the guidance-off batch graph the compiled renders run.
-Any other eager denoiser has no graph to keep, and there the two serial calls cost more than one batched guided call (B200, eager, random weights: ~2x at 256px,
-~1.3-1.5x at 512px, parity at 1024px). An eager guided call that runs out of memory batched retries as the two
-calls (half the activations) for the rest of that render. An active CFG-parallel router keeps the split eager too:
-its replica runs the guidance-off half concurrently, and it cannot pair one batched call. Graphs are read from the
-denoiser too: an img2img / inpaint pipeline built by ``from_pipe`` shares the transformer and its graph wrapper but not the root pipe's handles.
-"""
+"""Z-Image CFG as two guidance-off calls to avoid recompiles; resident denoisers only; Studio splits
+only when compiled or graph-replayed; declined under step cache; CFG-parallel uses run_pair;
+eager OOM retries split; UNSLOTH_DIFFUSION_ZIMAGE_CFG_SPLIT=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/diffusion_zimage_fused.py b/studio/backend/core/inference/diffusion_zimage_fused.py
index ed14c1bb064..6f385e4db3f 100644
--- a/studio/backend/core/inference/diffusion_zimage_fused.py
+++ b/studio/backend/core/inference/diffusion_zimage_fused.py
@@ -1,20 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Z-Image-Turbo attention inside the regional compile: RoPE as ``addcmul`` in the card's probed fma form
-(bit-identical to the complex multiply Inductor cannot lower) and one fused QKV GEMM (exact for int8:
-per-row scales). ``to_q/to_k/to_v`` weights become views of the fused one; the fused Linear is used only
-while they are still the modules it was built from, so LoRA / later wrappers fall back to stock.
-
-int8 projections (fused QKV, ``to_out``) run through ``diffusion_int8_fused.int8_linear``: torchao's own math without
-torchao 0.17's always-on zero-point correction, which re-sums the weight rows on every call.
-
-ConvRot (int8 with a block-Hadamard input rotation): q, k and v rotate the SAME input, and the rotation acts on the
-shared input axis, so the three rotated weights concatenate along the output axis like plain ones. The fused Linear is
-then itself a ConvRotLinear at the parts' group: one rotation and one activation quant feed the fused GEMM instead of
-three of each. Same ops on the same input, so the fused output equals the three separate rotated projections.
-Kill switch: ``UNSLOTH_DIFFUSION_ZIMAGE_FUSED=0``.
-"""
+"""Z-Image-Turbo fused QKV GEMM (LoRA wrappers fall back to stock); UNSLOTH_DIFFUSION_ZIMAGE_FUSED=0"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/engine_install.py b/studio/backend/core/inference/engine_install.py
index 97147a34815..7f9d63068a3 100644
--- a/studio/backend/core/inference/engine_install.py
+++ b/studio/backend/core/inference/engine_install.py
@@ -1,17 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Opt-in serving environments. No engine packages are imported into Studio.
-
-When Studio's own PyTorch and CUDA libraries are the ones an engine is locked to,
-its environment runs on Studio's interpreter and holds only the packages Studio
-lacks or pins differently; Studio's site-packages follow its own on sys.path.
-Otherwise it is a complete isolated environment.
-
-Installation is serialized across Studio processes. Environments are built at
-their final paths (venv scripts contain absolute paths); only the active marker
-is replaced. Runtime leases prevent removing an environment another Studio uses.
-"""
+"""Opt-in engine envs share Studio torch/CUDA when locked, else isolated; none imported into Studio;
+installs serialized; runtime leases block removing an env in use"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/external_provider.py b/studio/backend/core/inference/external_provider.py
index 9e64284cbd4..67912a2984c 100644
--- a/studio/backend/core/inference/external_provider.py
+++ b/studio/backend/core/inference/external_provider.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Async HTTP client proxying chat completions to external LLM providers. Most use OpenAI-compatible
-/v1/chat/completions; Anthropic uses the native Messages API, translated here."""
+"""Async HTTP client for external LLM providers: /v1/chat/completions, Anthropic Messages translated"""
import asyncio
import base64
diff --git a/studio/backend/core/inference/external_tool_transport.py b/studio/backend/core/inference/external_tool_transport.py
index 8d6f62aa5e4..b999c30b30f 100644
--- a/studio/backend/core/inference/external_tool_transport.py
+++ b/studio/backend/core/inference/external_tool_transport.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Transport that drives the shared Unsloth tool loop over any external provider.
-
-``ExternalProviderClient.stream_chat_completion`` is the single point every
-external provider passes through: the OpenAI-compatible route yields its lines
-directly, and the Anthropic, Gemini, Responses and Kimi sub-streams are each
-translated into OpenAI chunk shape and re-yielded through it. Wrapping that one
-generator therefore covers self-hosted llama.cpp / vLLM / Ollama / custom
-endpoints and the hosted APIs alike.
-"""
+"""Tool loop over ExternalProviderClient.stream_chat_completion, which every external provider uses"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/family_name_match.py b/studio/backend/core/inference/family_name_match.py
index 0325460d32a..d4133760257 100644
--- a/studio/backend/core/inference/family_name_match.py
+++ b/studio/backend/core/inference/family_name_match.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Separator-insensitive family-name matching (``qwen_image_2.1`` == ``Qwen-Image-2.1``) shared by
-the image and video family tables. Path separators stay boundaries."""
+"""Separator-insensitive family match shared by image/video tables; path separators are boundaries"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/family_profile.py b/studio/backend/core/inference/family_profile.py
index 316a3fd0ce4..f49e750d244 100644
--- a/studio/backend/core/inference/family_profile.py
+++ b/studio/backend/core/inference/family_profile.py
@@ -1,21 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-family policy data carried on ``DiffusionFamily.profile`` / ``VideoFamily.profile``.
-
-Stdlib only (the transformer-quant smoke-probe child imports its consumers). Everything a new family needs beyond its
-registry row lives here as data; the consumer modules (transformer quant, text-encoder quant, untiled VAE decode,
-preview, step skip, trusted repos) derive their lookup tables from the registries through ``profile_table`` and keep
-their historical names and lookup semantics.
-
-The quant fields are baked into PUBLISHED prequant artifacts and validated at load (``diffusion_prequant.
-_validate_checkpoint`` requires an artifact's exclude tokens to be a superset of ``exclude_tokens_for_scheme``), so a
-change to ``int8_exclude_tokens`` / ``int8_convrot`` / ``nvfp4_zero_row_tokens`` on a family with a hosted checkpoint
-needs a rebuild and republish; tests/test_diffusion_family_data_freeze.py pins every resolved value.
-
-Scheme names are spelled as plain strings ("int8", "fp8", "mxfp8", "nvfp4") to keep this module import-free; they
-equal ``diffusion_transformer_quant.TQ_*``.
-"""
+"""Stdlib only; quant fields are baked into published artifacts, so changing them on a family with a
+hosted checkpoint needs rebuild and republish"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/file_history.py b/studio/backend/core/inference/file_history.py
index 869481a0209..55601391b55 100644
--- a/studio/backend/core/inference/file_history.py
+++ b/studio/backend/core/inference/file_history.py
@@ -1,17 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-chat history of the files tool calls change, so /rewind can put them back.
-
-Blobs are content addressed under the account's ``file_history/objects`` and indexed in a SQLite
-file next to them (WAL, one short transaction per tool call, always on the tool's worker thread,
-never the event loop). The index keeps the last stored image of every file in a folder, so the
-image a python or terminal call overwrites is already stored when the call starts: the stat walk
-those tools already take is diffed against it, and only files whose (mtime, size) moved are read.
-
-Execution state is not tracked: processes, installed packages and anything outside the chat's
-folder stay as they are after a rewind.
-"""
+"""Per-chat file history for /rewind; index work always on the tool's worker thread, never the event
+loop; processes and packages not restored"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/flm_files.py b/studio/backend/core/inference/flm_files.py
index 6a1a52a0389..e8d3537c18d 100644
--- a/studio/backend/core/inference/flm_files.py
+++ b/studio/backend/core/inference/flm_files.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Download a FastFlowLM model's files with resume, into the folder FastFlowLM reads.
-
-FastFlowLM's own pull cannot resume. It writes each file straight to its final name, starts a
-failed file over from zero (three tries), must finish each file within an hour, and takes a file a
-killed pull left half-written as complete. Studio downloads the files here instead: each one goes
-to ``<name>.partial``, continues from there with a Range request after any interruption, and is
-renamed only once its hash matches. lemond's pull then finds every file present and only
-registers the model.
-"""
+"""Resumable FastFlowLM downloads into the folder it reads; renamed from .partial once hash matches"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/flux3_prompt_upsampler.py b/studio/backend/core/inference/flux3_prompt_upsampler.py
index 86c899544e6..82f6cfd2793 100644
--- a/studio/backend/core/inference/flux3_prompt_upsampler.py
+++ b/studio/backend/core/inference/flux3_prompt_upsampler.py
@@ -1,23 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""FLUX.3 Image Klein prompt upsampling through a llama.cpp sidecar.
-
-FLUX.3 was trained on ~250-word captions, and a short request ("a gymnast doing a backflip") renders broken
-anatomy. BFL ships a prompt upsampler (a Qwen3.5-9B fine-tune) that rewrites the request into such a caption;
-ComfyUI's FLUX.3 templates run it by default. Studio runs a GGUF of it in one ``llama-server`` on an ephemeral
-127.0.0.1 port, loaded on demand and unloaded after the dictation keep-alive (or right after the call when VRAM is
-tight, so the DiT and text encoder never denoise next to it). The diffusers graph's own ``prompt_upsampler`` step
-stays dropped (``diffusion_flux3.flux3_blocks``); this replaces it.
-
-Prompts and sampling follow ComfyUI's FLUX.3 templates. The system prompts are BFL's ``system_prompts.json``
-(black-forest-labs/flux-3-image-klein-pup at commit 8b069751), byte-identical to ``SYSTEM_PROMPTS`` in diffusers'
-``modular_pipelines/flux3/prompt_upsampler.py`` at d42ebf9c6e (huggingface/diffusers#15058). The reference
-preparation is adapted from that file's ``get_reference_size`` / ``prepare_reference`` (Apache-2.0).
-
-Weights only ever come from the unsloth GGUF repo below or a local override; nothing is fetched implicitly by a
-generate call, the UI drives the download. Any failure leaves the prompt as typed.
-"""
+"""FLUX.3 prompt upsampler via llama-server; weights never fetched by generate, failures keep prompt"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/gallery_flags.py b/studio/backend/core/inference/gallery_flags.py
index bfb4fd0559e..65562669459 100644
--- a/studio/backend/core/inference/gallery_flags.py
+++ b/studio/backend/core/inference/gallery_flags.py
@@ -1,25 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pin / archive / manual-order flags for the image and video galleries.
-
-Library state, NOT part of a generation recipe: a PNG's text chunk and a clip's sidecar
-describe how the media was made, while "I pinned this" describes how the user files it. So
-flags live in their own ``.flags.json`` beside the media rather than in the recipe, and a
-record missing from the store simply has no flags.
-
-One store per gallery directory, keyed by the same id the gallery uses (the file stem):
-
- {"version": 1, "items": {"<id>": {"pinned_at": 1712345678.0, "archived": true}}}
-
-A dragged item also stores ``order_at``, a sort key on the mtime scale used in place of its mtime.
-Only moved items get one, and new media still lands first.
-
-The filename is skipped by the galleries' ``*.png`` / ``*.mp4`` globs, so a store sitting in
-the directory is invisible to listing. Every read fails safe: a corrupt, hand-edited or
-unreadable store degrades to "no flags", never to an error, because losing a pin is a far
-better outcome than a gallery that will not list.
-"""
+"""Pin/archive/order flags in .flags.json beside media, not the recipe; corrupt store means no flags"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/gallery_projects.py b/studio/backend/core/inference/gallery_projects.py
index a305e02f3ea..8ec4ea0fadf 100644
--- a/studio/backend/core/inference/gallery_projects.py
+++ b/studio/backend/core/inference/gallery_projects.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Copy a gallery image or clip into a chat project's folder.
-
-Files land in ``<project root>/sandbox/{images,videos,audio}``, where the project's chats run their
-tools. It is a copy, so the gallery keeps its item.
-"""
+"""Copies a gallery item (not moves) into <project root>/sandbox/{images,videos,audio} for chat tools"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/generate_image_tool.py b/studio/backend/core/inference/generate_image_tool.py
index 85f2c0926c3..9a6e10627a7 100644
--- a/studio/backend/core/inference/generate_image_tool.py
+++ b/studio/backend/core/inference/generate_image_tool.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The ``generate_image`` chat tool: one image on the image model already loaded in Unsloth Studio.
-
-The tool runs on a chat worker thread. It hands the Images route's core to the server loop,
-bound to the calling account, so the image lands in that account's gallery and goes through
-the same access checks. It never loads or unloads a model.
-"""
+"""Chat tool: one image on the loaded image model for the caller's account; never loads/unloads models"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/generate_video_tool.py b/studio/backend/core/inference/generate_video_tool.py
index 81a53ee7c62..91d8c209e15 100644
--- a/studio/backend/core/inference/generate_video_tool.py
+++ b/studio/backend/core/inference/generate_video_tool.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The ``generate_video`` chat tool: one clip on the video model already loaded in Unsloth Studio.
-
-It goes through the same job path as ``POST /v1/videos`` (``_create_openai_video``) with no
-model named, so it never loads, switches or unloads a model. The job runs on the video
-backend's own thread; the tool polls it and copies the finished MP4 into the chat workdir.
-"""
+"""Chat tool: a clip on the loaded video model, as POST /v1/videos does; never loads/switches/unloads"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/generation_ticket.py b/studio/backend/core/inference/generation_ticket.py
index 54d9d6c3b43..06b6359e1d3 100644
--- a/studio/backend/core/inference/generation_ticket.py
+++ b/studio/backend/core/inference/generation_ticket.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Stop one image generation without touching any other run of the same account.
-
-A caller binds a ticket in its context; ``asyncio.to_thread`` copies the context into the engine
-thread, where the engine hands the ticket its per-generation cancel event. Stopping the ticket
-sets only that event, whether the run is still queued or already denoising.
-"""
+"""Cancels one image run via a context ticket; asyncio.to_thread carries it, other runs untouched"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/generation_timing.py b/studio/backend/core/inference/generation_timing.py
index 29b2088e68e..064f52b6a3d 100644
--- a/studio/backend/core/inference/generation_timing.py
+++ b/studio/backend/core/inference/generation_timing.py
@@ -1,21 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Prefill/decode timing for the safetensors generate paths.
-
-Transformers reports no timings of its own, so the prompt and generation speeds the
-chat UI reads off llama-server's ``timings`` object have to be measured here. The
-split point is the first logits-processor call, which transformers makes once the
-prefill forward pass has produced its logits, before the first token is sampled.
-
-Reaching that callback only means the kernels were queued, so each stamp waits for the
-device first. Without the wait a 2048-token prefill on an RTX 3080 reads as 28 ms
-instead of 77 ms, inflating prompt throughput 2.7x and charging the rest to decode.
-
-Kept in a dependency-light leaf module (torch + transformers only, no unsloth / peft)
-so the arithmetic can be unit-tested without loading a model, matching
-``core.inference.presence_penalty``.
-"""
+"""Prefill/decode timing; each stamp waits for the device or prefill reads too fast; leaf module:
+torch and transformers only, no unsloth or peft imports"""
import time
diff --git a/studio/backend/core/inference/gpu_arbiter.py b/studio/backend/core/inference/gpu_arbiter.py
index e278109bd7a..abc2b54c268 100644
--- a/studio/backend/core/inference/gpu_arbiter.py
+++ b/studio/backend/core/inference/gpu_arbiter.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GPU arbiter for Unsloth's heavy GPU consumers.
-
-The chat backends, diffusion, and video share the GPUs. Before taking them each calls
-``acquire_for(owner)``. Under the default policy that evicts every other resident, so two large
-models never sit in VRAM at once. Under "always" (Keep multiple models loaded set to Always) it
-refuses instead of evicting a chat, image or video model. The arbiter only sequences residency
-(freeing is each backend's teardown); eviction runs under the lock, so a transfer is atomic vs
-other acquires.
-
-Residents are tracked in ``_residents`` with the physical GPU ids each one uses (None when not
-known). ``_owner`` stays the last claimant, and tests may still set it directly: while it
-disagrees with ``_residents``, ``_owner`` wins.
-"""
+"""GPU arbiter: default evicts other residents, 'always' refuses instead; eviction runs under lock"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/gpu_residency.py b/studio/backend/core/inference/gpu_residency.py
index 28120f680eb..c8e29dc029b 100644
--- a/studio/backend/core/inference/gpu_residency.py
+++ b/studio/backend/core/inference/gpu_residency.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Whether an image or video model can stay on a GPU next to chat, and what to unload when it can't.
-
-Keep multiple models loaded set to When they fit or Always lets the GPU arbiter keep several residents. This module
-prices them: a media resident holds the weights plus generation headroom it was admitted with, a new media load is
-priced from the files already on disk, and live free VRAM decides whether it fits. Anything it cannot price is
-treated as not fitting, so the caller frees memory first (fit) or refuses (always). Modelled on training_vram.py.
-"""
+"""Prices image/video residents against live free VRAM; anything unpriceable counts as not fitting"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/host_pinning.py b/studio/backend/core/inference/host_pinning.py
index 64618a39a02..891952e593c 100644
--- a/studio/backend/core/inference/host_pinning.py
+++ b/studio/backend/core/inference/host_pinning.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Integrated GPUs skip pinned host memory: their VRAM is system RAM, so a pinned copy only takes RAM from the GPU
-(ComfyUI does the same). An unclassifiable device answers discrete (pinning allowed)."""
+"""Integrated GPUs skip pinned host memory (VRAM is RAM); unclassifiable devices count as discrete"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/hub_reachability.py b/studio/backend/core/inference/hub_reachability.py
index 04eb1ba572d..d9c9c4c45fb 100644
--- a/studio/backend/core/inference/hub_reachability.py
+++ b/studio/backend/core/inference/hub_reachability.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-process verdict on whether the Hub endpoint answers. After one transport failure, cached-load Hub calls use
-their fallback for ``TTL_SECONDS`` instead of each waiting out a timeout. HTTP answers never set the verdict.
-"""
+"""Per-process: transport failure (not HTTP) makes cached Hub calls use fallback for TTL_SECONDS"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/image_gallery.py b/studio/backend/core/inference/image_gallery.py
index 1173b32206f..53bc4df8aca 100644
--- a/studio/backend/core/inference/image_gallery.py
+++ b/studio/backend/core/inference/image_gallery.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Disk-backed persistence for generated images.
-
-Each image is a PNG under ``workspace_root()/images`` with its recipe embedded as PNG text chunks:
-an ``unsloth`` JSON blob (the source of truth) plus an Automatic1111-style ``parameters`` string,
-so a downloaded PNG carries its own settings. The route owns the schema; this only stores files.
-"""
+"""Image PNGs in workspace_root()/images; recipe in an unsloth JSON text chunk (source of truth)"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/instruction_pin.py b/studio/backend/core/inference/instruction_pin.py
index 0a48b2dadb0..858fd1e8fe3 100644
--- a/studio/backend/core/inference/instruction_pin.py
+++ b/studio/backend/core/inference/instruction_pin.py
@@ -1,34 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep the user's standing instructions when the rolling window evicts everything else.
-
-The defect this exists for. `context_window.truncate_oldest_messages` protects system and
-developer groups, the final group, and the newest USER group. So "do task B, and always
-report results as a table" is safe only while it IS the newest user turn. After a few
-agent turns and a short follow-up -- "continue", "yes", "keep going" -- the newest user
-group is that filler, and the instruction becomes an ordinary eviction candidate: the
-oldest one, so the first to go.
-
-Then the archive cannot rescue it either, because the forced recall on the compaction
-turn uses the latest user message as its query. The archive gets searched for the word
-"continue".
-
-That follow-up is not a contrived case. OpenCode writes a synthetic "Continue if you have
-next steps" turn after every auto compaction, and Zed emits "Continue where you left
-off", so in both, the newest user turn straight after a compaction is filler by
-construction. Everyone else's answer is to ask a summarizer to remember the instruction;
-this is the deterministic version, and Zed's 80 KB verbatim replay of recent user
-messages is the closest existing thing to it.
-
-Two knobs, both off by default so the change ships inert:
-
- ROLLING_INSTRUCTION_PIN_GROUPS how many instruction groups to hold (0 = today)
- ROLLING_INSTRUCTION_PIN_MAX_TOKENS absolute ceiling on what they may cost
-
-The pin is applied through `truncate_oldest_messages`'s existing `protected_message_ids`
-parameter, so nothing in the rolling-window layer changes.
-"""
+"""Keeps standing instructions past filler turns; opt-in via ROLLING_INSTRUCTION_PIN_GROUPS (0 = off)"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/key_exchange.py b/studio/backend/core/inference/key_exchange.py
index 6087e38ebd5..ae7db920b17 100644
--- a/studio/backend/core/inference/key_exchange.py
+++ b/studio/backend/core/inference/key_exchange.py
@@ -1,20 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""
-RSA key pair for encrypting API keys in transit.
-
-The frontend encrypts API keys with the server's public key before sending
-them; the backend decrypts with its private key before forwarding to external
-providers.
-
-The key pair is generated at server startup, lives only in memory, and is
-regenerated on each restart. The frontend fetches the public key via
-GET /api/providers/public-key on load.
-
-A per-request AES-256-GCM key carries the secret and RSA-OAEP wraps only that
-key: encrypting the secret under RSA directly would cap it at 190 bytes.
-"""
+"""RSA-OAEP wraps a per-request AES-256-GCM key (RSA alone caps at 190 bytes); keypair lives only in
+memory, new per start; GET /api/providers/public-key"""
import base64
import hashlib
diff --git a/studio/backend/core/inference/lemonade_server.py b/studio/backend/core/inference/lemonade_server.py
index 69219845d2f..ba26930fd65 100644
--- a/studio/backend/core/inference/lemonade_server.py
+++ b/studio/backend/core/inference/lemonade_server.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Private Lemonade process serving FastFlowLM on the AMD NPU.
-
-Uses authenticated loopback and owns the child process tree. Runtime, config and models
-stay under Studio's home; a separate FLM_MODEL_PATH prevents other FastFlowLM installs
-from deleting these models (lemonade-sdk/lemonade#3375). No torch or transformers imports.
-"""
+"""Private Lemonade serving FastFlowLM on AMD NPU over authenticated loopback; no torch or
+transformers imports; FLM_MODEL_PATH stops other FLM installs deleting models"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/llama_admission.py b/studio/backend/core/inference/llama_admission.py
index 06c6100690f..e651bcf6ff4 100644
--- a/studio/backend/core/inference/llama_admission.py
+++ b/studio/backend/core/inference/llama_admission.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Admission control for local llama-server generation requests.
-
-These helpers deliberately know nothing about FastAPI, SSE or the OpenAI-compatible route shape.
-They only coordinate how many upstream generation requests may be active for one llama-server
-backend and provide a cancellable FIFO queue for excess requests.
-"""
+"""Per-backend concurrency limit with a cancellable FIFO queue for llama-server; no FastAPI or SSE"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/llama_http.py b/studio/backend/core/inference/llama_http.py
index 88790fd0c01..6d2e613f4a6 100644
--- a/studio/backend/core/inference/llama_http.py
+++ b/studio/backend/core/inference/llama_http.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Shared pooled httpx.AsyncClient for NON-streaming calls to the local llama-server.
-
-Streaming generation must NOT use this. It relies on ``Connection: close`` and
-``max_keepalive_connections=0`` so a client disconnect tears down the upstream
-socket and stops GPU decode (PR #5749). This pooled client is only for short
-request/response proxy calls (non-streaming completions, embeddings) where
-reusing a connection removes per-request setup cost. Per-request ``timeout`` is
-still passed at each call site.
-"""
+"""Pooled httpx for non-streaming llama-server calls; streaming must bypass it to stop GPU decode."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/llama_server_args.py b/studio/backend/core/inference/llama_server_args.py
index f46324b967d..d7200d1bf69 100644
--- a/studio/backend/core/inference/llama_server_args.py
+++ b/studio/backend/core/inference/llama_server_args.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Boundary validator for user-supplied llama-server pass-through args. Reject only flags Unsloth
-manages (model identity, auth, network, parallel slots). Everything else (sampling, ``-c``,
-``-ngl``, ``--flash-attn``, ``--cache-type-*``, ``--spec-*``, ``--jinja``, ...) is appended after
-Unsloth's auto-set flags so llama.cpp's last-wins parser lets the user override. Ref:
-https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md"""
+"""Rejects only Unsloth-managed flags (model, auth, network, slots); user flags come last and win."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/llama_stats.py b/studio/backend/core/inference/llama_stats.py
index c97aae186a2..3615f19135f 100644
--- a/studio/backend/core/inference/llama_stats.py
+++ b/studio/backend/core/inference/llama_stats.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Translate llama-server's Prometheus /metrics into a periodic, vLLM-style
-engine-stats log line (generation/prompt throughput, requests in flight).
-
-llama-server already computes these (it needs `--metrics`); this lifts them
-into Unsloth's structured log so the terminal shows serving health, not just
-per-request access lines. Emitted only while there is activity.
-"""
+"""Turns llama-server /metrics into periodic vLLM-style stats lines, only while busy; needs --metrics."""
import math
import os
diff --git a/studio/backend/core/inference/local_model_resolver.py b/studio/backend/core/inference/local_model_resolver.py
index 1394b5b504a..ff402aae0ef 100644
--- a/studio/backend/core/inference/local_model_resolver.py
+++ b/studio/backend/core/inference/local_model_resolver.py
@@ -1,17 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Resolve an OpenAI-request ``model`` string to a downloaded local model.
-
-Used by the opt-in auto-switch path. Two kinds of local model qualify: a GGUF
-(served by llama.cpp, with a quant that is actually on disk) and a non-GGUF
-checkpoint such as safetensors or MLX weights (served by the inference
-orchestrator). The match is conservative either way: only names that map to
-something already downloaded are eligible, so an arbitrary OpenAI model string
-still falls through to the loaded model (drop-in compat) and no surprise
-multi-GB download is ever triggered. The local-model scan is cached for a few
-seconds since auto-switch consults it per request.
-"""
+"""Maps an OpenAI model string to a downloaded GGUF or non-GGUF model; unknown names fall through to
+the loaded model; never triggers a download."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/ltx2_import_compat.py b/studio/backend/core/inference/ltx2_import_compat.py
index bd5bc7047b1..d0371bc94bc 100644
--- a/studio/backend/core/inference/ltx2_import_compat.py
+++ b/studio/backend/core/inference/ltx2_import_compat.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Let the diffusers LTX-2 pipelines import on the transformers Studio pins.
-
-diffusers 0.40 imports ``Gemma4UnifiedForConditionalGeneration`` (transformers >= 5.10) at module level in every
-``diffusers.pipelines.ltx2.pipeline_ltx2*`` module, but only uses it in the ``text_encoder`` annotation (huggingface/
-diffusers#14773). When transformers lacks it, bind an inert placeholder only while those modules import, then remove
-it. Retire once diffusers guards the import or the transformers pin reaches 5.10.
-"""
+"""Binds an inert Gemma4UnifiedForConditionalGeneration placeholder only while LTX-2 diffusers
+modules import, then removes it; for transformers below 5.10."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/mcp_config_import.py b/studio/backend/core/inference/mcp_config_import.py
index fdefa361e72..1b2317ade89 100644
--- a/studio/backend/core/inference/mcp_config_import.py
+++ b/studio/backend/core/inference/mcp_config_import.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Parse a standard ``mcpServers`` JSON config (Claude Desktop / Cursor / Cline
-/ VS Code) into entries the existing MCP storage understands. See issue #5936.
-
-A stdio entry (``command`` + ``args`` + ``env``) is joined into the single
-command string the ``url`` field already stores; a remote entry (``url`` +
-``headers``) maps straight through. Parsing never raises on a single bad entry:
-it returns ``(entries, errors)`` so one malformed server can't sink the import.
-"""
+"""Parses mcpServers JSON into (entries, errors) so one bad entry cannot sink the import."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/mcp_image.py b/studio/backend/core/inference/mcp_image.py
index ce753f15b6b..75abf7edb9b 100644
--- a/studio/backend/core/inference/mcp_image.py
+++ b/studio/backend/core/inference/mcp_image.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Send a user's attached image to a mapped MCP tool field without the model seeing its bytes.
-
-A server opts in by mapping one top-level string field of a tool. The model only ever sees the
-placeholder ``ATTACHED_IMAGE`` in that field; the tool loop asks the user before every call that
-would carry the image, and ``execute_tool`` swaps the bytes in after that approval.
-"""
+"""Image bytes hidden from the model: opted-in fields get ATTACHED_IMAGE, swapped in after approval."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_auto_switch.py b/studio/backend/core/inference/media_auto_switch.py
index c0b67b881ee..d4e0f1a90f7 100644
--- a/studio/backend/core/inference/media_auto_switch.py
+++ b/studio/backend/core/inference/media_auto_switch.py
@@ -1,30 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in model auto-switch for the image and video generation APIs.
-
-The chat twin lives in ``local_model_resolver`` + ``routes.inference``: a ``/v1`` request
-naming a downloaded GGUF loads it before serving. Media had no equivalent, so
-``POST /v1/images/generations`` answered 503 unless someone had already picked a model on the
-Images page, and ``model`` was documented as informational. This resolves that name against
-the downloaded image/video models, drains what the backend is doing, and runs the load the
-picker would run.
-
-Off by default (``media_api_auto_switch_model``), so existing clients see no change.
-
-Only downloaded models resolve, and an unknown name is refused rather than answered by
-whatever is resident. Nothing here starts a download: the media equivalent of the chat
-auto-download setting would let one API key spend tens of GB, which is its own decision.
-
-Both waits are bounded, because Unsloth's secure-mode tunnel caps an origin response near 100
-seconds. Exceeding a bound leaves the work running and asks the caller to retry, the contract
-``begin_load`` already gives the UI.
-
-This module is the orchestration. The pieces it drives live next to it: ``media_model_index``
-resolves a name and recognises the resident model, ``media_locality`` proves a pick is already
-downloaded, ``media_switch_backends`` waits out work a switch would interrupt,
-``media_switch_locks`` serializes switches, and ``media_switch_errors`` holds the refusals.
-"""
+"""Opt-in media auto-switch (media_api_auto_switch_model); never downloads; refuses unknown names;
+waits are bounded near the ~100 s tunnel cap, and exceeding one leaves work running and asks
+retry."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_catalog.py b/studio/backend/core/inference/media_catalog.py
index e6ef303b19c..6a099fed322 100644
--- a/studio/backend/core/inference/media_catalog.py
+++ b/studio/backend/core/inference/media_catalog.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The image and video models Unsloth Studio can offer, built from the family registries.
-
-Pure and torch-free. Rows carry no path, so account filtering keys on ``id``; the route filters
-per request and this payload is never filtered in place.
-"""
+"""Torch-free image/video model list from family registries; rows carry no paths, so filter per
+request by id, never in place."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_chat_tools.py b/studio/backend/core/inference/media_chat_tools.py
index bda6d582660..c11ec5807f8 100644
--- a/studio/backend/core/inference/media_chat_tools.py
+++ b/studio/backend/core/inference/media_chat_tools.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Chat tools that render on the image or video model already loaded in Unsloth Studio.
-
-Every registry that needs to know these tools (sentinel stripping, always-safe, dedupe
-exemptions, the Anthropic allow-list) reads ``MEDIA_CHAT_TOOLS`` so the lists can't drift.
-The module has no heavy imports at load time; the status helpers import lazily.
-"""
+"""Chat tools for the loaded image/video model; registries read MEDIA_CHAT_TOOLS so they cannot
+drift; no heavy imports at load, status helpers import lazily."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_keepwarm.py b/studio/backend/core/inference/media_keepwarm.py
index 36adf79ab30..d2da196aaa7 100644
--- a/studio/backend/core/inference/media_keepwarm.py
+++ b/studio/backend/core/inference/media_keepwarm.py
@@ -1,22 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in idle auto-unload for the diffusion image and video backends.
-
-The image and video pipelines are the largest thing Unsloth holds in VRAM, and until now only
-the chat GGUF was freed when the user walked away: one generation and a navigate-away left
-several GB resident forever. This is the same mechanism rather than a second one -- the same
-in-flight bookkeeping (``LlamaKeepWarmMiddleware`` already tracks the generate routes) and one
-step per tick of ``llama_keepwarm.idle_unload_loop``. The TTL is its own setting, off by
-default, so nothing here runs until the user asks for it: the tick returns before it resolves
-a backend, which is also what keeps torch out of an Unsloth that never opened these pages.
-
-Each backend owns its teardown barrier, so this decides only WHEN: it calls the same
-``unload()`` the arbiter's evictor calls, resolved through ``get_active_diffusion_engine()``
-so a native sd.cpp selection stops the sd-server instead of a diffusers pipeline that was
-never loaded. Device-agnostic on purpose: CUDA, ROCm, XPU and MPS free VRAM, and a CPU load
-frees the host RAM the same weights occupy there, which is just as much the user's.
-"""
+"""Opt-in idle unload for image/video backends, off by default; the tick returns before resolving a
+backend so torch stays out; calls the arbiter's unload()."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_load_ids.py b/studio/backend/core/inference/media_load_ids.py
index 1f32868802d..5120eaa6beb 100644
--- a/studio/backend/core/inference/media_load_ids.py
+++ b/studio/backend/core/inference/media_load_ids.py
@@ -1,26 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Client load tokens for the image and video slots, so an unload can name the load it means.
-
-A load request may carry ``load_token`` (an opaque id the client makes up). The load route
-records it when the engine accepts the load, under ``account_access.media_load_lock``, together
-with the engine, its load epoch (``_load_token``, bumped by every begin_load and unload) and the
-state that was resident before. ``POST .../unload`` with ``expected_load_id`` then unloads only
-while that record still describes the engine: no begin_load or unload ran since (same epoch),
-and either a load is in flight (it can only be that one) or a state that load published is
-resident. Anything else answers without touching the slot:
-
-- ``superseded``: the token was admitted, but its load ended or another load replaced it;
-- ``cancelled``: the token was never admitted (its POST is still on its way, or was lost), so it
- is remembered and that load is refused when it arrives, for the account that sent the unload only.
-
-A load sent without a token gets one from Studio, and the status routes report the token of the
-load in the slot as ``load_id``, so a client can unload exactly the model it saw.
-
-The check and the unload run under the same lock as the admission, so no load can be admitted
-between them. Loads without a token, and unloads without ``expected_load_id``, behave as before.
-"""
+"""load_token and expected_load_id: unload only while that load still owns the slot, else answer
+superseded or cancelled without touching it; check and unload share the admission lock; loads
+without a token and unloads without expected_load_id behave as before."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_locality.py b/studio/backend/core/inference/media_locality.py
index 5ac3cb6bb3b..2c67abee2d4 100644
--- a/studio/backend/core/inference/media_locality.py
+++ b/studio/backend/core/inference/media_locality.py
@@ -1,19 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Proving a media model is already downloaded, before the switch evicts anything for it.
-
-Auto-switch never downloads. That promise is easy to state and hard to keep, because the index
-only sees CHECKPOINTS: a GGUF or single-file pick loads its text encoders and VAE from a
-companion base repo, HiDream-I1 fetches a 16 GB Llama encoder no amount of pipeline on disk
-accounts for, and an LTX-2.3 checkpoint pulls VAE, audio and connector artifacts the planner
-only recognises by name. Any of those would let one API request spend tens of gigabytes.
-
-So locality is verified through the same download planner ``/images/download-plan`` serves, and
-the answer is tri-state: complete, incomplete by some number of bytes, or unverifiable. Zero
-bytes from a planner that failed is not evidence of a complete cache, and the switch refuses on
-anything short of proof.
-"""
+"""Proves a media model is downloaded via the download planner (tri-state); refuses unless complete;
+auto-switch never downloads; a planner failure is not proof."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_model_index.py b/studio/backend/core/inference/media_model_index.py
index 20a94354515..6f17ba693aa 100644
--- a/studio/backend/core/inference/media_model_index.py
+++ b/studio/backend/core/inference/media_model_index.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which downloaded media model a requested name means, and whether it is the resident one.
-
-Two halves of one question. The index walks the model roots once per few seconds and maps every
-name a downloaded image or video model answers to onto the load spec its route takes. The
-matching half then decides whether the backend already holds that exact build, which is what
-lets a switch be skipped rather than reloading the model that is already serving.
-
-Only downloaded models are indexed. A name that resolves to nothing is refused by the caller
-rather than answered by whichever model happens to be resident.
-"""
+"""Maps downloaded media model names to load specs and flags the resident build; unresolved names
+are refused by the caller, never answered by the resident model."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_switch_backends.py b/studio/backend/core/inference/media_switch_backends.py
index 3ab686a8873..22392150b98 100644
--- a/studio/backend/core/inference/media_switch_backends.py
+++ b/studio/backend/core/inference/media_switch_backends.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Reaching the media backends, and waiting until nothing a switch would interrupt is running.
-
-Loading a media model is not a private act. The load route takes the GPU through the arbiter,
-whose cross-owner handoff unloads whichever owner holds it, so a switch can cancel a video
-generation or terminate a streaming chat completion that has nothing to do with the request that
-asked for it. The drain here waits all of that out first, and refuses rather than interrupting.
-"""
+"""Waits for unrelated work to drain or refuses; arbiter handoff would cancel video or chat streams."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_switch_errors.py b/studio/backend/core/inference/media_switch_errors.py
index e41a241162d..a9d296036c4 100644
--- a/studio/backend/core/inference/media_switch_errors.py
+++ b/studio/backend/core/inference/media_switch_errors.py
@@ -1,16 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Refusals the media model auto-switch answers a generation request with.
-
-Every one of these is an ordinary outcome rather than a fault. The switch never downloads,
-never cuts a running generation short, and never outlives the ~100 second window Unsloth's
-secure-mode tunnel gives an origin response, so where it cannot serve the request it says which
-of those it hit and asks the caller to retry.
-
-Each refusal is rendered in the error shape of the route that raised it: the OpenAI-compatible
-body for ``/v1``, a plain string for the native media routes.
-"""
+"""Ordinary refusals that ask callers to retry; the switch never downloads, never cuts a running
+generation short, never outlives the ~100 s tunnel window; /v1 gets OpenAI error bodies, native
+routes plain strings."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/media_switch_locks.py b/studio/backend/core/inference/media_switch_locks.py
index 370870bd6b6..33c60799c81 100644
--- a/studio/backend/core/inference/media_switch_locks.py
+++ b/studio/backend/core/inference/media_switch_locks.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Serialization and bookkeeping for media model switches.
-
-One switch at a time per backend, so two requests cannot race the single pipeline slot, plus a
-single cross-backend lock every GPU-taking switch queues on. Without the latter two switchers
-each see the other as work they would interrupt and refuse each other; queueing makes the second
-a waiter instead.
-
-The counters exist because the request that is switching is itself tracked by the middleware.
-A request parked on a switch lock holds no work, and a request performing a switch is not using
-the backend it is counted against, so both are discounted when a switch asks whether anything
-else is running.
-
-The locks are per running loop, like ``_auto_switch_lock`` in ``routes.inference``: a
-module-level ``asyncio.Lock`` binds to the loop that first awaited it and hangs a second one.
-"""
+"""Serializes switches: one at a time per backend, plus one cross-backend GPU lock every GPU-taking
+switch queues on; locks are per event loop, since a module-level asyncio.Lock hangs a second
+loop."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/memory_contract.py b/studio/backend/core/inference/memory_contract.py
index 5b345b92690..d1da4393224 100644
--- a/studio/backend/core/inference/memory_contract.py
+++ b/studio/backend/core/inference/memory_contract.py
@@ -1,31 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One canonical memory estimate, and the two legacy shapes projected from it.
-
-Studio answers "how much memory would this load take" on two routes:
-
-* ``POST /api/inference/estimate-memory`` -- the Load Model panel
-* ``GET /api/models/kv-cache-estimate`` -- the Hub memory bar
-
-They already share the ``_gguf_memory_breakdown`` planner, so the arithmetic
-cannot drift. What used to drift is everything around it, and the sharp edge is
-that ``weights_bytes`` exists on both, is an ``int`` on both, and means
-different things: every resident file on the inference route, the quant file
-alone on the models route. Nothing in the type system separates those, so a
-caller reading the wrong one is simply wrong, quietly.
-
-This module is the fix. :func:`build_memory_estimate` turns a planner breakdown
-into the canonical :class:`MemoryEstimate`, whose two unambiguous fields replace
-that one ambiguous one. The two ``project_*`` functions then map the canonical
-model back onto each route's existing wire shape, byte for byte, so no client
-sees a change. The legacy meaning of ``weights_bytes`` is applied in exactly one
-place per route, right here, where the two sit next to each other and the
-difference is impossible to miss.
-
-Everything here is pure: no I/O, no probing, no network. The planner does that
-work; this only renames and reshapes what it returned.
-"""
+"""Canonical memory estimate projected byte for byte onto POST /api/inference/estimate-memory and
+GET /api/models/kv-cache-estimate; no client change; weights_bytes differs by route; pure."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/message_content.py b/studio/backend/core/inference/message_content.py
index f47120da36e..915f6f3c286 100644
--- a/studio/backend/core/inference/message_content.py
+++ b/studio/backend/core/inference/message_content.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Normalize chat-message `content` (string or OpenAI multimodal list) to text.
-
-String-only formatting paths called string ops directly on `content` and broke
-on the list form (#4383). `content_to_text` collapses either shape to a string,
-dropping non-text parts. No heavy imports, so it is unit-testable alone.
-"""
+"""Collapses message content (string or OpenAI multimodal list) to text, dropping non-text parts; no
+heavy imports, so unit-testable alone."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/mlx_diffusion_convert.py b/studio/backend/core/inference/mlx_diffusion_convert.py
index 44174e02f3c..9d82c59e4a8 100644
--- a/studio/backend/core/inference/mlx_diffusion_convert.py
+++ b/studio/backend/core/inference/mlx_diffusion_convert.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Diffusion GGUF -> mflux pre-quantized transformer layout (numpy + gguf only, streamed per tensor).
-
-Q4_0 / Q4_1 / Q8_0 map exactly onto MLX affine group-32 (dequant = q * scale + bias):
- Q4_0: scale d, bias -8d; Q4_1: scale d, bias m; Q8_0: q = qs + 128, scale d, bias -128d.
-Q5_0 / Q5_1 likewise onto 5-bit (Q5_0: bias -16d; Q5_1: bias m), the fifth bit coming from the block's qh word.
-Q4_K / Q5_K keep their codes too: each 32-wide sub-block is affine with scale d * sc and bias -dmin * m, so they land
-on MLX 4 / 5-bit group-32; only the scale product is rounded to the 16-bit scale dtype, as the d of Q4_0 already is.
-Q6_K uses 16-wide groups, which MLX does not have: its exact dequantized values are re-quantized to 8-bit group-32,
-whose step is at most a quarter of Q6_K's own. Q2_K / Q3_K (16-wide, 2-3 bits) are refused.
-"""
+"""Diffusion GGUF to mflux layout (numpy and gguf only, streamed per tensor); Q2_K and Q3_K refused;
+Q6_K re-quantized to 8-bit; others map onto MLX group-32."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/mlx_inference.py b/studio/backend/core/inference/mlx_inference.py
index ca076fd9642..e43adb1ced0 100644
--- a/studio/backend/core/inference/mlx_inference.py
+++ b/studio/backend/core/inference/mlx_inference.py
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: AGPL-3.0-only
-"""MLX inference backend for Apple Silicon. Drop-in replacement for InferenceBackend, same
-interface, using mlx-lm/mlx-vlm instead of torch/transformers for model loading and generation."""
+"""MLX inference backend for Apple Silicon; drop-in InferenceBackend replacement using mlx-lm/mlx-vlm."""
import copy
import difflib
diff --git a/studio/backend/core/inference/mlx_speculative.py b/studio/backend/core/inference/mlx_speculative.py
index 669eb760f31..58de629e6ed 100644
--- a/studio/backend/core/inference/mlx_speculative.py
+++ b/studio/backend/core/inference/mlx_speculative.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which drafter an MLX load speculates with: ``speculative_type`` and ``spec_draft_model`` resolved
-against the target's own MTP head and the companion drafters already in the local Hugging Face cache."""
+"""Resolves MLX speculative_type and spec_draft_model to the target's MTP head or cached drafters."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/model_ids.py b/studio/backend/core/inference/model_ids.py
index 27ec12c79e8..7d3f3f3bfbd 100644
--- a/studio/backend/core/inference/model_ids.py
+++ b/studio/backend/core/inference/model_ids.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Public model identifiers for the OpenAI-compatible API.
-
-The exposed API must report a stable, clean model id rather than the absolute
-on-disk path of a local GGUF. The internal identifier for a direct local load is
-the absolute ``.gguf`` path, which leaks the host filesystem layout and is
-awkward for clients to round-trip. ``public_model_id`` maps such an internal
-identifier to a clean name while leaving Hugging Face repo ids (``org/model``)
-and already-clean names untouched.
-"""
+"""Keeps host paths out of API model ids: public_model_id maps absolute .gguf paths, leaves repo ids."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/model_slots.py b/studio/backend/core/inference/model_slots.py
index d085da81ad9..05a47e61860 100644
--- a/studio/backend/core/inference/model_slots.py
+++ b/studio/backend/core/inference/model_slots.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Models kept loaded alongside the primary one, each with its own llama-server and orchestrator.
-A task naming one sets ``routed_slot``, so the usual backend getters answer with that slot."""
+"""Models kept loaded beside the primary, each with its own llama-server; routed_slot selects one."""
import asyncio
import atexit
diff --git a/studio/backend/core/inference/mxc_drive_alias.py b/studio/backend/core/inference/mxc_drive_alias.py
index 2611d8e881f..a12fbe5227f 100644
--- a/studio/backend/core/inference/mxc_drive_alias.py
+++ b/studio/backend/core/inference/mxc_drive_alias.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Drive-letter aliases for the session workdir of an isolated cmd Terminal launch.
-
-Inside an MXC AppContainer, Git for Windows cannot resolve its working directory: the drive-letter form
-of GetFinalPathNameByHandleW is denied and the GetLongPathNameW fallback has to list every ancestor.
-From a drive root there is nothing above to resolve, so a launch runs from ``X:\\`` mapped onto the
-canonical workdir with DefineDosDeviceW, the same mapping ``subst`` makes. The mapping only changes how
-the workdir is spelled; MXC still grants the canonical folder and nothing else.
-"""
+"""Drive-root alias of the workdir (DefineDosDeviceW, like subst) so Git can resolve its cwd in MXC;
+it only respells the path, and MXC still grants only the canonical folder."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/mxc_read_grants.py b/studio/backend/core/inference/mxc_read_grants.py
index 218c0d6efca..e4e97c7ed93 100644
--- a/studio/backend/core/inference/mxc_read_grants.py
+++ b/studio/backend/core/inference/mxc_read_grants.py
@@ -1,13 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One-time AppContainer read grants on Studio's runtime folders for MXC's AppContainer + DACL tier.
-
-On that tier wxc-exec grants every readonly path per launch with an inheritable ACE, which Windows
-propagates to every file below it and reverts on exit, so a Python environment costs 10+ s per
-command (microsoft/mxc#572). wxc-exec skips a path whose DACL already grants ALL APPLICATION PACKAGES
-read and execute, as Windows ships C:\\Windows and Program Files. Granting that once on the runtime
-folders Studio owns lets every later launch skip the walk. Read and execute only, never write.
-"""
+"""Read/execute-only AppContainer grant on runtime folders lets wxc-exec skip the per-launch ACE walk."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/native_audio.py b/studio/backend/core/inference/native_audio.py
index 0b501e1f4af..eb87be4d86c 100644
--- a/studio/backend/core/inference/native_audio.py
+++ b/studio/backend/core/inference/native_audio.py
@@ -14,13 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Native Transformers/Diffusers audio generation backends.
-
-This module intentionally has no ML imports at module import time. The worker uses
-``is_native_audio_model`` before choosing its MLX or Unsloth runtime, including on
-Apple Silicon, and imports torch/transformers only after the normal version and
-remote-code security gates have run.
-"""
+"""No ML imports at load; torch/transformers load only after version and remote-code security gates."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/npu_backend.py b/studio/backend/core/inference/npu_backend.py
index 5ddb6f8d699..adb6553e4e1 100644
--- a/studio/backend/core/inference/npu_backend.py
+++ b/studio/backend/core/inference/npu_backend.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Manage FastFlowLM NPU models through a private Lemonade server.
-
-Installs and validates the runtime, manages its catalog, and loads models by
-``lemonade:<id>``. Health checks confirm residency and context length.
-GGUF models are unsupported. This module does not import the GPU stack.
-"""
+"""Runs FastFlowLM NPU models via a private Lemonade server; loads lemonade:<id>; GGUF unsupported;
+does not import the GPU stack."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/offload_cost_model.py b/studio/backend/core/inference/offload_cost_model.py
index c0e0061b6fb..64ce8c1ab1e 100644
--- a/studio/backend/core/inference/offload_cost_model.py
+++ b/studio/backend/core/inference/offload_cost_model.py
@@ -1,38 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Relative throughput of a candidate offload placement.
-
-The planner needs to RANK placements, not predict absolute t/s. So this models
-the marginal cost of moving a tensor group off the GPU, in milliseconds per
-token, and leaves the resident baseline as a free parameter the caller supplies
-or ignores.
-
-Two regimes, measured separately because they have different mechanisms:
-
-``generation``
- One token at a time. Host-resident weights are computed by the CPU backend,
- NOT streamed to the GPU. Measured directly: with the dense FFN spilled,
- generation scales with thread count (2.42 / 5.83 / 11.82 t/s at 4 / 16 / 64
- threads) while a fully resident run does not move at all (87.30 vs 87.31 at
- 4 vs 64). So the cost scales with the HOST's compute and memory bandwidth,
- not with the PCIe generation.
-
-``prefill``
- A whole ubatch at once. ggml's scheduler sends the large GEMM to the GPU and
- copies the weights in, so this regime IS link-bound, and it reads the FULL
- tensor rather than only the activated slice.
-
-The distinction matters most for MoE: generation touches ``n_used / n_expert``
-of the expert weights per token, but a 512-token prefill ubatch touches
-essentially all of them. MoE therefore tolerates spilling far better than a
-dense model during generation and slightly WORSE during prefill.
-
-Calibration is in ``_RATE_RATIOS`` and comes from the measurements in
-``plans/impl_planner_cost.md``. Rates are expressed as multiples of the
-contiguous-weight rate, because ratios transfer across machines much better than
-absolute milliseconds do.
-"""
+"""Ranks offload placements; spilled weights are CPU-bound in generation but link-bound in prefill."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/offload_layout.py b/studio/backend/core/inference/offload_layout.py
index a65d07920bd..252c1ae108b 100644
--- a/studio/backend/core/inference/offload_layout.py
+++ b/studio/backend/core/inference/offload_layout.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GGUF tensor layout, bucketed by where each tensor is allowed to live.
-
-Split out from ``offload_planner`` on purpose: this half does file IO and knows
-about GGUF key names, the other half is pure arithmetic. The planner can then be
-tested exhaustively from hand-built layouts with no fixtures on disk.
-"""
+"""GGUF tensor layout by placement bucket; file IO and GGUF keys live here, not in offload_planner."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/offload_planner.py b/studio/backend/core/inference/offload_planner.py
index 622d5db5a95..c5c151ed046 100644
--- a/studio/backend/core/inference/offload_planner.py
+++ b/studio/backend/core/inference/offload_planner.py
@@ -1,23 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Placement planner: spill weights with ``-ot``, never the KV cache.
-
-llama.cpp's ``--fit on`` spills whole layers through ``n_gpu_layers``, and a
-layer's KV cache is allocated on ``model.dev_layer(il)`` (llama-kv-cache.cpp),
-so spilling a layer drags its cache to host RAM with it. Measured at 128K on one
-B200, that is the expensive direction by a wide margin:
-
- weights spilled, cache resident 71.63 t/s
- cache spilled, weights resident 3.24 t/s
-
-``-ot`` overrides tensor buffer types WITHOUT touching layer assignment, so the
-cache stays put: measured ``offloaded 66/66 layers to GPU`` with the whole cache
-on CUDA0 even when every block tensor was forced to the host.
-
-This module is pure arithmetic over a :class:`ModelLayout`. It performs no IO and
-reads no globals, so the whole decision table is testable directly.
-"""
+"""Spill weights with -ot, never the KV cache: spilling a layer moves its cache to host RAM too."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/openai_auto_download.py b/studio/backend/core/inference/openai_auto_download.py
index c763a8e86c5..8f460edb8f3 100644
--- a/studio/backend/core/inference/openai_auto_download.py
+++ b/studio/backend/core/inference/openai_auto_download.py
@@ -1,27 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in: fetch a GGUF a /v1 request names but this server doesn't have.
-
-Auto-switch only loads models already on disk. With
-``openai_api_auto_download_model`` on, a miss that looks like a real Hub repo is
-fetched in the background and the request is told to retry rather than held
-open: a quant is routinely tens of GB, far longer than any client (or the
-Cloudflare edge on ``--secure``) will wait, and the inference lifecycle gate must
-not be held meanwhile. The resident model keeps serving, and the retry that lands
-after the download goes through the ordinary auto-switch path.
-
-Admission is deliberately narrow, since a request only needs an API key:
-- ``namespace/name`` only, and only when the Hub confirms GGUF weights. A
- namespace is not evidence of intent (LiteLLM and OpenRouter address every
- provider that way), so ``gpt-4`` and ``anthropic/claude-3.5-sonnet`` alike
- fall through to the resident model as before.
-- GGUF only, decided from the remote file list, not the repo name: GGUF runs
- under llama.cpp, which never imports repo Python.
-- ``auto_map`` is refused, so ``trust_remote_code`` is only ever granted
- deliberately in the UI, never by an API call.
-- One download at a time, so a key holder cannot fan out fetches.
-"""
+"""Opt-in background fetch of a missing GGUF (namespace/name, Hub-confirmed); request told to retry,
+one download at a time; auto_map refused, so trust_remote_code is never granted by an API call"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/openai_codex_auth.py b/studio/backend/core/inference/openai_codex_auth.py
index 7120d1326ca..160bec92cb3 100644
--- a/studio/backend/core/inference/openai_codex_auth.py
+++ b/studio/backend/core/inference/openai_codex_auth.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""ChatGPT/Codex public-client OAuth owned by the Unsloth backend.
-
-OAuth transient material never crosses the API boundary: callers receive only an
-opaque flow id and safe user-facing authorization metadata.
-"""
+"""ChatGPT/Codex OAuth; transient tokens never leave the backend, callers get only an opaque flow id."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/openai_codex_tool_loop.py b/studio/backend/core/inference/openai_codex_tool_loop.py
index 73d4ba6adf3..ad4e940a18e 100644
--- a/studio/backend/core/inference/openai_codex_tool_loop.py
+++ b/studio/backend/core/inference/openai_codex_tool_loop.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Unsloth-owned tool execution loop for the ChatGPT Codex subscription transport.
-
-The loop itself now lives in ``core.inference.studio_tool_loop`` and is shared
-with every other external provider. What stays here is the Codex transport: the
-app-server call signature, its conversation-affinity ids, and the encrypted
-reasoning replay that only this provider emits.
-"""
+"""Codex transport only; the shared tool loop lives in core.inference.studio_tool_loop."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/passthrough_healing.py b/studio/backend/core/inference/passthrough_healing.py
index 31b729a4111..8e3b3c87c88 100644
--- a/studio/backend/core/inference/passthrough_healing.py
+++ b/studio/backend/core/inference/passthrough_healing.py
@@ -1,29 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Tool-call healing for the client-tool passthrough.
-
-With server-side tools disabled (``unsloth run --disable-tools``, every
-``unsloth start`` coding agent), requests carrying the client's own ``tools``
-bypass Unsloth's tool loop and are relayed to/from llama-server verbatim. Small
-GGUF models often emit their tool calls as TEXT (``<tool_call>{...}</tool_call>``,
-Gemma ``<|tool_call>...``, ``<function=...>`` XML) instead of structured
-``tool_calls`` -- on the passthrough that text reaches the agent as prose and
-the turn dies. This module promotes such text back into structured calls on the
-RESPONSE side only: the upstream request body is never touched, no extra
-generation is issued, so llama-server slot/KV-cache reuse is byte-identical.
-
-Healing only ever fires when the request declared client tools, and only
-promotes calls whose function name exactly matches a declared tool. Promotion
-removes EXACTLY the promoted calls' markup spans (the parser reports them):
-undeclared calls, unparseable blocks, and suppressed alternate formats keep
-every byte and relay as text, so healing can never silently delete model
-output. Responses without a tool signal and requests without tools are untouched, as is
-any request whose ``response_format`` constrains decoding: a grammar has already fixed what
-the reply means. Per-request opt-out:
-``auto_heal_tool_calls: false``. Process kill-switch:
-``UNSLOTH_DISABLE_TOOL_CALL_HEALING=1``.
-"""
+"""Turns text tool calls into structured ones for declared tools only, response side; never deletes
+unmatched output; response_format requests untouched; auto_heal_tool_calls false and
+UNSLOTH_DISABLE_TOOL_CALL_HEALING=1 opt out"""
import json
import os
diff --git a/studio/backend/core/inference/prefix_boundary.py b/studio/backend/core/inference/prefix_boundary.py
index 338401493ad..9209501f670 100644
--- a/studio/backend/core/inference/prefix_boundary.py
+++ b/studio/backend/core/inference/prefix_boundary.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Where a conversation with no saved thread was last cut, so later requests cut in the same place and reuse
-the prompt cache. Process-local and in memory only: a restart costs one recut.
-"""
+"""Cut point for thread-less chats, reused so the prompt cache hits; process-local, lost on restart."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/prequant_header_probe.py b/studio/backend/core/inference/prequant_header_probe.py
index 195722bc297..bed1fca9560 100644
--- a/studio/backend/core/inference/prequant_header_probe.py
+++ b/studio/backend/core/inference/prequant_header_probe.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Read a SAFETENSORS pre-quant checkpoint's ``format`` + ``metadata`` without reading its weights.
-
-A ``.pt`` (pickle) is never opened. Readers never raise and fail open (None = unknown).
-"""
+"""Reads a safetensors checkpoint's format and metadata, never its weights; never opens .pt; never
+raises, fails open with None if unknown"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/prequant_legacy_int8.py b/studio/backend/core/inference/prequant_legacy_int8.py
index 2aa067c0de3..cc6128f4cd3 100644
--- a/studio/backend/core/inference/prequant_legacy_int8.py
+++ b/studio/backend/core/inference/prequant_legacy_int8.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Read hosted INT8 ``.pt`` pre-quants on torchao >= 0.18, which deleted the v1 int8 classes they pickle.
-
-Still ``weights_only = True``: inert stand-ins (dispatch raises) are registered under the deleted names
-only for that load, and each weight is validated as symmetric per-row int8, then rebuilt bit-identical
-as the installed torchao's ``Int8Tensor``. A torchao that still ships the classes loads as before.
-"""
+"""Loads INT8 .pt on torchao >= 0.18 via inert stand-ins for deleted classes; weights_only kept on."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/prequant_native.py b/studio/backend/core/inference/prequant_native.py
index 36a6d186d0f..6db246e88b0 100644
--- a/studio/backend/core/inference/prequant_native.py
+++ b/studio/backend/core/inference/prequant_native.py
@@ -1,29 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Rebuild a safetensors pre-quant checkpoint's int8 / fp8 weights without torchao's deserializer.
-
-The file layout is torchao's own (``flatten_tensor_state_dict``): ``<fqn>._weight_qdata`` and
-``<fqn>._weight_scale`` plus one JSON entry per weight. Reading it back through torchao's
-``unflatten_tensor_state_dict`` ties every load to that release's constructor kwargs, and that has
-already broken once (0.18 wrote ``reduce_range``, which 0.17 refuses). The two schemes Unsloth ships
-are simple enough to describe without torchao:
-
- int8 w[n, k] = qdata[n, k] (int8) * scale[n] symmetric, per output row
- activations: dynamic symmetric per-token int8
- fp8 w[n, k] = qdata[n, k] (float8_e4m3fn) * scale[n] per output row (or one scale per tensor)
- activations: dynamic fp8 with the recorded granularity
-
-so this module parses the JSON itself, validates the tensors against that description, and builds
-whatever class the INSTALLED torchao uses for the scheme. In particular an int8 artifact converted from
-a torchao v1 checkpoint (``unsloth_quant_layout.int8_source == "torchao_v1"``) is rebuilt as the v1
-``LinearActivationQuantizedTensor`` where torchao still ships it (<= 0.17), which makes it
-bit-identical, class for class, to reading the original ``.pt`` there; 0.18 and later get the
-``Int8Tensor`` the legacy-pickle decoder produces. Anything this module does not recognise
-returns None and the caller uses torchao's own reader, so nvfp4 / mxfp8 artifacts are unaffected.
-
-Kill switch: ``UNSLOTH_PREQUANT_NATIVE_REBUILD=0`` always uses torchao's reader.
-"""
+"""Rebuilds int8/fp8 pre-quants without the torchao deserializer; unknown layouts return None and
+the caller falls back to the torchao reader; UNSLOTH_PREQUANT_NATIVE_REBUILD=0 disables it"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/prequant_safetensors.py b/studio/backend/core/inference/prequant_safetensors.py
index e665933d9ab..0fd97f90274 100644
--- a/studio/backend/core/inference/prequant_safetensors.py
+++ b/studio/backend/core/inference/prequant_safetensors.py
@@ -1,48 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Read and write a pre-quantized checkpoint as ``.safetensors`` instead of a ``torch.save`` pickle.
-
-torchao's weight subclasses (``Float8Tensor``, ``Int8Tensor``, ``NVFP4Tensor``, ...) are wrapper
-tensors: several plain tensors plus reconstruction metadata behind one logical weight. safetensors
-stores flat tensors only, which is why every pre-quant artifact Unsloth has published so far is a
-pickle. torchao >= 0.16 closes that gap with ``flatten_tensor_state_dict`` /
-``unflatten_tensor_state_dict``, the same pair ``transformers`` and ``diffusers`` use for their own
-torchao checkpoints, so the subclass is split into ``<fqn>._weight_qdata`` / ``._weight_scale`` and a
-JSON description of how to put it back.
-
-Why bother, given the pickle is already read under ``weights_only`` plus a constructor allowlist:
-
-- That allowlist is a real gate, not a formality. ``restricted_prequant_load_supported`` returns
- False when torch cannot express it or when torchao does not ship a scheme's constructors, and the
- callers in ``video.py`` then refuse the checkpoint outright and fall back to dense. A safetensors
- artifact has no constructors to allowlist, so that whole failure mode does not apply to it.
-- A pickle has to be parsed before anything about it is known. A safetensors header is a JSON blob at
- the front of the file, so the scheme / base model / filter checks run off a few KB, before a single
- weight byte is read, and a mismatched artifact costs a header read rather than a full parse.
-- mmap, lazy per-tensor reads, the Hub's file viewer and cross-framework reads all come for free.
-
-**On-disk layout.** Tensors are exactly what ``flatten_tensor_state_dict`` produces. The header is
-torchao's own metadata (``tensor_names`` plus one JSON entry per weight, which is what makes the file
-readable by anything that understands torchao checkpoints) with two namespaced keys added:
-
- "unsloth_format" -> the same format tag the pickle carries in ckpt["format"]
- "unsloth_metadata" -> JSON of the same dict the pickle carries in ckpt["metadata"]
-
-``is_metadata_torchao`` walks ``tensor_names`` only, so the extra keys do not disturb it.
-
-**Writing needs a newer torchao than reading does.** Only the new-style subclasses can be flattened,
-and through torchao 0.17 the int8 config still produces the legacy
-``LinearActivationQuantizedTensor`` over an ``AffineQuantizedTensor``; 0.18 produces ``Int8Tensor``,
-which flattens. Both versions RECONSTRUCT an ``Int8Tensor`` file happily, so this binds the machine
-that builds an artifact, never the one that loads it. fp8 has been flattenable since 0.16.
-
-**No new format tag.** The tags (``..._v1``, the rotated ``..._v2``) describe what the WEIGHTS mean,
-and that is unchanged by the container; a rotated safetensors artifact is still ``_v2`` and still
-refused by a build that cannot rotate. Old builds are kept away from these files by the FILENAME,
-not the tag: they resolve ``<Model>-<SCHEME>.pt`` and know nothing of a ``.safetensors`` sibling, so
-a repo can host both and each build reads the one it understands.
-"""
+"""Safetensors pre-quants with no new format tag; old builds ignore the sibling and read the .pt by
+filename; int8 write needs torchao >= 0.18, reading works on older"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/presence_penalty.py b/studio/backend/core/inference/presence_penalty.py
index 7e4377e7642..d671762a273 100644
--- a/studio/backend/core/inference/presence_penalty.py
+++ b/studio/backend/core/inference/presence_penalty.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Presence-penalty logits helpers for the safetensors/MLX inference paths.
-
-Kept in a dependency-light leaf module (torch + transformers only, no unsloth /
-peft) so the pure logic can be imported and unit-tested without pulling in the
-full inference backend. ``core.inference.inference`` re-exports these for the
-runtime generate paths.
-"""
+"""Presence-penalty logits helpers; torch and transformers only, so they import without the backend."""
import torch
diff --git a/studio/backend/core/inference/pricing.py b/studio/backend/core/inference/pricing.py
index 0702859d15d..342f761e52f 100644
--- a/studio/backend/core/inference/pricing.py
+++ b/studio/backend/core/inference/pricing.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-MTok pricing tables and ``calculate_cost`` (usage block -> USD).
-
-Sources: Anthropic prompt-caching docs (5m write 1.25x, 1h write 2x,
-read 0.1x), web search ($10/1000), code execution; OpenAI pricing page.
-"""
+"""Per-MTok prices; calculate_cost maps usage to USD, cache writes 1.25x (5m) or 2x (1h), reads 0.1x."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/providers.py b/studio/backend/core/inference/providers.py
index 43f9615a6bb..34f66c4ca61 100644
--- a/studio/backend/core/inference/providers.py
+++ b/studio/backend/core/inference/providers.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Static registry of supported external LLM providers. All expose OpenAI-compatible
-/v1/chat/completions endpoints with Bearer token auth and SSE streaming."""
+"""Static registry of LLM providers, all OpenAI-compatible (/v1/chat/completions, Bearer auth, SSE)."""
import ipaddress
import os
diff --git a/studio/backend/core/inference/react_preview.py b/studio/backend/core/inference/react_preview.py
index fc6e096d31c..d4652d8a04d 100644
--- a/studio/backend/core/inference/react_preview.py
+++ b/studio/backend/core/inference/react_preview.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Compile a chat React component for the preview frame (Node + oxc-transform, never evaluated).
-
-Always returns a status dict (ok / error / unavailable), never raises, so a missing Node is a
-message in the preview rather than a 500.
-"""
+"""Compiles a chat React preview via Node + oxc-transform and never evaluates it; never raises, so a
+missing Node is a status message"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/repetition_guard.py b/studio/backend/core/inference/repetition_guard.py
index dc025d9b7a0..dfd64a6f11f 100644
--- a/studio/backend/core/inference/repetition_guard.py
+++ b/studio/backend/core/inference/repetition_guard.py
@@ -1,20 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Is this truncated fragment worth continuing, or is the model just echoing itself?
-
-Only asked on the length-continuation path. A turn cut off mid-answer is normally resumed
-by handing the partial back and asking for the rest, but a model stuck in a repetition loop
-can spend an entire window echoing one fragment, and continuing THAT stitches the echo into
-the final answer instead of finishing it. The nudge has to be withheld before it is sent,
-not regretted afterwards.
-
-The approach and the thresholds follow NousResearch/hermes-agent's `agent/repetition_guard.py`,
-written after an incident where a single turn produced a 60,698-char response delivered as
-31 messages. Deliberately conservative in the same way: only LONG verbatim repeats covering
-a majority of the fragment trip it, so a sentence cut mid-word, a repeated heading, or code
-with similar-looking lines are all still continued.
-"""
+"""Skips the length-continuation nudge when a truncated fragment is mostly long verbatim repeats."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/rocm_bf16.py b/studio/backend/core/inference/rocm_bf16.py
index be7548e83fd..b17eafbf84e 100644
--- a/studio/backend/core/inference/rocm_bf16.py
+++ b/studio/backend/core/inference/rocm_bf16.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Native bf16 on a ROCm card, by gfx target.
-
-``torch.cuda.is_bf16_supported()`` returns True on every HIP build without looking at the device.
-bf16 math needs MFMA (gfx908+ CDNA), WMMA or bf16 dot (gfx11+) per llvm/lib/Target/AMDGPU/AMDGPU.td;
-GCN, Vega and RDNA1/2 emulate it through fp32, so they get float16, as pre-Ampere NVIDIA does.
-``UNSLOTH_STUDIO_ROCM_BF16=1`` restores torch's answer everywhere; ``=0`` forces float16.
-"""
+"""bf16 only on gfx908+ (CDNA) or gfx11+; other ROCm cards get float16 since torch always says yes."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/safetensors_pread.py b/studio/backend/core/inference/safetensors_pread.py
index 6f3d53ed6be..bd9ad9bef01 100644
--- a/studio/backend/core/inference/safetensors_pread.py
+++ b/studio/backend/core/inference/safetensors_pread.py
@@ -1,17 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Windows media loads read converted safetensors shards with safetensors' ``pread`` backend instead of mmap (#9977,
-#14513).
-
-torch maps a shard copy-on-write and Windows charges the whole view to commit while transformers holds every shard
-open, so a converting load commits the stored bytes next to the converted copy: LTX-2's 48.7 GB fp32 Gemma3 loaded at
-bf16 needs ~73 GB, a 16.7 GB bf16 Qwen-Image encoder loaded at fp16 ~38 GB, and torch's unchecked ``MapViewOfFile``
-NULL is an access violation. ``pread`` reads each tensor into its own buffer, freed once converted (what
-transformers >= 5.17 does on Windows, huggingface/transformers#48341; ComfyUI and llama.cpp map read-only instead).
-A shard loaded at its stored dtype keeps mmap: its mapping is the loaded weight, and the small-host route keeps it
-paged from disk. ``UNSLOTH_SAFETENSORS_PREAD=0|1`` disables / forces it on any OS.
-"""
+"""Windows converting loads use pread instead of mmap to save commit; UNSLOTH_SAFETENSORS_PREAD=0|1."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/sandbox_setup_job.py b/studio/backend/core/inference/sandbox_setup_job.py
index 54c6c1c588a..62aca1b2c4a 100644
--- a/studio/backend/core/inference/sandbox_setup_job.py
+++ b/studio/backend/core/inference/sandbox_setup_job.py
@@ -1,9 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One-click OS sandbox setup from Unsloth: install bubblewrap on Linux, install and prepare MXC on Windows.
-
-Nothing from a request reaches the command line: the operation name picks a constant plan.
-"""
+"""Installs bubblewrap or MXC; request input never reaches the command line, only a fixed plan."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/sandbox_setup_plan.py b/studio/backend/core/inference/sandbox_setup_plan.py
index 938b5986b19..83021138cd9 100644
--- a/studio/backend/core/inference/sandbox_setup_plan.py
+++ b/studio/backend/core/inference/sandbox_setup_plan.py
@@ -1,9 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""What it takes to get OS isolation on this computer, and whether Unsloth can do it from Settings.
-
-Detection only: nothing here runs a privileged command.
-"""
+"""Detects OS isolation support and setup needs from Settings; never runs a privileged command."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/sandbox_site/sitecustomize.py b/studio/backend/core/inference/sandbox_site/sitecustomize.py
index 640d1412de1..a5966a0b1b0 100644
--- a/studio/backend/core/inference/sandbox_site/sitecustomize.py
+++ b/studio/backend/core/inference/sandbox_site/sitecustomize.py
@@ -1,31 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Sandbox-side compatibility shim for ChatGPT code-interpreter paths.
-
-Models habitually write to /mnt/data (or /mnt/outputs, /home/sandbox,
-/workspace), none of which exist in the Unsloth sandbox. This module sits on the
-sandbox subprocess PYTHONPATH (see ``tools._build_safe_env``), so it loads at
-interpreter startup in every sandboxed ``python`` run and any Python the
-``terminal`` tool launches.
-
-It remaps those prefixes onto the CWD in ``open`` / ``io.open``, ``os.open``,
-``os.makedirs`` / ``os.mkdir`` and ``pathlib.Path.mkdir``. A write/create to a
-convention prefix always heals onto the CWD; a READ heals only when the mapped
-target already exists (re-reading an earlier write), so a genuinely missing
-input stays truthful on the path the model used instead of silently reading a
-same-basename workdir file. Since prefix lists cannot cover every invented path,
-``open`` / ``io.open`` also get a create-mode fallback: an absolute path outside
-the CWD whose parent is missing is redirected to the basename in the CWD. Reads
-and mkdir never use the fallback (an arbitrary absolute directory can legitimately
-succeed). It is collision-safe: it refuses to redirect onto an existing CWD file
-(letting open raise). The patch set (io.open, os.open, os.mkdir, Path.mkdir, and
-the <3.11 ``_NormalAccessor.open``) covers the low-level entry points pathlib
-routes through. A one-line stderr notice fires on the first remap, and everything
-is wrapped in try/except so a failure never breaks the interpreter.
-
-Identical with and without output streaming because the child env is.
-"""
+"""Remaps invented paths like /mnt/data onto CWD; reads heal only if the target exists; all wrapped
+in try/except so a failure never breaks the interpreter; no redirect onto existing CWD file"""
import builtins
import io
diff --git a/studio/backend/core/inference/sd_cpp_args.py b/studio/backend/core/inference/sd_cpp_args.py
index 2085ca42f22..35030b17212 100644
--- a/studio/backend/core/inference/sd_cpp_args.py
+++ b/studio/backend/core/inference/sd_cpp_args.py
@@ -1,15 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pure command builder for the ``sd-cli`` (stable-diffusion.cpp) native engine.
-
-No torch / diffusers / subprocess: a pure function of its arguments, so argv construction
-unit-tests without a GPU, binary, or model files. sd.cpp consumes the SAME split GGUF assets as
-the diffusers path -- a transformer (``--diffusion-model``), a VAE (``--vae``), and text encoders
-wired to the family flag (Z-Image Qwen3 -> ``--llm``, Qwen-Image Qwen2-VL -> ``--qwen2vl``, FLUX.1
--> ``--clip_l`` / ``--t5xxl``). The diffusers memory policy maps to sd.cpp's offload flags here, so
-one knob drives both engines. Ref: sd.cpp ``examples/cli`` and ``docs/z_image.md``.
-"""
+"""Pure sd-cli argv builder for stable-diffusion.cpp; no torch, diffusers or subprocess imports, so
+tests need no GPU, binary, or model files"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/sd_cpp_cudnn.py b/studio/backend/core/inference/sd_cpp_cudnn.py
index bfb7f3cab3c..43e07747761 100644
--- a/studio/backend/core/inference/sd_cpp_cudnn.py
+++ b/studio/backend/core/inference/sd_cpp_cudnn.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""A CUDA 12 cuDNN for sd.cpp fork builds with cuDNN attention (sm80+ Linux), named to the child via GGML_CUDA_CUDNN_LIB.
-
-torch cu130's cuDNN (CUDA 13) loads in a CUDA 12 binary but builds no plan. Installed with ``--target`` outside the venv:
-the cu12 and cu13 wheels both write ``nvidia/cudnn/lib/libcudnn.so.9``. Never loaded into this process.
-"""
+"""CUDA 12 cuDNN for sd.cpp, named via GGML_CUDA_CUDNN_LIB, installed with --target outside the
+venv; never loaded into this process"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/sd_cpp_engine.py b/studio/backend/core/inference/sd_cpp_engine.py
index 8ff412e8eb0..aae49a59b33 100644
--- a/studio/backend/core/inference/sd_cpp_engine.py
+++ b/studio/backend/core/inference/sd_cpp_engine.py
@@ -1,15 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Native stable-diffusion.cpp (``sd-cli``) engine for the diffusion backend.
-
-Mirrors the chat backend's llama.cpp shell-out: locate a prebuilt / built binary, run it as a
-one-shot subprocess. The CPU / Apple-Silicon / low-VRAM tier; diffusers stays the default on
-CUDA / ROCm / XPU. Thin: ``find_sd_cpp_binary()`` (env -> install layouts -> in-tree -> PATH),
-``SdCppEngine`` (``is_available`` / ``version`` + a ``generate`` that builds argv, runs sd-cli,
-returns the PNG path), and the pure ``select_diffusion_engine(...)`` routing decision. Everything
-heavy is reached only inside ``generate`` / ``version``, so import is free and tests stay hermetic.
-"""
+"""sd-cli engine for CPU, Apple Silicon and low-VRAM; diffusers stays default on CUDA/ROCm/XPU;
+heavy work only in generate/version so import is free"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/sd_cpp_server.py b/studio/backend/core/inference/sd_cpp_server.py
index 6bccf6eaca0..b4b94dbf8e8 100644
--- a/studio/backend/core/inference/sd_cpp_server.py
+++ b/studio/backend/core/inference/sd_cpp_server.py
@@ -1,35 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Persistent ``sd-server`` (stable-diffusion.cpp) process manager.
-
-The native diffusion tier used to shell out to one-shot ``sd-cli`` per image, which
-reloaded the multi-GB GGUF from disk every generation. ``sd-server`` (the upstream
-``examples/server`` target) loads the model once at spawn and serves many generations
-over HTTP, exactly like the chat backend's persistent ``llama-server``. This manager
-owns ONLY the process + HTTP lifecycle; the backend (``sd_cpp_backend.py``) still owns
-asset resolution, request validation, and the public Unsloth surface.
-
-Shape mirrors ``core/rag/embed_llama_server.py``:
- * ``start`` -- pick a free loopback port, spawn the server (model loads here),
- drain stdout on a daemon thread, poll until ready.
- * ``img_gen`` -- POST ``/sdcpp/v1/img_gen`` (the whole batch in one request),
- poll the async job to a terminal state, return image bytes.
- * ``vid_gen`` -- POST ``/sdcpp/v1/vid_gen`` (MiniMax-H3 native video), same polling,
- return the encoded container (video + muxed audio).
- * ``stop`` -- SIGTERM -> wait -> SIGKILL, join the drain thread (idempotent).
-
-Readiness is real: upstream ``main.cpp`` loads the model BEFORE it binds the port and
-prints ``listening on:``, so a 200 from ``GET /v1/models`` (a trivial handler) means the
-model is loaded; a load failure exits the process before listening and is surfaced with
-the captured log tail. (The richer ``/sdcpp/v1/capabilities`` handler can block in some
-builds, so it is not used for readiness.) The job JSON has no per-step field, so step progress is recovered by
-parsing the server's stdout (the same ``N/M`` lines ``sd-cli`` emits), routed to the
-active generation's callback.
-
-Import-light on purpose (no torch / diffusers / PIL), so selecting the native tier on
-a CPU box never drags the GPU stack into the process.
-"""
+"""Persistent sd-server; ready on 200 from GET /v1/models (not capabilities, which can block);
+routes POST /sdcpp/v1/img_gen and POST /sdcpp/v1/vid_gen; import-light, no torch/diffusers/PIL"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/sglang_server.py b/studio/backend/core/inference/sglang_server.py
index 5816ff5aaf6..89ddc7cc3bf 100644
--- a/studio/backend/core/inference/sglang_server.py
+++ b/studio/backend/core/inference/sglang_server.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""TorchAO API compatibility for the pinned SGLang server.
-
-Executed by the isolated engine Python, including multiprocessing children.
-No engine packages are imported into Studio's environment.
-"""
+"""TorchAO compat for the pinned SGLang server; runs in the isolated engine Python, not Studio's."""
import os
import runpy
diff --git a/studio/backend/core/inference/sse_control_frames.py b/studio/backend/core/inference/sse_control_frames.py
index 25b98c16382..e7738cefb87 100644
--- a/studio/backend/core/inference/sse_control_frames.py
+++ b/studio/backend/core/inference/sse_control_frames.py
@@ -1,26 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep a provider's bytes off Unsloth's own control channel.
-
-Unsloth multiplexes its UI control protocol onto the same SSE stream a provider's
-chunks are relayed on. The chat client picks those frames out structurally: a
-top-level ``type`` of ``tool_start`` / ``tool_end`` / ``tool_output`` /
-``tool_args`` / ``tool_status`` (and the local-runtime ``diffusion_frame`` /
-``reasoning_summary``) becomes a tool card, a badge or a canvas rather than
-assistant text, as does a ``_toolEvent`` / ``_toolStatus`` key stamped inside an
-otherwise ordinary chunk.
-
-Every one of those frames is written by this server. A provider endpoint -- a
-user-configured base_url, so not necessarily one Unsloth or the user controls --
-has no legitimate reason to emit any of them, and a verbatim relay makes its copy
-indistinguishable from ours at the client: a forged card can claim a tool the
-user trusts ran and returned something harmless, carrying
-``provenance: {"source": "local"}``, when nothing ran at all. So strip the
-control vocabulary out of everything that arrives from a provider. The
-``delta.reasoning`` alias Ollama and newer vLLM send is renamed to the canonical
-``reasoning_content``, streamed deltas only. The rest of the chunk stays as it was.
-"""
+"""Strips Unsloth control frames from provider SSE so providers cannot forge tool cards or provenance."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/stream_errors.py b/studio/backend/core/inference/stream_errors.py
index 6cf03181137..d631d21a39e 100644
--- a/studio/backend/core/inference/stream_errors.py
+++ b/studio/backend/core/inference/stream_errors.py
@@ -1,28 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Turn a mid-stream llama-server error chunk into something the user can act on.
-
-llama-server can fail a request after the stream has already opened. It sends one
-``{"error": {"message": ...}}`` chunk and closes. Two callers read that stream and both
-handled it badly:
-
-- ``core.research_runs`` raised ``RuntimeError("Local model stream failed")``, discarding
- whatever the server said. The user saw a generic failure with no cause and no remedy.
-- ``core.inference.llama_cpp``'s chat loops only ever read ``finish_reason`` out of
- ``choices``. An error chunk carries no ``choices``, so nothing was recorded: the reply
- was emitted with whatever text had accumulated and no ``incomplete`` stamp, which reads
- to the user as the model stopping mid-sentence for no reason.
-
-The error worth naming is KV-cache exhaustion. With ``--parallel N --kv-unified``,
-llama.cpp allocates ONE cache of ``n_ctx`` tokens but reports ``n_ctx_slot = n_ctx`` to
-every slot, so N concurrent generations may each be admitted believing they own the whole
-window. When their combined length crosses it, the decode fails and llama.cpp kills every
-task involved, not just the one that tipped it over. Two chats running at once is enough.
-The server's own wording for that is "Context size has been exceeded", which sounds like
-the prompt was too long and sends the user off to shorten a conversation that was never
-the problem.
-"""
+"""Maps mid-stream llama-server errors to KV-cache exhaustion from parallel slots, not a long prompt."""
from typing import Any, Optional
diff --git a/studio/backend/core/inference/stt_audiocpp_sidecar.py b/studio/backend/core/inference/stt_audiocpp_sidecar.py
index 7c63a1159cc..410513ef36f 100644
--- a/studio/backend/core/inference/stt_audiocpp_sidecar.py
+++ b/studio/backend/core/inference/stt_audiocpp_sidecar.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""audio.cpp speech-to-text sidecar for Unsloth dictation.
-
-Serves any audio.cpp ASR GGUF (Qwen3-ASR, Parakeet, Canary, Moonshine, Nemotron and
-whatever else audio.cpp transcribes) through one ``audiocpp_server`` child, with the same lifecycle as the
-whisper.cpp sidecar: loads on demand, stays warm for the keep-alive window, yields
-to training, and is paused while the managed runtime is being replaced. Audio is
-decoded with PyAV like every other engine and handed to the server as a 16 kHz mono
-WAV file it reads by path (``/v1/audio/transcriptions/details``), which also returns
-the timestamps and speakers a model produces.
-"""
+"""audio.cpp ASR sidecar, whisper.cpp lifecycle: yields to training and pauses during runtime
+replacement; 16 kHz mono WAV by path to /v1/audio/transcriptions/details"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/stt_download_worker.py b/studio/backend/core/inference/stt_download_worker.py
index 8afdfd08b5c..d0c2fea317e 100644
--- a/studio/backend/core/inference/stt_download_worker.py
+++ b/studio/backend/core/inference/stt_download_worker.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Out-of-process byte transfer for one dictation model download.
-
-The sidecars plan the download in-process and run only the transfer here. A
-thread cannot be interrupted, so cancelling means terminating a process: like
-``hub.workers.hf_download``, cancel is a SIGTERM and the negative returncode is
-what the caller reads as cancelled rather than failed. HF partials resume
-byte-exact, so a SIGTERM costs only the chunk in flight.
-"""
+"""Dictation model byte transfer in its own process; SIGTERM cancel shows as negative returncode and
+costs only the chunk in flight, since HF partials resume byte-exact"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/stt_mlx.py b/studio/backend/core/inference/stt_mlx.py
index 99b4ce196cc..9ad905fa25f 100644
--- a/studio/backend/core/inference/stt_mlx.py
+++ b/studio/backend/core/inference/stt_mlx.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Speech-to-text checkpoints the Transformers dictation engine runs through mlx-audio (Apple Silicon,
-which gets mlx-audio with mlx-vlm). Chosen by config model_type: mlx-audio loads both mlx-community
-quants and the original safetensors. Whisper keeps its Transformers path."""
+"""mlx-audio STT checkpoints chosen by config model_type; Whisper stays on Transformers."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/stt_mtmd_sidecar.py b/studio/backend/core/inference/stt_mtmd_sidecar.py
index ea4c42c5e52..fdf71d2bf75 100644
--- a/studio/backend/core/inference/stt_mtmd_sidecar.py
+++ b/studio/backend/core/inference/stt_mtmd_sidecar.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""llama.cpp multimodal (mtmd) speech-to-text sidecar for Unsloth dictation.
-
-whisper.cpp loads only the Whisper architecture, so newer ASR models run through
-llama.cpp instead: a text model plus an audio mmproj, served by `llama-server`
-and driven by the OpenAI audio content part.
-
-Owns one `llama-server` on an ephemeral 127.0.0.1 port, loaded on demand and
-unloaded after the same keep-alive as the other sidecars. Each model is two GGUF
-files, so downloads run the shared worker twice.
-"""
+"""mtmd STT sidecar for non-Whisper ASR: one llama-server on an ephemeral 127.0.0.1 port; two GGUFs."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/stt_sidecar.py b/studio/backend/core/inference/stt_sidecar.py
index 643f0e1a156..0a67c304108 100644
--- a/studio/backend/core/inference/stt_sidecar.py
+++ b/studio/backend/core/inference/stt_sidecar.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Standalone speech-to-text (STT) sidecar for dictation.
-
-Loads a Whisper model (via Transformers) in a spawn child of its own, separate from the chat model's
-inference subprocess, so dictation works with any chat model without evicting it. Curated defaults
-plus any Transformers-compatible Whisper repo; weights come through Unsloth's Model Hub and stay
-warm briefly between dictations. CUDA runs float16; MPS and CPU run float32.
-
-Everything except the model itself stays here: device choice, the Hub cache, audio decoding,
-windowing and the idle timer. Only the load and the generate happen in
-core/inference/stt_transformers_worker.py, because an accelerator context is never returned while
-the process holding it lives and the backend must not be the process that takes one.
-"""
+"""Whisper dictation sidecar; load and generate run in stt_transformers_worker.py in a spawn child."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/stt_transformers_worker.py b/studio/backend/core/inference/stt_transformers_worker.py
index ce200ede388..0f1e798281e 100644
--- a/studio/backend/core/inference/stt_transformers_worker.py
+++ b/studio/backend/core/inference/stt_transformers_worker.py
@@ -1,21 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Whisper (Transformers) dictation in a spawn child, and the handle for it.
-
-A CUDA context costs ~700 MiB on a current card and is never returned while the
-process that created it lives, so an in-process load left the backend that much
-heavier for good: unloading the model frees the weights and nothing else (the
-rule is written down in core/inference/gpu_arbiter.py). whisper.cpp and
-llama.cpp dictation already serve from their own processes; this puts the
-Transformers engine on the same footing, so an idle unload ends a process and
-the context goes with it.
-
-Both sides live here: ``run_stt_worker`` is the child entrypoint (imported by
-name in the child, so it must stay at module scope for Windows spawn), and
-``WhisperWorker`` is the parent-side handle the sidecar holds instead of a
-model object.
-"""
+"""Whisper dictation in spawn child (CUDA context dies with it); run_stt_worker must be module-level."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/template_capabilities.py b/studio/backend/core/inference/template_capabilities.py
index 8db18f50d20..fe4b3c2b714 100644
--- a/studio/backend/core/inference/template_capabilities.py
+++ b/studio/backend/core/inference/template_capabilities.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Does this chat template ever put the tool catalog into the prompt?
-
-Answers Studio's one yes/no per model, deciding whether the tool controls are live.
-
-Do not go back to matching substrings: that reads spelling, not meaning, and called
-Granite 3.3 tool-less for writing `{%- if tools and not available_tools -%}`.
-
-Over-approximates on purpose. A spurious yes shows a control the backend re-checks;
-a spurious no silently disables a working feature, which is the bug this replaces.
-"""
+"""Does a chat template ever put tools in the prompt; errs toward yes, never by substring matching."""
from functools import lru_cache
diff --git a/studio/backend/core/inference/tensor_fallback.py b/studio/backend/core/inference/tensor_fallback.py
index 0d7fe2a1284..5759d8731a4 100644
--- a/studio/backend/core/inference/tensor_fallback.py
+++ b/studio/backend/core/inference/tensor_fallback.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Tensor-parallel -> layer-split auto-fallback for GGUF loads.
-
-Kept in its own module (no FastAPI / httpx deps) so the orchestration can be
-unit-tested with a fake loader, without a GPU or a running llama-server.
-"""
+"""Tensor-parallel to layer-split fallback for GGUF loads; kept free of FastAPI/httpx for unit tests."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/tool_call_parser.py b/studio/backend/core/inference/tool_call_parser.py
index 0dd449de519..6603e1eac9f 100644
--- a/studio/backend/core/inference/tool_call_parser.py
+++ b/studio/backend/core/inference/tool_call_parser.py
@@ -1,17 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Backend-neutral tool-call parser shared by GGUF, safetensors, and MLX, so the safetensors + MLX
-agentic loop sees the same call shape llama-server gives GGUF. Formats:
-``<tool_call>{json}</tool_call>`` (Qwen / Hermes);
-``<function=name><parameter=k>v</parameter></function>`` (Qwen3.5 xml);
-``<|python_tag|>NAME.call(k="v", ...)`` and ``<|python_tag|>{"name":..., "parameters":...}``
-(Llama-3); bare ``{"name":..., "parameters":...}`` (Llama-3.2); ``[TOOL_CALLS]`` array /
-``name{json}`` / ``name[ARGS]{json}`` (Mistral v0.3 through Large 3);
-``<|tool_call>call:NAME{k:<|"|>v<|"|>}<tool_call|>`` (Gemma 4); the fullwidth-pipe envelopes of
-DeepSeek R1 / V3 / V3.1; ``<tool_call>NAME<arg_key>..<arg_value>..</tool_call>`` (GLM 4.5-4.7);
-and the ``<|tool_calls_section_begin|>`` form (Kimi K2). Missing closing tags / brackets are
-tolerated: models often truncate mid-stream."""
+"""Backend-neutral tool-call parser for all backends; tolerates missing closing tags from truncation."""
# Lazy annotations keep the standalone python 3.9 import working.
from __future__ import annotations
diff --git a/studio/backend/core/inference/tool_loop_controller.py b/studio/backend/core/inference/tool_loop_controller.py
index 0f9dff2f39a..529e100d132 100644
--- a/studio/backend/core/inference/tool_loop_controller.py
+++ b/studio/backend/core/inference/tool_loop_controller.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Shared controller state for Unsloth local agentic tool loops.
-
-This module is intentionally dependency-light: it owns only per-response
-ledger state and value objects used by the GGUF and safetensors loops.
-Route/SSE conversion, tool execution, and model streaming stay in the
-backend-specific modules.
-"""
+"""Dependency-light per-response ledger for GGUF and safetensors loops; execution lives in backends."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/tool_path_approval.py b/studio/backend/core/inference/tool_path_approval.py
index 5754d69ea5a..d14c0c36844 100644
--- a/studio/backend/core/inference/tool_path_approval.py
+++ b/studio/backend/core/inference/tool_path_approval.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Approval decisions for file access that leaves the session sandbox.
-
-Split out of ``tools.py`` because it is a subsystem rather than a handful of helpers: the read and
-write silent roots, the shared ``_path_needs_approval`` predicate, and the two operand scanners that
-decide which tokens of a terminal command or which arguments of a python snippet are paths at all.
-
-The import between this module and ``tools`` runs both ways, so both sides bind the MODULE rather
-than its names and resolve attributes at call time. That is what keeps the cycle harmless whichever
-module is imported first.
-"""
+"""Sandbox-escape file approval; tools.py and this module import each other, so both bind the module."""
import ast
import fnmatch
diff --git a/studio/backend/core/inference/tool_stream_exec.py b/studio/backend/core/inference/tool_stream_exec.py
index 25d14af877c..3e6e0279261 100644
--- a/studio/backend/core/inference/tool_stream_exec.py
+++ b/studio/backend/core/inference/tool_stream_exec.py
@@ -1,25 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Streaming wrapper around blocking server-side tool execution.
-
-``stream_tool_execution`` runs a blocking tool call in a worker thread and
-turns it into a generator that yields:
-
-* ``{"type": "tool_output", "tool_name", "tool_call_id", "text"}`` -- an
- incremental stdout/stderr chunk (python/terminal tools) for live UI output,
- or, with empty ``text``, a dict the tool passed to its callback (the browser
- tools' ``browser_action`` requests for the chat tab);
-* ``{"type": "heartbeat"}`` -- emitted whenever nothing else has been yielded
- for ``heartbeat_interval_s`` seconds, so the SSE route can write a
- keepalive and reverse proxies (Cloudflare tunnels cap idle streams at
- ~100 s) never see a silent connection while a tool runs;
-
-and *returns* the tool's final result string via ``StopIteration.value``
-(``result = yield from stream_tool_execution(...)``). The returned result is
-byte-identical to calling the tool directly, so tool-result parsing, nudging,
-and healing downstream are untouched.
-"""
+"""Streams tool output and heartbeats (proxies cap idle at ~100 s); returns the result unchanged."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.py
index 62480b3859e..bc59dbb6ec8 100644
--- a/studio/backend/core/inference/tools.py
+++ b/studio/backend/core/inference/tools.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Tool definitions and executors for LLM tool calling: web search (DuckDuckGo), Python code
-execution, and terminal commands."""
+"""Tool definitions and executors for LLM calls: DuckDuckGo search, Python code, terminal commands."""
import ast
import base64
diff --git a/studio/backend/core/inference/video_cosmos3.py b/studio/backend/core/inference/video_cosmos3.py
index e7509fe2cf6..7382fdb1491 100644
--- a/studio/backend/core/inference/video_cosmos3.py
+++ b/studio/backend/core/inference/video_cosmos3.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Cosmos3 (nvidia/Cosmos3-Nano, nvidia/Cosmos3-Edge) on diffusers' ``Cosmos3OmniPipeline``.
-
-The guardrail (``cosmos_guardrail``) is built whenever ``model_index.json`` enables it and raises ``ImportError``
-without the package, so Studio refuses the load up front; ``UNSLOTH_COSMOS3_SAFETY_CHECKER=0`` opts out.
-"""
+"""Cosmos3 pipeline; load refuses a missing guardrail, opt out with UNSLOTH_COSMOS3_SAFETY_CHECKER=0."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_denoiser_prequant.py b/studio/backend/core/inference/video_denoiser_prequant.py
index 99616e8cc5d..1768a21fb94 100644
--- a/studio/backend/core/inference/video_denoiser_prequant.py
+++ b/studio/backend/core/inference/video_denoiser_prequant.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Seed a conventional video pipeline with hosted pre-quantized denoisers, all-or-nothing.
-
-The MoE's second expert uses the ``task`` slot with NO filename fallback: it would load expert 1 as expert 2.
-"""
+"""Hosted denoisers seed a video pipeline all or nothing; MoE expert 2 uses task slot, never filename."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_encode.py b/studio/backend/core/inference/video_encode.py
index 304d3441e7a..5ada88bff8f 100644
--- a/studio/backend/core/inference/video_encode.py
+++ b/studio/backend/core/inference/video_encode.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""diffusers' ``encode_video`` stream (libx264 defaults, yuv420p, same audio helpers) with x264 frame threads:
-PyAV opens codecs with ``thread_type = SLICE``, so every frame waits for its slowest slice.
-``UNSLOTH_STUDIO_VIDEO_FRAME_THREADS=0`` restores the diffusers call."""
+"""Frame-threaded x264 encode (SLICE stalls each frame); UNSLOTH_STUDIO_VIDEO_FRAME_THREADS=0 reverts."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_families.py b/studio/backend/core/inference/video_families.py
index 73d862d0e78..bb181513d3c 100644
--- a/studio/backend/core/inference/video_families.py
+++ b/studio/backend/core/inference/video_families.py
@@ -1,19 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pure helpers for text-to-video model identification.
-
-The video registry mirrors ``diffusion_families`` (no torch/diffusers imports, so
-everything unit-tests without the heavy runtime) but is a SEPARATE registry with a
-separate backend: video pipelines take frame/fps arguments, return frame stacks
-(and, for LTX-2, synchronized audio) instead of PIL images, and their artifacts are
-MP4s. Keeping the registries apart means neither picker can mis-route a checkpoint
-to the wrong engine.
-
-A video checkpoint published as a single-file GGUF only carries the DiT weights;
-the VAE / text encoder / connectors / vocoder come from the companion diffusers
-base repo, exactly like the image GGUF path.
-"""
+"""Pure helpers with no torch/diffusers imports (unit-testable without the runtime); separate video
+registry so no picker misroutes; GGUF is DiT-only, needs a base repo"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_frames.py b/studio/backend/core/inference/video_frames.py
index 2b44ba0fa8d..0383365ec76 100644
--- a/studio/backend/core/inference/video_frames.py
+++ b/studio/backend/core/inference/video_frames.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Convert a decoded clip to uint8 RGB frames on its own device, bit-identical to the np / pil export
-(float32 ``(x * 255).round()`` matches numpy); out-of-range clips or non CUDA / CPU devices use the original path."""
+"""On-device uint8 RGB conversion, bit-identical to np/pil; non-CUDA/CPU or out-of-range falls back."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_gallery.py b/studio/backend/core/inference/video_gallery.py
index 7e307d01a0a..1d3ac86dae6 100644
--- a/studio/backend/core/inference/video_gallery.py
+++ b/studio/backend/core/inference/video_gallery.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Disk-backed persistence for generated videos.
-
-Each video is a pair under ``workspace_root()/videos``: ``{id}.mp4`` holds the bytes, ``{id}.json``
-holds the recipe (an MP4 has no portable text-chunk like a PNG). The pair travels together; a lone
-file is not a valid record. Dumb storage: the route owns the schema; this only reads/writes/sorts.
-"""
+"""Video pairs {id}.mp4 + {id}.json (recipe) in workspace_root()/videos; a lone file is invalid."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_hv15_comfy.py b/studio/backend/core/inference/video_hv15_comfy.py
index 9bd82a546b3..559a07b6c71 100644
--- a/studio/backend/core/inference/video_hv15_comfy.py
+++ b/studio/backend/core/inference/video_hv15_comfy.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""HunyuanVideo-1.5 original (ComfyUI) layout -> diffusers names, for ``load_comfy_quant_transformer`` (diffusers has
-no single-file converter for it). Row-only reshapes keep int8 / fp8 codes and per-row scales exact: fused qkv
-projections split by thirds, ``final_layer.adaLN_modulation.1`` swaps ``[shift; scale]`` to ``[scale; shift]``.
-Torch-free."""
+"""HunyuanVideo-1.5 ComfyUI to diffusers names; torch-free; row-only reshapes keep quant codes and
+per-row scales exact"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_hv15_vae.py b/studio/backend/core/inference/video_hv15_vae.py
index 4292a49ec1a..f004416badf 100644
--- a/studio/backend/core/inference/video_hv15_vae.py
+++ b/studio/backend/core/inference/video_hv15_vae.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""HunyuanVideo-1.5 VAE: build the causal attention mask with one masked_fill instead of a Python loop.
-
-The stock per-row loop unrolls under compile into a graph inductor cannot schedule (RecursionError in
-``reorder_for_peak_memory``). Same values, bit-identical decode.
-"""
+"""Causal mask via one masked_fill; the Python loop unrolls under compile into a RecursionError."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_i2v.py b/studio/backend/core/inference/video_i2v.py
index a234d82e06c..1e3314b593e 100644
--- a/studio/backend/core/inference/video_i2v.py
+++ b/studio/backend/core/inference/video_i2v.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Run a first-frame render by swapping the loaded pipeline's class to its image-to-video class.
-
-Not ``from_pipe``: it casts every shared module to float32 (undoing fp32-VAE / bf16-DiT, GGUF,
-torchao, offload hooks) and builds a second object lacking what Studio set on the loaded one.
-"""
+"""First-frame render swaps the loaded pipeline's class in place; from_pipe would recast to float32."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_ltx2.py b/studio/backend/core/inference/video_ltx2.py
index f14121f76cd..b27925597f4 100644
--- a/studio/backend/core/inference/video_ltx2.py
+++ b/studio/backend/core/inference/video_ltx2.py
@@ -1,25 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""LTX-2.3 pipeline assembly for diffusers 0.39.
-
-diffusers 0.39 ships every LTX-2.3 model class but its single-file loader maps every LTX-2
-checkpoint to the 2.0 config, so 2.3 checkpoints fail a shape check at load. The community
-transformer-only GGUFs also carry the DiT + connectors but NOT the text projections, VAEs, or
-vocoder that 2.3 moved out of the transformer. This assembles the full 2.3 pipeline:
-
-- transformer: from the checkpoint via ``from_single_file`` with the 2.3 config overrides and the
- ``prompt_adaln_single`` keys pre-renamed (the library converter doesn't know them).
-- connectors: from the checkpoint's connector keys plus the ``text_embedding_projection`` tensors,
- fetched from the companion file in ``unsloth/LTX-2.3-GGUF`` when not bundled.
-- video/audio VAE, vocoder: from the checkpoint when bundled, else the companion files.
-- scheduler, text encoder (Gemma3), tokenizer: from the LTX-2.0 base repo, which 2.3 shares.
-
-Every config and rename table mirrors diffusers' ``scripts/convert_ltx2_to_diffusers.py`` (the
-authoritative 2.3 mapping the loader hasn't absorbed). Assembled through the constructor, not
-``from_pretrained``, because the vocoder class differs from the base pin (``LTX2VocoderWithBWE`` vs
-``LTX2Vocoder``) and the type gate would reject it.
-"""
+"""LTX-2.3 pipeline is built via the constructor; from_pretrained's type gate rejects the 2.3 vocoder."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_ltx25.py b/studio/backend/core/inference/video_ltx25.py
index 5f50fa05897..f883c3562a6 100644
--- a/studio/backend/core/inference/video_ltx25.py
+++ b/studio/backend/core/inference/video_ltx25.py
@@ -1,22 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""LTX-2.5 on diffusers' LTX-2 pipelines.
-
-LTX-2.5 keeps the LTX-2.3 DiT layout (minus the video FFN bias, plus a keyframe position embedding) and the 2.3 conv
-VAE, but conditions on a fine-tuned Gemma 4 12B (``Gemma4UnifiedForConditionalGeneration``) that only transformers
->= 5.10.1 provides. Studio's server runs an older transformers, so the encoder runs in a spawned worker on the
-``.venv_t5_510`` sidecar (``video_ltx25_te_worker``) and hands back the packed prompt embeddings; ``pipe.encode_prompt``
-is replaced by a call into that worker, and everything after it (connectors, DiT, VAE, vocoder) runs here.
-
-Generation follows the reference two-stage distilled recipe: stage 1 at half resolution on the 8 distilled sigmas,
-the latent x2 spatial upsampler, then stage 2 at full resolution on 0.85 / 0.725 / 0.421875 with the stage-1 audio
-latents carried over, CFG 1 and every other guidance off, sampled euler-ancestral. Image-to-video conditions the first
-latent frame through ``LTX2ConditionPipeline`` at CRF 18, strength 0.7 in stage 1 and 1.0 in stage 2. The dev (full)
-DiT runs the pipeline's own single-stage SFT recipe instead.
-
-Everything here is gated on the ``ltx-2.5`` family; no other family reaches this module.
-"""
+"""LTX-2.5 pipeline, gated to the ltx-2.5 family (no other family reaches this module); Gemma 4
+encoder runs in a worker on the .venv_t5_510 transformers 5.10 sidecar"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_ltx25_te_worker.py b/studio/backend/core/inference/video_ltx25_te_worker.py
index 926fe8a4b7f..c96df5590e6 100644
--- a/studio/backend/core/inference/video_ltx25_te_worker.py
+++ b/studio/backend/core/inference/video_ltx25_te_worker.py
@@ -1,19 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""LTX-2.5 Gemma 4 text encoder, in a spawned worker on the transformers 5.10 sidecar.
-
-The server process runs Studio's default transformers, which has no ``Gemma4UnifiedForConditionalGeneration``. This
-entry point runs in a fresh spawned interpreter: it prepends ``.venv_t5_510`` to ``sys.path`` BEFORE anything imports
-transformers (the same activation the chat / training workers use), loads the encoder and tokenizer from the LTX-2.5
-pack, and answers encode requests with the packed hidden states diffusers' ``LTX2Pipeline._get_gemma_prompt_embeds``
-computes (every hidden state stacked on a last axis and flattened, left padding to ``max_sequence_length``).
-
-Protocol (multiprocessing queues): the worker sends ``{"type": "ready", ...}`` once the model is loaded, then answers
-``{"type": "encode", "id", "prompts", "max_sequence_length"}`` with ``{"type": "embeds", "id", "embeds", "mask"}``
-(host tensors; bf16 ``[B, L, hidden * (layers + 1)]`` and int64 ``[B, L]``); ``{"type": "shutdown"}`` ends it. Any
-failure is ``{"type": "error", "error": "..."}``. Must import nothing heavy at module level.
-"""
+"""LTX-2.5 Gemma 4 encoder worker; prepends .venv_t5_510 to sys.path before any transformers import;
+must import nothing heavy at module level"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_ltx2_vae_tiles.py b/studio/backend/core/inference/video_ltx2_vae_tiles.py
index 927c0fe43e2..f69bdc07741 100644
--- a/studio/backend/core/inference/video_ltx2_vae_tiles.py
+++ b/studio/backend/core/inference/video_ltx2_vae_tiles.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Seam-free LTX-2 / 2.3 VAE decode: the fewest, largest tiles that fit free VRAM (untiled when it fits).
-
-Stock tiles (16 latents, 2-latent blend) are narrower than the decoder's receptive field, so every seam shows a line.
-Kill switch ``UNSLOTH_VIDEO_VAE_WIDE_TILES=0``; ``UNSLOTH_VIDEO_VAE_UNTILED=0`` keeps >= 2 tiles. Tiles span every
-frame: Studio never decodes LTX framewise.
-"""
+"""Seam-free LTX-2/2.3 VAE tiling: widest tiles fitting VRAM; tiles span every frame, Studio never
+decodes framewise; UNSLOTH_VIDEO_VAE_WIDE_TILES=0 reverts; UNSLOTH_VIDEO_VAE_UNTILED=0 keeps >=2
+tiles"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_adaln.py b/studio/backend/core/inference/video_minimax_h3_adaln.py
index 140b97399b8..bfbaff139a0 100644
--- a/studio/backend/core/inference/video_minimax_h3_adaln.py
+++ b/studio/backend/core/inference/video_minimax_h3_adaln.py
@@ -1,41 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""MiniMax-H3's PRUNED (curve-form) adaptive layer norm, for hosted pre-quantized denoisers.
-
-MiniMax-H3 spends roughly 40% of its parameters on modulation. Every block owns an
-``adaln_proj.linear`` of shape ``(6 * hidden_size * 3, time_embed_dim)`` = ``(96768, 2688)``, and
-with 50 blocks plus ``norm_out`` that is ~26 GB of the 66 GB denoiser, all of it recomputed from a
-timestep embedding that only ever takes one of a few dozen distinct values in a sampling run.
-
-The reference ComfyUI implementation removes that redundancy. ``silu(time_embedder(t))``, viewed as
-a function of ``t`` over a fixed 1025-point grid on ``[0, 1]``, is a smooth curve living in a
-rank-8 affine subspace, so it factors as ``u(t) ~= mean + B @ c(t)`` with ``B`` of shape
-``(2688, 8)`` and the 8 coordinates ``c(t)`` tabulated per grid point. Folding ``B`` into the
-projection collapses each block's modulation to ``(96768, 8)``:
-
- dense: y = W_dense @ silu(temb) + b_dense
- curve: y = W_curve @ c(t) + b_curve, W_curve = W_dense @ B, b_curve = b_dense + W_dense @ mean
-
-The factorization is AFFINE, not a pure rank-8 product: the bias absorbs the curve's mean. A key
-rename that inherits ``b_dense`` is wrong by an order of magnitude. Nothing here re-derives the
-factorization; the hosted checkpoints ship ``W_curve`` / ``b_curve`` / the table already fitted, and
-this module only rebuilds the module shapes and the forward that consume them.
-
-``MiniMaxH3Transformer3DModel`` cannot load that form as shipped: against the dense config it is 4
-keys missing (``time_embedder.linear_1/linear_2.{weight,bias}``), 1 unexpected
-(``time_embedder.table``) and 51 shape mismatches (every ``adaln_proj.linear.weight`` plus
-``norm_out.linear.weight``, ``(*, 8)`` against ``(*, 2688)``). So a hosted pre-quantized H3 denoiser
-is unloadable by every route until the model is reshaped to match, which is what
-``apply_h3_adaln_curve`` does, in place, between ``from_config`` and ``load_state_dict``.
-
-Two behavioural differences from the dense path, both load-bearing:
-
-* No SiLU. The tabulated curve is the activation's OWN output projected onto the basis, so applying
- SiLU again would square the nonlinearity.
-* The table is indexed by the RAW timestep, not by the Fourier features. ``time_proj`` is therefore
- bypassed (it is parameter-free, so the state dict is unaffected).
-"""
+"""MiniMax-H3 curve-form AdaLN; apply_h3_adaln_curve runs between from_config and load_state_dict;
+no SiLU; raw timestep indexes the table; b_curve = b_dense + W_dense @ mean"""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_attn.py b/studio/backend/core/inference/video_minimax_h3_attn.py
index f90956a0eba..39a416dba73 100644
--- a/studio/backend/core/inference/video_minimax_h3_attn.py
+++ b/studio/backend/core/inference/video_minimax_h3_attn.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""MiniMax-H3 attention fast path, one kill switch (``=0``) per lever:
-
-1. ``UNSLOTH_H3_STRIDED_ATTN``: torch cuDNN / flash SDPA take the permuted (B, S, H, D) views, so the q / k / v and
- output copies disappear; bit-identical (attention kernels are layout-invariant).
-2. ``UNSLOTH_H3_FUSED_QKV``: one row-concatenated int8 ``to_qkv`` (one rotation, act quant and GEMM instead of three);
- bit-identical because int accumulation is exact and the dequant epilogue is per row.
-3. ``UNSLOTH_H3_ATTN_ARCH``: flash instead of cuDNN on the archs in ``H3_FLASH_FASTER_ARCHS`` only.
-"""
+"""MiniMax-H3 attention fast paths, each off with its env var set to 0: UNSLOTH_H3_STRIDED_ATTN
+(permuted SDPA views, no copies), UNSLOTH_H3_FUSED_QKV (one row-concatenated int8 to_qkv),
+UNSLOTH_H3_ATTN_ARCH (flash only on H3_FLASH_FASTER_ARCHS); the first two are bit-identical."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_comfy.py b/studio/backend/core/inference/video_minimax_h3_comfy.py
index 53147d0742a..c3e76656954 100644
--- a/studio/backend/core/inference/video_minimax_h3_comfy.py
+++ b/studio/backend/core/inference/video_minimax_h3_comfy.py
@@ -1,10 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""MiniMax-H3 denoisers in ComfyUI's layout for ``load_comfy_quant_transformer``: key map (fused qkv split by thirds,
-``mlp.fc1`` ``[gate; value]`` -> SwiGLU ``[value; gate]``, rows move whole so codes and scales stay exact), the pruned
-curve adaLN from ``adaln_t_table``'s shape, and the float32 tensors the pruned model keeps. The partition (fl2va /
-ref2va) is not in the tensors, so it comes from the file name."""
+"""MiniMax-H3 denoisers in ComfyUI layout: fused qkv split by thirds; mlp.fc1 [gate; value] ->
+SwiGLU [value; gate], rows moved whole so codes and scales stay exact; pruned adaLN curve sized
+from adaln_t_table; float32 tensors kept; partition is not in the tensors: read it from the file
+name."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_pdd.py b/studio/backend/core/inference/video_minimax_h3_pdd.py
index 1f7b5f0d630..1d7beb98c2d 100644
--- a/studio/backend/core/inference/video_minimax_h3_pdd.py
+++ b/studio/backend/core/inference/video_minimax_h3_pdd.py
@@ -1,22 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""MiniMax-H3 PDD (parallel decoding distillation) checkpoints: the stacked output-head bank.
-
-A PDD ``with_heads`` file stores ``pdd_steps`` (32) video and audio output heads stacked along the rows of
-``final_layer.video_out`` / ``final_layer.audio_out`` (``[32 * 96, 5376]`` and ``[32 * 32, 5376]``): head 0 is a full
-head and every later head is an offset from it. One sampler step from ``sigma`` to ``sigma_next`` covers a contiguous
-run of fine intervals on the unshifted grid, and consumes head 0 plus the dt-weighted mean of the offsets it spans.
-This matches ComfyUI's PDD head selection (``FinalLayer.forward`` / ``_pdd_head``) term for term.
-
-Graph safety: the ``(sigma, sigma_next)`` pair is a device tensor on each bank (``pdd_state``), rewritten in place by
-a forward pre-hook on the denoiser before every call, and the head selection is pure tensor math on it. Nothing about
-the step is a Python constant, so a CUDA graph replays it with new sigmas and torch.compile never specializes on it.
-Without device float64 (Intel Arc A-series) the float64 math stays on the host; only the cast weights go to the device.
-
-A ``without_heads`` bake keeps the plain single heads and needs an external head bank applied by a custom node, which
-Studio does not have, so it is refused rather than run as a plain trunk (that renders wrong output with no error).
-"""
+"""with_heads stacks 32 video/audio heads (head 0 full, rest offsets); step uses head 0 + dt-
+weighted offset mean; sigma pair is a device tensor rewritten in place by a pre-hook, so CUDA
+graph replays and torch.compile never specializes; Intel Arc keeps float64 on host; without_heads
+refused."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_qknorm.py b/studio/backend/core/inference/video_minimax_h3_qknorm.py
index e4af37f987a..03ffac4da86 100644
--- a/studio/backend/core/inference/video_minimax_h3_qknorm.py
+++ b/studio/backend/core/inference/video_minimax_h3_qknorm.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""MiniMax-H3 fused q/k RMSNorm + partial RoPE, one read and one write per row (``UNSLOTH_H3_QK_ROPE=0`` = off).
-
-Rounds where the eager bf16 chain rounds; only the order of the sum of squares is free, so rstd can differ in the
-last fp32 bit (bounded at one bf16 step by the tests). Opaque custom op with a fake kernel; Triton on NVIDIA CUDA
-only, the stock math everywhere else.
-"""
+"""Fused q/k RMSNorm + partial RoPE (off with UNSLOTH_H3_QK_ROPE=0); Triton on NVIDIA CUDA only,
+stock math elsewhere; rstd may differ in the last fp32 bit."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_residency.py b/studio/backend/core/inference/video_minimax_h3_residency.py
index 7cdfe21c7c5..47d220e78ab 100644
--- a/studio/backend/core/inference/video_minimax_h3_residency.py
+++ b/studio/backend/core/inference/video_minimax_h3_residency.py
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep as much of a streamed MiniMax-H3 denoiser on the device as the card allows: the top-level group first, then a
-prefix of its block groups, re-fitted per request. Resident groups keep their pinned host copy, so demoting is free.
-
-``UNSLOTH_H3_DIT_RESIDENT=0`` keeps everything streamed.
-"""
+"""Keeps as much of a MiniMax-H3 denoiser on device as fits: top-level group first, then a prefix of
+its block groups; re-fitted per request; demotion is free; UNSLOTH_H3_DIT_RESIDENT=0 keeps all
+streamed."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_te.py b/studio/backend/core/inference/video_minimax_h3_te.py
index 64374a44166..eb364670a4b 100644
--- a/studio/backend/core/inference/video_minimax_h3_te.py
+++ b/studio/backend/core/inference/video_minimax_h3_te.py
@@ -1,49 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Load MiniMax-H3's Qwen3-VL conditioner from a hosted QUANTIZED checkpoint.
-
-The H3 Diffusers path runs every component under ``ComponentsManager.enable_auto_cpu_offload``,
-so its VRAM floor is the LARGEST SINGLE RESIDENT COMPONENT, not their sum. The released bfloat16
-conditioner is 66.7 GB and the released denoiser is 66.3 GB, which is why seeding a 20 GB
-pre-quantized denoiser moved that floor by nothing at all: the encoder simply became the largest
-component instead. The encoder is the only remaining lever.
-
-``diffusion_te_prequant`` cannot serve this one. Its artifacts are layerwise-fp8 STORAGE casts of
-a dense encoder saved as ``torch.load``-able state dicts, which halve the bytes but keep every
-released tensor. The hosted H3 conditioner is a different artifact in two independent ways, and
-both savings stack:
-
- 1. It carries 50 of the released 64 decoder layers, and no ``lm_head`` and no final ``norm``
- (47.97 GiB against 62.14 GiB for ``MiniMaxAI/MiniMax-H3`` ``text_encoder/``).
- 2. Those 50 layers' four attention and three MLP projections are ConvRot INT8
- (25.28 GiB, i.e. 27.14 GB resident).
-
-Dropping the tail is LOSSLESS here, not an approximation. MiniMax-H3 conditions the transformer on
-``hidden_states[50]`` of the conditioner and never touches the language-model head -- see
-``diffusers/modular_pipelines/minimax_h3/modular_pipeline.py`` (``text_encoder_layer`` returns 50,
-"MiniMax-H3 reads `hidden_states[50]`, not the final one") and ``.../encoders.py``
-``get_qwen3vl_prompt_embeds``, which calls ``text_encoder.model(..., output_hidden_states=True)``
-and returns ``outputs.hidden_states[text_encoder_layer]``. Decoder layers 51-64 and ``lm_head``
-therefore cannot influence the conditioning by construction. Comparing the hosted file's tensor
-names against ``MiniMaxAI/MiniMax-H3``'s own shard index confirms the artifact drops EXACTLY that
-set and nothing else: 902 names that map 1:1 onto the released ones, the remainder being decoder
-layers 50-63 (0-based), ``model.language_model.norm.weight`` and ``lm_head.weight``.
-
-There is one mechanical catch, and it is the reason this module builds 51 layers rather than 50.
-``output_hidden_states`` yields ``[embeddings, layer_0_out, ..., layer_{N-1}_out]`` where the LAST
-entry is post-``norm``. A stack truncated to exactly 50 layers therefore returns a NORMALIZED
-``hidden_states[50]``, which is not the conditioning the released weights were trained against;
-diffusers refuses that case outright (``encoders.py``: "The last hidden state of a stack truncated
-to exactly 50 layers is post-norm"). Building a 51st slot that passes its input through unchanged
-puts ``hidden_states[50]`` back where it belongs -- the raw output after 50 real layers, bit-identical
-to what the full 64-layer conditioner produces there -- for no weights and no compute, and keeps
-``len(layers) == config.num_hidden_layers`` honest so the diffusers guard passes on a true statement.
-
-Best-effort throughout, exactly like ``diffusion_prequant``: any missing / unreadable / mismatched
-artifact returns None and the caller loads the released bfloat16 encoder instead. Inert with
-nothing configured.
-"""
+"""Qwen3-VL conditioner (50 of 64 layers, no lm_head/norm, ConvRot INT8); lossless as H3 reads
+hidden_states[50]; 51st pass-through slot avoids post-norm and keeps
+len(layers)==config.num_hidden_layers (diffusers guard); inert unless configured; bad artifacts
+fall back to released bf16 encoder."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_minimax_h3_vae.py b/studio/backend/core/inference/video_minimax_h3_vae.py
index f7f55c237f5..fbb13e3dac2 100644
--- a/studio/backend/core/inference/video_minimax_h3_vae.py
+++ b/studio/backend/core/inference/video_minimax_h3_vae.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Faster MiniMax-H3 video VAE encode and decode: Triton-fused GroupNorm/SiLU/pad, RMSNorm/rope/SwiGLU and
-tile batching around Diffusers' own matmuls and convolutions.
-
-Levers: fused_encoder, fp16_encoder, fused_decoder, tile_batch, fp16_accum, int8_decoder (opt-in,
-``UNSLOTH_H3_VAE_INT8=1``). ``UNSLOTH_H3_VAE_FAST=0`` disables all. NVIDIA CUDA with Triton only; else stock.
-"""
+"""Faster MiniMax-H3 video VAE encode/decode: Triton GroupNorm/SiLU/pad, RMSNorm/rope/SwiGLU fusions
+and tile batching around Diffusers' own matmuls/convs; UNSLOTH_H3_VAE_FAST=0 disables all;
+int8_decoder is opt-in via UNSLOTH_H3_VAE_INT8=1; CUDA+Triton only, else stock."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_moe_pair.py b/studio/backend/core/inference/video_moe_pair.py
index 350fe50ed8a..8a549f3fd9a 100644
--- a/studio/backend/core/inference/video_moe_pair.py
+++ b/studio/backend/core/inference/video_moe_pair.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pair the two expert files of a dual-expert (Wan2.2-A14B) video DiT by their high/low noise token.
-
-The high-noise expert is the pipeline's ``transformer`` (early steps), the low-noise one ``transformer_2``.
-"""
+"""Pairs the two expert files of a dual-expert (Wan2.2-A14B) video DiT by high/low noise token;
+high-noise is transformer, low-noise is transformer_2."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_nvenc.py b/studio/backend/core/inference/video_nvenc.py
index cf9ca41e688..1cd711d4c89 100644
--- a/studio/backend/core/inference/video_nvenc.py
+++ b/studio/backend/core/inference/video_nvenc.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Opt-in NVENC H.264 mp4 export (``UNSLOTH_STUDIO_VIDEO_ENCODER=nvenc``); libx264 on any failure. Not the default:
-larger files, and slower than libx264 on many-core hosts."""
+"""Opt-in NVENC H.264 mp4 export (UNSLOTH_STUDIO_VIDEO_ENCODER=nvenc), falls back to libx264 on
+failure; not default: larger files, slower on many-core hosts."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_stream_encode.py b/studio/backend/core/inference/video_stream_encode.py
index badbf44667f..5a0bca6e870 100644
--- a/studio/backend/core/inference/video_stream_encode.py
+++ b/studio/backend/core/inference/video_stream_encode.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Encode a Wan or MiniMax-H3 clip while its VAE is still decoding.
-
-The streamed mp4 is used only when its frames equal the final frames bit for bit, else the clip is encoded as
-before. H3 declares its audio stream up front as ``encode_x264`` does and muxes the soundtrack at the end.
-``UNSLOTH_STUDIO_VIDEO_STREAM_ENCODE=0`` turns it off.
-"""
+"""Encodes a Wan or MiniMax-H3 clip while its VAE decodes; the streamed mp4 is used only if its
+frames equal the final frames bit for bit, else re-encoded; H3 declares audio up front (as
+encode_x264) and muxes it last; UNSLOTH_STUDIO_VIDEO_STREAM_ENCODE=0 disables."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_stream_residency.py b/studio/backend/core/inference/video_stream_residency.py
index 8621fe13d59..aba2815fd7f 100644
--- a/studio/backend/core/inference/video_stream_residency.py
+++ b/studio/backend/core/inference/video_stream_residency.py
@@ -1,19 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep the top-level group and a block prefix of a block-streamed Wan or HunyuanVideo-1.5 denoiser resident, re-fitted
-per request.
-
-Room = free + unused cache + already resident - need. Need is the streamed floor + base overhead + the runtime estimate,
-or, for a request no larger (pixels x frames) than a completed one, that request's measured peak x 1.15 + 1 GiB; the
-estimate stays the lower bound. Resident groups keep their host copy, so streaming them again is a pointer swap.
-Kill switches: UNSLOTH_VIDEO_DIT_RESIDENT=0, UNSLOTH_VIDEO_DIT_RESIDENT_BLOCKS=0 (top-level group only),
-UNSLOTH_VIDEO_DIT_RESIDENT_MEASURED=0 (estimate only).
-
-Calibration is not Wan-only: ``arm_request`` arms the same peak measurement for any video family, and every recorded
-peak also lands in a process-wide table keyed by the loaded model (``calibration_key``), so a reload of the same model
-and the offload refusal (``measured_extra_mib``) reuse it. ``UNSLOTH_VIDEO_DIT_RESIDENT_MEASURED=0`` turns reuse off.
-"""
+"""Keeps top group and block prefix of a Wan or HunyuanVideo-1.5 denoiser resident, re-fitted per
+request; need estimate stays the lower bound; kill switches UNSLOTH_VIDEO_DIT_RESIDENT=0,
+UNSLOTH_VIDEO_DIT_RESIDENT_BLOCKS=0 (top group only), UNSLOTH_VIDEO_DIT_RESIDENT_MEASURED=0
+(estimate only)."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/video_wan_fused.py b/studio/backend/core/inference/video_wan_fused.py
index dce648601c2..8e73e62f3a1 100644
--- a/studio/backend/core/inference/video_wan_fused.py
+++ b/studio/backend/core/inference/video_wan_fused.py
@@ -1,15 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Fused fp16 Triton kernels for diffusers' ``WanTransformerBlock`` (T4 and other fp16-only GPUs).
-
-Stock keeps norm / AdaLN modulation / gated residuals / rotary in float32 tensors (a float32 ``[B, L, 6, D]`` table per
-block for TI2V-5B). The kernels do the same per-element math, rounding in float32 exactly where the stock op chain does
-and to fp16 once, so the output is bit-identical (self-checked once per device before use). LayerNorm stats come from
-``native_layer_norm`` on the fp16 rows, bit-identical to ``layer_norm(x.float())`` (4-wide vectorised loads either way).
-Scope: fingerprinted block, fp16 CUDA (non-ROCm), no grad, not compiling. Kill switches
-``UNSLOTH_DIFFUSION_WAN_FUSED_ADALN=0`` (all), ``UNSLOTH_DIFFUSION_WAN_FUSED_ROPE=0`` (rotary only).
-"""
+"""Fused fp16 Triton kernels for diffusers' WanTransformerBlock on fp16-only GPUs (T4); bit-
+identical to stock float32 rounding, self-checked per device; fp16 CUDA non-ROCm, no grad, not
+compiling; UNSLOTH_DIFFUSION_WAN_FUSED_ADALN=0 (all), UNSLOTH_DIFFUSION_WAN_FUSED_ROPE=0 (rotary
+only)."""
from __future__ import annotations
diff --git a/studio/backend/core/inference/vllm_server.py b/studio/backend/core/inference/vllm_server.py
index 080eab6cfe9..9768ddfa269 100644
--- a/studio/backend/core/inference/vllm_server.py
+++ b/studio/backend/core/inference/vllm_server.py
@@ -1,13 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Launches the pinned vLLM server with its API key guarding every route.
-
-Executed by the isolated engine Python. vLLM's middleware only guards /v1, /v2, /inference (and /cohere in 0.30),
-so /invocations (SageMaker) and /tokenize answer without the key; Studio sends the key on every
-request, /health included, so guarding "/" costs it nothing. The key arrives as VLLM_API_KEY,
-never on the command line.
-"""
+"""Launches the pinned vLLM server, run by the isolated engine Python, with the API key guarding '/'
+(every route): vLLM's middleware only covers /v1, /v2, /inference (and /cohere in 0.30), not
+/invocations or /tokenize; key comes from VLLM_API_KEY, never on the command line."""
import importlib
import runpy
diff --git a/studio/backend/core/inference/wsl_host.py b/studio/backend/core/inference/wsl_host.py
index cfd9d6d00d0..46fc15aee96 100644
--- a/studio/backend/core/inference/wsl_host.py
+++ b/studio/backend/core/inference/wsl_host.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Managed engines on native Windows run inside a private WSL2 distro that Studio owns.
-
-Studio stays a Windows process: it enables WSL (one UAC prompt), imports a pinned Ubuntu rootfs
-as its own distro, and drives everything through ``wsl.exe`` argv lists. The engine's HTTP
-server is reached through WSL2's localhost forwarding. The user's own distros are never touched.
-"""
+"""Native-Windows engines run in a private WSL2 distro Studio imports and drives via wsl.exe,
+reached over localhost forwarding; user's distros never touched."""
from __future__ import annotations
diff --git a/studio/backend/core/library.py b/studio/backend/core/library.py
index a7eb8a30039..6e621eba847 100644
--- a/studio/backend/core/library.py
+++ b/studio/backend/core/library.py
@@ -1,24 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One listing over every place a Studio file can live.
-
-Sources, each with its own id prefix so an item id says where its bytes are:
-
-- ``upload:<id>`` a file uploaded straight into the Library
-- ``attachment:<message_id>:<attachment_id>`` a file attached to a chat message
-- ``image:<id>`` an image from the Images page gallery
-- ``sandbox:<session_id>:<relative path>`` a file a chat tool wrote into its sandbox
-- ``video:<id>`` a clip from the Video page gallery
-- ``audio:<id>`` a clip from the Audio page's history
-- ``model:<training|exported>:<path>`` a fine-tuned model under outputs/ or exports/ (no bytes:
- a model is a directory, opened in chat instead)
-
-The message and session ids are URL-encoded, since any string can be one and a colon would end it.
-
-Bytes are always served by the source's own route (``fileUrl``); the Library only lists, deletes
-and layers its overlay (name, favorite, folder) on top.
-"""
+"""Lists Studio files by id prefix: upload:<id>, attachment:<message_id>:<attachment_id>,
+image:<id>, sandbox:<session_id>:<relative path>, video:<id>, audio:<id>,
+model:<training|exported>:<path>; message and session ids are URL-encoded; bytes come from each
+source's fileUrl."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/__init__.py b/studio/backend/core/rag/__init__.py
index 5dda48afc9f..e8efe4dc8b8 100644
--- a/studio/backend/core/rag/__init__.py
+++ b/studio/backend/core/rag/__init__.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""RAG core package. Import submodules lazily; keep this free of top-level
-submodule imports to avoid pulling in heavy deps."""
+"""RAG core package; submodules are imported lazily, so no top-level submodule imports here (avoids
+heavy deps)."""
__all__ = [
"config",
diff --git a/studio/backend/core/rag/captioner.py b/studio/backend/core/rag/captioner.py
index 5a3c597c2ea..87a32e84229 100644
--- a/studio/backend/core/rag/captioner.py
+++ b/studio/backend/core/rag/captioner.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Vision-model helpers for ingestion: figure captioning and scanned-page OCR.
-
-Both turn pixels into indexable text and are a no-op (never raise) without a loaded
-vision model. They reuse the chat model's vision endpoint, so it must be served with
-``--ubatch-size`` >= one image's tokens (some encoders, e.g. Gemma, attend
-non-causally and abort otherwise); Unsloth's vision chat already requires this."""
+"""Figure captioning and scanned-page OCR for ingestion; no-op (never raises) without a loaded
+vision model; chat endpoint needs --ubatch-size >= the tokens of one image."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/chunking.py b/studio/backend/core/rag/chunking.py
index 7b57855fe36..26e8c59ae58 100644
--- a/studio/backend/core/rag/chunking.py
+++ b/studio/backend/core/rag/chunking.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Page-aware recursive-separator chunking with token overlap. Each chunk records
-its ``[page_char_start, page_char_end)`` span and ``source_page_index``, used by
-the locator pass to highlight it on the PDF page."""
+"""Page-aware recursive-separator chunking with token overlap; chunks record
+page_char_start/page_char_end and source_page_index for locator highlights."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/conversation_archive.py b/studio/backend/core/rag/conversation_archive.py
index f80929f64cf..53945a7ac99 100644
--- a/studio/backend/core/rag/conversation_archive.py
+++ b/studio/backend/core/rag/conversation_archive.py
@@ -1,18 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep the turns the rolling context window evicts, and hand them back on request.
-
-Each evicted turn is indexed into a per-thread RAG scope, reusing the store, chunker, embedder and
-hybrid retrieval that back attached documents. The stored transcript is never touched; this is only
-a search index over turns the projection cannot carry.
-
-Two properties are load-bearing and easy to break. The archive is CUMULATIVE: nothing is cleared or
-re-scoped per compaction, so the fifth compaction can still find what the first evicted (on MRCR v2
-over 11 compaction events, cumulative scored 0.450 against 0.058 for latest-compaction-only). And
-nothing here may break a chat: every entry point no-ops on failure, because the alternative to a
-degraded archive is a working conversation, not an error.
-"""
+"""Search index over evicted turns in a per-thread RAG scope; transcript untouched; cumulative,
+never reset per compaction; entry points no-op on failure."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/embed_llama_server.py b/studio/backend/core/rag/embed_llama_server.py
index fa3587ee670..bde53f9c9bb 100644
--- a/studio/backend/core/rag/embed_llama_server.py
+++ b/studio/backend/core/rag/embed_llama_server.py
@@ -1,17 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GGUF embedder over the bundled llama.cpp, served via HTTP (no torch).
-
-Opt-in (``RAG_EMBED_BACKEND=llama-server``). Runs a dedicated ``llama-server --embedding``
-subprocess on its own port and calls its OpenAI-style ``/v1/embeddings`` + ``/tokenize``, fully
-isolated from the chat backend.
-
-Device is ``auto`` (GPU when present, else CPU, falling back to CPU if a GPU server fails);
-``RAG_EMBED_DEVICE`` forces it. We call only llama_cpp's *static* helpers (no torch), copying the
-instance-coupled bits locally, since constructing a ``LlamaCppBackend`` runs an ``__init__`` reaper
-that kills any Unsloth llama-server, so each request re-spawns ours if it died.
-"""
+"""Opt-in GGUF embedder (RAG_EMBED_BACKEND=llama-server, no torch): own llama-server --embedding
+subprocess on /v1/embeddings and /tokenize; auto falls back to CPU if GPU fails, RAG_EMBED_DEVICE
+forces; each request respawns it if dead; only llama_cpp static helpers, no LlamaCppBackend()."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/embeddings.py b/studio/backend/core/rag/embeddings.py
index 8874bd65e6d..dcaf00919af 100644
--- a/studio/backend/core/rag/embeddings.py
+++ b/studio/backend/core/rag/embeddings.py
@@ -1,20 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Dense embedder facade dispatching to a process-wide backend from ``config.EMBED_BACKEND`` (``auto``
-picks by hardware): ``sentence-transformers`` (torch) or ``llama-server`` (GGUF, no torch).
-
-Either way the embedder stays off the GPU unless asked: this one runs in the backend process, where
-a CUDA context outlives every unload, and the other runs in a child. See ``_device``.
-
-Backends produce different vectors, so switching requires rebuilding the index. We degrade to
-llama.cpp rather than crash when ST breaks on a machine: an init-time probe falls back before any
-vector is produced (so spaces cannot mix), and a runtime ``encode`` failure swaps the process to
-llama-server for the rest of its life (KBs already embedded with ST should then be reindexed).
-
-Torch driver faults bypass Python handlers, so ``_load_device`` probes allocation in a child and
-falls back to CPU without changing the embedding space.
-"""
+"""Dense embedder facade over config.EMBED_BACKEND (sentence-transformers or llama-server); off GPU
+unless asked; backends differ, so switching needs reindex; ST failure falls back to llama-server;
+_load_device probes in a child and falls back to CPU without changing the embedding space."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/ingestion.py b/studio/backend/core/rag/ingestion.py
index ae474d26abb..a152203ad23 100644
--- a/studio/backend/core/rag/ingestion.py
+++ b/studio/backend/core/rag/ingestion.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""In-process threaded ingestion: parse -> chunk -> embed -> store.
-``start_ingestion`` returns ``(document_id, job_id)`` immediately and runs on a
-daemon thread, pushing progress onto a per-job queue (streamed as SSE by
-``job_events``). Documents are deduped by content hash per scope."""
+"""Threaded in-process ingestion (parse, chunk, embed, store); start_ingestion returns (document_id,
+job_id) at once; docs dedupe by content hash per scope."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/locators.py b/studio/backend/core/rag/locators.py
index b05765c5602..384b54dd9b5 100644
--- a/studio/backend/core/rag/locators.py
+++ b/studio/backend/core/rag/locators.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Map a chunk to highlight rectangles on its page (computed at ingest).
-
-The chunk's leading phrase is anchored in the page word list (``get_text("words")``),
-so matching survives ligatures and dehyphenation that glyph-exact ``search_for``
-misses. Matched words union per line into rects normalized to 0..1. Missing
-PyMuPDF, a too-short anchor, or no unique match yields no regions (never a guess).
-"""
+"""Highlight rects for a chunk, anchored on its leading phrase in PyMuPDF word list (survives
+ligatures); missing PyMuPDF, short anchor or no unique match yields no regions, never a guess."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/office_formats.py b/studio/backend/core/rag/office_formats.py
index 9bb76249248..7cda4c84be7 100644
--- a/studio/backend/core/rag/office_formats.py
+++ b/studio/backend/core/rag/office_formats.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Text from Office, OpenDocument, e-book, email and RTF files, using only the stdlib.
-
-Each reader returns ``[(text, page_number), ...]``: one entry per slide (numbered), or
-per sheet / chapter (unnumbered). Table rows are joined with " | ", as for .docx.
-"""
+"""Stdlib readers for Office, OpenDocument, e-book, email and RTF; (text, page_number) per slide,
+unnumbered per sheet or chapter; table rows joined by ' | '."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/parsers.py b/studio/backend/core/rag/parsers.py
index cac84bfcc34..bc5542795a4 100644
--- a/studio/backend/core/rag/parsers.py
+++ b/studio/backend/core/rag/parsers.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Document parsing -> list[Page], one dispatch with lazy optional deps.
-
-PDFs keep per-page boundaries (``page_number``); txt/md/docx/html return a single
-page. ``parse(path, want_images=True)`` also returns embedded images. Heavy imports
-are lazy, so importing this module never fails on a missing dep.
-"""
+"""Document parsing to list[Page]; PDFs keep per-page page_number, txt/md/docx/html give one page;
+deps are lazy so importing never fails on a missing one."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/reembed.py b/studio/backend/core/rag/reembed.py
index 8780a90366a..70bd52803bd 100644
--- a/studio/backend/core/rag/reembed.py
+++ b/studio/backend/core/rag/reembed.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Re-embed documents indexed under a different embedder than the current one.
-
-Dense search skips such documents, so after an embedding model switch they are reachable by
-keyword search only. This re-encodes each one's stored chunk text and swaps its vectors in place,
-keeping document and chunk ids (citations keep resolving) and needing no source file, OCR or
-captioning. One job per account; it follows the current model, so a switch mid-job is absorbed.
-"""
+"""Re-embeds docs indexed under a different embedder (dense search skips them) from stored chunk
+text, keeping ids; one job per account; follows current model, so a mid-job switch is absorbed."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/retrieval.py b/studio/backend/core/rag/retrieval.py
index b39d2558acd..9ba8361305c 100644
--- a/studio/backend/core/rag/retrieval.py
+++ b/studio/backend/core/rag/retrieval.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Lexical (FTS5) + dense (vec0 cosine) retrieval fused via Reciprocal Rank
-Fusion. ``dense_score`` is carried so callers can apply a similarity floor."""
+"""Lexical (FTS5) and dense (vec0 cosine) retrieval fused by Reciprocal Rank Fusion; dense_score is
+kept so callers can apply a similarity floor."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/store.py b/studio/backend/core/rag/store.py
index 4af9969f29c..d3d7c6efe28 100644
--- a/studio/backend/core/rag/store.py
+++ b/studio/backend/core/rag/store.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Unified SQLite store: relational chunks + FTS5 lexical + sqlite-vec dense.
-
-Module-level functions each take a ``conn`` the caller opens and closes. Inserts
-are incremental: ``add_chunks`` appends one document's rows without rebuilding the
-scope. Scope ("kb_<id>" / "thread_<id>") is a column on every table and the vec0
-partition key.
-"""
+"""Unified SQLite store (chunks, FTS5, sqlite-vec); caller-opened conn; add_chunks appends
+incrementally; scope kb_<id>/thread_<id> is the vec0 partition key."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/tool.py b/studio/backend/core/rag/tool.py
index cd6c17459c8..fff24432287 100644
--- a/studio/backend/core/rag/tool.py
+++ b/studio/backend/core/rag/tool.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""``search_knowledge_base`` LLM tool: scope resolution + hit formatting.
-
-KB scope wins; otherwise project and thread scopes combine so project chats also
-see their own attachments. Hits render as ``<chunk>`` blocks for the model,
-plus a parallel citation source-map for clickable sources. Each call opens and
-closes its own ``rag_db`` connection.
-"""
+"""search_knowledge_base LLM tool: KB scope wins, else project and thread scopes combine."""
from __future__ import annotations
diff --git a/studio/backend/core/rag/web_rank.py b/studio/backend/core/rag/web_rank.py
index 43e9fa43567..878c76daf0f 100644
--- a/studio/backend/core/rag/web_rank.py
+++ b/studio/backend/core/rag/web_rank.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Ephemeral web-RAG for deep research auto-read.
-
-Deep research auto-reads the top search results so synthesis is grounded in page text rather
-than short snippets. Whole pages make a small local model loop on boilerplate, so scraped pages
-go through the *same* retrieval pipeline the knowledge base uses and only the most relevant
-passages are folded into the evidence.
-
-Nothing here re-implements chunking, embedding, retrieval, ranking, or rendering; it wires
-Unsloth's existing KB components to the live scrape. The only difference from a persisted KB is
-the corpus: pages are ingested under a unique throwaway scope deleted in a ``finally`` block, so
-an auto-read never pollutes a user's knowledge base, like the per-thread attachment RAG already
-does on the same store.
-"""
+"""Deep research auto-read web RAG: pages go in a throwaway scope deleted in finally, not the KB."""
from __future__ import annotations
diff --git a/studio/backend/core/research/citations.py b/studio/backend/core/research/citations.py
index 49059ba107d..35540e564dc 100644
--- a/studio/backend/core/research/citations.py
+++ b/studio/backend/core/research/citations.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Rewriting Deep Research report citations to the sources actually gathered.
-
-A local model invents URLs, renumbers references, and appends its own source list. Every
-citation is canonicalized against the run's catalogs, and anything that does not resolve to a
-gathered web source or document chunk is stripped rather than shown as supported.
-"""
+"""Rewrites Deep Research citations to gathered sources; invented or unresolved ones are stripped."""
from __future__ import annotations
diff --git a/studio/backend/core/research/parsing.py b/studio/backend/core/research/parsing.py
index 7de83acd0c8..dab2513b532 100644
--- a/studio/backend/core/research/parsing.py
+++ b/studio/backend/core/research/parsing.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Reading structured decisions out of a local model's free-form output.
-
-Plans, agent actions, research state, and the synthesis audit arrive as JSON that a small
-model routinely wraps in prose, truncates, or emits from its reasoning channel instead. Every
-parser here recovers what it can and validates the result against what the run actually holds.
-"""
+"""Recovers JSON from prose-wrapped or truncated small-model output, checked against the run state."""
from __future__ import annotations
diff --git a/studio/backend/core/research/redaction.py b/studio/backend/core/research/redaction.py
index a35b6273dc2..803e8bab1bd 100644
--- a/studio/backend/core/research/redaction.py
+++ b/studio/backend/core/research/redaction.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keeping private data out of Deep Research web queries and prompts.
-
-Search queries leave the machine, so credentials, personal identifiers, and private network
-addresses are stripped before a query is issued. Prompt-delimiter tags in gathered evidence
-are escaped so untrusted text cannot close a wrapper block and inject instructions, and a
-source URL cannot close its own citation to inject a link.
-"""
+"""Strips credentials and private addresses from search queries; escapes prompt tags in evidence."""
from __future__ import annotations
diff --git a/studio/backend/core/systemone/clef_runtime.py b/studio/backend/core/systemone/clef_runtime.py
index 36a75a5fcd5..c0d49deb790 100644
--- a/studio/backend/core/systemone/clef_runtime.py
+++ b/studio/backend/core/systemone/clef_runtime.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Cloudflare Clef decision models for the Decision API, served from a spawn child.
-
-Clef is a Qwen3.5 / Qwen3.8 backbone (9B or 27B) with a joint schema head, so it only runs on a
-GPU, through Unsloth's loader and its fast linear attention kernels. Unsloth patches transformers
-process-wide and a CUDA context is never returned while its process lives, so the model gets its
-own process: unloading ends it and the memory goes with it (as core/inference/stt_transformers_worker.py).
-"""
+"""Clef decision models run in a spawn child: CUDA memory is only returned when that process exits."""
from __future__ import annotations
diff --git a/studio/backend/core/systemone/gguf_export_contract.py b/studio/backend/core/systemone/gguf_export_contract.py
index 2169feccd4f..05632681368 100644
--- a/studio/backend/core/systemone/gguf_export_contract.py
+++ b/studio/backend/core/systemone/gguf_export_contract.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""On-disk contract for a decision fine-tune's GGUF export, shared by the exporter and the Decision API.
-
-An export lives in ``<run folder>/gguf/``: ``model-<QUANT>.gguf``, an optional ``mmproj-<QUANT>.gguf``
-and ``export.json``::
-
- {"format": "unsloth-decision-gguf", "version": 1, "layout": "clef" | "laya",
- "quantizations": ["Q8_0", ...],
- "files": {"Q8_0": {"model": "model-Q8_0.gguf", "mmproj": "mmproj-Q8_0.gguf" | null}},
- "source_fingerprint": fingerprint(run folder, layout)}
-
-The fingerprint covers what the served probabilities depend on, so retraining or recalibrating the
-folder makes an older export stale.
-"""
+"""GGUF export contract: export.json maps quants to files; retrain or recalibrate makes it stale."""
from __future__ import annotations
diff --git a/studio/backend/core/systemone/native_worker.py b/studio/backend/core/systemone/native_worker.py
index 9847fa9a1a9..fb462003773 100644
--- a/studio/backend/core/systemone/native_worker.py
+++ b/studio/backend/core/systemone/native_worker.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Decisions from a GGUF on a private loopback llama-server (``POST /v1/systemone``).
-
-Ported from wasimysaid's native worker in #12770. The server is Studio's own llama.cpp. Clef answers
-are rebuilt with the formatter the PyTorch path uses, so the public response does not depend on the
-backend (llama.cpp's own confidence is a normalised formula, PyTorch's the winning probability).
-GGUF-only models (Kev, lev, Nimble, OpenJev, Laya GGUFs) have no Studio reference, so llama.cpp's
-answer is the reference: checked, then passed through.
-"""
+"""Private loopback llama-server at POST /v1/systemone; Clef answers rebuilt with the PyTorch
+formatter so the public response does not depend on the backend; GGUF-only models are checked,
+then passed through"""
from __future__ import annotations
diff --git a/studio/backend/core/training/dataset_bounds.py b/studio/backend/core/training/dataset_bounds.py
index 4d05ed6933c..286a36b6393 100644
--- a/studio/backend/core/training/dataset_bounds.py
+++ b/studio/backend/core/training/dataset_bounds.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Row bound for a max_steps run.
-
-TRL prepares the whole train_dataset in the SFTTrainer constructor and never looks
-at max_steps, so a 30-step run over a large corpus tokenizes millions of rows to
-read a few hundred. The count is known before any of that work happens.
-
-This module holds no torch and no unsloth imports: both loaders use it, and the
-MLX one runs on hosts where importing core.training.trainer would drag in a torch
-stack that need not exist.
-"""
+"""Row bound for max_steps runs, computed before TRL tokenizes train_dataset; must stay torch-free."""
import json
import os
diff --git a/studio/backend/core/training/diffusion_checkpoint.py b/studio/backend/core/training/diffusion_checkpoint.py
index d1d2b2c0925..6b07bf5691b 100644
--- a/studio/backend/core/training/diffusion_checkpoint.py
+++ b/studio/backend/core/training/diffusion_checkpoint.py
@@ -1,33 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Resumable checkpoints for diffusion (image / future video) LoRA training.
-
-A diffusion run used to write exactly one thing, the deployable adapter, at the very end, so a stop
-at step 11 left the AdamW moments, the LR-schedule position, the RNG streams and the step counter to
-die with the subprocess: restarting the same configuration began again at step 1. This module is the
-single writer and the single reader of the state that makes a run continuable.
-
-Layout, under the run's own ``output_dir`` (so the resumed run keeps writing into the same folder
-the adapter is published from): ``<output_dir>/pytorch_lora_weights.safetensors`` is the deployable
-adapter (unchanged), and each ``checkpoint-<N>/`` holds ``trainer_state.json`` (manifest +
-completion marker), ``adapter_model.safetensors`` (peft-format LoRA tensors),
-``ema_adapter.safetensors`` (the EMA shadow, when ema_decay > 0), ``optimizer.pt``, ``scheduler.pt``
-and ``rng_state.pt`` (torch CPU + per-device CUDA RNG states).
-
-``trainer_state.json`` is written LAST inside a hidden staging directory, and the whole staging
-directory is then promoted with a single ``os.replace``. A process killed at any point leaves either
-the previous checkpoint or a ``.tmp-checkpoint-*`` directory that no scanner ever matches, never a
-half-written ``checkpoint-<N>`` that looks valid.
-
-Identity: every bundle records the training identity it belongs to (family, base repo + revision,
-dataset fingerprint, LoRA targets/rank/alpha, precision). ``preflight_resume`` compares that against
-the incoming request and refuses a mismatch with a user-facing reason, so the start route can reject
-BEFORE it evicts the resident GPU model.
-
-``kind`` ("image" today) is carried in both the manifest and the identity so a future video trainer
-can write and validate its own bundles through this same code without a format change.
-"""
+"""Resumable diffusion LoRA checkpoints, promoted atomically; preflight_resume refuses an identity
+mismatch BEFORE the start route evicts the resident GPU model"""
from __future__ import annotations
diff --git a/studio/backend/core/training/diffusion_clip_formats.py b/studio/backend/core/training/diffusion_clip_formats.py
index 10d44862406..f109b183fe8 100644
--- a/studio/backend/core/training/diffusion_clip_formats.py
+++ b/studio/backend/core/training/diffusion_clip_formats.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The one list of video container extensions a training dataset may hold.
-
-Unsloth's diffusion dataset layer grew up image-only, so the routes carry their own
-``_DIFFUSION_DATASET_IMAGE_EXTS``. Clips need the same treatment, but a clip dataset is read
-by the trainer and written by the upload endpoint, and those live on opposite sides of the
-backend. Putting the set in either one makes the other import it across a layer it has no
-business importing (the routes would pull a trainer module; the trainer would pull FastAPI).
-So it lives here, in a module with no imports at all, and both sides read it from here.
-
-Keeping it in one place is not cosmetic. Discovery, the upload allowlist and the duplicate-stem
-check all have to agree on what a clip is: a container the upload accepts but discovery does
-not count is a dataset that uploads fine and then trains on nothing.
-"""
+"""Video container extensions for clips, kept import-free so the trainer and upload route share it."""
from __future__ import annotations
diff --git a/studio/backend/core/training/diffusion_fp8_prequant.py b/studio/backend/core/training/diffusion_fp8_prequant.py
index 329c5f7cf9a..1c8e5cfe381 100644
--- a/studio/backend/core/training/diffusion_fp8_prequant.py
+++ b/studio/backend/core/training/diffusion_fp8_prequant.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""base_precision="fp8" training straight from a hosted ``unsloth/*-FP8`` denoiser checkpoint.
-
-Same file Studio fp8 inference resolves (one download, dense bf16 never fetched). Layout ``<fqn>._weight_qdata`` e4m3
-[out, in] + ``<fqn>._weight_scale`` fp32 [out, 1] is FrozenFp8Linear's per-row format. Anything unexpected returns None
-and the caller loads bf16.
-"""
+"""Loads an unsloth/*-FP8 denoiser for fp8 base; None on unexpected layout, so the caller uses bf16."""
from __future__ import annotations
diff --git a/studio/backend/core/training/diffusion_frozen_fp8.py b/studio/backend/core/training/diffusion_frozen_fp8.py
index 4666d04828a..2adfc2d5008 100644
--- a/studio/backend/core/training/diffusion_frozen_fp8.py
+++ b/studio/backend/core/training/diffusion_frozen_fp8.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""fp8 compute for the frozen base linears of a LoRA run.
-
-Each weight is quantized once to e4m3 (float scale per output row) and its bf16 copy freed; backward returns only
-grad_x, so nothing from x is saved (torchao's Float8Linear re-quantizes the bf16 weight ~4x per layer per step).
-GEMMs use unit scales with row scales applied after: rowwise ``_scaled_mm`` on sm100 routes to an untuned CUTLASS
-kernel, tensorwise to cuBLAS (aten ScaledBlas.cpp).
-"""
+"""Frozen base linears in fp8 e4m3, quantized once; backward returns only grad_x, so x is not saved."""
import torch
import torch.nn as nn
diff --git a/studio/backend/core/training/diffusion_h3_clips.py b/studio/backend/core/training/diffusion_h3_clips.py
index 7ce79f6e14b..a7ee47008ca 100644
--- a/studio/backend/core/training/diffusion_h3_clips.py
+++ b/studio/backend/core/training/diffusion_h3_clips.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The clip dataset layer for MiniMax-H3 LoRA training.
-
-MiniMax-H3 is the first family Unsloth trains from **clips with sound** rather than stills,
-and it has no still-image shortcut: its video VAE encodes ``17 * n + 5`` pixel frames at a
-time (a 1-frame clip is not a valid input, unlike LTX-2's), and every forward carries audio
-rows in the same packed sequence as the video rows. So the dataset unit is a video file with
-a soundtrack, and this module is the part of that which needs no torch and no diffusers:
-discovery, captions, the frame/latent/row arithmetic, and the canvas rule.
-
-The decode itself (``decode_clip``) needs PyAV, which the video backend already depends on.
-Everything above it is pure filesystem + arithmetic so the geometry contract is unit-testable
-on a CPU-only box.
-"""
+"""MiniMax-H3 clip datasets: frames must be 17*n+5, with no still-image path; torch-free geometry."""
from __future__ import annotations
diff --git a/studio/backend/core/training/diffusion_samples.py b/studio/backend/core/training/diffusion_samples.py
index 61b67c117ab..382f24712f9 100644
--- a/studio/backend/core/training/diffusion_samples.py
+++ b/studio/backend/core/training/diffusion_samples.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Fixed-seed preview images during diffusion LoRA training. A round never touches training state:
-fork_rng, private noise generator, a fresh scheduler copy, and force_eager for a compiled model."""
+"""Fixed-seed preview rounds never touch training state: fork_rng, private noise, scheduler copy."""
from __future__ import annotations
diff --git a/studio/backend/core/training/diffusion_train_common.py b/studio/backend/core/training/diffusion_train_common.py
index b7156c14ec3..b0742cc08de 100644
--- a/studio/backend/core/training/diffusion_train_common.py
+++ b/studio/backend/core/training/diffusion_train_common.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Shared, family-agnostic building blocks for diffusion LoRA training: dataset discovery, request
-config + validation, image loading, event emission, the stop protocol, adapter publishing, and
-the family/trainer registry, so the SDXL U-Net trainer (``diffusion_lora_trainer``) and the
-flow-matching DiT trainers share them. The pure helpers have no torch/diffusers import at call
-time and are unit-tested without a GPU; this module only routes a request to the right training
-loop."""
+"""Shared diffusion LoRA helpers and family registry; pure helpers avoid torch, so tests need no GPU."""
from __future__ import annotations
diff --git a/studio/backend/core/training/diffusion_train_extras.py b/studio/backend/core/training/diffusion_train_extras.py
index 80d1f24d84a..6e39749c749 100644
--- a/studio/backend/core/training/diffusion_train_extras.py
+++ b/studio/backend/core/training/diffusion_train_extras.py
@@ -1,34 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Optional extras for the diffusion LoRA trainers: LoRA EMA, the persistent
-conditioning cache, and aspect-ratio bucketing.
-
-Everything here is opt-in and family-agnostic:
-
-- ``LoRAEMA`` keeps an exponential moving average of ONLY the trainable LoRA
- parameters. Short LoRA runs (a few hundred steps) can't afford the classic
- 0.9999 decay -- the shadow would still be ~frozen at the init when the run
- ends -- so the default decay is 0.99 with a warmup ramp that keeps early
- updates responsive. The EMA weights export as a SECOND adapter next to the
- primary one, so the user can A/B both.
-
-- ``PersistentConditioningCache`` stores the trainer's precomputed conditioning
- tensors (VAE latent posterior stats + text-encoder embeddings) on disk as one
- safetensors file per item, keyed by content hash + family + resolution. On a
- warm start the trainer can skip loading the VAE and the multi-GB text
- encoders entirely. The cached latent tensors are EXACTLY what the in-memory
- path produces (the family's ``encode_latent_stats`` output with all
- normalisation -- including Qwen's per-channel latents_mean/std -- already
- folded in, held in fp32), so a cache hit is bit-identical to a fresh encode.
-
-- Aspect-ratio bucketing assigns each image a same-area bucket resolution
- (width/height multiples of a divisor the VAE + patching can consume) and
- batches only within a bucket, so a mixed-aspect dataset trains without
- square-cropping away composition.
-
-Pure helpers avoid torch at import time so the CPU unit tests stay light.
-"""
+"""Opt-in extras: LoRA EMA (0.99 default decay, exported as a second adapter), conditioning cache
+(bit-identical to a fresh encode), aspect bucketing; pure helpers avoid torch at import time"""
from __future__ import annotations
diff --git a/studio/backend/core/training/diffusion_training_service.py b/studio/backend/core/training/diffusion_training_service.py
index 9ac2211eb0b..d9c1414a385 100644
--- a/studio/backend/core/training/diffusion_training_service.py
+++ b/studio/backend/core/training/diffusion_training_service.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""A small job service for diffusion LoRA training.
-
-This is deliberately separate from the LLM ``TrainingBackend``: that backend's
-lifecycle (LLM config build, per-run SQLite rows, and matplotlib plots) is specific
-to text training and would mis-handle a diffusion run. This service does only what a
-diffusion job needs -- spawn the trainer subprocess, pump its
-events (``model_load_*`` / ``progress`` / ``complete`` / ``error``) into an in-memory
-status snapshot, and support stop -- and is polled over JSON by the route layer.
-
-The subprocess context, target, and queues are injectable so the service can be unit
-tested without real multiprocessing or torch: tests pass a fake context whose Process
-runs a scripted target on a thread.
-"""
+"""Diffusion LoRA job service: runs the trainer subprocess, kept apart from the LLM TrainingBackend."""
from __future__ import annotations
diff --git a/studio/backend/core/training/drafter.py b/studio/backend/core/training/drafter.py
index 5dcb8dd3ee1..ba1e60e62b9 100644
--- a/studio/backend/core/training/drafter.py
+++ b/studio/backend/core/training/drafter.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Speculative-decoding drafter trained after the fine-tune.
-
-Models with a native MTP head retrain it (llama.cpp `draft-mtp`, vLLM `method="mtp"`); models without one get
-an EAGLE-3 drafter in the speculators layout (llama.cpp `draft-eagle3`, vLLM `method="eagle3"`). A fresh MTP
-head on an architecture without an MTP graph would run in neither engine, so it is never offered.
-"""
+"""Speculative drafter after fine-tune: retrain native MTP, else EAGLE-3; never a fresh MTP head."""
from __future__ import annotations
diff --git a/studio/backend/core/training/s3_dataset.py b/studio/backend/core/training/s3_dataset.py
index d2d3289c46a..3051e5a7b01 100644
--- a/studio/backend/core/training/s3_dataset.py
+++ b/studio/backend/core/training/s3_dataset.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""
-S3 dataset loader.
-
-Downloads dataset files (parquet / json / jsonl / csv) from an AWS S3 bucket
-to a local temp directory so the existing local-file dataset path can consume
-them. boto3 is an optional dependency installed on the first S3 load if missing.
-
-Audio keys download too, keeping their prefix-relative layout, and audio values in
-JSON/JSONL/CSV manifests are rewritten to the local paths (``datasets.Audio`` opens path
-strings verbatim). Parquet manifests are not rewritten: their paths must already resolve.
-
-The S3 config dict mirrors ``models.training.S3Config.model_dump()`` (snake_case
-keys): bucket, region, prefix, access_key_id, secret_access_key, use_iam_role.
-Credentials are read once to build the client and never logged or persisted.
-"""
+"""S3 dataset download to a local temp dir; boto3 is optional and installed on first S3 load if
+missing; audio paths in JSON/JSONL/CSV manifests rewritten to local; parquet paths must already
+resolve; credentials never logged or persisted"""
from __future__ import annotations
diff --git a/studio/backend/core/training/token_preview.py b/studio/backend/core/training/token_preview.py
index e0309e3f89a..e8cabf7b702 100644
--- a/studio/backend/core/training/token_preview.py
+++ b/studio/backend/core/training/token_preview.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Owns the token preview subprocess (core.training.token_preview_worker).
-
-One worker at a time, kept for the model it was started for so typing in the preview answers in
-milliseconds; a request for another model, a training start or an idle timeout ends it.
-"""
+"""Token preview subprocess: one worker, kept for its model; a switch, training or idle ends it."""
from __future__ import annotations
diff --git a/studio/backend/core/training/token_preview_worker.py b/studio/backend/core/training/token_preview_worker.py
index c73e1bf4b4b..bb47242c5cd 100644
--- a/studio/backend/core/training/token_preview_worker.py
+++ b/studio/backend/core/training/token_preview_worker.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Token preview subprocess: loads only a model's tokenizer and shows how training would tokenize and
-mask a few dataset rows or a typed text.
-
-Runs the same formatting, chat template and completion masking calls as the training worker, so
-what the preview marks as trained is what the run trains on. It never touches a GPU: the parent
-starts it with every accelerator hidden, and it exits on its own once idle.
-"""
+"""Tokenizer-only preview subprocess; same formatting and masking as training, and never uses a GPU."""
from __future__ import annotations
diff --git a/studio/backend/core/training/training.py b/studio/backend/core/training/training.py
index b6e714e2b4c..50bb6840df0 100644
--- a/studio/backend/core/training/training.py
+++ b/studio/backend/core/training/training.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""
-Training backend — subprocess orchestrator.
-
-Each job runs in a fresh spawn subprocess (solving transformers version-switching);
-the in-process UnslothTrainer singleton is only used inside the worker. This file
-orchestrates the subprocess lifecycle, pumps events from the worker's mp.Queue, and
-exposes the same API to routes/training.py. Pattern follows data_recipe/jobs/manager.py.
-"""
+"""Each job runs in a fresh spawn subprocess so transformers versions can switch between jobs."""
from core.inference.inference_gate import pauses_background_embedding
from core.training.account_jobs import (
diff --git a/studio/backend/core/youtube_transcript.py b/studio/backend/core/youtube_transcript.py
index cfb80b85cd7..7d6f412675b 100644
--- a/studio/backend/core/youtube_transcript.py
+++ b/studio/backend/core/youtube_transcript.py
@@ -1,17 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Read a YouTube video's captions as plain text, with no third-party client.
-
-Two hops, both against youtube.com. ``POST /youtubei/v1/player`` with the ANDROID
-InnerTube client lists the caption tracks and the video metadata, then the chosen
-track's ``baseUrl`` is downloaded as ``fmt=json3`` and flattened.
-
-The ANDROID client matters. Caption URLs taken from the watch page's
-``ytInitialPlayerResponse`` belong to the WEB client, and YouTube now answers those
-with 200 and an empty body unless the request carries a proof-of-origin token, which
-only its BotGuard JS can mint. The ANDROID client's URLs still resolve unsigned.
-"""
+"""Captions via ANDROID InnerTube player API; WEB-client caption URLs need a proof-of-origin token."""
from __future__ import annotations
diff --git a/studio/backend/hub/endpoint_proxy.py b/studio/backend/hub/endpoint_proxy.py
index e9edaf46ab8..16d555a7a75 100644
--- a/studio/backend/hub/endpoint_proxy.py
+++ b/studio/backend/hub/endpoint_proxy.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Same-origin relays to a custom Hub endpoint and datasets server.
-
-The page's CSP is fixed when it is served, and the desktop app's when it launches, so the
-browser reaches an endpoint saved later through these. The Unsloth session goes in
-``Authorization``; the browser's Hugging Face token travels in ``X-HF-Authorization`` and is
-sent on to the configured endpoint only. The first path segment names the endpoint, so the
-page's caches, keyed on its Hub URL, never mix two endpoints' answers.
-"""
+"""Same-origin relays to custom Hub endpoint and datasets server; first path segment names the
+endpoint so caches never mix answers from two endpoints; HF token in X-HF-Authorization goes only
+to the configured endpoint"""
from __future__ import annotations
diff --git a/studio/backend/hub/modelscope/router.py b/studio/backend/hub/modelscope/router.py
index f6b7341e82f..fc1b31a6bde 100644
--- a/studio/backend/hub/modelscope/router.py
+++ b/studio/backend/hub/modelscope/router.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The Hugging Face Hub API, read-only, over ModelScope: ``HF_ENDPOINT`` points here.
-
-A loopback server on its own thread serves this process and its workers, since a
-synchronous Hub call made on the main event loop could never be answered by it;
-the browser uses a mount in the main app, whose catalog routes need Studio auth.
-"""
+"""Read-only Hub API over ModelScope for HF_ENDPOINT: loopback server on its own thread, not the
+main event loop; browser uses the main-app mount, whose catalog routes need Studio auth"""
from __future__ import annotations
diff --git a/studio/backend/hub/schemas/inventory.py b/studio/backend/hub/schemas/inventory.py
index 698857f24af..a544f03e73c 100644
--- a/studio/backend/hub/schemas/inventory.py
+++ b/studio/backend/hub/schemas/inventory.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pydantic schemas for the Hub inventory layer (/api/hub/*).
-
-Kept independent from upstream models/models.py so the Hub module can ship
-without modifying any upstream schema."""
+"""Pydantic Hub inventory schemas, kept independent of upstream models/models.py by design."""
from pydantic import BaseModel, Field, PrivateAttr, model_validator
from typing import List, Literal, Optional
diff --git a/studio/backend/hub/services/models/hermes.py b/studio/backend/hub/services/models/hermes.py
index 6298bac2730..b3f0d7f096f 100644
--- a/studio/backend/hub/services/models/hermes.py
+++ b/studio/backend/hub/services/models/hermes.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Hermes model inventory: the GGUFs Hermes Desktop's one-click download stages.
-
-Hermes keeps its managed runtime's weights as flat ``.gguf`` files directly in
-``<hermes root>/models``, with vision projectors and speculative-decode drafters
-tucked under a ``models/assets/`` subdirectory so its own router never lists them
-as servable. Which files count is decided by
-``hermes_cli.local_runtime.bootstrap.staged_models``; :func:`staged_gguf_files`
-mirrors that rule, because a file Hermes does not consider servable is one Studio
-must not offer to load either.
-"""
+"""Hermes GGUF inventory; mirrors hermes_cli's staged_models rule, so unservable files stay hidden."""
from __future__ import annotations
diff --git a/studio/backend/hub/services/models/local_model_actions.py b/studio/backend/hub/services/models/local_model_actions.py
index 831dd946126..1ac7d018239 100644
--- a/studio/backend/hub/services/models/local_model_actions.py
+++ b/studio/backend/hub/services/models/local_model_actions.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Reveal and delete for on-device models outside the Hugging Face cache (LM Studio, custom
-folders, ./models, Ollama, Hermes, oMLX). Only a path the local inventory lists is accepted, so
-callers cannot probe or remove arbitrary files."""
+"""Reveal and delete for non-HF-cache local models; only inventory-listed paths accepted, so callers
+cannot probe or remove arbitrary files."""
from __future__ import annotations
diff --git a/studio/backend/hub/services/models/ollama.py b/studio/backend/hub/services/models/ollama.py
index efead366e4c..c67efecfac0 100644
--- a/studio/backend/hub/services/models/ollama.py
+++ b/studio/backend/hub/services/models/ollama.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Ollama model inventory: manifest parsing and writable-symlink materialization.
-
-Ollama stores models content-addressed under ``<root>/manifests/`` and
-``<root>/blobs/``. Inventory scans read the manifests directly (no writes),
-returning rows whose ``id`` is an opaque ``ollama-manifest:`` reference. The
-load path then calls :func:`materialize_ollama_model_ref`, which creates a
-``.gguf``-named symlink (or hardlink) so that downstream loaders see a path
-with the GGUF suffix without copying multi-GB blobs inside an API request.
-"""
+"""Ollama inventory is read-only; materialize_ollama_model_ref makes a .gguf link to blobs, no copy."""
from __future__ import annotations
diff --git a/studio/backend/hub/services/training_downloads.py b/studio/backend/hub/services/training_downloads.py
index b76af5dbd24..c28ad362293 100644
--- a/studio/backend/hub/services/training_downloads.py
+++ b/studio/backend/hub/services/training_downloads.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Training-owned transfers in the same registry and API as Hub downloads.
-
-The trainer owns its subprocess, so cancellation must stop that exact loading
-worker rather than enqueue a signal behind a blocking native Xet call. Progress
-describes current files only; leaving a load phase never verifies a full repo.
-"""
+"""Training downloads share the Hub registry; cancel kills the loader subprocess, not a queued
+signal; progress covers current files only and leaving a load phase never verifies the full repo."""
from __future__ import annotations
diff --git a/studio/backend/hub/utils/comfy_models.py b/studio/backend/hub/utils/comfy_models.py
index 802d6b38784..a299c3c389a 100644
--- a/studio/backend/hub/utils/comfy_models.py
+++ b/studio/backend/hub/utils/comfy_models.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""ComfyUI models-folder discovery and loose single-file diffusion checkpoints.
-
-Role folders hold many loose ``.safetensors`` with no ``config.json``; each denoiser is listed as its
-own row when its header says DiT. A local DiT's text encoder is taken from the layout's text-encoder
-folders when one fits (``diffusion_comfy_components.pick_comfy_text_encoders``); VAE folders are
-resolved but nothing loads from them. No torch: called on every listing.
-"""
+"""Loose ComfyUI checkpoints; no torch import (runs on every listing); VAE folders never loaded."""
from __future__ import annotations
diff --git a/studio/backend/hub/utils/download_registry.py b/studio/backend/hub/utils/download_registry.py
index 8b83048df65..e12c9f0ebf9 100644
--- a/studio/backend/hub/utils/download_registry.py
+++ b/studio/backend/hub/utils/download_registry.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""HF cache inspection, download registry state, and orphan-worker reaping. Worker spawning and exit handling live in :mod:`hub.services.download_lifecycle`; this module owns the registry state machine plus the cache/marker inspection those workers depend on.
-
-Resume model: up to huggingface_hub 1.17 the HTTP transport supported true partial-file resume, opening ``<etag>.incomplete`` in append mode and sending ``Range: bytes={resume_size}-``. 1.18 replaced that with a process-unique ``<etag>.<nonce>.incomplete`` opened ``"wb"`` and unlinked on the way out, so no transport resumes within a file any more and a surviving partial is litter (see :func:`hf_partials_are_resumable`); resume is now whole-file only, with ``snapshot_download`` skipping shards already materialized. The XET transport CANNOT resume from a ``.incomplete`` partial at all, since ``hf_xet.download_files`` rewrites the destination from scratch, though network-level dedup still happens through the separate chunk cache these helpers never touch.
-
-Cross-transport corruption: a partial written by XET (or ``hf_transfer``'s parallel-Range writer) can be sparse, with a high reported size and zero-filled gaps below, and feeding it to the HTTP resumer would produce a correct-sized blob whose internal bytes are silently wrong. So transport markers are kept at the download's scope (repo for snapshots/datasets, variant for GGUF) and an HTTP partial is never inherited unless the marker proves the previous writer was the same single-stream sequential writer. Marker writes go through tmp+rename in :func:`prepare_cache_for_transport` before the worker hands off to ``snapshot_download``, so the next process always sees a consistent provenance signal.
-"""
+"""HF cache and registry; HTTP partials resume only if a marker proves a sequential writer (XET or
+hf_transfer partials can be sparse and silently wrong); XET cannot resume; markers written
+tmp+rename before snapshot_download handoff."""
from __future__ import annotations
diff --git a/studio/backend/hub/utils/gguf_header_delta.py b/studio/backend/hub/utils/gguf_header_delta.py
index 0298c61331a..d15e355a6b9 100644
--- a/studio/backend/hub/utils/gguf_header_delta.py
+++ b/studio/backend/hub/utils/gguf_header_delta.py
@@ -1,16 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Rebuild a republished image / video GGUF from the cached older copy when only its header changed.
-
-A metadata fix (an architecture label, a new KV) rewrites the GGUF header and leaves every tensor byte alone, but the
-file's sha256 changes, so huggingface_hub downloads the whole file again. Here the new header is fetched with a Range
-request, its tensor table is checked against the cached copy's, and the new file is written as the new header plus the
-cached copy's tensor data, hashed in the same pass. It is kept only when its sha256 equals the Hub's.
-
-Opt-in (Images / Video loads, and image / video GGUFs in the download manager). No network unless the file for the
-target commit is missing AND an older snapshot holds the same path; anything unproven falls back to the normal
-download, and nothing here raises."""
+"""Rebuilds header-only GGUF changes from the cached copy; opt-in; no network unless the target-
+commit file is missing and an older snapshot has it; falls back to normal download, never raises;
+keeps only if sha256 matches Hub."""
from __future__ import annotations
diff --git a/studio/backend/hub/utils/host_paths.py b/studio/backend/hub/utils/host_paths.py
index 5c9c01afd1a..f7d415c9661 100644
--- a/studio/backend/hub/utils/host_paths.py
+++ b/studio/backend/hub/utils/host_paths.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep the host's filesystem layout inside the host. For an ``sk-unsloth`` API key every host
-path in an inventory payload is replaced by an opaque reference, stable for the life of the
-server so a client can still group rows. Output encoding, not an authorization decision.
-"""
+"""Swaps host paths for stable opaque refs under sk-unsloth keys; encoding only, not authorization."""
from __future__ import annotations
diff --git a/studio/backend/hub/utils/mlx_variants.py b/studio/backend/hub/utils/mlx_variants.py
index 3ae9dbbf52e..dd4fe6bdf10 100644
--- a/studio/backend/hub/utils/mlx_variants.py
+++ b/studio/backend/hub/utils/mlx_variants.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Precision folders of one Hub repo (``2-bit/``, ``6-bit/``, ``8bit/``), each a whole MLX
-checkpoint, offered and loaded as variants of that repo the way GGUF quants are."""
+"""MLX precision folders (2-bit/, 6-bit/, 8bit/) of one repo, offered as variants like GGUF quants."""
from __future__ import annotations
diff --git a/studio/backend/hub/utils/state_dir.py b/studio/backend/hub/utils/state_dir.py
index 4d5e721cbb5..bd4b2d52f67 100644
--- a/studio/backend/hub/utils/state_dir.py
+++ b/studio/backend/hub/utils/state_dir.py
@@ -1,18 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Filesystem layout for Hub download state.
-
-State sits beside HF's cache (under Unsloth's own cache root) so it survives ``huggingface-cli delete-cache`` and any other HF-side lifecycle:
-
- <studio cache>/hub-state/
- manifests/cache-<digest>/<key>.json expected-files manifest
- cancelled/cache-<digest>/<key>.json cancel marker
-
-The cache digest isolates state for the same repo across selectable Hub caches. The ``<key>`` mirrors HF's cache dir naming (models--<owner>--<name>, plus ``--variant--<variant>`` for a GGUF variant, datasets--<owner>--<name>) while keeping manifest, cancel-marker and atomic-write temp filenames inside common filesystem basename limits; very long repo IDs use a stable hash instead.
-
-Path accessors are read-only unless a writer passes ``create=True``, and all return ``Optional[Path]``, yielding ``None`` when directory creation fails so callers fall through to existing on-disk-only behavior.
-"""
+"""Hub download state beside HF cache; paths read-only unless create=True; None when dir creation
+fails, so callers fall back to on-disk-only behavior."""
from __future__ import annotations
diff --git a/studio/backend/hub/workers/hf_download.py b/studio/backend/hub/workers/hf_download.py
index 54514e91336..b921dc7432b 100644
--- a/studio/backend/hub/workers/hf_download.py
+++ b/studio/backend/hub/workers/hf_download.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""HuggingFace Hub download worker, spawned as a subprocess so SIGKILL stops all chunk threads.
-
-Resume safety: downloads here MUST be single-stream sequential writers so the parent's SIGKILL then restart loop can rely on ``os.path.getsize(.incomplete)`` for the resume offset. Enforced by setting ``HF_HUB_DISABLE_XET=1`` and ``HF_HUB_ENABLE_HF_TRANSFER=0`` on the spawning side (see :mod:`hub.utils.download_registry`) for transport=http; passing ``max_workers=1`` to ``snapshot_download`` so files download serially and the at-most-one-active-`.incomplete` invariant holds globally; letting ``prepare_cache_for_transport`` purge any pre-existing ``.incomplete`` blobs not provably from the same sequential writer; and restoring huggingface_hub's 1.17 append-mode writer where safe (see :mod:`hub.utils.resumable_partials`), since 1.18+ writes a process-unique partial and unlinks it, leaving this loop nothing to resume from.
-
-If the final byte count does not match what HF declared, huggingface_hub raises ``EnvironmentError`` ("Consistency check failed: ..."), which is surfaced on stderr so the watcher can show the exact message to the user.
-"""
+"""HF download subprocess (SIGKILL stops chunk threads); resume needs single-stream writes, enforced
+by HF_HUB_DISABLE_XET=1, HF_HUB_ENABLE_HF_TRANSFER=0 (http), max_workers=1, purge of unprovable
+.incomplete blobs."""
from __future__ import annotations
diff --git a/studio/backend/lan_access.py b/studio/backend/lan_access.py
index 8e991e133c5..92bb15ffca8 100644
--- a/studio/backend/lan_access.py
+++ b/studio/backend/lan_access.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Runtime LAN listener for Unsloth Studio.
-
-Unsloth binds 127.0.0.1 by default, so a phone or laptop on the same network cannot reach it without
-relaunching with ``-H 0.0.0.0``. This module adds a second uvicorn listener over the already-running app, on the
-machine's own network addresses and the same port, and takes it away again -- no restart, and the loopback
-socket keeps serving the desktop app throughout.
-
-The listener binds each detected address explicitly rather than the wildcard: ``0.0.0.0`` collides with the
-loopback socket that already holds the port. It runs on the primary server's event loop with ``lifespan="off"``,
-so the app's startup and shutdown handlers stay owned by the primary server and never fire twice.
-
-The settings-managed listener remains IPv4 only. Address discovery also serves an existing IPv6 wildcard launch,
-while link-local IPv6 addresses are omitted because another device cannot use them without the listener's
-interface scope.
-"""
+"""Extra LAN listener on each detected address, not 0.0.0.0 (collides with loopback); lifespan=off
+so startup and shutdown stay with primary and never fire twice; settings listener IPv4 only;
+link-local IPv6 omitted."""
from __future__ import annotations
diff --git a/studio/backend/loggers/config.py b/studio/backend/loggers/config.py
index bf4f2edea3a..3ca0b4f3c71 100644
--- a/studio/backend/loggers/config.py
+++ b/studio/backend/loggers/config.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Structured logging configuration via structlog.
-
-Environment-specific formats (JSON for prod, console for dev), ISO timestamps, context-var
-integration, log-level filtering, and logger caching.
-"""
+"""Structlog config: JSON logs in prod, console in dev, ISO timestamps, context vars, level filter."""
import logging
import os
diff --git a/studio/backend/loggers/handlers.py b/studio/backend/loggers/handlers.py
index b2f7544e8d5..6053f1e3a2f 100644
--- a/studio/backend/loggers/handlers.py
+++ b/studio/backend/loggers/handlers.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Structured logging handlers and middleware: LoggingMiddleware (request/response logging with timing),
-filter_sensitive_data (structlog processor for sanitization), and get_logger (factory for structured loggers).
-"""
+"""Logging middleware and get_logger; filter_sensitive_data is a structlog sanitizing processor."""
from __future__ import annotations
diff --git a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper.py b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper.py
index 1af8133cc53..bee9d09158e 100644
--- a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper.py
+++ b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Multi-repo GitHub scraper for the Unsloth seed plugin.
-
-Drives the GraphQL scraper in `scraper_impl/` per repo, capped via trial_limits
-to stop at `limit` items per resource. Then reads the per-resource JSONL shards
-and flattens them into one unified JSONL with stable columns (`item_type`,
-`repo`, `number`, `title`, `body`, ...).
-"""
+"""Multi-repo GitHub scraper; caps each resource with trial_limits, then merges shards to one JSONL."""
from __future__ import annotations
diff --git a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/queries.py b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/queries.py
index d0db45053da..1dc7223a7d3 100644
--- a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/queries.py
+++ b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/queries.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""GraphQL queries for GitHub data scraping.
-
-GitHub's GraphQL rejects queries with unused fragments, so each query includes
-only the fragments it references.
-"""
+"""GitHub GraphQL queries; include only referenced fragments, since GitHub rejects unused ones."""
F_ACTOR = """
fragment ActorFields on Actor {
diff --git a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.py b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.py
index e94f251795c..5cdda3e920d 100644
--- a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.py
+++ b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Scraper orchestration: issues, PRs, discussions, commits, releases, etc.
-
-Resumable via state file. Writes JSONL shards under data/{repo}/{resource}.jsonl.
-"""
+"""Resumable GitHub resource scraper (issues, PRs, discussions, ...); writes JSONL shards per repo."""
from __future__ import annotations
diff --git a/studio/backend/requirements/engines/engine_compat.py b/studio/backend/requirements/engines/engine_compat.py
index d6cdebeb83d..76cac7c731a 100644
--- a/studio/backend/requirements/engines/engine_compat.py
+++ b/studio/backend/requirements/engines/engine_compat.py
@@ -1,18 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Writes <lock>.compat.json: every constraint the locked packages place on each other, and the
-download size of each locked wheel this platform installs.
-
-A shared engine skips a locked package when Studio already has a version all of these accept,
-so the engine's own dependency graph decides, not the lock's exact pin. The lock's .in pins are
-Studio's choices and are left out. Run after `uv pip compile`:
-
- python studio/backend/requirements/engines/engine_compat.py vllm-linux-cu130-torch213
-
-Packages a lock takes from its engine's own index (TARGETS) are priced from that index; their
-requirements are not read, since such a lock is always an isolated environment.
-"""
+"""Writes <lock>.compat.json after uv pip compile; shared engine skips a locked package when Studio
+already has a version all constraints accept, so its own graph decides, not the pin; TARGETS
+locks priced from index, requirements not read; .in pins excluded."""
from __future__ import annotations
diff --git a/studio/backend/requirements/single-env/patch_metadata.py b/studio/backend/requirements/single-env/patch_metadata.py
index 6c3ee4af524..ce97d540d5b 100644
--- a/studio/backend/requirements/single-env/patch_metadata.py
+++ b/studio/backend/requirements/single-env/patch_metadata.py
@@ -2,15 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Relax strict metadata pins so pip check passes on the single-env stack.
-
-Why:
-- data-designer pins huggingface-hub>=1.0.1 and pyarrow<20.
-- unsloth/transformers pins huggingface-hub<1.
-- studio datasets pins pyarrow>=21.
-
-Runtime works with hub 0.36.x + pyarrow 23.x; only the metadata conflicts.
-"""
+"""Relaxes strict pins so pip check passes; runtime works with hub 0.36.x and pyarrow 23.x."""
from __future__ import annotations
diff --git a/studio/backend/routes/browser.py b/studio/backend/routes/browser.py
index 12fd1eb7509..649f1dab43f 100644
--- a/studio/backend/routes/browser.py
+++ b/studio/backend/routes/browser.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""In-app browser: pages are fetched here (SSRF-guarded, since most sites refuse framing) and
-rendered in ``/frame``, an opaque-origin sandbox; an injected script routes navigations back here.
-"""
+"""In-app browser: pages fetched with an SSRF guard, rendered in an opaque-origin /frame sandbox."""
from __future__ import annotations
diff --git a/studio/backend/routes/browser_network.py b/studio/backend/routes/browser_network.py
index 907476ee804..377a92fcc53 100644
--- a/studio/backend/routes/browser_network.py
+++ b/studio/backend/routes/browser_network.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The page shell's fetch and XMLHttpRequest. Wrapped to count the page's requests in flight, so the
-browser agent can wait for content a page fetches after load before it reads the page; and to send
-the page's requests to its own site through the panel, as the sandbox's opaque origin makes them
-cross-origin. Runs inside ``boot`` in routes/browser.py."""
+"""Page fetch/XHR wrappers run inside boot; count in-flight requests, route own-site calls via panel."""
BROWSER_NETWORK_JS = r"""
const nativeFetch = window.fetch.bind(window);
diff --git a/studio/backend/routes/chat_history.py b/studio/backend/routes/chat_history.py
index ed240e2c979..f39797e5cb9 100644
--- a/studio/backend/routes/chat_history.py
+++ b/studio/backend/routes/chat_history.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Chat history API routes backed by studio.db.
-
-SQLite-backed handlers are sync defs unless they also perform asynchronous cleanup; those mixed
-handlers explicitly send their database transaction through Starlette's threadpool.
-"""
+"""Chat history API; sync SQLite handlers, except mixed ones that use Starlette's threadpool."""
import asyncio
import os
diff --git a/studio/backend/routes/library.py b/studio/backend/routes/library.py
index 6ec751814c0..37bd379d9a6 100644
--- a/studio/backend/routes/library.py
+++ b/studio/backend/routes/library.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Library API: one view over uploads, chat attachments, generated images and audio, fine-tuned
-models and sandbox files, plus folders, favorites and renames. See ``core.library`` for the sources."""
+"""Library API over uploads, attachments, media, models and sandbox files; sources in core.library."""
import hashlib
import hmac
diff --git a/studio/backend/routes/llama.py b/studio/backend/routes/llama.py
index 45902d8e426..c8204d689d9 100644
--- a/studio/backend/routes/llama.py
+++ b/studio/backend/routes/llama.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""llama.cpp prebuilt update endpoints -- the single main update item.
-
-GET /api/llama/update-status -> is a newer prebuilt available + job state
-GET /api/llama/update-changelog -> new carried changes since the installed build
-POST /api/llama/update -> download + atomically swap to the latest
-
-Detection reuses utils.llama_cpp_freshness; the swap reuses install_llama_prebuilt.py via
-utils.llama_cpp_update. Both fail open so the UI never blocks on a missing marker / offline GitHub.
-
-whisper.cpp updates piggyback here: the status payload carries a whisper sub-status (update_available is the
-llama OR whisper union) and the apply job chains a whisper phase after the llama phase when whisper is behind,
-with a per-phase breakdown in job.phases. All pre-existing top-level fields keep their shape, so older clients
-keep working unchanged. audio.cpp is the third chained phase, offered when the managed runtime is not the release
-this Studio pins, with its own sub-status.
-"""
+"""llama.cpp prebuilt update routes: GET /api/llama/update-status, GET /api/llama/update-changelog,
+POST /api/llama/update; fail open; old top-level fields keep shape so older clients work; whisper
+and audio.cpp chain as phases."""
from __future__ import annotations
diff --git a/studio/backend/routes/llama_compat.py b/studio/backend/routes/llama_compat.py
index 0424054dbec..bbd5d394635 100644
--- a/studio/backend/routes/llama_compat.py
+++ b/studio/backend/routes/llama_compat.py
@@ -1,19 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Answer engine discovery probes with JSON, or with a 404, but never with the app.
-
-Probes for engine endpoints used to land on main.py's SPA catch-all, so ``GET /props`` returned 200 and a page
-of HTML. That is worse than a 404: a probe reads the status before the body. Served here: ``/props``,
-``/v1/props``, ``/version``, a passthrough to the resident llama-server for ``GET /metrics``, ``GET /slots``,
-``POST /tokenize`` and ``POST /detokenize`` (#11705), owner only, and Open WebUI's llama.cpp model management
-(``GET /models``, ``POST /models/load``, ``POST /models/unload``, #10610). Everything else in llama-server's
-table gets an explicit 404, on its real method as well as GET.
-
-Deliberately NOT served: Ollama's ``/api/tags`` and ``/api/show``. Answering them makes a client select Ollama
-and then fail on ``/api/chat``, which Studio does not implement; the reporting user's client instead fell back
-to the OpenAI surface and worked. Advertising a protocol we do not have is the HTML 200 again, one layer up.
-"""
+"""Engine probes answer JSON or 404, never SPA HTML: /props, /v1/props, /version, owner-only GET
+/metrics, GET /slots, POST /tokenize, POST /detokenize, GET /models, POST /models/load,
+/models/unload; other llama-server routes 404; Ollama /api/tags and /api/show not served."""
from __future__ import annotations
diff --git a/studio/backend/routes/npu.py b/studio/backend/routes/npu.py
index ab258bbf8d3..8fab8b4cdd5 100644
--- a/studio/backend/routes/npu.py
+++ b/studio/backend/routes/npu.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""NPU detection, setup and model management.
-
-Loading and chat use the inference routes. All routes here except status are owner-only.
-"""
+"""NPU detection, setup and models; all routes but status are owner-only; chat uses inference routes."""
from __future__ import annotations
diff --git a/studio/backend/routes/profile_stats.py b/studio/backend/routes/profile_stats.py
index adf67e7935c..8c76f8d86cc 100644
--- a/studio/backend/routes/profile_stats.py
+++ b/studio/backend/routes/profile_stats.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Usage numbers for the Profile settings tab. Read-only aggregation over the local studio.db (see
-``storage.profile_stats_db``). Nothing is uploaded.
-"""
+"""Read-only usage stats for the Profile tab, aggregated from local studio.db; nothing is uploaded."""
import asyncio
from datetime import date
diff --git a/studio/backend/routes/providers.py b/studio/backend/routes/providers.py
index 6d9b89c42dc..51629202e3d 100644
--- a/studio/backend/routes/providers.py
+++ b/studio/backend/routes/providers.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""API routes for external LLM provider management: the provider-type registry, CRUD for saved provider
-configurations and their API keys, the RSA public key used to encrypt those keys, connectivity tests, and model
-listing.
-"""
+"""External LLM provider routes: types, saved configs; API keys RSA-encrypted; tests, model listing."""
import asyncio
import hashlib
diff --git a/studio/backend/routes/rag.py b/studio/backend/routes/rag.py
index 4bf445d656f..1b129cccacf 100644
--- a/studio/backend/routes/rag.py
+++ b/studio/backend/routes/rag.py
@@ -1,15 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""HTTP API for the RAG engine: KB CRUD, uploads, SSE ingestion, search. Single-tenant: the subject gates
-access, not data.
-
-Without a working sqlite-vec the router still mounts, and one contract covers every endpoint. The KB list is
-polled, so it answers 200 with an empty list carrying an availability marker, which is what lets a client tell
-an empty store from a machine where RAG cannot run. Every other endpoint but /extract-text, which only parses,
-answers 503 stating the same reason.
-Nothing logs a traceback for it: the condition is fixed for the session and rag_db warns about it exactly once.
-"""
+"""No sqlite-vec: KB list gives empty 200 with availability marker; other routes 503 except
+/extract-text (parse only); single-tenant, subject gates access, not data"""
from __future__ import annotations
diff --git a/studio/backend/routes/settings.py b/studio/backend/routes/settings.py
index 8aa1d248012..2508cb4df14 100644
--- a/studio/backend/routes/settings.py
+++ b/studio/backend/routes/settings.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Settings policy: the account, shared and owner routers decide who may reach each
-/api/settings path."""
+"""Access to each /api/settings path is decided by the account, shared and owner routers"""
import asyncio
import functools
diff --git a/studio/backend/routes/training_vram.py b/studio/backend/routes/training_vram.py
index f49e13fe4fb..e8f9bd80ae4 100644
--- a/studio/backend/routes/training_vram.py
+++ b/studio/backend/routes/training_vram.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Memory coordination between inference and training. Uses live free VRAM to keep resident chat and STT
-models when they fit. STT is evicted before chat when training needs memory.
-"""
+"""Chat and STT models stay resident only if free VRAM fits; STT is evicted before chat for training"""
import sys
from typing import Any, Callable, Dict, List, Optional, Tuple
diff --git a/studio/backend/routes/whisper.py b/studio/backend/routes/whisper.py
index b4a64e5c28a..f43d4c432c3 100644
--- a/studio/backend/routes/whisper.py
+++ b/studio/backend/routes/whisper.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""whisper.cpp prebuilt status endpoint.
-
-GET /api/whisper/update-status -> is a newer prebuilt available + job state
-
-Detection reuses utils.whisper_cpp_freshness and fails open so the UI never blocks on a missing marker /
-offline GitHub. There is no whisper-only update trigger: whisper updates piggyback on the single main update
-item (POST /api/llama/update chains a whisper phase when whisper is behind).
-"""
+"""GET /api/whisper/update-status: prebuilt state; fails open; updates via POST /api/llama/update"""
from __future__ import annotations
diff --git a/studio/backend/state/active_generations.py b/studio/backend/state/active_generations.py
index 60026b198a3..80786200106 100644
--- a/studio/backend/state/active_generations.py
+++ b/studio/backend/state/active_generations.py
@@ -1,20 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Registry of in-flight chat generations, keyed by conversation.
-
-New Chat leaves the previous conversation streaming, so /load and /unload need
-to know which chats a reload would interrupt: they refuse with 409 unless the
-caller opts in to cancelling them, and GET /inference/active-generations lets
-the UI name them. A frontend guard alone would miss a second tab or a REST call.
-
-Entries hold the same threading.Event as the per-run cancel registry in
-routes/inference.py, so cancel_all() closes each generation's own upstream
-stream and never signals llama-server itself.
-
-A plain dict plus a threading.Lock: no signals, no process groups, no event loop
-affinity, so it behaves identically on Linux, macOS, Windows and WSL.
-"""
+"""In-flight chats: /load and /unload 409 unless opted in to cancel; GET /inference/active-
+generations lists them; cancel_all spares llama-server"""
from __future__ import annotations
diff --git a/studio/backend/state/browser_actions.py b/studio/backend/state/browser_actions.py
index b10c85e418f..2ef3c5a91b0 100644
--- a/studio/backend/state/browser_actions.py
+++ b/studio/backend/state/browser_actions.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Browser actions the chat tab runs for a tool loop, and the results it posts back.
-
-The browser lives in the tab (a proxied frame or a desktop native view), the loop in this process.
-A browser tool registers a slot, asks the tab through the chat stream (a ``tool_output`` event
-carrying ``browser_action``), and blocks here until ``POST /api/inference/browser-action-result``
-answers with the same unguessable id. Shaped like ``tool_approvals``: registered before it is
-announced, first answer wins, scoped to the session and account that asked.
-"""
+"""Browser tool slots answered by POST /api/inference/browser-action-result; first answer wins;
+registered before announced; scoped to session and account"""
from __future__ import annotations
diff --git a/studio/backend/state/run_subscribers.py b/studio/backend/state/run_subscribers.py
index 0afc29e48c4..47ea43e06a5 100644
--- a/studio/backend/state/run_subscribers.py
+++ b/studio/backend/state/run_subscribers.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which durable runs currently have a browser watching them.
-
-"Durable" means cancel_on_disconnect is off, not that the tab is gone, so nothing downstream could
-tell a watching user from an abandoned run. ``state.tool_approvals.wait_tool_decision`` needs that:
-its park ceiling is only defensible for a run nobody is watching.
-
-Keyed by (account, run) then by follower. Account, because studio.db is per-account
-(``utils.paths.storage_roots.studio_db_path``) and the run id is the client's
-(``CreateChatGenerationRun.runId``), so two accounts can hold the same id and one tenant's follower
-would answer for another's run. Follower, because two tabs (or a reconnect overlapping the stream it
-replaces) share a run, and a single stamp let either one's cleanup delete the other's heartbeat.
-
-A heartbeat rather than a reference count: a count must be decremented by a ``finally`` an abandoned
-generator may never reach, and a leaked increment would park an abandoned approval forever.
-"""
+"""Runs watched by a browser, keyed by (account, run) then follower; durable means
+cancel_on_disconnect off, not tab gone; wait_tool_decision park ceiling relies on it; heartbeats,
+not refcount"""
from __future__ import annotations
diff --git a/studio/backend/state/tool_approvals.py b/studio/backend/state/tool_approvals.py
index b741e4ea37e..3f8b54d3e85 100644
--- a/studio/backend/state/tool_approvals.py
+++ b/studio/backend/state/tool_approvals.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Per-call tool-call confirmation gate.
-
-When a chat request sets ``confirm_tool_calls``, the agentic loop pauses before executing each tool and waits here for the user's decision, which arrives via ``POST /api/inference/tool-confirm`` on a separate connection.
-
-Each gated call is identified by a unique ``approval_id`` (minted with ``new_approval_id``) that the loop registers here and echoes in the ``tool_start`` stream event. The frontend sends that exact id back, so a stale or duplicate confirmation, or a second tool awaiting a decision in the same session, can never resolve the wrong call; ``session_id`` is kept alongside purely as a scope check.
-
-The slot is registered with ``begin_tool_decision`` *before* the loop yields ``tool_start``, closing the race where a fast confirmation (or an auto "Always allow") could arrive before the waiter exists. ``wait_tool_decision`` then blocks and cleans up its own slot.
-"""
+"""Per-call approval gate keyed by approval_id; begin_tool_decision registers before tool_start"""
import os
import secrets
diff --git a/studio/backend/state/tool_policy.py b/studio/backend/state/tool_policy.py
index 87f4d468266..5444ac19c95 100644
--- a/studio/backend/state/tool_policy.py
+++ b/studio/backend/state/tool_policy.py
@@ -1,30 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Process-level server-side tool policy.
-
-Two slots, both set at startup and consulted by the inference route gates.
-
-The OVERRIDE (`set_tool_policy`) comes from an explicit `--enable-tools`/
-`--disable-tools` and beats the request:
-
- None -> no CLI override (default). Per-request `enable_tools` is honored.
- True -> CLI forced tools on for every request. Not on /v1/messages: that channel
- cannot present a confirmation prompt, so it takes the on direction from the
- request itself (see _anthropic_selects_server_tools).
- False -> CLI forced tools off for every request, /v1/messages included.
-
-The DEFAULT (`set_tool_policy_default`) is what an omitted `enable_tools` falls
-back to. `unsloth studio run` installs True for every bind, `--secure` included,
-so a plain request to a tool-capable model can use tools. It is only a default:
-a request that says `enable_tools: false` (what the Unsloth UI sends with its tool
-pills off) turns them off, which the override deliberately would not.
-
-No other launcher installs it. `unsloth studio`, the desktop app and Colab leave
-it unset, so an omitted `enable_tools` still means no tools there, which is what
-paths like `n > 1`, `max_tool_calls_per_message: 0` and the pre-switch
-passthrough guard are built around.
-"""
+"""CLI override (--enable-tools/--disable-tools) beats the request, except True on /v1/messages
+where the request decides; default applies only when enable_tools is omitted, set only by unsloth
+studio run; other launchers leave it unset, so no tools"""
import contextvars
from contextlib import contextmanager
diff --git a/studio/backend/state/unattended_runs.py b/studio/backend/state/unattended_runs.py
index 8942d359787..0f758f645ee 100644
--- a/studio/backend/state/unattended_runs.py
+++ b/studio/backend/state/unattended_runs.py
@@ -1,23 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Stop durable runs whose owner asked for them to end once no tab is watching.
-
-A durable chat run or Deep Research run outlives its tab by design (#10365), which is what most
-people want from a long research task. Some want the opposite: closing the tab should stop the
-run, as the browser-owned stream always did. The client says so per run (``stopWhenUnattended``
-on admission), and this watchdog cancels such a run once ``run_subscribers`` has heard from no
-follower for ``_GRACE_S``.
-
-Attendance, not the closing request: a phone that kills a background tab sends nothing at all.
-The grace is what lets a reload, a follower reconnecting after a network blip (its backoff tops
-out at 8s), or a second tab pick the run up before it is stopped. A run nobody ever attaches to
-counts its grace from when it was watched, so a tab that closes between admission and its first
-event stream still stops the run.
-
-In memory, like ``run_subscribers``: a chat run does not survive a restart anyway, and a Deep
-Research run is re-armed from its stored config at startup and whenever a follower reattaches.
-"""
+"""Ends stopWhenUnattended runs once no follower for _GRACE_S; attendance, not a close request, counts"""
from __future__ import annotations
diff --git a/studio/backend/storage/library_db.py b/studio/backend/storage/library_db.py
index dae53cece5c..83947d1a048 100644
--- a/studio/backend/storage/library_db.py
+++ b/studio/backend/storage/library_db.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Library state in studio.db.
-
-The Library lists files that already live elsewhere (chat uploads, generated images, sandbox
-files), so it only stores what those sources cannot: folders, and a per-item overlay of display
-name, favorite flag and folder. Files uploaded straight into the Library are the one source it
-owns; their bytes sit under ``account_path("library")``.
-"""
+"""Library state (studio.db): folders and an overlay for files kept elsewhere, except Library uploads"""
import sqlite3
import threading
diff --git a/studio/backend/storage/profile_stats_db.py b/studio/backend/storage/profile_stats_db.py
index a588f88f7c3..e7b1b301017 100644
--- a/studio/backend/storage/profile_stats_db.py
+++ b/studio/backend/storage/profile_stats_db.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Profile usage statistics derived from studio.db.
-
-Read-only aggregation over chat threads/messages (with their per-message ``metadata_json``), content-free API
-usage receipts, and training runs/metrics. The numbers are only as complete as the local history retained after
-each feature was introduced. Chat and training tables predate authenticated subjects and therefore remain
-install-wide; API usage receipts are filtered to the requesting subject.
-
-Token counts live inside each message's metadata blob, so they cannot be summed in SQL portably (JSON1 is not
-guaranteed on every bundled SQLite). Rows are streamed once in (thread, time) order and every metric is folded
-in that single pass, then memoised against per-source count/timestamp fingerprints so reopening the Profile tab
-is free until history changes.
-"""
+"""Read-only usage stats from studio.db; chat and training are install-wide, API receipts per subject"""
import csv
import io
diff --git a/studio/backend/storage/providers_db.py b/studio/backend/storage/providers_db.py
index d6b0e663e05..02d66ede406 100644
--- a/studio/backend/storage/providers_db.py
+++ b/studio/backend/storage/providers_db.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""SQLite storage for external LLM provider configurations.
-
-Same pattern as studio_db.py (module-level functions, raw sqlite3, WAL, per-function connections). API keys are
-NOT stored here: they live only in the browser (localStorage) and are sent encrypted per-request. Enabled model
-selections and discovered catalog IDs are stored server-side so remote Unsloth clients see the same connection
-state (#7281).
-"""
+"""SQLite for LLM providers; API keys stay in the browser and are sent encrypted per request"""
from __future__ import annotations
diff --git a/studio/backend/storage/rag_db.py b/studio/backend/storage/rag_db.py
index a0e39057d5a..687fbd71cc1 100644
--- a/studio/backend/storage/rag_db.py
+++ b/studio/backend/storage/rag_db.py
@@ -1,17 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""SQLite storage for the RAG engine.
-
-Same pattern as providers_db.py / studio_db.py (module functions, raw sqlite3, WAL, per-call connections, lazy
-schema), but every connection also loads sqlite-vec (vec0 needs it per-connection). If it cannot load,
-get_connection() raises RagExtensionUnavailable rather than failing import, and rag_available() reports the
-machine as one where RAG cannot run.
-
-One rag.db holds the ``documents`` / ``chunks`` model, the FTS5 lexical index (``chunks_fts``) and the
-sqlite-vec dense index (``chunks_vec``, created lazily by ensure_vec once the embedding dim is known, since vec0
-bakes the dim into the column type).
-"""
+"""Every connection loads sqlite-vec; if it fails get_connection raises RagExtensionUnavailable,
+never at import; rag_available reports it; chunks_vec made lazily by ensure_vec"""
import logging
import re
diff --git a/studio/backend/storage/sqlite_gate.py b/studio/backend/storage/sqlite_gate.py
index d9877c78a54..a75542347fb 100644
--- a/studio/backend/storage/sqlite_gate.py
+++ b/studio/backend/storage/sqlite_gate.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""One process-wide gate around every Studio SQLite connection open and close.
-
-SQLite 3.51.0-3.51.1 deadlocks when one thread's WAL close (unixIsSharingShmNode) races another
-thread's open or close of the same file: they take the VFS and inode mutexes in opposite order
-(fixed in 3.51.2, #10022). The VFS mutex is process-wide, so one wedged file hangs every database
-(#9008): studio.db, auth.db and rag.db all open through here. Gating only close() still deadlocks.
-"""
+"""Serializes every open and close: SQLite 3.51.0-3.51.1 deadlocks when a WAL close races another open"""
from __future__ import annotations
diff --git a/studio/backend/studio_mcp/errors.py b/studio/backend/studio_mcp/errors.py
index e5a3d354a02..12a57cefef6 100644
--- a/studio/backend/studio_mcp/errors.py
+++ b/studio/backend/studio_mcp/errors.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Turn a forwarded route's failure into an MCP ToolError the agent can act on. Unsloth Studio routes fail in several shapes (``{"detail"}`` on /api, the OpenAI envelope on /v1, gpu_busy three ways, a 200 that carries ``_deferred_error`` or ``status: "error"``, an NDJSON error line), and every message is scrubbed of host paths before it leaves.
-
-A failure the agent can branch on starts with a tag, ``[<code> k=v] <message>``, such as ``[gpu_busy retry_after=12]`` or ``[not_loaded kind=image]``. A plain refusal has no tag."""
+"""Route failures as MCP ToolError, host paths scrubbed; leading [code k=v] tag marks actionable codes"""
from __future__ import annotations
diff --git a/studio/backend/studio_mcp/forward.py b/studio/backend/studio_mcp/forward.py
index 3df6a688a68..face552347f 100644
--- a/studio/backend/studio_mcp/forward.py
+++ b/studio/backend/studio_mcp/forward.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""MCP tools reach Unsloth Studio through its own HTTP routes, in-process, as the API-key caller. Calling the route functions directly would skip the auth dependency, so the call would run as the owner and see host paths; going through the app means each call is authenticated, account-scoped and redacted exactly as the same request from the agent would be.
-
-The in-process client is deliberately remote: a TEST-NET peer and an ``.invalid`` Host fail every loopback, LAN and keyless check, so a forwarded call can never use keyless access, whatever Unsloth Studio's keyless scope. Only the caller's key and, where a route reads it, the Hub token header are sent; nothing from the inbound request is copied."""
+"""In-process as the API-key caller so auth and redaction apply; TEST-NET peer and .invalid Host
+make keyless access impossible; only the key and Hub token header are sent"""
from __future__ import annotations
diff --git a/studio/backend/studio_mcp/video_queue.py b/studio/backend/studio_mcp/video_queue.py
index b93a4947ce5..2918b435a85 100644
--- a/studio/backend/studio_mcp/video_queue.py
+++ b/studio/backend/studio_mcp/video_queue.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Videos queued over MCP. Unsloth Studio makes one video at a time and refuses a second while one runs, so an agent submitting a shot list would have to retry each clip itself. generate_video instead queues a refused clip here, in order, and a background task per account submits each one once the video before it ends; get_job and cancel take the queue id.
-
-The queue lives only as long as the Unsloth Studio MCP server process: a restart drops every queued video that has not started. It is per account, shared by that account's keys, and an id from another account reads as unknown."""
+"""Queues videos Studio refused while busy, submitting each in order once the previous one ends; per
+account; lost on MCP server restart"""
from __future__ import annotations
diff --git a/studio/backend/utils/api_errors.py b/studio/backend/utils/api_errors.py
index 4941df1e8af..be0222d926b 100644
--- a/studio/backend/utils/api_errors.py
+++ b/studio/backend/utils/api_errors.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Error-envelope helpers for the OpenAI/Anthropic-compatible ``/v1/*`` API surface.
-
-FastAPI's defaults emit ``{"detail": ...}`` bodies, but real OpenAI/Anthropic clients expect provider-specific envelopes, so Unsloth's own client-error responses on ``/v1/*`` are re-wrapped as ``{"error": {"message", "type", "param", "code"}}`` for the OpenAI surface and ``{"type": "error", "error": {"type", "message"}}`` for any path under ``/v1/messages``.
-
-CRITICAL: the handlers installed by :func:`install_api_error_handlers` are global but ONLY transform paths starting with ``/v1/``. Every other path (``/api/...``, frontend routes) reproduces FastAPI's default behavior byte-for-byte, because the frontend depends on the ``{"detail": ...}`` shape for ``/api/*``.
-"""
+"""Re-wrap /v1/* errors in OpenAI or Anthropic envelopes; other paths keep FastAPI's detail shape"""
import math
import re
diff --git a/studio/backend/utils/audio_tokens.py b/studio/backend/utils/audio_tokens.py
index 16ab39b0e5e..96f0625292f 100644
--- a/studio/backend/utils/audio_tokens.py
+++ b/studio/backend/utils/audio_tokens.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Tokenizer-based audio_type classification.
-
-Directly under ``utils`` so the cache scanner can classify a snapshot without
-dragging in ``utils/models/__init__.py`` and the model-config stack.
-"""
+"""Tokenizer-based audio_type; lives in utils so the cache scanner avoids importing utils/models"""
from __future__ import annotations
diff --git a/studio/backend/utils/auth_safe.py b/studio/backend/utils/auth_safe.py
index 1abfdd3f713..c6c882cff3b 100644
--- a/studio/backend/utils/auth_safe.py
+++ b/studio/backend/utils/auth_safe.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Credential-safe urllib redirects. Stdlib-only: the standalone installers import it
-without reaching the rest of the backend."""
+"""Credential-safe urllib redirects; stdlib-only so standalone installers can import it"""
import urllib.parse
import urllib.request
diff --git a/studio/backend/utils/cache_inventory.py b/studio/backend/utils/cache_inventory.py
index 48fdffc0211..803ab1c041a 100644
--- a/studio/backend/utils/cache_inventory.py
+++ b/studio/backend/utils/cache_inventory.py
@@ -1,24 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Size and empty the caches this install fills up, and nothing else.
-
-The API takes a KEY, never a path, and this module is the only thing that turns
-one into a directory, so "may this be deleted" is answered from the resolved
-directory rather than from what was asked for. The rules, in order:
-
-* The key is one of ``CACHE_DEFINITIONS``.
-* Its root is an absolute existing directory, at least two components below the
- filesystem anchor, and neither a symlink nor a Windows junction.
-* It is not, and does not contain, anything in ``protected_paths()``.
-* It does not sit inside anything in ``protected_trees()``.
-* It does not contain another key's root whose own clear is narrower than
- emptying it (``sheltered_roots``).
-* It is emptied, never removed, so nothing recreates it with the wrong
- permissions.
-* A symlink inside it is unlinked rather than followed, and a directory whose
- real path leaves it is skipped.
-"""
+"""Empties (never removes) only CACHE_DEFINITIONS roots, refusing protected paths, protected trees
+and symlink roots; symlinks inside are unlinked, never followed"""
from __future__ import annotations
diff --git a/studio/backend/utils/child_stdio.py b/studio/backend/utils/child_stdio.py
index 58cc4c3e17e..f3c05ec6cd3 100644
--- a/studio/backend/utils/child_stdio.py
+++ b/studio/backend/utils/child_stdio.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Make a Python child agree with the parent that its pipes are UTF-8.
-
-A child's ``sys.stdout`` uses ``locale.getpreferredencoding()``, which on
-Windows is the ANSI code page. Reading that pipe as UTF-8 would then mangle any
-non-ASCII the child prints, so the child has to be told which encoding to emit.
-Only needed for Python children; llama.cpp and node already emit UTF-8.
-"""
+"""Tells Python children to emit UTF-8: on Windows their stdout defaults to the ANSI code page"""
from __future__ import annotations
diff --git a/studio/backend/utils/client_ip.py b/studio/backend/utils/client_ip.py
index 6a097496b9a..5b77753a26b 100644
--- a/studio/backend/utils/client_ip.py
+++ b/studio/backend/utils/client_ip.py
@@ -1,21 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Resolve the caller's IP for rate limiting.
-
-Trust model, in order:
- 1. If the operator opts in via ``UNSLOTH_STUDIO_TRUST_FORWARDED`` (Unsloth behind
- their own reverse proxy), honor the *rightmost* ``X-Forwarded-For`` hop -- the
- one the trusted proxy appended. The leftmost entry is client-controlled and
- spoofable, so this assumes a proxy that appends (or overwrites) the header;
- only enable the env var behind such a proxy.
- 2. A loopback peer relaying Unsloth's own Cloudflare tunnel (``app.state.cloudflare_url``,
- Host naming it): ``CF-Connecting-IP``, set by Cloudflare's edge, so tunnel visitors
- don't share the local cloudflared bucket. Without that tunnel the header is forgeable.
- 3. Any other loopback relay: ``relayed:<peer>``, one bucket per relay, never a local caller.
- 4. Otherwise the socket peer, so a direct LAN caller can't spoof a header to
- dodge a per-IP limit.
-"""
+"""Trust order: rightmost X-Forwarded-For only if UNSLOTH_STUDIO_TRUST_FORWARDED (leftmost is
+spoofable; enable only behind an appending proxy); CF-Connecting-IP only via loopback tunnel;
+relayed:<peer>; socket peer"""
from __future__ import annotations
diff --git a/studio/backend/utils/code_integrity.py b/studio/backend/utils/code_integrity.py
index 0906fdb2274..2db348a5d16 100644
--- a/studio/backend/utils/code_integrity.py
+++ b/studio/backend/utils/code_integrity.py
@@ -1,9 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Recognise a Windows code integrity refusal in a failed process launch.
-
-Smart App Control, WDAC and AppLocker all refuse through the same kernel path.
-"""
+"""Detects Windows code integrity refusals (Smart App Control, WDAC, AppLocker) in failed launches"""
from __future__ import annotations
diff --git a/studio/backend/utils/coding_agents.py b/studio/backend/utils/coding_agents.py
index b3f063456ac..a8bb12fcf61 100644
--- a/studio/backend/utils/coding_agents.py
+++ b/studio/backend/utils/coding_agents.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Detect which `unsloth start <agent>` coding-agent CLIs are on PATH.
-
-The web UI only ever shows the user the "claude" flavor of the `unsloth start`
-command (see agent-command.ts), leaving anyone using Codex, OpenCode, and the
-other supported agents to manually edit the copied command. This module gives
-the frontend a way to ask which of those CLIs are actually installed so it can
-default to one the user can run immediately.
-"""
+"""Detects which unsloth start <agent> CLIs are on PATH so the UI can default to a runnable one"""
import os
import shutil
diff --git a/studio/backend/utils/cuda_driver_prime.py b/studio/backend/utils/cuda_driver_prime.py
index d12a687b1f1..c2f73ac493d 100644
--- a/studio/backend/utils/cuda_driver_prime.py
+++ b/studio/backend/utils/cuda_driver_prime.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Run ``cuInit`` via ctypes (releases the GIL) before torch's first CUDA probe, which holds the GIL for the
-whole multi-second driver init and freezes the event loop. Idempotent; never raises. Concurrent callers wait on an
-Event rather than entering torch's GIL-holding call. ``UNSLOTH_STUDIO_DISABLE_CUDA_PRIME=1`` disables it.
-"""
+"""Early cuInit via ctypes before the torch CUDA probe, releasing the GIL; idempotent, never raises;
+UNSLOTH_STUDIO_DISABLE_CUDA_PRIME=1 disables it"""
from __future__ import annotations
diff --git a/studio/backend/utils/datasets/cache_safe.py b/studio/backend/utils/datasets/cache_safe.py
index 80dc414190e..13e13ff35a6 100644
--- a/studio/backend/utils/datasets/cache_safe.py
+++ b/studio/backend/utils/datasets/cache_safe.py
@@ -1,19 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Permission-safe wrapper around datasets.load_dataset.
-
-A shared HF datasets cache can contain subtrees owned by another user (for
-example populated by an earlier root-run job). datasets then raises
-"[Errno 13] Permission denied: ..._builder.lock" while locking the cached
-builder, killing the training run even though the dataset itself is fine.
-Retry such loads in an Unsloth-owned cache so the run proceeds; the worst case
-is one rebuild of the dataset in the fallback location.
-
-On Windows, huggingface_hub's concurrent symlink capability probe can also
-publish a brief false positive and raise WinError 1314; only then, retry in
-its regular-file cache mode for this worker.
-"""
+"""Retries load_dataset in an Unsloth-owned cache on Errno 13 from a shared HF cache; on Windows,
+only WinError 1314 retries in regular-file cache mode for this worker"""
import logging
import os
diff --git a/studio/backend/utils/datasets/completion_masking.py b/studio/backend/utils/datasets/completion_masking.py
index 83d11e7f635..586064e3acc 100644
--- a/studio/backend/utils/datasets/completion_masking.py
+++ b/studio/backend/utils/datasets/completion_masking.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Completion-only masking policy shared by the CUDA and MLX training paths.
-
-Decides how train_on_responses_only is applied for a model: explicit dataset
-markers when requested, otherwise chat template auto-detection with manual
-TEMPLATE_TO_RESPONSES_MAPPER markers as the fallback. gpt-oss included: its
-quantized checkpoints ship a different chat template, so only detection from
-the actual template is reliable.
-"""
+"""Completion-only masking for CUDA and MLX: explicit dataset markers if requested, else template
+detection with manual markers as fallback; gpt-oss must use detection, not markers"""
from .iterable import is_streaming_dataset
from .model_mappings import (
diff --git a/studio/backend/utils/datasets/model_mappings.py b/studio/backend/utils/datasets/model_mappings.py
index 81a76e19083..84ec18830ba 100644
--- a/studio/backend/utils/datasets/model_mappings.py
+++ b/studio/backend/utils/datasets/model_mappings.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Model and template mappings for dataset processing.
-
-Maps model names to their chat templates and response markers.
-"""
+"""Maps model names to chat templates and response markers for dataset processing."""
TEMPLATE_TO_MODEL_MAPPER = {
"phi-3.5": (
diff --git a/studio/backend/utils/datasets/vlm_processing.py b/studio/backend/utils/datasets/vlm_processing.py
index 1b3744a7f39..ae075cb65bd 100644
--- a/studio/backend/utils/datasets/vlm_processing.py
+++ b/studio/backend/utils/datasets/vlm_processing.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""
-VLM (Vision-Language Model) processing utilities.
-
-Generates smart instructions for VLM datasets via content analysis and
-heuristics.
-"""
+"""VLM dataset utilities that generate instructions from content analysis and heuristics."""
import re
from itertools import islice
diff --git a/studio/backend/utils/debug_log_export.py b/studio/backend/utils/debug_log_export.py
index 0ce17d35b90..078f302d3de 100644
--- a/studio/backend/utils/debug_log_export.py
+++ b/studio/backend/utils/debug_log_export.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Pack every log the viewer may read into one redacted ZIP.
-
-Same allowlist as the picker (`debug_log_sources.list_sources`) through the same
-`redact_log_text`, so the bundle can hold no file, and no credential, the tab
-would not have shown.
-
-The per-family cap upstream bounds FILES, not bytes, and the session log is
-never rotated. Hence two more bounds here, a tail per file and a budget across
-all of them, both cutting from the FRONT: the end of a log explains the problem.
-"""
+"""Packs viewer-readable logs into one redacted ZIP, trimming from the front since log ends matter."""
from __future__ import annotations
diff --git a/studio/backend/utils/debug_log_reader.py b/studio/backend/utils/debug_log_reader.py
index 155555bbe4c..c0f267781d3 100644
--- a/studio/backend/utils/debug_log_reader.py
+++ b/studio/backend/utils/debug_log_reader.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Bounded reads of a log file for the Settings > Logs viewer.
-
-The active session log is never rotated and only pruned at startup (run.py
-retains the newest 20 files), so it can be many GB by the time someone opens
-this. Everything here seeks from the end and reads a bounded window, so cost
-does not scale with file size.
-
-read_tail and read_since return REDACTED lines. The raw reader is private so a
-later caller cannot forget.
-"""
+"""Bounded log-tail reads that seek from the end, so cost ignores file size; output is redacted."""
from __future__ import annotations
diff --git a/studio/backend/utils/desktop_shell_env.py b/studio/backend/utils/desktop_shell_env.py
index be1c0c0ecaa..45baa93ffee 100644
--- a/studio/backend/utils/desktop_shell_env.py
+++ b/studio/backend/utils/desktop_shell_env.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Give the desktop app the ROCm environment a terminal launch already has.
-
-unsloth#9926: ``shell_path::fix_path()`` in src-tauri reads the login shell and
-keeps PATH out of it, dropping every ROCm variable beside it. Parity, not
-policy: only a desktop launch, only an AMD host, only allowlisted names that
-are absent here. Every other launch reads no shell.
-"""
+"""Only desktop launches on AMD hosts copy allowlisted ROCm vars that are absent here from the login
+shell; every other launch reads no shell"""
from __future__ import annotations
diff --git a/studio/backend/utils/diffusers_repair.py b/studio/backend/utils/diffusers_repair.py
index 89814eaae96..2a0681fb6d1 100644
--- a/studio/backend/utils/diffusers_repair.py
+++ b/studio/backend/utils/diffusers_repair.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Startup self-heal for the pinned Diffusers main build, or the pinned release while
-diffusers-main.txt is commented out.
-
-Older installers can miss the pinned build during an update. Repair before importing the app:
-the build also upgrades huggingface_hub, which would otherwise mix new files with cached modules.
-Opt out with UNSLOTH_DISABLE_DIFFUSERS_AUTOREPAIR=1.
-"""
+"""Startup repair of pinned Diffusers before import; UNSLOTH_DISABLE_DIFFUSERS_AUTOREPAIR=1 opts out."""
from __future__ import annotations
diff --git a/studio/backend/utils/download_transport_settings.py b/studio/backend/utils/download_transport_settings.py
index 5dc75fca151..f421ebf3411 100644
--- a/studio/backend/utils/download_transport_settings.py
+++ b/studio/backend/utils/download_transport_settings.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The install's download transport preference: HTTPS, Xet, or Auto.
-
-Stored so the choice follows the install rather than one browser's localStorage. Nothing picked
-means Auto, which is what downloads ran on before this setting existed.
-"""
+"""Download transport (HTTPS, Xet or Auto) saved per install, not browser localStorage; default Auto."""
from __future__ import annotations
diff --git a/studio/backend/utils/first_token_timeout.py b/studio/backend/utils/first_token_timeout.py
index 888cec8844e..6369c61d99f 100644
--- a/studio/backend/utils/first_token_timeout.py
+++ b/studio/backend/utils/first_token_timeout.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Installation-wide local inference wait limit and request-scoped prefill lease.
-
-Infinity represents Unlimited in deadline arithmetic only; socket APIs receive None.
-The mutable wait state crosses asyncio.to_thread's copied context so durable runs can
-renew their lease during an explicitly permitted wait, without disabling orphan cleanup.
-"""
+"""Wait limit and prefill lease; Infinity is unlimited in deadline math, None for sockets; durable
+runs renew the lease during permitted waits without disabling orphan cleanup"""
from __future__ import annotations
diff --git a/studio/backend/utils/forwarded_headers.py b/studio/backend/utils/forwarded_headers.py
index 776f7783948..66f15fcfe78 100644
--- a/studio/backend/utils/forwarded_headers.py
+++ b/studio/backend/utils/forwarded_headers.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which forwarded headers rewrite the ASGI client and scheme.
-
-uvicorn's default (``proxy_headers=True``, ``forwarded_allow_ips="127.0.0.1"``) lets any loopback peer pick
-``request.client`` via ``X-Forwarded-For``, so only Colab and ``UNSLOTH_STUDIO_TRUST_FORWARDED`` keep it;
-otherwise only requests from Studio's own Cloudflare tunnel are rewritten.
-"""
+"""Rewrites client and scheme only for the Studio Cloudflare tunnel, since any loopback peer could
+spoof X-Forwarded-For; only Colab or UNSLOTH_STUDIO_TRUST_FORWARDED keep the default"""
from __future__ import annotations
diff --git a/studio/backend/utils/gguf_archs.py b/studio/backend/utils/gguf_archs.py
index 47c0a28945b..35979ec91c9 100644
--- a/studio/backend/utils/gguf_archs.py
+++ b/studio/backend/utils/gguf_archs.py
@@ -1,18 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The speech-architecture verdict, as a leaf module with no package baggage.
-
-It lives here rather than beside the rest of the GGUF metadata helpers because
-``utils.models.__init__`` eagerly imports ``model_config``, which imports ``yaml``.
-``core.inference.llama_cpp`` needs this verdict at import time, and reaching it through
-``utils.models`` made the whole models package -- and PyYAML with it -- a hard import
-dependency of the chat backend. That took the repo's own Source lint job red, where
-``tests/studio/load_freeze/test_load_orchestrator.py`` imports the backend without PyYAML
-installed.
-
-Every caller imports from here, so there is exactly ONE definition.
-"""
+"""Speech-architecture verdict, single definition; a leaf, so importing it does not pull in PyYAML."""
from __future__ import annotations
diff --git a/studio/backend/utils/gpu_memory_events.py b/studio/backend/utils/gpu_memory_events.py
index f04467fa19f..08517d3fdfb 100644
--- a/studio/backend/utils/gpu_memory_events.py
+++ b/studio/backend/utils/gpu_memory_events.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Generation counter bumped when Studio changes what is resident on the GPUs.
-Import-free so backends can decorate load/unload without pulling in utils.hardware."""
+"""Generation counter bumped when Studio changes GPU residency; import-free to avoid utils.hardware."""
import functools
import threading
diff --git a/studio/backend/utils/happy_eyeballs.py b/studio/backend/utils/happy_eyeballs.py
index 2bee7329633..b5d11458181 100644
--- a/studio/backend/utils/happy_eyeballs.py
+++ b/studio/backend/utils/happy_eyeballs.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""RFC 8305 Happy Eyeballs for sync connects.
-
-``socket.create_connection`` applies ``timeout`` per resolved address, so a black-holed
-family (VPN without IPv6) costs one timeout per address (python/cpython#88810). httpx's
-sync backend and ``http.client`` call it; ``requests`` does not (urllib3 2.x has its own
-loop). Spawned children must re-activate, like :mod:`utils.native_tls`.
-"""
+"""RFC 8305 for sync connects, since create_connection waits a full timeout per black-holed address;
+spawned children must re-activate, like utils.native_tls"""
from __future__ import annotations
diff --git a/studio/backend/utils/hardware/gpu_query.py b/studio/backend/utils/hardware/gpu_query.py
index 64725546637..1fa54e66c30 100644
--- a/studio/backend/utils/hardware/gpu_query.py
+++ b/studio/backend/utils/hardware/gpu_query.py
@@ -1,15 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Cached, coalesced nvidia-smi reads: drop-in for ``subprocess.run`` with a bounded wait.
-
-Categories: ``static`` (inventory fields, TTL 60 s like the eGPU-aware physical inventory),
-``display`` (live fields inside :func:`display_reads`, TTL 3 s, stale-while-revalidate),
-``critical`` (live fields anywhere else: never cached or joined, since another process's
-allocation raises no Studio event). ``subprocess.run(timeout=...)`` waits unboundedly for a
-killed child on a blocked driver, so the child runs on a daemon thread. Failures are never
-served and replace older answers. ``UNSLOTH_GPU_QUERY_CACHE=0`` disables all of this.
-"""
+"""Cached nvidia-smi reads (static 60 s, display 3 s TTL); critical live fields never cached or
+joined; failures never served; UNSLOTH_GPU_QUERY_CACHE=0 disables all"""
from __future__ import annotations
diff --git a/studio/backend/utils/hardware/npu.py b/studio/backend/utils/hardware/npu.py
index ea5ea4aa4d7..e621d3c0f82 100644
--- a/studio/backend/utils/hardware/npu.py
+++ b/studio/backend/utils/hardware/npu.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Detect AMD NPUs without starting a runtime.
-
-XDNA 2 (1022:17f0) is supported unless ``UNSLOTH_STUDIO_ENABLE_NPU=0`` hides it; XDNA 1
-(1022:1502) is not. Runtime readiness is checked separately by ``flm validate``.
-"""
+"""Detects AMD XDNA 2 NPUs (1022:17f0) without starting a runtime; UNSLOTH_STUDIO_ENABLE_NPU=0 hides."""
from __future__ import annotations
diff --git a/studio/backend/utils/hf_endpoint.py b/studio/backend/utils/hf_endpoint.py
index 26e1346c02e..d60c5aa3242 100644
--- a/studio/backend/utils/hf_endpoint.py
+++ b/studio/backend/utils/hf_endpoint.py
@@ -1,19 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Centralised HuggingFace endpoint configuration.
-
-Backend code that constructs HF URLs directly (i.e. *outside* of
-``huggingface_hub`` calls) should use :func:`get_hf_endpoint` instead of
-hard-coding ``https://huggingface.co``. The value is read through
-:func:`utils.utils.hf_endpoint_url` — the single source of truth for
-``HF_ENDPOINT`` parsing — so both entry points stay in lockstep.
-
-The datasets-server base URL is independent from the Hub mirror: most Hub
-mirrors do not proxy the datasets-server API, so a mirrored ``HF_ENDPOINT``
-never implicitly redirects datasets-server traffic. Operators who do run a
-mirrored datasets-server must set ``HF_DATASETS_SERVER`` explicitly.
-"""
+"""Build URLs via get_hf_endpoint; datasets-server ignores HF_ENDPOINT, so only an operator running
+a mirrored datasets-server needs HF_DATASETS_SERVER set"""
from __future__ import annotations
diff --git a/studio/backend/utils/hf_probe.py b/studio/backend/utils/hf_probe.py
index 313d6e39436..4fd9e8a5225 100644
--- a/studio/backend/utils/hf_probe.py
+++ b/studio/backend/utils/hf_probe.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Probe optional Hub files without caching missing entries.
-
-``hf_hub_download`` can leave a ref pointing to a snapshot that is not on disk after a 404, causing
-``scan_cache_dir`` to omit the repo. Metadata requests answer the same question without changing
-the cache.
-"""
+"""Probe optional Hub files via metadata, since hf_hub_download can leave a dangling ref after a 404."""
from __future__ import annotations
diff --git a/studio/backend/utils/hf_xet_fallback.py b/studio/backend/utils/hf_xet_fallback.py
index 034a8ab42fe..bbdcdf074bb 100644
--- a/studio/backend/utils/hf_xet_fallback.py
+++ b/studio/backend/utils/hf_xet_fallback.py
@@ -1,22 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Unsloth shim over the shared ``unsloth_zoo.hf_xet_fallback`` Xet -> HTTP stall fallback.
-
-Re-exports the shared API and injects Unsloth's marker-aware cache purge
-(``prepare_cache_for_transport``) so the download manager keeps its ``.transport``
-marker semantics on the HTTP retry.
-
-Import discipline: ``unsloth_zoo``'s ``__init__`` eagerly imports ``transformers``. The workers
-import this shim at startup (to decide the per-worker Xet env flip) *before* activating the model's
-``transformers`` sidecar. Activation only prepends the sidecar to ``sys.path``, so a ``transformers``
-already cached in ``sys.modules`` (via an eager ``unsloth_zoo`` import here) wins -- pinning the
-default 4.57.x and regressing Qwen3.5 / GLM-4.7 / gemma-4 training with
-``Tokenizer class TokenizersBackend does not exist``. So the shared backend is loaded **lazily**
-(``_load_shared``), only on first use of a heavy download helper, i.e. after the sidecar is active.
-``child_should_disable_xet`` and the ``DEFAULT_*`` constants are defined locally so importing them
-never triggers the heavy load.
-"""
+"""unsloth_zoo Xet fallback shim; loaded lazily so transformers isn't pinned before the model sidecar."""
from __future__ import annotations
diff --git a/studio/backend/utils/host_memory.py b/studio/backend/utils/host_memory.py
index bfd4ed1280c..d3ce9f415c8 100644
--- a/studio/backend/utils/host_memory.py
+++ b/studio/backend/utils/host_memory.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Host RAM this process can use: psutil / meminfo capped by the tightest enforcing cgroup level.
-
-psutil reads the whole machine, so under a container or systemd MemoryMax it admits work the cgroup
-OOM-kills. Torch-free: the polled /api/system route calls it."""
+"""Usable host RAM, capped by cgroup limits since psutil sees the whole machine; torch-free."""
from __future__ import annotations
diff --git a/studio/backend/utils/hub_mirror_probe.py b/studio/backend/utils/hub_mirror_probe.py
index 3ab723046db..bb86b47f1ce 100644
--- a/studio/backend/utils/hub_mirror_probe.py
+++ b/studio/backend/utils/hub_mirror_probe.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Log a warning when a custom Hub endpoint redirects to huggingface.co (hf-mirror.com does outside
-mainland China), which huggingface_hub otherwise follows silently. No token, no redirect followed."""
+"""Warns when a custom Hub endpoint redirects to huggingface.co, which huggingface_hub would follow
+silently; sends no token and follows no redirect"""
from __future__ import annotations
diff --git a/studio/backend/utils/hub_settings.py b/studio/backend/utils/hub_settings.py
index 365f36a9237..d946d955398 100644
--- a/studio/backend/utils/hub_settings.py
+++ b/studio/backend/utils/hub_settings.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The install's model source and Hugging Face endpoint, saved in settings.
-
-The saved values are applied as ``HF_ENDPOINT`` / ``HF_DATASETS_SERVER``, which
-everything in Unsloth -- huggingface_hub, datasets, the browser via /api/health,
-and every worker process spawned afterwards -- already follows. Until the owner
-saves, whatever the operator exported stays in effect; where Hugging Face is
-restricted, with nothing saved or exported, the source defaults to ModelScope.
-ModelScope as the source points ``HF_ENDPOINT`` at the loopback adapter in
-``hub.modelscope``.
-"""
+"""Saved source (HF or ModelScope) sets HF_ENDPOINT and HF_DATASETS_SERVER; operator-exported env
+holds until saved; restricted HF with nothing set defaults to ModelScope"""
from __future__ import annotations
diff --git a/studio/backend/utils/inference/__init__.py b/studio/backend/utils/inference/__init__.py
index 9dc9c087676..63666bae5a0 100644
--- a/studio/backend/utils/inference/__init__.py
+++ b/studio/backend/utils/inference/__init__.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""
-Inference utility functions
-"""
+"""Inference utility functions; exports load_inference_config."""
from utils.inference.inference_config import load_inference_config
diff --git a/studio/backend/utils/kernel_install.py b/studio/backend/utils/kernel_install.py
index 70a5bc1ef42..4486b2da191 100644
--- a/studio/backend/utils/kernel_install.py
+++ b/studio/backend/utils/kernel_install.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Kernel install pieces shared by Studio setup, the training worker, the SSM runtime and
-`unsloth install-kernels [names]`.
-
-Imports only stdlib, wheel_utils and child_stdio so setup and torch-less hosts can import it.
-The CLI is wheel-only (never a source build) and uses --no-deps so torch is never touched.
-"""
+"""Kernel install helpers; imports only stdlib, wheel_utils and child_stdio so torch-less hosts can
+import; CLI is wheel-only with --no-deps"""
from __future__ import annotations
diff --git a/studio/backend/utils/lifespan_shutdown.py b/studio/backend/utils/lifespan_shutdown.py
index 09250451537..6649a7e1bbb 100644
--- a/studio/backend/utils/lifespan_shutdown.py
+++ b/studio/backend/utils/lifespan_shutdown.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Resilient FastAPI lifespan shutdown cleanup.
-
-On an abrupt shutdown (Windows console-close, interpreter teardown racing
-uvicorn) the loop's default executor may already be dead, so an unguarded
-``asyncio.to_thread`` raise here would abort the nested-lifespan unwind and
-surface as "Application shutdown failed". Dependency-injected so it can be
-unit-tested without the heavy backend import graph.
-"""
+"""Shutdown cleanup that tolerates a dead default executor, so asyncio.to_thread cannot abort unwind."""
import asyncio
import contextvars
diff --git a/studio/backend/utils/llama_cpp_source.py b/studio/backend/utils/llama_cpp_source.py
index dcc70702b21..c767dc241dd 100644
--- a/studio/backend/utils/llama_cpp_source.py
+++ b/studio/backend/utils/llama_cpp_source.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""llama.cpp converter sources (convert_lora_to_gguf.py, gguf-py) from the Unsloth fork's releases.
-
-Each unslothai/llama.cpp release carries ``llama.cpp-source-<tag>.tar.gz`` and the
-``llama-prebuilt-sha256.json`` that pins its digest, so no git and no ggml-org download is
-needed. The backend cannot import the studio/ installer scripts (see
-utils/prebuilt/runtime_libs.py), hence this small standalone copy.
-"""
+"""Fetches llama.cpp converter sources from unslothai release tarballs, verified by sha256 manifest."""
from __future__ import annotations
diff --git a/studio/backend/utils/log_redaction.py b/studio/backend/utils/log_redaction.py
index 5e70c07c077..c8240078b8e 100644
--- a/studio/backend/utils/log_redaction.py
+++ b/studio/backend/utils/log_redaction.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Mask credentials in log text before it leaves the process.
-
-Nothing redacts secrets today: loggers/handlers.py:filter_sensitive_data only masks native path leases, and raw output (faulthandler dumps, uvicorn, third party prints) never passes through a structlog processor at all. The log viewer invites users to copy lines into a bug report, so the masking happens on read.
-
-Every pattern is anchored on a known credential prefix or a key name. There is deliberately NO generic "long high entropy string" rule: that would eat sha256 blob digests, HF revisions, snapshot paths and GGUF tensor names, exactly the content someone opened the log to read.
-"""
+"""Masks credentials in logs on read; anchored on known prefixes or key names, never generic entropy."""
from __future__ import annotations
diff --git a/studio/backend/utils/log_retention.py b/studio/backend/utils/log_retention.py
index 7b0b788f019..0a7cdeb4a0c 100644
--- a/studio/backend/utils/log_retention.py
+++ b/studio/backend/utils/log_retention.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep-newest-N retention for the per-session log directories.
-
-The server session log has capped itself since it was added; the llama-server and
-diffusion-server subprocess logs beside it never did, so they accumulated one file per
-model load for the life of the install (319 files going back two months on the machine
-this was found on). One helper so a fourth log directory cannot quietly opt out again.
-"""
+"""Keep-newest-N pruning for all per-session log directories, so a new one cannot quietly opt out."""
from __future__ import annotations
diff --git a/studio/backend/utils/model_aliases.py b/studio/backend/utils/model_aliases.py
index c57dd2562dd..964ffb64fa2 100644
--- a/studio/backend/utils/model_aliases.py
+++ b/studio/backend/utils/model_aliases.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Owner-defined, install-wide model aliases (``fast-chat`` -> a real model id) for API clients.
-
-Resolved once at the ASGI edge, so access checks, auto-switch and the resolver all see the real
-id: an alias never grants what its target would not. Names exclude ``/`` and ``:`` so they can
-never shadow a repo id or a ``model:quant`` pin."""
+"""Install-wide model aliases resolved once at the ASGI edge, before access checks; never grant more
+than the target; names exclude / and :"""
from __future__ import annotations
diff --git a/studio/backend/utils/model_memory_settings.py b/studio/backend/utils/model_memory_settings.py
index 2c5937d06cf..126e9deeb0b 100644
--- a/studio/backend/utils/model_memory_settings.py
+++ b/studio/backend/utils/model_memory_settings.py
@@ -1,18 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Persisted model-memory residency controls.
-
-``keep_resident`` -- weights never go back to system RAM while loaded: no idle
-auto-unload, and ``--mlock`` so the OS cannot page them out and re-fault them in.
-
-``no_ram_reserve`` -- avoids locked or reserved weight buffers. Uses DirectIO on
-supported Windows builds when full GPU offload is confirmed, otherwise keeps
-llama.cpp's default mmap path. Required CPU buffers can still use host RAM.
-
-Both on means "live in VRAM, keep no RAM copy, never idle-unload". ``--mlock`` is
-itself a full-model RAM reservation, so ``no_ram_reserve`` wins on that flag.
-"""
+"""keep_resident: weights never return to system RAM while loaded, no idle auto-unload, --mlock;
+no_ram_reserve avoids locked or reserved weight buffers; both on = VRAM only, and no_ram_reserve
+wins over --mlock."""
from __future__ import annotations
diff --git a/studio/backend/utils/model_sampling_defaults.py b/studio/backend/utils/model_sampling_defaults.py
index c50f4637c4a..525a7640f1a 100644
--- a/studio/backend/utils/model_sampling_defaults.py
+++ b/studio/backend/utils/model_sampling_defaults.py
@@ -1,9 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Per-model sampling defaults a user saved; a request that leaves a field unset gets them before the
-model's recommendation. Not stored in the launch overrides: a row there counts as a load override
-and shadows a broader one."""
+"""Saved per-model sampling defaults fill unset request fields before the model's recommendation;
+kept out of launch overrides, where a row would count as a load override and shadow broader ones."""
from __future__ import annotations
diff --git a/studio/backend/utils/models/diffusion_lm.py b/studio/backend/utils/models/diffusion_lm.py
index 6f13aefca5c..90027f4b2c7 100644
--- a/studio/backend/utils/models/diffusion_lm.py
+++ b/studio/backend/utils/models/diffusion_lm.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Text-diffusion language models (LLaDA, Dream, SDAR, DiffusionGemma, ...), detected from config.json alone.
-
-Torch-free mirror of the profile matching in ``unsloth/models/diffusion_profiles.py``; same names, same
-order (a profile's ``model_types`` and ``architectures`` are both tried before the next profile, and
-LLaDA-MoE precedes LLaDA because both report ``model_type = "llada"``). ``test_diffusion_lm_studio.py``
-keeps the two in sync. Not to be confused with Studio's image / video diffusion pipelines.
-"""
+"""Diffusion LM detection; torch-free mirror of diffusion_profiles.py, keep LLaDA-MoE before LLaDA."""
from pathlib import Path
from typing import Mapping, Optional
diff --git a/studio/backend/utils/models/drafters/__init__.py b/studio/backend/utils/models/drafters/__init__.py
index 82b182671fc..02f23bf6e89 100644
--- a/studio/backend/utils/models/drafters/__init__.py
+++ b/studio/backend/utils/models/drafters/__init__.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Speculative drafter discovery, ranking and budgeting.
-
-One home for the rules a drafter sidecar obeys. Import from this facade rather
-than from the submodules, so the internal split can change without touching
-every call site.
-"""
+"""Speculative drafter discovery, ranking and budgeting facade; import from here, not submodules."""
from utils.models.drafters.common import (
_drafter_launch_path,
diff --git a/studio/backend/utils/models/drafters/budget.py b/studio/backend/utils/models/drafters/budget.py
index 8e6e2736e66..3fe631d3c57 100644
--- a/studio/backend/utils/models/drafters/budget.py
+++ b/studio/backend/utils/models/drafters/budget.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""What a drafter costs the training coexistence guard.
-
-The guard admits an inference load only if it fits beside a running training
-job, so it has to price the drafter that load will actually make resident. It
-sees a repository listing, never a header, which is what makes this its own
-problem rather than a detail of discovery: the rules that decide WHICH sidecar
-lands cannot all be evaluated here, so the budget bounds them instead.
-"""
+"""Drafter cost for the training coexistence guard; sees only repo listings, so it bounds the sidecar."""
from typing import Callable, Mapping
diff --git a/studio/backend/utils/models/drafters/preference.py b/studio/backend/utils/models/drafters/preference.py
index 4d60afb14aa..72b9ea203a0 100644
--- a/studio/backend/utils/models/drafters/preference.py
+++ b/studio/backend/utils/models/drafters/preference.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Ranking keys that decide which sidecar a load prefers.
-
-The download, the snapshot reuse and the offline cache lookup share them, so a
-repo resolves the same way whichever reaches it first. The local scan does not:
-detect_mtp_file ranks size-first (``_smallest_first``) because a folder holding
-several copies costs disk, while these rank speed-first because the hub path is
-choosing what to spend a download on. Same family, sometimes a different copy.
-"""
+"""Hub download, snapshot and offline lookup rank speed-first; detect_mtp_file ranks size-first."""
from pathlib import Path
from typing import Iterable, Optional
diff --git a/studio/backend/utils/models/gguf_metadata.py b/studio/backend/utils/models/gguf_metadata.py
index 2d336009d76..5b25658e09c 100644
--- a/studio/backend/utils/models/gguf_metadata.py
+++ b/studio/backend/utils/models/gguf_metadata.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""``general.*`` reader for GGUF headers, used by ``detect_mmproj_file`` to
-pair weights and projectors via ``general.base_model.0.repo_url``."""
+"""GGUF general.* reader; detect_mmproj_file pairs projectors via general.base_model.0.repo_url."""
from __future__ import annotations
diff --git a/studio/backend/utils/multi_model_settings.py b/studio/backend/utils/multi_model_settings.py
index 1c4c4d7d924..75bf4dbdd68 100644
--- a/studio/backend/utils/multi_model_settings.py
+++ b/studio/backend/utils/multi_model_settings.py
@@ -1,16 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Persisted "Keep multiple models loaded" mode: off, fit (When they fit) or always.
-
-The setting belongs to the installation, so it is always read and written in the owner's
-database. Each account has its own studio.db, and a managed account reading its own would
-see the default and unload the owner's kept models.
-
-Older builds stored only the ``keep_multiple_models_loaded`` bool. The bool still decides
-on or off, and ``multi_model_mode`` only tells When they fit from Always, so an older build
-that turns the setting off wins after an upgrade.
-"""
+"""Off/fit/always multi-model mode in owner's DB; legacy keep_multiple_models_loaded can force off."""
from __future__ import annotations
diff --git a/studio/backend/utils/native_path_leases.py b/studio/backend/utils/native_path_leases.py
index 67792910a24..daaa8ac06f4 100644
--- a/studio/backend/utils/native_path_leases.py
+++ b/studio/backend/utils/native_path_leases.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Verification for Tauri native path signed grants.
-
-Rust signs compact ``base64url(payload_json).base64url(hmac)`` grants. The
-frontend can see and forward the grant, but cannot change it without breaking
-the HMAC. The backend verifies the original payload segment bytes, then
-re-stats the path before any native read.
-"""
+"""Verifies Tauri native path grants: HMAC over the original payload bytes, then re-stats the path."""
from __future__ import annotations
diff --git a/studio/backend/utils/native_tls.py b/studio/backend/utils/native_tls.py
index 852e3359169..16ae51ad25a 100644
--- a/studio/backend/utils/native_tls.py
+++ b/studio/backend/utils/native_tls.py
@@ -1,26 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Verify TLS against the OS trust store (corporate TLS-inspection proxies).
-
-Python's ``ssl`` trusts only certifi's roots, so behind a TLS-inspecting proxy (Cisco Umbrella, Zscaler, Netskope) every huggingface.co request fails with ``CERTIFICATE_VERIFY_FAILED``: the proxy re-signs traffic with a corporate CA that lives only in the OS store. A shell user can export ``SSL_CERT_FILE``, but GUI launches (macOS ``.app``, desktop shortcuts) never read shell profiles.
-
-``truststore.inject_into_ssl()`` makes ``ssl.SSLContext`` verify against the OS store instead, the runtime counterpart of ``UV_NATIVE_TLS`` in install.sh. Injection is process-wide but does not survive a spawn, so every network-touching entry point calls :func:`activate_native_tls` before its first TLS connection; the ``python -c`` probes and the standalone prebuilt installers carry an inline copy of the gating because they cannot import backend modules.
-
-truststore is vendored at ``backend/vendor/`` rather than depended on, so no Unsloth user gains a package for a proxy they do not have (see the README there). Every consumer appends that directory to ``sys.path`` and imports the top-level name, which keeps a truststore the user installed themselves in front of ours.
-
-On by default for macOS and Windows, and on Linux only for the desktop app's own
-backend (#9218); a headless ``unsloth studio`` keeps the
-``UNSLOTH_STUDIO_NATIVE_TLS=1`` opt-in, since distro OpenSSL configurations vary
-and an operator in a shell can export it. ``0`` opts out anywhere.
-
-``SSL_CERT_FILE``/``REQUESTS_CA_BUNDLE`` stay exclusive, not additive: httpx
-builds its context from ``SSL_CERT_FILE`` alone, so pointing it at a private CA
-still costs you the public roots and the Hub with them. Install the CA in the OS
-store instead, which is what this module then reaches.
-
-Client side only: the injected class verifies a peer chain on every handshake, so an ``SSLContext`` built after activation cannot serve TLS. Unsloth serves plain HTTP on loopback and ``test_native_tls_entrypoints.py`` keeps it that way; a future in-process HTTPS listener needs ``truststore.SSLContext`` for outbound connections instead of this process-wide injection.
-"""
+"""Uses OS trust store for TLS-inspecting proxies; headless Linux needs UNSLOTH_STUDIO_NATIVE_TLS=1."""
from __future__ import annotations
diff --git a/studio/backend/utils/paths/file_manager.py b/studio/backend/utils/paths/file_manager.py
index bfaf9a30b8a..14a8df03fe2 100644
--- a/studio/backend/utils/paths/file_manager.py
+++ b/studio/backend/utils/paths/file_manager.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Which file manager ``reveal_in_file_manager`` would open on this host, if any.
-
-Reported by ``/api/health`` so the UI offers Reveal only where it can show something to the person
-at the machine, and names it the way the platform does. A loopback URL is not enough on its own: an
-SSH port-forward, a container or a headless server all look like localhost to the browser.
-"""
+"""Local file manager for reveal_in_file_manager, from /api/health; loopback alone is not enough."""
from __future__ import annotations
diff --git a/studio/backend/utils/paths/relocations.py b/studio/backend/utils/paths/relocations.py
index b191f83a0e5..be1635c1640 100644
--- a/studio/backend/utils/paths/relocations.py
+++ b/studio/backend/utils/paths/relocations.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Folders the installation owner moved a kind of file to (Settings > Library > Files on disk).
-
-Only the owner's folders move: a managed account keeps every file in its private workspace, so a
-choice is read in the owner context alone. Kept in the owner's app settings and cached, since the
-galleries resolve their folder on every file lookup.
-"""
+"""Owner-only folder moves per file kind; managed accounts keep files in their private workspace."""
from __future__ import annotations
diff --git a/studio/backend/utils/pid_records.py b/studio/backend/utils/pid_records.py
index e4a9a6668b5..1a6e33a3530 100644
--- a/studio/backend/utils/pid_records.py
+++ b/studio/backend/utils/pid_records.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Line four adds clock-stable linux:<boot_id>:<start_ticks>; keep the first three
-lines backward compatible and the Rust reader in process_identity.rs aligned.
-"""
+"""PID record line 4 is linux:<boot_id>:<start_ticks>; keep lines 1-3 compatible, Rust reader aligned."""
from __future__ import annotations
diff --git a/studio/backend/utils/prebuilt/__init__.py b/studio/backend/utils/prebuilt/__init__.py
index c41cd1150d3..34a8d210994 100644
--- a/studio/backend/utils/prebuilt/__init__.py
+++ b/studio/backend/utils/prebuilt/__init__.py
@@ -1,11 +1,4 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Backend-importable prebuilt helpers.
-
-The installers reuse install_llama_prebuilt.py directly; this package holds the
-backend-side shapes the studio/ scripts cannot provide (the backend runs with
-studio/backend as its sys.path root): runtime_libs (wheel CUDA dirs), child_env
-(secret scrubbing + WSL ROCm dirs), freshness_flow and update_flow (the shared
-mechanics behind the *_cpp_freshness / *_cpp_update twins).
-"""
+"""Backend-side prebuilt helpers; the studio/ installer scripts are not importable from the backend."""
diff --git a/studio/backend/utils/prebuilt/child_env.py b/studio/backend/utils/prebuilt/child_env.py
index ba12c27bb57..6f0d851bf07 100644
--- a/studio/backend/utils/prebuilt/child_env.py
+++ b/studio/backend/utils/prebuilt/child_env.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Child-process environment hygiene for the managed ggml servers.
-
-Secret-env scrubbing and the WSL2 ROCm library-dir probe, shared by the STT
-sidecar (and any future launcher of a downloaded binary). Kept in sync with
-install_llama_prebuilt.py's scrub_env / _wsl_system_rocm_lib_dirs; the backend
-cannot import the studio/ installer scripts, so this copy stays importable with
-only the backend root on sys.path.
-"""
+"""Secret-env scrubbing and WSL2 ROCm lib dirs for managed ggml servers; synced with
+install_llama_prebuilt.py; must stay importable with only the backend root on sys.path."""
from __future__ import annotations
diff --git a/studio/backend/utils/prebuilt/runtime_libs.py b/studio/backend/utils/prebuilt/runtime_libs.py
index 1a5a541f2f5..ab45dc54f8c 100644
--- a/studio/backend/utils/prebuilt/runtime_libs.py
+++ b/studio/backend/utils/prebuilt/runtime_libs.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""CUDA runtime dirs the loader does not find on its own (Python wheels, privately vendored dirs).
-
-Kept in sync with install_llama_prebuilt.py's python_runtime_dirs and
-prebuilt_core.py's linux_runtime_dirs_for_required_libraries; the backend cannot
-import the studio/ installer scripts, so this small copy stays importable with
-only the backend root on sys.path.
-"""
+"""CUDA runtime dirs the loader misses; synced with install_llama_prebuilt.py and prebuilt_core.py;
+must stay importable with only the backend root on sys.path."""
from __future__ import annotations
diff --git a/studio/backend/utils/preview_rate_limit.py b/studio/backend/utils/preview_rate_limit.py
index 8c22cd5b051..81c66d50b72 100644
--- a/studio/backend/utils/preview_rate_limit.py
+++ b/studio/backend/utils/preview_rate_limit.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Coarse per-IP sliding-window rate limit for the public ``/p`` preview chat.
-
-A signed link stops ref guessing, but anyone with a link can still drive GPU
-generation. This bounds sustained abuse from a single source. In-process and
-single-worker only (like the login limiter in ``routes/auth.py``); Unsloth runs as
-one uvicorn process, so a shared store isn't needed.
-"""
+"""Per-IP sliding-window rate limit for the public /p preview chat; in-process, single-worker only."""
from __future__ import annotations
diff --git a/studio/backend/utils/process_lifetime.py b/studio/backend/utils/process_lifetime.py
index 7e8c5c6ee17..56f5d77febb 100644
--- a/studio/backend/utils/process_lifetime.py
+++ b/studio/backend/utils/process_lifetime.py
@@ -1,27 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Bind Unsloth child processes to the parent's lifetime so none survive an
-abnormal parent exit (terminal-window close, Task Manager "End Task", SIGKILL,
-crash) -- the cooperative shutdown path only runs on graceful exits.
-
-Windows: one parent-owned Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE.
-The parent is assigned to it, children inherit it automatically, and the OS
-reaps every process in the job when the parent's last handle closes. Mirrors the
-desktop app's job in studio/src-tauri/src/windows_job.rs.
-
-POSIX: each long-lived child sets prctl(PR_SET_PDEATHSIG) on Linux via a tiny
-preexec hook. Linux's signal is per-direct-child only, so multiprocessing
-workers are also tracked for terminate_all.
-
-macOS has neither mechanism, so tracked children are also recorded on disk and
-the next startup sweeps whatever the previous run left behind
-(reap_recorded_children). That record is the only reaper macOS has after a
-crash, a Force Quit or a closed terminal.
-
-Best-effort throughout: any failure degrades to today's behavior, never raises.
-Stdlib only.
-"""
+"""Kills Unsloth children when the parent dies abnormally (Job Object, PDEATHSIG, macOS disk record
+swept at startup); best-effort, never raises; stdlib only."""
from __future__ import annotations
diff --git a/studio/backend/utils/region.py b/studio/backend/utils/region.py
index 35f974cb82c..7e5f8dc6052 100644
--- a/studio/backend/utils/region.py
+++ b/studio/backend/utils/region.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Whether this host is in a region where Hugging Face is restricted, decided as install.sh /
-install.ps1 decide it: no network call. Mainland China is the one such region today."""
+"""Host region check (Mainland China today), same rule as install.sh/install.ps1; no network call."""
from __future__ import annotations
diff --git a/studio/backend/utils/security/__init__.py b/studio/backend/utils/security/__init__.py
index 6fc6cbce2b1..2b8c4e12716 100644
--- a/studio/backend/utils/security/__init__.py
+++ b/studio/backend/utils/security/__init__.py
@@ -1,16 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Security helpers for the ``trust_remote_code`` boundary.
-
-Two orthogonal questions: ``trusted_org.is_trusted_org_repo`` (may we AUTO-enable
-remote code for this name?) and ``remote_code_scan`` (WHAT would run if the user
-opts in?). The load paths try ``trust_remote_code=False`` first and, on the
-transformers "requires trust_remote_code" error, scan the repo's ``auto_map``,
-surface findings + a pinning fingerprint, and require explicit consent before
-retrying with it enabled. Detection (is-vision / version / size) reads raw
-``config.json`` and never enters this flow.
-"""
+"""trust_remote_code boundary: trusted_org gates auto-enable; remote_code_scan lists what would run;
+explicit consent required before retrying with it enabled; detection reads raw config."""
from utils.security.consent import ( # noqa: F401
RemoteCodeDecision,
diff --git a/studio/backend/utils/security/consent.py b/studio/backend/utils/security/consent.py
index c4ee7105300..2f0d8f8b14e 100644
--- a/studio/backend/utils/security/consent.py
+++ b/studio/backend/utils/security/consent.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Consent gate for loads that would execute model repo code.
-
-The LOAD-path counterpart to the capability probes (which read raw config and never need remote code). A deliberate load calls ``evaluate_remote_code_consent`` right before passing ``trust_remote_code=True``, and decides by the severity of a static scan of the repo's ``auto_map`` ``.py``: no ``auto_map`` in any config (model/tokenizer/processor) means nothing runs, so allow; CRITICAL (reverse shell, IMDS, credential theft, droppers) is a hard block, never approvable even first-party, defending a compromised trusted repo; HIGH/MEDIUM (subprocess/exec/eval/network/b64decode, or a large embedded blob) blocks but is user-approvable, with the dialog pinning approval to the scanned ``fingerprint``, for EVERY repo since first-party is not a blanket bypass; an ``auto_map`` present but unscannable (gated/offline/listing failure) fails closed as a hard block, since unseen code cannot be verified or fingerprinted.
-
-Hardening plus consent, not a sandbox: static patterns are evadable, so subprocess / venv isolation remains the containment layer.
-"""
+"""Remote-code consent: CRITICAL always blocks; HIGH/MEDIUM need approval; unscannable fails closed."""
import os
from dataclasses import dataclass, field
diff --git a/studio/backend/utils/security/dataset_media.py b/studio/backend/utils/security/dataset_media.py
index 482d85006f0..f80b864672a 100644
--- a/studio/backend/utils/security/dataset_media.py
+++ b/studio/backend/utils/security/dataset_media.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Keep a managed account's dataset media to files it may read, and validate Arrow data files.
-
-Media decoders open a cell's ``path`` locally or fetch Hub URLs with the server's token as fallback, so for a
-managed account local paths must be readable by it (extracted archive members only via a recorded, readable
-source archive), Hub URLs use only a caller-supplied token, and other URLs are refused. ``.arrow`` tables are
-validated in full because pyarrow's IPC reader trusts declared offsets. ``install()`` patches lazily, idempotent.
-"""
+"""Managed-account dataset media limited to readable local paths and Hub URLs with caller token
+only; other URLs refused; .arrow fully validated; install() lazy, idempotent."""
import functools
import importlib.abc
diff --git a/studio/backend/utils/security/hub_data_files.py b/studio/backend/utils/security/hub_data_files.py
index 98c0582d3a0..2bafcae0d8d 100644
--- a/studio/backend/utils/security/hub_data_files.py
+++ b/studio/backend/utils/security/hub_data_files.py
@@ -1,18 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Refuse Hub dataset cards that point at host files.
-
-datasets joins a card's relative ``data_files`` and ``data_dir`` to the repo (``hf://datasets/<repo>@<rev>``)
-but keeps an absolute path, a ``file://`` / ``local://`` URL or an absolute ``data_dir`` as given, so a Hub
-repo whose README lists ``/home/owner/private.csv`` makes ``load_dataset("org/repo")`` read that host file.
-No real card does that, and it would let anyone who can name a Hub dataset to Studio read host files
-through a preview or a load. A Hub card may name relative paths and hf / http(s) URLs only, and for a managed
-account hf only: an http(s) URL makes the server dial wherever the card says (a redirect included), which would let
-a managed account read loopback, LAN or cloud metadata services the rest of Studio keeps from it.
-
-``install()`` patches ``datasets`` once it is imported, without importing it at startup; it is idempotent.
-"""
+"""Refuses Hub cards whose data_files or data_dir point at host paths or file:// URLs; managed
+accounts hf:// only; install() patches datasets lazily, never at startup, idempotent."""
import functools
import importlib.abc
diff --git a/studio/backend/utils/security/remote_code_approvals.py b/studio/backend/utils/security/remote_code_approvals.py
index b3643c1e454..e07b03c4c24 100644
--- a/studio/backend/utils/security/remote_code_approvals.py
+++ b/studio/backend/utils/security/remote_code_approvals.py
@@ -1,15 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Persistent, per-user trust_remote_code approval cache.
-
-Remembers a user's explicit approval so the consent gate can skip only the DIALOG on a
-later load of the SAME unchanged code. The gate ALWAYS re-scans (the cache never skips the
-scan), so CRITICAL is hard-blocked every time and a hand-edited store cannot auto-approve
-malicious code. Keyed per subject; honored only when the content fingerprint matches AND
-the scanner-rules version matches AND (when resolvable) the commit SHA matches. CRITICAL is
-never stored or honored, and any store/SHA error degrades to "ask again", never auto-approve.
-"""
+"""Per-user approval cache skips only the dialog, honored only on matching fingerprint, rules
+version and SHA; gate always re-scans, never stores CRITICAL; errors mean ask again, never auto-
+approve."""
from __future__ import annotations
diff --git a/studio/backend/utils/security/trusted_org.py b/studio/backend/utils/security/trusted_org.py
index b43cc4e27d1..f100822506d 100644
--- a/studio/backend/utils/security/trusted_org.py
+++ b/studio/backend/utils/security/trusted_org.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Trusted-org checks for the ``trust_remote_code`` auto-enable paths.
-
-A bare ``name.startswith("unsloth/")`` is spoofable by a local path like
-``./unsloth/evil``. ``is_trusted_org_repo`` rejects local paths, requires an
-``org/repo`` under a trusted org, and (online) confirms via the Hub. Fails CLOSED
-on any uncertainty and never raises; a False just means "do not auto-enable".
-"""
+"""Trusted-org check for remote-code auto-enable; rejects local paths, fails closed on any
+uncertainty, never raises; a bare name prefix is spoofable."""
from __future__ import annotations
diff --git a/studio/backend/utils/sentencepiece_guard.py b/studio/backend/utils/sentencepiece_guard.py
index 51855c93899..1814958f297 100644
--- a/studio/backend/utils/sentencepiece_guard.py
+++ b/studio/backend/utils/sentencepiece_guard.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Studio's spelling of the Windows sentencepiece rule in unsloth/import_fixes.py.
-
-Studio cannot reach that one by importing unsloth: that runs unsloth/__init__.py, whose GPU
-branch pulls torch, Triton, transformers and the model stack into processes built to stay
-light, and can open a competing GPU context. So the rule lives here, stdlib only, importable
-at the very top of any Studio process. tests/test_windows_no_sentencepiece.py drives both
-spellings through the same cases.
-"""
+"""Stdlib-only copy of unsloth/import_fixes.py's Windows sentencepiece rule; avoids the GPU stack."""
import os
import sys
diff --git a/studio/backend/utils/ssm_runtime.py b/studio/backend/utils/ssm_runtime.py
index cf7079e1629..341780d06b6 100644
--- a/studio/backend/utils/ssm_runtime.py
+++ b/studio/backend/utils/ssm_runtime.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Auto-install the SSM/Mamba kernels a hybrid model lazy-imports during ``from_pretrained``;
-the inference-path counterpart of the training worker's install.
-"""
+"""Auto-installs SSM/Mamba kernels that hybrid models lazy-import during from_pretrained."""
from __future__ import annotations
diff --git a/studio/backend/utils/stall_watchdog.py b/studio/backend/utils/stall_watchdog.py
index c96d3beb2b6..7ae38caa87f 100644
--- a/studio/backend/utils/stall_watchdog.py
+++ b/studio/backend/utils/stall_watchdog.py
@@ -1,14 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Dump every thread's stack from inside the backend while its event loop is stalled (#9712).
-
-Two capture paths. Loop stuck with the GIL free: the watchdog thread counts consecutive slow
-no-op probes and dumps from Python. GIL held: no Python thread runs, so each beat re-arms
-``faulthandler.dump_traceback_later`` as a dead man's switch; its C timer thread dumps without
-the GIL. Off unless UNSLOTH_STUDIO_STALL_WATCHDOG=1. Dumps go to the stderr fd (below run.py's
-tee). Assumes it is the only user of faulthandler's process-global delayed-dump timer.
-"""
+"""Stack dump on backend stall, opt-in via UNSLOTH_STUDIO_STALL_WATCHDOG=1; uses faulthandler's
+process-global dump timer, so it must be the only user of that timer."""
from __future__ import annotations
diff --git a/studio/backend/utils/studio_tls.py b/studio/backend/utils/studio_tls.py
index 4112910a930..aa7c2d800e3 100644
--- a/studio/backend/utils/studio_tls.py
+++ b/studio/backend/utils/studio_tls.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""HTTPS served by Studio itself from a user-supplied certificate and key (``--ssl-certfile`` / ``--ssl-keyfile``).
-
-Studio still calls its own ``/v1`` (data recipes, research runs) from children that cannot be told to trust a
-private certificate, so a TLS launch also serves plain HTTP on an ephemeral ``127.0.0.1`` port for those
-self-calls; :func:`loopback_http_port` names it.
-"""
+"""HTTPS from user-supplied --ssl-certfile/--ssl-keyfile; a TLS launch also serves plain HTTP on an
+ephemeral 127.0.0.1 port (loopback_http_port) for Studio's own /v1 self-calls from children that
+cannot trust the cert."""
from __future__ import annotations
diff --git a/studio/backend/utils/torch_device_probe.py b/studio/backend/utils/torch_device_probe.py
index 435d4d4b3a8..319a1d6b778 100644
--- a/studio/backend/utils/torch_device_probe.py
+++ b/studio/backend/utils/torch_device_probe.py
@@ -1,10 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Probe torch allocation in a child so driver crashes do not kill the backend.
-
-Only a child that ran cleanly to the end marks an accelerator usable: a crash, a hang, a kill and a probe that could not run or be read all leave it unusable, since the allocation this stands in front of ends the process rather than raising. Ordinary Python errors are the exception, because the child ran and reported, so the in-process loader raises the same error and describes it better. CPU takes the opposite default, since it cannot fault a driver and condemning it would change the embedding backend. Set ``UNSLOTH_STUDIO_DISABLE_DEVICE_PROBE=1`` to skip the probe.
-"""
+"""Probes torch allocation in a child so a driver crash cannot kill the backend; only a clean exit
+marks an accelerator usable (crash, hang, kill or unreadable result does not), Python errors
+aside. CPU is never condemned. UNSLOTH_STUDIO_DISABLE_DEVICE_PROBE=1 skips it."""
from __future__ import annotations
diff --git a/studio/backend/utils/torch_warmup.py b/studio/backend/utils/torch_warmup.py
index 96af7fa9f41..c17930db40e 100644
--- a/studio/backend/utils/torch_warmup.py
+++ b/studio/backend/utils/torch_warmup.py
@@ -1,12 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Import the ML stack on a background thread while the backend finishes booting.
-
-Started from the LAST line of main.py's lifespan: everything above is on the critical path to binding the socket and would contend for the GIL, and uvicorn binds as soon as the lifespan returns, so the warm overlaps serving rather than boot. Idempotent, never fatal (a failed stage is logged, left cold and retried by whoever needs it), and never half-initialised, since stages delegate to the module owning the cache.
-
-This does NOT make torch-dependent endpoints cheap while it runs: anything reaching get_device() blocks until the hardware stage finishes, so `async def` handlers there must use asyncio.to_thread.
-"""
+"""Imports the ML stack on a background thread, started last in main.py's lifespan so it overlaps
+serving; idempotent, never fatal, never half-initialised; torch endpoints block on get_device()
+until hardware stage ends, so async handlers must use asyncio.to_thread."""
from __future__ import annotations
diff --git a/studio/backend/utils/transformers_dtype.py b/studio/backend/utils/transformers_dtype.py
index 6b976e8baea..9443544a2c4 100644
--- a/studio/backend/utils/transformers_dtype.py
+++ b/studio/backend/utils/transformers_dtype.py
@@ -1,25 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Version-safe fp-dtype kwarg for transformers/sentence-transformers loads.
-
-transformers renamed the ``torch_dtype`` kwarg to ``dtype`` in 4.56.0, and emits
-``torch_dtype is deprecated! Use dtype instead!`` when the old name is passed. But our floor (``transformers>=4.51.3``) predates ``dtype`` and only
-accepts ``torch_dtype``, so a bare rename would ``TypeError`` on the floor. Pick
-the name the installed version accepts instead.
-
-Answers the same question as ``unsloth_zoo.hf_utils.HAS_TORCH_DTYPE`` but derives
-it independently, for two reasons. It uses a ``packaging.version`` check rather
-than that constant's ``"torch_dtype" in PretrainedConfig.__doc__`` sniffing, which
-raises ``TypeError`` under ``python -OO`` / ``PYTHONOPTIMIZE=2`` (docstrings are
-stripped to ``None``, and ``"torch_dtype" in None`` is a type error). And it avoids
-importing the constant at all: the RAG
-embedder warms here at startup in the lean main process, and reading it would run
-``unsloth_zoo``'s package ``__init__`` (torch import, GPU/Pytorch checks, the
-patching banner) as a side effect. The embedder is deliberately torch-optional (it
-degrades to the ``llama-server`` GGUF backend), so it must not drag in that
-heavyweight import just to read one bool.
-"""
+"""Picks the fp dtype kwarg the installed transformers accepts: torch_dtype before 4.56.0 (the
+4.51.3 floor needs it), dtype after. Avoids unsloth_zoo's HAS_TORCH_DTYPE, which breaks under
+python -OO and whose import runs a torch-importing __init__."""
from functools import lru_cache
diff --git a/studio/backend/utils/transformers_latest.py b/studio/backend/utils/transformers_latest.py
index 62b132128e9..114315946f9 100644
--- a/studio/backend/utils/transformers_latest.py
+++ b/studio/backend/utils/transformers_latest.py
@@ -1,38 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Latest-transformers support check for brand-new model architectures.
-
-When a model's ``model_type`` is absent from every installed transformers overlay
-(base 4.57.x plus the .venv_t5_530/550/510 sidecars and, if provisioned, .venv_t5_latest),
-Unsloth cannot load it today. This module answers, without authentication, code execution,
-or trust_remote_code:
-
- 1. Does the LATEST transformers release on PyPI ship this ``model_type``?
- 2. Does transformers ``main`` on GitHub ship it (installable from main after consent)?
-
-Sources (all unauthenticated; raw.githubusercontent.com is not API rate-limited and
-api.github.com is deliberately never used):
- - https://pypi.org/pypi/transformers/json -> latest release version
- - https://raw.githubusercontent.com/huggingface/transformers/{ref}/src/transformers/
- models/auto/configuration_auto.py + auto_mappings.py -> CONFIG_MAPPING_NAMES
-
-The fetched sources are parsed with the same AST extractor the static router uses
-(:func:`utils.transformers_version._model_types_from_source`), so the remote answer is
-computed exactly like the local overlay answer.
-
-Results are cached in memory and in a small JSON snapshot under ``studio_root()/cache``
-(ttl ~1 day) so repeated tier resolutions never re-fetch; failures are backed off in
-memory. Every fetch is bounded by an explicit wall-clock budget on the transfer (not just
-the socket timeout, which only bounds one read), so a hung or drip-feeding network cannot
-block model loading. Fully offline-safe: offline env vars or the kill switch
-``UNSLOTH_STUDIO_NO_LATEST_TRANSFORMERS=1`` make every check return None (current
-behavior preserved).
-
-The consented install path (:func:`install_latest_transformers`) provisions the
-persistent ``.venv_t5_latest`` sidecar via
-:func:`utils.transformers_version.ensure_latest_transformers_venv`.
-"""
+"""Checks whether PyPI's latest or GitHub main transformers ships a missing model_type, with no
+auth, code execution or trust_remote_code; each fetch has a wall-clock budget so a hung network
+never blocks loading; UNSLOTH_STUDIO_NO_LATEST_TRANSFORMERS=1 or offline env vars make checks
+return None."""
import contextlib
import json
diff --git a/studio/backend/utils/update_status.py b/studio/backend/utils/update_status.py
index f0326c419ca..166098467f8 100644
--- a/studio/backend/utils/update_status.py
+++ b/studio/backend/utils/update_status.py
@@ -1,11 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Web update status helpers for browser-served Unsloth Studio.
-
-Side-effect light: no network work at import time or from /api/health.
-The PyPI check is lazy, cached, and only for PyPI-managed installs.
-"""
+"""Update status for browser-served Studio: no network at import or from /api/health; the PyPI check
+is lazy, cached, and only for PyPI-managed installs."""
from __future__ import annotations
diff --git a/studio/backend/utils/uv_path_safety.py b/studio/backend/utils/uv_path_safety.py
index 6d55703eb22..6559d8ec1a1 100644
--- a/studio/backend/utils/uv_path_safety.py
+++ b/studio/backend/utils/uv_path_safety.py
@@ -1,13 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Hand uv a space-free `-c`/`--override`/`-r` file path (issue #6503).
-
-uv splits `-c`/`--override` (and UV_OVERRIDE) on whitespace, so a path with a
-space truncates. Windows tries the 8.3 short form first; otherwise (and on POSIX)
-a space-free temp path is used (removed at exit). Falls back to the original path
-on error. Shared by install_python_stack and utils.mlx_repair.
-"""
+"""Gives uv a space-free -c/--override/-r file path (uv splits -c/--override on whitespace): 8.3
+short name on Windows, else a temp copy removed at exit; falls back to the original path on
+error."""
from __future__ import annotations
diff --git a/studio/backend/utils/uvicorn_h11_shutdown.py b/studio/backend/utils/uvicorn_h11_shutdown.py
index d2b58c0a572..1eb442d4a5f 100644
--- a/studio/backend/utils/uvicorn_h11_shutdown.py
+++ b/studio/backend/utils/uvicorn_h11_shutdown.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Silence uvicorn's h11 shutdown traceback on Windows (issue #8404).
-
-Every clean shutdown on Windows printed an unhandled asyncio traceback ending in ``h11._util.LocalProtocolError: can't handle event type Response when role=SERVER and state=CLOSED``. Nothing breaks, but a full traceback on a normal exit reads as a crash and gets reported as one.
-
-The sequence, all of it in third-party code. First, ``uvicorn.Server.shutdown()`` walks the live connections and calls ``H11Protocol.shutdown()`` (``uvicorn/protocols/http/h11_impl.py``), which sends ``h11.ConnectionClosed()``, moving the h11 server state to CLOSED, then calls ``transport.close()``. Second, the browser is still polling ``/api/inference/status`` and ``/api/inference/monitor`` on that keep-alive connection, so a request can already be sitting in the socket, and on Windows the proactor transport still hands it to the protocol after ``close()``: ``_ProactorReadPipeTransport._loop_reading()`` assigns ``length`` from ``fut.result()`` before returning early on ``self._closing``, and its ``finally:`` clause calls ``_data_received()`` anyway (CPython ``Lib/asyncio/proactor_events.py``). ``close()`` does cancel ``_read_fut``, but a read whose overlapped ``WSARecv()`` already completed had ``_ov`` cleared by ``_OverlappedFuture.set_result()``, so ``cancel()`` is a no-op and the done callback queued before ``close()`` still runs. CPython 3.9 also set ``data = None`` in that branch and so never delivered, and 3.10 dropped that line when the reader moved to ``recv_into()``, which is why the report needs 3.10 or newer; the selector transport used on Linux and macOS removes the reader inside ``close()``, and uvloop calls ``_stop_reading()`` inside its own ``close()`` (and does not build on Windows at all), so this is Windows-only in practice. Third, h11 sees bytes after it expected EOF, so ``next_event()`` raises ``RemoteProtocolError``, uvicorn logs "Invalid HTTP request received." and calls ``send_400_response()``, whose very first ``self.conn.send(...)`` raises ``LocalProtocolError`` because the server state is CLOSED; nothing catches it, so it escapes ``data_received()`` back into the proactor read callback and asyncio's default handler prints the traceback.
-
-The fix stops step 2 from reaching h11 at all rather than swallowing the exception at the end: once ``ConnectionClosed`` is sent and the transport closed, no further byte can legally be written on that connection, so the inbound data belongs to a request that will never be answered and dropping it is exactly what the selector transport already does. Suppressing the ``LocalProtocolError`` instead would hide genuine protocol errors on live connections and leave the equally misleading "Invalid HTTP request received." warning behind.
-"""
+"""Stops the Windows proactor feeding bytes to h11 after uvicorn sent ConnectionClosed, which
+printed a spurious LocalProtocolError traceback on clean shutdown; dropping that data beats
+suppressing the error, which would hide real protocol errors."""
from __future__ import annotations
diff --git a/studio/backend/utils/video_cpu_settings.py b/studio/backend/utils/video_cpu_settings.py
index e585f9ddafa..d280d16a591 100644
--- a/studio/backend/utils/video_cpu_settings.py
+++ b/studio/backend/utils/video_cpu_settings.py
@@ -1,17 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Developer mode: the installation-wide opt-in that lets video generation run on a CPU-only host.
-
-Off by default. When on, ``video_capability()`` reports video as supported (experimental) on a host
-whose only blocker is the missing accelerator (reason ``no_accelerator``); every other refusal
-(detection failure, broken or missing torch, Intel Mac, a GPU that is present but unusable) stays
-blocked, since running on the CPU would not be what the user asked for there.
-
-Precedence: ``UNSLOTH_VIDEO_ALLOW_CPU`` in the backend environment, when set to a recognised
-boolean, wins over the persisted owner setting in both directions (an admin can force it on for a
-headless install, or off for a shared one). Unset or unrecognised falls through to the setting.
-"""
+"""Developer opt-in (off by default): video runs on a CPU-only host, experimental, only when
+no_accelerator is the sole blocker; other refusals stay. UNSLOTH_VIDEO_ALLOW_CPU, if a recognised
+boolean, overrides the saved setting."""
from __future__ import annotations
diff --git a/studio/backend/utils/vram_budget_settings.py b/studio/backend/utils/vram_budget_settings.py
index 4a1959bdaba..04e0fe5f2ef 100644
--- a/studio/backend/utils/vram_budget_settings.py
+++ b/studio/backend/utils/vram_budget_settings.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Persisted VRAM budget fraction: how much of each GPU a load may claim.
-
-The fit reserves a slice of every card the model and KV cache may not use, covering fragmentation, the per-device CUDA context and MoE routing. That slice was two hard-coded 0.97 constants in ``core.inference.llama_cpp`` (``_CTX_FIT_VRAM_FRACTION``, ``_GPU_PIN_VRAM_FRACTION``), so the only way to trade it for context was to edit the source.
-
-Raising the fraction hands the reserve back as context and the load can then OOM, which llama.cpp takes as a hard crash rather than a graceful degrade; lowering it pushes tight fits into CPU offload, which is what 0.90 did in #5106. Neither direction is free, so the default stays exactly where it was and an unset budget must resolve to ``VRAM_FRACTION_DEFAULT``.
-
-Precedence, matching ``openai_auto_switch_settings``: a stored value wins, the environment is a standalone startup default, the constant is the last resort.
-"""
+"""Persisted fraction of each GPU a load may claim; the rest is reserved for fragmentation, the CUDA
+context and MoE routing. Raising it risks llama.cpp OOM, lowering it pushes tight fits to CPU
+offload. Stored value beats the environment, which beats VRAM_FRACTION_DEFAULT."""
from __future__ import annotations
diff --git a/studio/backend/utils/xet_notice_settings.py b/studio/backend/utils/xet_notice_settings.py
index 6a7fff4fd3e..a5590f61a6c 100644
--- a/studio/backend/utils/xet_notice_settings.py
+++ b/studio/backend/utils/xet_notice_settings.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Lifetime count of the Xet "download is running" notice.
-
-It lived in localStorage, which is per-origin, and an Unsloth origin is not stable:
-run.py falls back past port 8888 when Jupyter has it, and Colab and the tunnel differ
-again. Each new origin handed out a fresh three, so the notice never stopped.
-"""
+"""Lifetime Xet notice count; localStorage was per-origin and origins change (port fallback, Colab,
+tunnel), so each origin reset it; the notice never stopped."""
from __future__ import annotations
diff --git a/studio/install_audio_cpp_prebuilt.py b/studio/install_audio_cpp_prebuilt.py
index c8147266625..6d9887eedad 100644
--- a/studio/install_audio_cpp_prebuilt.py
+++ b/studio/install_audio_cpp_prebuilt.py
@@ -1,40 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Install a prebuilt ``audiocpp_server`` (audio.cpp) for Studio's audio.cpp engine.
-
-audio.cpp vendors its own patched ggml, so unlike whisper.cpp it cannot share the
-llama.cpp runtime: every bundle is self-contained (the server links ggml statically).
-Releases are named ``audio-<tag>-bin-<os>-<arch>-<backend>.{zip,tar.gz}``, the scheme
-upstream uses and the Unsloth fork keeps, so one resolver serves both. Windows CUDA
-bundles need the CUDA runtime DLLs, which upstream publishes as a separate
-``audio-<tag>-cudart-windows-x64-<line>.zip``; that download is skipped when the
-running Python's torch already ships the same CUDA runtime line.
-
-The bundle is extracted into a staging directory beside the managed tree, started once
-with ``--help`` so a bundle this host cannot load is refused, and swapped in only then,
-so an interrupted or unusable install never replaces a working tree.
-
-The newest unslothai/audio.cpp release is installed unless ``UNSLOTH_AUDIO_CPP_TAG`` (or
-``--published-release-tag``) names one. The release is resolved like whisper.cpp's, through
-prebuilt_core: the download host first, then the GitHub API. Every bundle and CUDA runtime
-archive must match the sha256 in the release's own ``audio-cpp-prebuilt-sha256.json``, which
-is bound to the release tag; an archive the index does not cover is refused. That checksum
-comes from the same release as the archive, so it proves integrity (a corrupt or swapped
-download), not authenticity. A user-picked repo or tag whose release publishes no index
-falls back to GitHub's asset digest.
-
-A re-run whose install record already names the newest release (one HEAD to github.com,
-no API call) or the pinned one (no network call) downloads nothing, an intact install newer
-than the release a lookup names is never replaced by it, and a lookup that cannot answer
-keeps a complete install.
-
-Usage:
- python studio/install_audio_cpp_prebuilt.py # auto-detect host
- python studio/install_audio_cpp_prebuilt.py --accelerator cpu
- python studio/install_audio_cpp_prebuilt.py --print-asset # resolve only
- python studio/install_audio_cpp_prebuilt.py --published-release-tag v0.9.1-unsloth.1
-"""
+"""Installs prebuilt audiocpp_server, checked with --help before swap; archives must match audio-
+cpp-prebuilt-sha256.json (uncovered refused); newest release unless UNSLOTH_AUDIO_CPP_TAG or
+--published-release-tag names one; a newer intact install is never replaced; a failed lookup
+keeps the install."""
from __future__ import annotations
diff --git a/studio/install_manifest.py b/studio/install_manifest.py
index 2b87a121679..5397c8de6a9 100644
--- a/studio/install_manifest.py
+++ b/studio/install_manifest.py
@@ -1,19 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Install-completeness manifest for Unsloth Studio.
-
-install_python_stack.py drops the manifest before the dependency pass and writes
-it back only after the last step, so its presence means "the install finished".
-Read by `unsloth studio verify-install`, `desktop-capabilities` (and through it
-the Tauri preflight) and setup.sh/setup.ps1's fast path.
-
-Without it an installer killed part-way leaves a venv with `unsloth` but not
-studio.txt's dependencies, which still answers `-h` and so looked ready right up
-until the backend died on `import structlog`.
-
-Must import inside that half-installed venv: stdlib only, `packaging` optional.
-"""
+"""Install-completeness marker: install_python_stack.py drops it before the dependency pass and
+writes it after the last step, so presence means the install finished. Read by verify-install,
+desktop-capabilities and setup.sh/setup.ps1; stdlib only, packaging optional."""
from __future__ import annotations
diff --git a/studio/install_node_prebuilt.py b/studio/install_node_prebuilt.py
index f5e25426650..ac07031eef9 100644
--- a/studio/install_node_prebuilt.py
+++ b/studio/install_node_prebuilt.py
@@ -2,23 +2,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Cross-platform Node.js prebuilt installer for Unsloth Studio.
-
-Downloads an official Node.js archive from nodejs.org (or the dist mirror in
-``UNSLOTH_NODE_MIRROR``) into an isolated
-``<UNSLOTH_HOME>/node`` and never touches the system Node/npm. Pinning Node 24+
-LTS clears the Unsloth frontend build floor (Vite 8: Node ^20.19 || >=22.12,
-npm >= 11) with the npm it bundles.
-
-Archives are verified against sha256 digests pinned in ``node_prebuilt_pins.json``
-(committed in-tree), not a checksum re-fetched from the same origin as the archive.
-
-Mirrors ``install_llama_prebuilt.py`` so the setup scripts drive it the same way.
-Exit codes: 0 success, 1 error, 2 fallback, 3 busy, 4 access denied. A re-run that already matches
-logs "already matches" and returns 0 without downloading (the scripts grep it).
-A failed update that keeps a usable install logs "keeping existing isolated Node" and
-also returns 0 (the scripts grep that too).
-"""
+"""Installs isolated Node.js 24+ LTS into <UNSLOTH_HOME>/node, never touching system Node/npm;
+archives sha256-checked against in-tree node_prebuilt_pins.json, not from the archive origin;
+exit 0 success, 1 error, 2 fallback, 3 busy, 4 access denied; setup scripts grep the already
+matches line."""
from __future__ import annotations
diff --git a/studio/install_sd_cpp_prebuilt.py b/studio/install_sd_cpp_prebuilt.py
index b85613c4195..7cb4a714598 100644
--- a/studio/install_sd_cpp_prebuilt.py
+++ b/studio/install_sd_cpp_prebuilt.py
@@ -1,13 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Install a prebuilt ``sd-cli`` (stable-diffusion.cpp) for the native diffusion engine, the analogue of the chat backend's prebuilt llama-server. stable-diffusion.cpp publishes per-platform release zips (macOS-arm64/Metal, Linux x86_64 CPU, plus Vulkan / ROCm / Windows variants), so on Apple Silicon and CPU there is nothing to compile: resolve the asset, download, extract into ``~/.unsloth/stable-diffusion.cpp``, and the engine's finder picks it up. ``resolve_release_asset``, the host -> asset choice, is a pure function so the matching matrix is unit-tested without any network. CUDA / ROCm / XPU hosts stay on diffusers and never need this.
-
-Usage:
- python studio/install_sd_cpp_prebuilt.py # auto-detect host
- python studio/install_sd_cpp_prebuilt.py --accelerator vulkan
- python studio/install_sd_cpp_prebuilt.py --print-asset # resolve only
-"""
+"""Installs prebuilt sd-cli (stable-diffusion.cpp) into ~/.unsloth/stable-diffusion.cpp, the
+analogue of the chat backend's llama-server; resolve_release_asset is pure, so host matching is
+tested offline. CUDA, ROCm and XPU hosts stay on diffusers."""
from __future__ import annotations
diff --git a/studio/install_whisper_prebuilt.py b/studio/install_whisper_prebuilt.py
index 3429d86dda6..bffea569318 100644
--- a/studio/install_whisper_prebuilt.py
+++ b/studio/install_whisper_prebuilt.py
@@ -2,56 +2,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Cross-platform whisper.cpp (whisper-server) prebuilt installer for Unsloth Studio.
-
-Downloads a per-platform whisper.cpp bundle published by the Unsloth fork
-(``unslothai/whisper.cpp``) into an isolated ``<UNSLOTH_HOME>/whisper.cpp``,
-never a system whisper.cpp. The canonical install target matches the
-sidecar/build-script contract in ``stt_ggml_sidecar.py``:
-
- <install-dir>/build/bin/whisper-server (Unix)
- <install-dir>/build/bin/Release/whisper-server.exe (Windows)
-
-Bundles are dynamically linked: ``whisper-server`` needs ``libwhisper``,
-``libggml*`` and any GPU backend libraries. The binaries carry ``RUNPATH=$ORIGIN``
-so the installer co-locates every shared library from the archive into the same
-``build/bin`` directory and marks the server executable on Unix.
-
-Archives are verified against the release's own ``whisper-prebuilt-sha256.json``
-checksum index (same model as ``install_llama_prebuilt.py``). An asset absent
-from the index, or a release without it, fails closed (setup reports the prebuilt
-unavailable and local dictation uses Transformers STT). Being a same-origin
-checksum it proves integrity, not authenticity; pair the release with GitHub
-artifact attestations for provenance.
-
-Release resolution prefers the download host (``github.com/<repo>/releases/...``),
-fetching the manifest + checksum index with zero ``api.github.com`` calls (that
-API is rate-limited to 60 req/hour unauthenticated); the GitHub API is only a
-fallback on a 404 / malformed asset.
-
-The whole component-agnostic flow (verified downloads, safe extraction, the
-install lock, release resolution, checksum-index handling, the install driver,
-the resolve probe) lives in ``prebuilt_core.py`` and is shared with
-``install_llama_prebuilt.py``. This module keeps only the whisper specifics: the
-host mapping, install-tree layout, slim pairing with the installed llama.cpp ggml
-runtime, the pinned-release CPU escape hatch, the marker filename, and the CLI.
-Every retained public name is a thin wrapper tests can monkeypatch so the core
-observes the patch.
-
-Selection is slim-only for current releases (v1.9.1-unsloth.2+): every published
-bundle is a slim (ggml-less) whisper paired to the llama.cpp prebuilt, which
-provides all ggml backends. The per-accelerator fat selection chain was deleted
-with the fat bundles; the one legacy shape still honored is the published fat CPU
-bundle of an explicitly pinned pre-slim release.
-
-Mirrors ``install_node_prebuilt.py`` / ``install_llama_prebuilt.py``. Exit codes:
-0 success (or already current), 1 error, 2 incompatible paired release, 3 busy. A re-run
-that already matches logs "already matches" and returns 0 without downloading
-(the scripts grep it). A release lookup that could not answer at all also returns 0 when
-an intact, previously validated install is on disk, logging "update unavailable, existing
-prebuilt kept; keeping the existing complete install" -- llama.cpp's wording for its own
-identical outcome, and the substring the setup scripts grep to report it.
-"""
+"""Installs whisper-server from unslothai/whisper.cpp into <UNSLOTH_HOME>/whisper.cpp/build/bin,
+never a system copy; assets missing from whisper-prebuilt-sha256.json fail closed; re-runs that
+log already matches return 0; failed lookup with intact install returns 0 (setup scripts grep
+both logs)."""
from __future__ import annotations
diff --git a/studio/nvidia_probe.py b/studio/nvidia_probe.py
index 5761bbb6f50..9c6baab7b07 100644
--- a/studio/nvidia_probe.py
+++ b/studio/nvidia_probe.py
@@ -1,20 +1,10 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""NVIDIA inventory read from the driver's own libraries, for a host nvidia-smi cannot answer for.
-
-An absent, stale or hanging nvidia-smi read as a CPU host, which is fatal to the install.
-Ollama, Jan and lemonade ask NVML or the CUDA driver API instead, which ship with the driver.
-
-* NVML (`libnvidia-ml.so.1` / `nvml.dll`): the PHYSICAL inventory, unmasked like nvidia-smi;
- the caller applies CUDA_VISIBLE_DEVICES.
-* the CUDA driver API (`libcuda.so.1` / `nvcuda.dll`): honours the mask; used when NVML is
- unavailable.
-
-Always a child process with a deadline: these libraries block in-process in the states that
-hang nvidia-smi. Failing both, `/proc/driver/nvidia/version` names the driver, and the driver
-major bounds the CUDA major (13 needs R580+, 12 R525+, 11 R450+).
-"""
+"""NVIDIA inventory from driver libraries when nvidia-smi is absent or hangs. NVML gives physical
+devices (caller applies CUDA_VISIBLE_DEVICES); the CUDA driver API honours the mask. Always a
+child with a deadline; last resort /proc/driver/nvidia/version, whose major bounds the CUDA
+major."""
from __future__ import annotations
diff --git a/studio/prebuilt_core.py b/studio/prebuilt_core.py
index 3e82ceba99d..bc3d711dbc7 100644
--- a/studio/prebuilt_core.py
+++ b/studio/prebuilt_core.py
@@ -2,28 +2,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Component-agnostic machinery shared by the ggml-family prebuilt installers.
-
-``install_llama_prebuilt.py`` and ``install_whisper_prebuilt.py`` both run on
-this module, which owns two layers:
-
-1. Primitives: HTTP fetches with retries and token-safe redirects, verified
- downloads, safe archive extraction, the install lock, sha256 helpers, and
- CUDA runtime-line / compute-capability selection. Moved verbatim out of
- ``install_llama_prebuilt.py``, which re-exports them under their old names.
-
-2. The generic descriptor-driven install flow: release resolution (download
- host fast path, GitHub API fallback), checksum-index parsing, coverage-aware
- artifact selection, verified download + extraction + staged atomic
- activation, marker/fingerprint handling, and the resolve probe. Whisper runs
- entirely on this flow; a third component plugs in with a ``ComponentDescriptor``.
-
-Seam rule: every function calling a collaborator tests monkeypatch takes an
-``ops`` handle first. ``ops`` resolves names in the calling installer module's
-globals first (so a ``monkeypatch.setattr`` still wins) and falls back to this
-module's defaults, letting a descriptor-only component work with no installer
-module behind it.
-"""
+"""Shared core of the ggml prebuilt installers: verified downloads, safe extraction, install lock,
+and descriptor-driven release resolution and activation. Collaborators take an ops handle that
+resolves names in the caller's module first, so monkeypatches still apply."""
from __future__ import annotations
diff --git a/unsloth/_torchao_nodist.py b/unsloth/_torchao_nodist.py
index 681132a67f9..87a6715d12a 100644
--- a/unsloth/_torchao_nodist.py
+++ b/unsloth/_torchao_nodist.py
@@ -1,17 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Import real torchao on a torch built without torch.distributed (AMD's Windows ROCm wheels).
-
-torchao imports DTensor / DeviceMesh / the functional collectives at module scope and keys
-dispatch tables on c10d ops, none of which exist on such a build, so ``import torchao`` dies
-(pytorch/ao#3452; the upstream guard, pytorch/ao#4761, is unmerged). All of it only serves
-isinstance() checks and collective handlers that cannot run without distributed. So each torchao
-module body executes inside a window where imports made BY torchao code get inert stand-ins for
-missing torch.distributed modules and lookups made BY torchao code get inert keys for missing
-c10d ops. Everything else, torch internals imported meanwhile included, sees the real (absent)
-torch.distributed. Stdlib + torch only: Studio loads this file without importing unsloth.
-"""
+"""Imports real torchao on torch builds without torch.distributed (AMD Windows ROCm); only imports
+and c10d lookups made by torchao code get inert stand-ins, all else sees the real absence. Stdlib
+and torch only; Studio loads it without importing unsloth."""
import importlib
import importlib.abc
diff --git a/unsloth/bnb_availability.py b/unsloth/bnb_availability.py
index 5e120ac2bb4..650baceb3d6 100644
--- a/unsloth/bnb_availability.py
+++ b/unsloth/bnb_availability.py
@@ -9,21 +9,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Can bitsandbytes actually run a 4bit kernel here? A successful import does not say.
-
-From 0.46 a wheel whose native library never loaded still imports and hands back a
-`throw_on_call` closure for every symbol, so attribute reads alone see a healthy wheel,
-`ALLOW_BITSANDBYTES` stays true and 4bit dies inside a kernel instead of falling back to
-16bit up front. A real handle is a ctypes function pointer and carries `restype`; a
-deferred failure is a plain Python function and does not. That is the whole test, applied
-to every probed handle: the same verdict gates the module-scope binds in kernels/utils.py,
-where one bad symbol is the crash this exists to prevent.
-
-Decides the capability flags only, never importability - a CPU-only install is exactly
-this shape and its Python side works. A leaf module: imports nothing from unsloth
-(device_type.py imports it very early, so anything else is a cycle) and takes the
-device type as an argument.
-"""
+"""A bitsandbytes import can succeed with a dead native library (throw_on_call stubs, bnb 0.46+); a
+real ctypes handle has restype, a stub does not. Leaf module: imports nothing from unsloth,
+decides capability flags, never importability."""
__all__ = [
"bitsandbytes_symbols",
diff --git a/unsloth/dataprep/ebooks.py b/unsloth/dataprep/ebooks.py
index 3e506cdcad4..e4ea3b73d08 100644
--- a/unsloth/dataprep/ebooks.py
+++ b/unsloth/dataprep/ebooks.py
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Load EPUB books and, with Calibre installed, MOBI books on CPU.
-
-Pass a Hugging Face fast tokenizer, not model weights. Token counts exclude
-special tokens added later by a trainer; reserve space for those in chunk_size.
-"""
+"""Loads EPUB books, and MOBI books when Calibre is installed, on CPU. Pass a Hugging Face fast
+tokenizer, not model weights; token counts exclude special tokens a trainer adds later, so
+reserve room for them in chunk_size."""
from bisect import bisect_right
from html.parser import HTMLParser
diff --git a/unsloth/disk_utils.py b/unsloth/disk_utils.py
index 3442b6e4f60..147548a65f4 100644
--- a/unsloth/disk_utils.py
+++ b/unsloth/disk_utils.py
@@ -8,16 +8,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Access to unsloth_zoo.disk_utils that survives an older installed zoo.
-
-The disk sizing and Kaggle detection logic is owned by
-`unsloth_zoo.disk_utils` so the two packages cannot disagree about whether we
-are on Kaggle. unsloth pins a new enough unsloth_zoo, but a stale environment
-that satisfies `import unsloth_zoo` and not `unsloth_zoo.disk_utils` must
-still be able to save a model, so the fallbacks below keep the environment
-question answered correctly and turn the new disk guard into a no-op rather
-than an ImportError.
-"""
+"""Access to unsloth_zoo.disk_utils that survives an older zoo: the disk guard becomes a no-op, not
+an ImportError, and the Kaggle check still answers correctly."""
import os
diff --git a/unsloth/kernels/bnb_override.py b/unsloth/kernels/bnb_override.py
index 80f0d0a05ce..8b9d5deb646 100644
--- a/unsloth/kernels/bnb_override.py
+++ b/unsloth/kernels/bnb_override.py
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""bitsandbytes NF4 ``Linear4bit.forward`` on Unsloth's NF4 kernels: Triton dequantize + F.linear
-(bit-exact to bitsandbytes' dequantize) and ``fast_gemv`` for one decode row; dX recomputes the
-weight as bitsandbytes does. From bitsandbytes 0.50, shapes its fused 4-bit GEMM takes stay with it.
-Default on before bitsandbytes 0.50, and from 0.50 only on sm100 / sm120 (A100 / T4 batched decode
-measured 2-3% slower). UNSLOTH_BNB_NF4_LINEAR=1/0 forces it; UNSLOTH_BNB_TRITON=0 disables it."""
+"""Replaces bitsandbytes NF4 Linear4bit.forward with Unsloth's Triton dequant + F.linear and
+fast_gemv; from bnb 0.50 fused 4-bit GEMM shapes stay with bnb. On before 0.50, and from 0.50
+only on sm100/sm120; UNSLOTH_BNB_NF4_LINEAR=1/0 forces it, UNSLOTH_BNB_TRITON=0 disables it."""
import os
diff --git a/unsloth/kernels/int4_packed.py b/unsloth/kernels/int4_packed.py
index 5294b868fd9..fefae25ab0c 100644
--- a/unsloth/kernels/int4_packed.py
+++ b/unsloth/kernels/int4_packed.py
@@ -11,15 +11,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Triton kernels for compressed-tensors ``pack-quantized`` integer weights kept packed.
-
-Layout (compressed_tensors/compressors/pack_quantized/helpers.py): ``weight_packed`` is int32
-``[N, ceil(K / pf)]`` with ``pf = 32 // bits`` values per word, element ``j`` in bits
-``[j * bits, (j + 1) * bits)``, stored as ``q + 2 ** (bits - 1)``. ``weight_scale`` is ``[N, G]``;
-an asymmetric ``weight_zero_point`` is packed the same way along the OUTPUT dim ``[ceil(N / pf), G]``;
-act-order checkpoints carry ``weight_g_idx`` ``[K]`` (column -> group). The decode
-``(q - zp) * scale`` is exact in fp32, then rounded like compressed-tensors (scale dtype, then output).
-"""
+"""compressed-tensors pack-quantized weights: weight_packed int32 [N, ceil(K/pf)], pf = 32 // bits,
+element j at bits [j*bits, (j+1)*bits) as q + 2**(bits-1); weight_scale [N, G]; weight_zero_point
+packed along N as [ceil(N/pf), G]; act-order weight_g_idx [K]; decode exact in fp32."""
import functools
import inspect
diff --git a/unsloth/kernels/multi_lora.py b/unsloth/kernels/multi_lora.py
index bf4b386ee0a..a8022097fa5 100644
--- a/unsloth/kernels/multi_lora.py
+++ b/unsloth/kernels/multi_lora.py
@@ -1,14 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""
-Batched multi-LoRA training: many LoRA adapters on one frozen base model, trained in one batch.
-
-Each token belongs to one adapter (or none, id -1); tokens are stable-sorted by adapter once per batch
-and kernels gather rows through that order (like Punica SGMV, but with dX and per-adapter dA / dB).
-
-``UNSLOTH_MULTI_LORA_TRITON=0`` (or no CUDA / XPU) uses a PyTorch loop. LoRA dropout is unsupported.
-"""
+"""Batched multi-LoRA training on one frozen base: tokens (id -1 = no adapter) are stable-sorted by
+adapter once per batch and kernels gather through that order. UNSLOTH_MULTI_LORA_TRITON=0, or no
+CUDA/XPU, uses a PyTorch loop; LoRA dropout unsupported."""
from __future__ import annotations
diff --git a/unsloth/models/_block_compile.py b/unsloth/models/_block_compile.py
index 5bdedf725b9..ce842becd41 100644
--- a/unsloth/models/_block_compile.py
+++ b/unsloth/models/_block_compile.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""One torch.compile region per decoder layer for training (stock forward: attention, MLP or MoE,
-norms, LoRA, NF4). UNSLOTH_BLOCK_COMPILE=0 or UNSLOTH_COMPILE_DISABLE turns it off."""
+"""One torch.compile region per decoder layer for training over the stock forward (attention,
+MLP/MoE, norms, LoRA, NF4); UNSLOTH_BLOCK_COMPILE=0 or UNSLOTH_COMPILE_DISABLE turns it off."""
import contextlib
import functools
diff --git a/unsloth/models/_custom_dtype.py b/unsloth/models/_custom_dtype.py
index 17a2aae8a8b..00588531129 100644
--- a/unsloth/models/_custom_dtype.py
+++ b/unsloth/models/_custom_dtype.py
@@ -11,13 +11,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""`UNSLOTH_FORCE_CUSTOM_DTYPE` carries executable code in two of its five fields.
-
-Every value unsloth ships is a literal in `models/loader.py` and both readers run in
-the process that set it, so a value this process did not set has no legitimate source
-and its code fields are dropped rather than executed. The wire format is unchanged,
-since `unsloth_zoo` parses the same five fields on its own release schedule.
-"""
+"""UNSLOTH_FORCE_CUSTOM_DTYPE code fields run only if this process set the value, else dropped; wire
+format unchanged, unsloth_zoo parses the same five fields."""
__all__ = [
"register_custom_dtype",
diff --git a/unsloth/models/_decode_graphs.py b/unsloth/models/_decode_graphs.py
index 3dc8decdd08..0496977bd8d 100644
--- a/unsloth/models/_decode_graphs.py
+++ b/unsloth/models/_decode_graphs.py
@@ -1,32 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""CUDA-graph replay of the native one-token decode step.
-
-When it runs (decided per call, enabled()): UNSLOTH_DECODE_CUDA_GRAPHS=1 everywhere, =0 nowhere; unset,
-only for the generate() calls an RL trainer makes on the training model (GRPO / RLOO / online DPO /
-GKD ... through rl.py's unwrap_model_for_generation, rl_generation()) on NVIDIA CUDA, not for plain
-model.generate() and not on ROCm / HIP (graph replay there is not verified bitwise; =1 still forces it).
-The decode buffers and graphs of such a call are released when it returns to training: the next
-optimizer step invalidates the graphs anyway, and training gets the memory back.
-
-The eager decode step is host bound (hundreds of small launches per token). It is captured once per
-batch size as n_layers + 1 graph segments split at each layer's attention core, which runs eagerly
-between them over the true KV length (_decode_attention_core, the same code the eager step runs), so
-a replayed step computes bit for bit what the eager step computes, at every length, with no buckets:
-
-* the per-layer decode buffers (KV cache, projection scratch) persist across generate() calls and are
- sized up front to prompt + max_new_tokens, so the addresses the segments read and write hold;
-* the segments write K / V with index_copy_ at a device-side cache slot and index RoPE with a device
- position tensor, so they do not depend on the length either;
-* the first decode step after a prefill stays eager (it copies the prefill K / V into the cache), and
- sampling / logits processing stays in transformers.
-
-A graph bakes in every tensor address it reads and every host-side branch taken at capture, so the
-graphs are dropped when the model's parameters, LoRA adapters (cast caches included), quant states or
-RoPE tables move or change version; this is checked once per generate() call and after every
-optimizer step. Anything unsupported runs the eager step.
-"""
+"""CUDA-graph decode; UNSLOTH_DECODE_CUDA_GRAPHS=1 forces, =0 disables; unset, only RL-trainer
+generate on NVIDIA CUDA; graphs dropped when params, LoRA, quant or RoPE change."""
import math
import os
diff --git a/unsloth/models/_gc_train_scope.py b/unsloth/models/_gc_train_scope.py
index 7bd2554f120..eda93c3e4c4 100644
--- a/unsloth/models/_gc_train_scope.py
+++ b/unsloth/models/_gc_train_scope.py
@@ -1,26 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Freeze the setup-time heap for the duration of `Trainer.train()`.
-
-Libraries call `gc.collect()` several times inside `train()`. Each full collection walks every
-tracked object, and after loading a model, tokenizer, dataset and compiled code that heap is
-large: about 0.5 s per pass, 2 to 3 s per `train()` on a 0.6B / 1B LoRA run. `gc.freeze()` moves
-everything alive at train start into the permanent generation, so those passes only see objects
-created during training.
-
-The freeze must be undone when `train()` exits (normally, by exception or by KeyboardInterrupt):
-frozen objects are never collected, so a cyclic object dropped after training (the usual
-`del model; gc.collect()` in a notebook) would otherwise keep its memory forever.
-
-Rules:
-- Only the outermost `train()` freezes; nested calls (resume guards, per-instance wrappers) are
- counted and do nothing.
-- If something is already frozen at entry, the caller owns the freeze: Python cannot unfreeze
- only our objects, so we leave the heap alone and do not unfreeze on exit.
-- `gc.isenabled()` is never touched.
-- `UNSLOTH_GC_FREEZE=0` turns it off (read on each outermost entry).
-"""
+"""gc.freeze setup heap in outermost train() (nested calls no-op); unfreeze on exit unless caller
+already froze; UNSLOTH_GC_FREEZE=0 disables."""
import functools
import gc
diff --git a/unsloth/models/_gdn_op.py b/unsloth/models/_gdn_op.py
index bc27cd5c711..dc7a7435e99 100644
--- a/unsloth/models/_gdn_op.py
+++ b/unsloth/models/_gdn_op.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""fla's chunk_gated_delta_rule as an opaque op with a registered backward (training case only),
-checked bit-equal to ChunkGatedDeltaRuleFunction before use, so a Gated DeltaNet layer compiles
-as one graph."""
+"""fla chunk_gated_delta_rule as opaque op (training backward) so DeltaNet compiles as one graph."""
import inspect
from typing import Optional
diff --git a/unsloth/models/_sentence_transformer_unpadding.py b/unsloth/models/_sentence_transformer_unpadding.py
index 3d8f91cc0d3..24a4f05f7ee 100644
--- a/unsloth/models/_sentence_transformer_unpadding.py
+++ b/unsloth/models/_sentence_transformer_unpadding.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
-"""Training-only encoder unpadding for mean-pooled BERT / RoBERTa SentenceTransformers.
-
-Embeddings and pooling stay stock; only valid tokens enter the encoder, whose output is
-scattered back to the padded layout before pooling. Checkpoints are unchanged.
-"""
+"""Training-only: BERT/RoBERTa encoder runs on valid tokens, output re-padded before mean pooling;
+embeddings and pooling stay stock; checkpoints unchanged."""
from types import MethodType
diff --git a/unsloth/models/_uma_safetensors.py b/unsloth/models/_uma_safetensors.py
index f53c934383d..36d8a46fe99 100644
--- a/unsloth/models/_uma_safetensors.py
+++ b/unsloth/models/_uma_safetensors.py
@@ -1,19 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Faster safetensors weight loading on unified-memory (integrated) GPUs.
-
-A direct ``safe_open(..., device=<cuda>)`` on CUDA/HIP UMA GPUs (AMD APUs,
-NVIDIA GB10 Spark) misses torch's fast pinned-DMA path: the mmap-backed
-safetensors buffers aren't recognized, so it falls to a slow per-tensor copy
-with page faults. Cloning each tensor into a normal torch CPU allocation before
-moving it restores the fast path; outputs are bit-identical.
-
-CUDA/HIP only, and only for loads that pass a CUDA device to ``safe_open``
-directly: Intel XPU iGPUs and the CPU-open + later ``.to()`` flows (e.g. bnb /
-HQQ quantized loads) keep the stock path until they can be validated on real
-hardware.
-"""
+"""Direct safe_open(device=cuda) on CUDA/HIP UMA GPUs: clone tensors to CPU before moving (bit-
+identical); CPU-open then .to() (bnb/HQQ) and XPU keep stock path."""
import os
import functools
diff --git a/unsloth/models/_windows_safetensors.py b/unsloth/models/_windows_safetensors.py
index 694779332f6..a2f1a0fbebe 100644
--- a/unsloth/models/_windows_safetensors.py
+++ b/unsloth/models/_windows_safetensors.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Windows, transformers 5.0 - 5.16: read safetensors shards with ``pread`` instead of a copy-on-write mmap.
-
-transformers 5.x keeps every shard open for the whole load, and Windows charges each copy-on-write view to the commit
-limit in full, so a dtype-converting load needs ~2x the model in commit (os error 1455 / access violation). Backports
-huggingface/transformers#48341 (5.17). Opt out with ``UNSLOTH_SAFETENSORS_PREAD=0``.
-"""
+"""Windows, transformers 5.0-5.16: pread, not mmap (commit limit); UNSLOTH_SAFETENSORS_PREAD=0 off."""
import functools
import os
diff --git a/unsloth/models/compressed_tensors_bnb.py b/unsloth/models/compressed_tensors_bnb.py
index 60609ad15cb..c1785846bb4 100644
--- a/unsloth/models/compressed_tensors_bnb.py
+++ b/unsloth/models/compressed_tensors_bnb.py
@@ -10,9 +10,8 @@
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Re-quantize a compressed-tensors ``pack-quantized`` W4A16/W8A16 checkpoint into bitsandbytes
-4-bit per tensor during ``from_pretrained`` (no 16-bit copy on disk). Native MoE stacks keep
-transformers' ``DecompressExperts``; needs the transformers 5 weight-conversion loader."""
+"""Re-quantize compressed-tensors W4A16/W8A16 to bnb 4-bit during load, not native MoE (keeps
+DecompressExperts); needs transformers 5 weight-conversion loader."""
import inspect
import os
diff --git a/unsloth/models/compressed_tensors_int4.py b/unsloth/models/compressed_tensors_int4.py
index 9100785da03..8a92d11c037 100644
--- a/unsloth/models/compressed_tensors_int4.py
+++ b/unsloth/models/compressed_tensors_int4.py
@@ -11,14 +11,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Keep compressed-tensors ``pack-quantized`` INT4/INT8 Linears packed for LoRA training.
-
-The checkpoint's own ``weight_packed`` / ``weight_scale`` / ``weight_zero_point`` / ``weight_g_idx``
-load straight into ``Int4PackedLinear`` (no decompress, no re-quantization). ``.weight`` is the packed
-int32 tensor carrying an ``Int4QuantState``, so Unsloth's LoRA kernels treat it like a bitsandbytes
-weight and decode it exactly per use (kernels/int4_packed.py). ``UNSLOTH_COMPRESSED_TENSORS_INT4=nf4``
-selects the older NF4 re-quantization instead.
-"""
+"""Keep compressed-tensors INT4/INT8 packed for LoRA; UNSLOTH_COMPRESSED_TENSORS_INT4=nf4 requantizes."""
import contextlib
import functools
diff --git a/unsloth/models/diffusion.py b/unsloth/models/diffusion.py
index 2d8dada814f..821379ed8a5 100644
--- a/unsloth/models/diffusion.py
+++ b/unsloth/models/diffusion.py
@@ -8,14 +8,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-"""
-FastDiffusionModel: a transformers-only slow path for text-diffusion models (e.g. DiffusionGemma).
-
-These models use a block-diffusion sampling loop (custom generate) and a novel backbone, so we skip
-Unsloth's autoregressive kernel/compile patching and load the unmodified HF model (outputs stay
-bit-identical to transformers), keeping only the safe conveniences: 4bit/8bit loading, PEFT LoRA, the
-(model, tokenizer) API, and for_inference/for_training. Extend DIFFUSION_MODEL_TYPES as more land.
-"""
+"""FastDiffusionModel: unpatched HF text-diffusion models; outputs bit-identical to transformers."""
import os
import re
diff --git a/unsloth/models/diffusion_block.py b/unsloth/models/diffusion_block.py
index dfd29e7d07b..78c183c299d 100644
--- a/unsloth/models/diffusion_block.py
+++ b/unsloth/models/diffusion_block.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Block-diffusion families (LLaDA2.x, SDAR).
-
-Training follows BD3-LM (https://arxiv.org/abs/2503.09573): each row is fed as [x_t ; x_0] with position ids
-restarting at the clean copy. A noisy token sees its own noisy block and the clean blocks before it; clean tokens
-see clean blocks causally. The loss reads the noisy half at the same position (no shift).
-"""
+"""Block-diffusion (LLaDA2.x, SDAR), BD3-LM training: rows [x_t ; x_0]; loss on noisy half, no shift."""
import contextlib
import functools
diff --git a/unsloth/models/diffusion_gemma_objective.py b/unsloth/models/diffusion_gemma_objective.py
index d4ca337bfc6..6918655b339 100644
--- a/unsloth/models/diffusion_gemma_objective.py
+++ b/unsloth/models/diffusion_gemma_objective.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""DiffusionGemma block-diffusion SFT objective, matching the reference fine-tune of the released checkpoint
-(the recipe in TRL's examples/sft_diffusion_gemma/sft_diffusion_gemma.py)."""
+"""DiffusionGemma block-diffusion SFT objective matching TRL's examples/sft_diffusion_gemma recipe."""
import contextlib
diff --git a/unsloth/models/diffusion_infer.py b/unsloth/models/diffusion_infer.py
index cc142eea696..cd01a30f00b 100644
--- a/unsloth/models/diffusion_infer.py
+++ b/unsloth/models/diffusion_infer.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Shared pieces of the diffusion samplers' fast path: in-loop cancellation and throttled canvas frames, the
-active-block-only output head, and regional compile of the backbone for inference."""
+"""Diffusion fast-path helpers: in-loop cancel, throttled frames, active-block head, regional compile."""
import contextlib
import functools
diff --git a/unsloth/models/diffusion_infer_block.py b/unsloth/models/diffusion_infer_block.py
index b84700d2883..85be2724071 100644
--- a/unsloth/models/diffusion_infer_block.py
+++ b/unsloth/models/diffusion_infer_block.py
@@ -10,12 +10,7 @@
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Block diffusion decoding (SDAR, LLaDA2) with an exact prefix KV cache.
-
-Attention is block-causal, so a committed block's keys and values never change: they are computed once, and each
-denoising step forwards only the active block, and a finished block is committed in the same forward as the next
-block's first step, so the forward count matches the recompute sampler. Token selection runs on the device; the
-host syncs once per step (has the block finished early) and once per block (EOS)."""
+"""Block diffusion decoding (SDAR, LLaDA2) with exact prefix KV cache; committed KV computed once."""
import math
import sys
diff --git a/unsloth/models/diffusion_infer_dream.py b/unsloth/models/diffusion_infer_dream.py
index b97ac7fa6e3..c7f5cfd5ba7 100644
--- a/unsloth/models/diffusion_infer_dream.py
+++ b/unsloth/models/diffusion_infer_dream.py
@@ -10,12 +10,8 @@
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Dream's greedy diffusion_generate (generation_utils.py `_sample`, alg entropy / maskgit_plus / topk_margin,
-alg_temp 0), with logits only for the generated region and the transfer schedule worked out up front.
-
-The reference projects every position to the vocabulary each step and reads the masked count back to the host.
-The masked count drops by exactly the scheduled amount unless the model proposes the mask token itself, so the
-schedule is worked out before the loop; a run where that happened returns None and the caller falls back."""
+"""Dream greedy diffusion_generate with precomputed transfer schedule; returns None (caller falls
+back) if the model proposes the mask token."""
import math
diff --git a/unsloth/models/diffusion_loss.py b/unsloth/models/diffusion_loss.py
index 9431e0ce021..c5c2f065c10 100644
--- a/unsloth/models/diffusion_loss.py
+++ b/unsloth/models/diffusion_loss.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Weighted cross entropy for the diffusion objectives without [N, V] fp32 logits.
-
-Rows are processed in fixed-size chunks (the last one padded with ignored rows), so the compiled chunk kernels
-see one shape per vocabulary / chunk size and never recompile as the masked fraction or sequence length moves.
-Backward recomputes each chunk's logits instead of keeping them.
-"""
+"""Diffusion weighted CE in fixed-size chunks, no [N, V] fp32 logits; fixed shapes avoid recompiles."""
import os
diff --git a/unsloth/models/diffusion_masked.py b/unsloth/models/diffusion_masked.py
index 2460d9978c6..cd3697d9bb5 100644
--- a/unsloth/models/diffusion_masked.py
+++ b/unsloth/models/diffusion_masked.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Absorbing-mask diffusion LMs over one bidirectional sequence: LLaDA, LLaDA-MoE, Dream, Nemotron-Labs-Diffusion.
-
-Each response token is replaced by [MASK] with probability p, the clean prompt stays visible, and the
-loss is cross-entropy at the masked positions weighted by 1 / p. The families differ only in the knobs
-below, each taken from that family's published training code.
-"""
+"""Absorbing-mask diffusion (LLaDA, LLaDA-MoE, Dream, Nemotron-Labs-Diffusion); masked CE, 1/p weight."""
import functools
from dataclasses import dataclass
diff --git a/unsloth/models/diffusion_profiles.py b/unsloth/models/diffusion_profiles.py
index 43c9bbeb448..cfa6a93f049 100644
--- a/unsloth/models/diffusion_profiles.py
+++ b/unsloth/models/diffusion_profiles.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Per-family training recipes for text-diffusion language models.
-
-A profile names the checkpoints it handles (``model_types`` / ``architectures``), how they load, which
-LoRA targets are safe, and the training objective. ``DiffusionTrainer`` calls ``profile.compute_loss``
-on ordinary SFT batches (``input_ids``, ``attention_mask``, ``labels`` with -100 outside the response).
-"""
+"""Per-family diffusion recipes; compute_loss gets SFT batches with labels -100 outside the response."""
from dataclasses import dataclass, field
from typing import Optional
diff --git a/unsloth/models/diffusion_samplers.py b/unsloth/models/diffusion_samplers.py
index e24f181a99f..5910440209d 100644
--- a/unsloth/models/diffusion_samplers.py
+++ b/unsloth/models/diffusion_samplers.py
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Text generation for text-diffusion LMs: one sampler per DiffusionProfile name, each the family's published
-decoding recipe. Families shipping a sampler in their modeling code (Dream, LLaDA2, Nemotron-Labs-Diffusion,
-DiffusionGemma) are called as is; LLaDA / LLaDA-MoE and SDAR samplers live in separate scripts upstream and are
-re-implemented here."""
+"""Dream, LLaDA2, Nemotron-Labs-Diffusion, DiffusionGemma call samplers; LLaDA/SDAR re-implemented."""
import contextlib
import math
diff --git a/unsloth/models/float8_training.py b/unsloth/models/float8_training.py
index bdfc276c95a..bd789c8ec44 100644
--- a/unsloth/models/float8_training.py
+++ b/unsloth/models/float8_training.py
@@ -1,12 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Opt-in torchao float8 training for full finetuning: eligible nn.Linear layers become torchao Float8Linear (fp8 matmuls in forward and backward, high precision master weights).
-
-Usage: `FastModel.from_pretrained(..., full_finetuning = True, float8_training = True)`. True means the
-tensorwise recipe. By name it runs only on compute capability 12.x (RTX PRO 6000 / RTX 50 class), where it
-was measured faster than bfloat16 at equal loss. Other fp8 GPUs (H100, B200, ROCm) need an explicit
-`torchao.float8.Float8LinearConfig`. Works with native FSDP2 (UNSLOTH_FSDP2=1): convert, then shard."""
+"""Opt-in torchao float8 training; True = tensorwise, auto only on CC 12.x (else explicit
+torchao.float8.Float8LinearConfig); with native FSDP2 convert before sharding."""
from __future__ import annotations
diff --git a/unsloth/models/fp8_to_nf4.py b/unsloth/models/fp8_to_nf4.py
index c1403b2f2c7..11f36fa3c6a 100644
--- a/unsloth/models/fp8_to_nf4.py
+++ b/unsloth/models/fp8_to_nf4.py
@@ -10,13 +10,8 @@
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Load a block-FP8 checkpoint straight into bitsandbytes NF4 (``load_in_4bit = True``).
-
-The fp8 block is parked off the config so transformers runs a bnb 4bit load; each FP8 tensor is
-dequantized inside its weight converter right before bnb quantizes it, so only one converter's
-tensors are ever 16-bit and NF4 is bit-identical to loading the dequantized checkpoint. The
-checkpoint's ``modules_to_not_convert`` stay out of bitsandbytes.
-"""
+"""Block-FP8 checkpoint to bnb NF4 (load_in_4bit); each FP8 tensor dequantized just before
+quantizing (bit-identical); modules_to_not_convert stay out of bitsandbytes."""
import contextvars
import copy
diff --git a/unsloth/models/fsdp2.py b/unsloth/models/fsdp2.py
index 306f4402c63..3d088aad4fd 100644
--- a/unsloth/models/fsdp2.py
+++ b/unsloth/models/fsdp2.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""What Unsloth adds around accelerate's `fsdp2_prepare_model` (which already wraps per block,
-keeps the [norm, lm_head] tail gathered, groups tied embeddings). `UNSLOTH_FSDP2_ACCELERATE_DEFAULTS=1`
-skips the mixed precision fill and the last-block setting. bitsandbytes 4-bit (QLoRA) weights are
-sharded too, keeping their QuantState (`fsdp2_qlora.py`).
-"""
+"""Unsloth extras on accelerate's FSDP2; UNSLOTH_FSDP2_ACCELERATE_DEFAULTS=1 skips mixed precision."""
import contextlib
import dataclasses
diff --git a/unsloth/models/fsdp2_bnb_optim.py b/unsloth/models/fsdp2_bnb_optim.py
index bb0bf193200..f07ec148d4d 100644
--- a/unsloth/models/fsdp2_bnb_optim.py
+++ b/unsloth/models/fsdp2_bnb_optim.py
@@ -1,24 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""bitsandbytes 8-bit (and 32-bit) Adam / AdamW under native FSDP2, stepped on the local shards.
-
-bitsandbytes' kernels take plain tensors, and native FSDP2 parameters are DTensors. Each DTensor
-parameter's local shard is an ordinary tensor sharing the parameter's storage, and its gradient's local
-shard is the matching ordinary tensor, so bitsandbytes can step the shard in place. The optimizer
-keeps the DTensor parameters in its param_groups and its state keyed by them (the LR scheduler, the
-Trainer, gradient clipping, GradScaler and torch.distributed.checkpoint all see the same objects); only
-init_state / update_step hand bitsandbytes the local shards.
-
-The 8-bit state is quantized per 256-element block of each LOCAL shard, so it is not bitwise equal to
-one GPU, where the blocks run over the whole tensor. Which parameters get 8-bit state follows one GPU:
-bitsandbytes' `min_8bit_size` rule is applied to the full parameter size, not the shard size.
-
-state_dict() returns the state dequantized to float32, wrapped as DTensors laid out like each parameter,
-so the collective full-state save (get_optimizer_state_dict(full_state_dict = True)) gathers a
-world-size-independent checkpoint. load_state_dict() re-quantizes it: the inverse is exact when the
-blocks are unchanged (same world size), so a resume restores the same 8-bit state.
-"""
+"""bnb 8-bit (and 32-bit) Adam/AdamW on FSDP2: DTensor params stay in param_groups, only local
+shards go to bnb; 8-bit blocks per local shard, not bitwise 1-GPU; state_dict is world-size
+independent."""
import contextlib
import functools
diff --git a/unsloth/models/fsdp2_load.py b/unsloth/models/fsdp2_load.py
index 8e19133db36..67f99b2e383 100644
--- a/unsloth/models/fsdp2_load.py
+++ b/unsloth/models/fsdp2_load.py
@@ -1,31 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Memory-scalable loading for native FSDP2: each rank reads only its FSDP2 shard of the weights.
-
-Without it every rank loads the whole model before `shard_model`, so a model larger than one GPU cannot load.
-Inside `fsdp2_sharded_loading()` every transformers `from_pretrained` (FastLanguageModel, FastModel,
-FastVisionModel and plain transformers loaders all end there) builds the model on meta, then each rank reads
-from the safetensors checkpoint:
-
-* every nn.Linear weight except the output head as this rank's dim-0 chunk (torch.chunk rows, the slice
- `fully_shard` keeps), via safetensors `get_slice` (only those bytes are read);
-* everything else whole (embeddings, norms, biases, buffers), as the full load does.
-
-A chunk stays a plain tensor tagged with its full shape, so nn.Linear keeps its full features and
-get_peft_model builds full-size LoRA with the 1-GPU init. `shard_model` then swaps each chunk for a meta
-placeholder of the full shape (the layout planner sees the whole model), fully_shards, and installs the chunk
-as the FSDP2 local shard (padded as fully_shard pads it), so the full weight never exists on any rank. A chunk
-the layout keeps replicated (fit layout frozen weights, minority-dtype parameters) is all-gathered back,
-exactly what the full load would have held. 16-bit checkpoints only.
-
- with fsdp2_sharded_loading():
- model, tokenizer = FastLanguageModel.from_pretrained(name, load_in_4bit = False, ...)
- model = FastLanguageModel.get_peft_model(model, ...)
- trainer = SFTTrainer(model = model, ...) # UNSLOTH_FSDP2=1: shard_model installs the shards
-
-or `UNSLOTH_FSDP2_SHARDED_LOAD=1` next to `UNSLOTH_FSDP2=1` (Unsloth's loaders then run inside the context).
-"""
+"""Inside fsdp2_sharded_loading() or UNSLOTH_FSDP2_SHARDED_LOAD=1, each rank reads only its dim-0
+chunk of nn.Linear weights (not output head); others whole; 16-bit only."""
from __future__ import annotations
diff --git a/unsloth/models/fsdp2_native.py b/unsloth/models/fsdp2_native.py
index 329ef399ecf..e2612099d23 100644
--- a/unsloth/models/fsdp2_native.py
+++ b/unsloth/models/fsdp2_native.py
@@ -1,19 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Native FSDP2 for every Unsloth model, built directly on `torch.distributed.fsdp.fully_shard`.
-
- for unit in find_shard_units(model): fully_shard(unit, mp_policy = mp)
- fully_shard(model, mp_policy = mp)
-
-with `MixedPrecisionPolicy(param_dtype = compute dtype, reduce_dtype = float32)`. Neither accelerate's
-nor transformers' FSDP code wraps the model: Unsloth shards it before the optimizer exists and the
-Trainer / accelerate only see an already sharded `FSDPModule` (no second wrap, no DDP).
-
-Opt in with `UNSLOTH_FSDP2=1` (or `native`) under torchrun (WORLD_SIZE > 1).
-`UNSLOTH_FSDP2_BACKEND=accelerate` (or an `accelerate launch` FSDP config) keeps the accelerate
-path in `unsloth/models/fsdp2.py`. Nothing changes without the flag.
-"""
+"""Native fully_shard FSDP2 for all Unsloth models, applied before the optimizer exists; opt-in
+UNSLOTH_FSDP2=1 under torchrun; no second wrap, no DDP; UNSLOTH_FSDP2_BACKEND=accelerate keeps
+accelerate path."""
from __future__ import annotations
diff --git a/unsloth/models/fsdp2_native_quant.py b/unsloth/models/fsdp2_native_quant.py
index 505e82bf770..90b9755840f 100644
--- a/unsloth/models/fsdp2_native_quant.py
+++ b/unsloth/models/fsdp2_native_quant.py
@@ -1,19 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Quantized and exotic parameters under Unsloth's native FSDP2 wrap (`fsdp2_native.shard_model`).
-
-`shard_model` calls `fully_shard` on every repeated block and then on the root; around those calls
-`native_quant_context` makes bitsandbytes 4-bit weights shardable (packed bytes stored in the compute
-dtype, QuantState and the Params4bit class kept on the all-gathered weight, no mixed precision cast of
-packed bytes: `fsdp2_qlora.py`), and `after_native_shard` installs what saving and checkpointing need
-and checks that no trainable parameter was left out of FSDP2 (its gradient would not be reduced).
-
- with native_quant_context(model) as quant:
- for unit in units: fully_shard(unit, mp_policy = ...)
- fully_shard(model, mp_policy = ...)
- report = after_native_shard(model)
-"""
+"""bnb 4-bit shardable under native FSDP2; after_native_shard checks no trainable param skips FSDP2."""
__all__ = [
"native_quant_context",
diff --git a/unsloth/models/fsdp2_perf.py b/unsloth/models/fsdp2_perf.py
index e450e1a48bf..5cf1cedae33 100644
--- a/unsloth/models/fsdp2_perf.py
+++ b/unsloth/models/fsdp2_perf.py
@@ -1,31 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Throughput layout for native FSDP2 when the model fits on one GPU.
-
-Plain FSDP2 is slower than DDP for a model that fits on each GPU because it moves weights DDP never
-moves: every block's frozen LoRA base weights are all-gathered in forward and again for the backward
-(or gradient checkpointing) recompute, and full fine-tuning all-gathers each block twice per step.
-When the model fits, the layout here keeps:
-
- * frozen parameters replicated (passed as ``ignored_params``): never gathered, never reduced, exactly
- like DDP, and bitsandbytes 4-bit base weights stay plain ``Params4bit``;
- * trainable parameters, their gradients and optimizer state sharded as usual;
- * the gathered trainable weights resident from forward to backward (``reshard_after_forward=False``),
- one all-gather per step instead of two;
- * explicit next-block prefetch in forward and backward;
- * when only small trainable params are left (LoRA adapters), a single root unit: one all-gather and
- one reduce-scatter per step, no per-block hooks.
-
-Units holding no trainable parameter are not wrapped (no hooks, no empty collectives). Peak memory stays
-at or below DDP: frozen weights are what DDP holds, trainable weights are held once gathered plus one
-shard, and gradients plus optimizer state are sharded.
-
-Env overrides (read only when native FSDP2 is used): ``UNSLOTH_FSDP2_REPLICATE_FROZEN`` = auto | 1 | 0,
-``UNSLOTH_FSDP2_RESHARD_AFTER_FORWARD`` = auto | 1 | 0, ``UNSLOTH_FSDP2_PREFETCH`` = 1 | 0,
-``UNSLOTH_FSDP2_FIT_FRACTION`` (default 0.4 of one device's memory), ``UNSLOTH_FSDP2_FREE_FIT_FRACTION``
-(default max(0.5, fit fraction / 0.8) of free + cached + resident model memory, read after process group init).
-"""
+"""Throughput FSDP2 layout for models fitting one GPU: frozen weights replicated, trainable sharded."""
from dataclasses import dataclass, field
from typing import Optional
diff --git a/unsloth/models/fsdp2_qlora.py b/unsloth/models/fsdp2_qlora.py
index 584dafc1d43..169103ebb0a 100644
--- a/unsloth/models/fsdp2_qlora.py
+++ b/unsloth/models/fsdp2_qlora.py
@@ -1,25 +1,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""QLoRA (bitsandbytes 4-bit) under FSDP2.
-
-FSDP2 can only shard a frozen 4-bit weight whose packed bytes are stored in a float dtype: uint8 cannot
-become a sharded nn.Parameter before torch 2.12 and accelerate leaves it replicated on every rank. So:
-1. a fresh quantization stores the packed bytes as the compute dtype (`bnb_4bit_quant_storage`), and a
- pre-quantized uint8 checkpoint is reinterpreted (a view, no copy) as the same dtype after loading;
-2. FSDPParam keeps the bitsandbytes QuantState on the sharded and the all-gathered parameter (FSDP2
- rebuilds both as plain Parameters, which drops it), so the fused LoRA kernels and bnb's own forward
- still read `weight.quant_state`;
-3. FSDP2 mixed precision never casts packed 4-bit bytes (or any other non-float parameter), and an
- all-gather holding them moves bytes: when every input of a group shares one float dtype FSDP2
- copies them with `torch._foreach_copy_`, which on CUDA rewrites float16 / bfloat16 NaN bit patterns
- (about 1 in 60 packed float16 words) to the canonical NaN;
-4. `nonfloat_param_guard` lets torch < 2.12 shard what is still uint8; torch < 2.8, which wants one
- dtype per unit frozen weights included, leaves uint8 weights out of the units (replicated);
-5. SIZE_BASED_WRAP counts float-packed weights at their uint8 numel, so wrap decisions do not move.
-Float storage is used only when 2 and 3 can be patched and the wrap does not upcast the whole model.
-Method wrappers (not source rewrites, as in axolotl's monkeypatch/fsdp2_qlora.py) hold on torch 2.6 .. 2.14.
-"""
+"""QLoRA under FSDP2: packed 4-bit bytes stored as float dtype to shard, QuantState kept; mixed
+precision never casts them (foreach copy rewrites NaN bit patterns on CUDA); float storage only
+when patchable."""
__all__ = [
"is_params4bit",
diff --git a/unsloth/models/fsdp2_save.py b/unsloth/models/fsdp2_save.py
index 42e25d4eee9..3a155253fdd 100644
--- a/unsloth/models/fsdp2_save.py
+++ b/unsloth/models/fsdp2_save.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Saving an FSDP2-sharded model. Every rank must call the save: the shards are all-gathered one
-parameter at a time, rank 0 swaps the full tensors (on CPU) into the modules, runs the ordinary
-single-GPU save code, and puts the sharded parameters back. bitsandbytes 4-bit weights are gathered
-as raw bytes and rebuilt as Params4bit with their QuantState, so a merge can still dequantize them.
-"""
+"""FSDP2 save: every rank must call it; rank 0 runs the single-GPU save on gathered CPU tensors."""
__all__ = [
"fsdp2_units",
diff --git a/unsloth/models/fsdp2_vision.py b/unsloth/models/fsdp2_vision.py
index f1237d7de31..7dfb22a9fa9 100644
--- a/unsloth/models/fsdp2_vision.py
+++ b/unsloth/models/fsdp2_vision.py
@@ -1,19 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Mixed image / text micro-batches under native FSDP2.
-
-When one rank's micro-batch has images and another's does not, only the image rank runs the vision
-tower: its units all-gather on that rank alone and NCCL pairs the collectives wrongly (hang), and
-FSDP2 reduce-scatters only parameters whose gradient is not None, so even a vision tower held in the
-root unit (fit layout) desyncs at the reduce-scatter. Here a rank without images runs the vision
-encoder on a minimal dummy input before the language model (same collective order as an image rank)
-and adds `0.0 * sum(outputs)` to the multimodal model's output, so every vision parameter gets a zero
-gradient on that rank. No collective and no host sync is added (the decision is local: is
-`pixel_values` given). Installed only by `fsdp2_native.shard_model`, and only when some vision tower
-or projector parameter issues a gradient collective (FSDP2-managed, or replicated with an all-reduce
-hook). `UNSLOTH_FSDP2_VISION_DUMMY=0` turns it off (then every rank's micro-batch must carry an image).
-"""
+"""Image-less ranks run a dummy vision pass (else NCCL hangs); UNSLOTH_FSDP2_VISION_DUMMY=0
+disables, then every rank micro-batch must carry an image."""
import inspect
import os
diff --git a/unsloth/models/glm4_moe.py b/unsloth/models/glm4_moe.py
index 31b95e01810..30cb4a1ce74 100644
--- a/unsloth/models/glm4_moe.py
+++ b/unsloth/models/glm4_moe.py
@@ -9,16 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""
-GLM-4.7 Flash (GLM4 MoE Lite) optimized implementation using grouped GEMM.
-
-Key architecture differences from Qwen3 MoE:
-- Router uses sigmoid activation (not softmax)
-- Has routed_scaling_factor of 1.8
-- Has 1 shared expert that processes all tokens
-- Uses group-based selection before topk
-- Uses MLA (Multi-head Latent Attention)
-"""
+"""GLM-4.7 Flash MoE with sigmoid routing, routed_scaling_factor 1.8, a shared expert and MLA."""
from .loader_utils import DEFAULT_DEVICE_MAP
from .llama import *
diff --git a/unsloth/models/mistral_format.py b/unsloth/models/mistral_format.py
index 3c34233fdf6..070892b4b2a 100644
--- a/unsloth/models/mistral_format.py
+++ b/unsloth/models/mistral_format.py
@@ -14,13 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Load Mistral-format checkpoints (params.json + consolidated*.safetensors, no config.json,
-e.g. Mistral-Large-3) as transformers `mistral4` via a translated view of the same shards.
-
-Mistral-Small-4 ships in both formats with byte-identical tensors, which fixes the name
-mapping. Conversions are registered for one load only so `save_pretrained` writes
-transformers names. Only the text decoder loads; unrecognised checkpoints return None.
-"""
+"""Loads Mistral-format checkpoints as transformers mistral4 (text decoder only); conversions apply
+to one load only; unrecognised checkpoints return None."""
import contextlib
import functools
diff --git a/unsloth/models/modelopt_fp8.py b/unsloth/models/modelopt_fp8.py
index 2b6e311c546..a5d67a342ab 100644
--- a/unsloth/models/modelopt_fp8.py
+++ b/unsloth/models/modelopt_fp8.py
@@ -10,12 +10,7 @@
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Load NVIDIA ModelOpt FP8 checkpoints through transformers' fp8 quantizer.
-
-ModelOpt per-tensor FP8 equals transformers' static fp8 format except for scale names
-(``weight_scale`` / ``input_scale`` vs ``weight_scale_inv`` / ``activation_scale``), so the
-config block is rewritten to ``quant_method: fp8`` and the scales renamed via ``key_mapping``.
-"""
+"""ModelOpt FP8 checkpoints load via transformers' fp8 quantizer; scale names remapped by key_mapping."""
import fnmatch
import functools
diff --git a/unsloth/models/mxfp4_compressed_linear.py b/unsloth/models/mxfp4_compressed_linear.py
index 8b4fe99b733..d1b2822154b 100644
--- a/unsloth/models/mxfp4_compressed_linear.py
+++ b/unsloth/models/mxfp4_compressed_linear.py
@@ -11,11 +11,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Train through compressed-tensors ``mxfp4-pack-quantized`` Linears without unpacking them.
-
-Forward and backward dequantize the frozen weight per use (exact in bf16/fp16), so no 16-bit copy is kept.
-Remote-code MoE experts are stacked into unsloth_zoo ``Mxfp4StackedExperts`` instead (see ``compressed_tensors_bnb``).
-"""
+"""Trains mxfp4-pack-quantized Linears in place; frozen weight dequantized per use, no 16-bit copy."""
import functools
import os
diff --git a/unsloth/models/pp_native.py b/unsloth/models/pp_native.py
index cfef8809c30..85c5cc81a4f 100644
--- a/unsloth/models/pp_native.py
+++ b/unsloth/models/pp_native.py
@@ -1,42 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Pipeline parallelism (torch.distributed.pipelining) for any dense decoder, one stage per rank.
-
- model = FastLanguageModel.get_peft_model(model, ...) # LoRA first: same init as 1 GPU
- pp = apply_pipeline_parallel(model, init_device_mesh("cuda", (pp,), mesh_dim_names = ("pp",))["pp"],
- n_microbatches = 4)
-
-LoRA / QLoRA training of dense decoders (no Trainer, generate). Custom loop (torchrun --nproc_per_node pp),
-the same batch on every rank:
-
- optimizer = torch.optim.AdamW(pp.parameters(), lr = 2e-4) # this stage's trainable parameters
- loss = pp.step(input_ids, labels) # one optimizer step's batch: n_microbatches micro-batches
- pp.clip_grad_norm_(1.0) # global norm over every stage
- optimizer.step(); optimizer.zero_grad()
- pp.save_adapter("out") # collective: the standard 1-GPU PEFT adapter, written by rank 0
-
-Each rank keeps its contiguous slice of decoder layers (FLOP balanced, lm_head + loss counted on the last
-stage). The other layers become parameter-free pass-throughs, so the ModuleList length, layer indices and
-parameter names (adapter keys) do not change. Every stage runs the model's own forward: the first stage from
-input_ids, later stages substitute the received hidden states before their first layer, earlier stages stop
-after their last layer, and the last stage returns the model's own loss (lm_head + fused cross entropy, no
-logits are sent). The loss of each micro-batch is its summed token loss over the token count of the whole
-batch, as with gradient accumulation on one GPU.
-
-Composed with data / tensor parallelism (torchtitan's order: pp outermost, then dp, then tp; split first,
-then parallelize each stage), on one mesh covering every rank:
-
- mesh = init_device_mesh("cuda", (pp, dp, tp), mesh_dim_names = ("pp", "dp", "tp")) # any 2 or all 3
- pp = apply_pipeline_parallel(model, mesh["pp"], n_microbatches = 4) # 1. this rank's stage
- apply_tensor_parallel(model, mesh["tp"]) # 2. optional: tp inside the stage
- shard_model(model, FSDP2Config(mesh = mesh["dp"])) # 3. optional: FSDP2 over dp
- loss = pp.step(input_ids, labels) # this dp replica's slice of the global batch (same on pp / tp peers)
-
-The loss then averages over the tokens of the whole global batch (every dp replica), clip_grad_norm_ counts
-every gradient element once over the world, the GradScaler skip is decided over the world and save_adapter
-writes the 1-GPU adapter from global rank 0.
-"""
+"""Pipeline parallel, one stage per rank; LoRA first; order pp outermost then dp then tp, split
+before parallelizing; save_adapter is collective, rank 0 writes; param names unchanged."""
from __future__ import annotations
diff --git a/unsloth/models/reap.py b/unsloth/models/reap.py
index 9dbae6c63f2..ae33e930fae 100644
--- a/unsloth/models/reap.py
+++ b/unsloth/models/reap.py
@@ -1,14 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""REAP expert pruning (Router-weighted Expert Activation Pruning, arXiv:2510.13999).
-
-Same saliency, expert selection and schedule as llm-compressor's ``REAPPruningModifier``: each
-decoder layer is calibrated on the outputs of the already pruned layers before it, its lowest
-saliency experts are dropped, and the pruned layer produces the next layer's inputs. Expert
-outputs come from the model's own fused experts kernel (one call with every routed (token, slot)
-pair as its own row) instead of per-expert Linear modules, so no extra dependency is needed.
-"""
+"""REAP expert pruning (llm-compressor REAPPruningModifier), layer by layer on already-pruned inputs."""
import inspect
import json
diff --git a/unsloth/models/remote_moe_shims.py b/unsloth/models/remote_moe_shims.py
index 31f0392dc6f..68cee7d811c 100644
--- a/unsloth/models/remote_moe_shims.py
+++ b/unsloth/models/remote_moe_shims.py
@@ -10,9 +10,8 @@
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""Train-mode forwards for DeepSeek-V3-derived remote MoE ports (Kimi-K2.7, sarvam) whose gate
-asserts `not self.training` and whose block only computes under no-grad `moe_infer`. Keyed on
-structure, never repo name; no-op for transformers' own models."""
+"""Train-mode forwards for DeepSeek-V3-derived remote MoE ports, keyed on structure never repo name;
+no-op for the native transformers models."""
import functools
import os
diff --git a/unsloth/models/tp_env.py b/unsloth/models/tp_env.py
index dae8157207d..5f264de07a0 100644
--- a/unsloth/models/tp_env.py
+++ b/unsloth/models/tp_env.py
@@ -1,23 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Tensor parallelism from the environment, for unmodified training scripts.
-
- UNSLOTH_TP_SIZE=2 torchrun --nproc-per-node 2 train.py # tp 2
- UNSLOTH_TP_SIZE=2 torchrun --nproc-per-node 4 train.py # dp 2 (DDP-style) x tp 2
- UNSLOTH_TP_SIZE=2 UNSLOTH_FSDP2=1 torchrun --nproc-per-node 4 train.py # dp 2 (native FSDP2) x tp 2
-
-The layout is read once. The world splits into dp x tp ranks (tp the inner dimension, as in
-init_device_mesh(..., (dp, tp), ("dp", "tp"))). The script's own calls apply it:
-- FastLanguageModel / FastModel.from_pretrained: 16-bit checkpoints load through sharded_loading (each rank
- reads its slices of the attention / MLP projections); 4-bit loads in full and is sharded at get_peft_model.
-- get_peft_model: apply_tensor_parallel over mesh["tp"] once LoRA is attached (full-size LoRA, 1-GPU init).
-- Trainer.__init__: tensor parallel if get_peft_model did not apply it; native FSDP2 shards over mesh["dp"]
- (UNSLOTH_FSDP2=1), otherwise gradients are averaged over mesh["dp"] before clipping and the optimizer step.
-So the order is always split (pipeline parallel, not from the environment yet) -> tp -> FSDP2.
-
-UNSLOTH_TP_SHARDED_LOAD=0 loads 16-bit checkpoints in full on every rank instead (then shards them).
-"""
+"""UNSLOTH_TP_SIZE sets tp from the env (layout read once); order tp then FSDP2 (UNSLOTH_FSDP2=1)
+over dp, else dp grads averaged before clipping and the optimizer step."""
from __future__ import annotations
diff --git a/unsloth/models/tp_replica.py b/unsloth/models/tp_replica.py
index 74776442ebd..59efac453ed 100644
--- a/unsloth/models/tp_replica.py
+++ b/unsloth/models/tp_replica.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Post-training cells on a tensor parallel model; every rank must make these calls.
-
-- for_inference / generate: every rank gathers a whole one-GPU replica in place; the sharded parameters come
- back on for_training or the next training forward. tp rank 0's RNG is copied so all ranks sample alike.
-- saves / exports: weights are gathered to global rank 0, which runs the single-process save; the other ranks
- wait on the rendezvous store (no collective timeout, no NCCL watchdog) and return rank 0's result.
-"""
+"""Post-training calls on a TP model, every rank must make them; saves gather to rank 0 while other
+ranks wait (no collective timeout); generate copies tp rank 0 RNG."""
from __future__ import annotations
diff --git a/unsloth/optimizers/state_offload.py b/unsloth/optimizers/state_offload.py
index 087a1c76902..1b6acb7ceea 100644
--- a/unsloth/optimizers/state_offload.py
+++ b/unsloth/optimizers/state_offload.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Optimizer-state-only CPU offload (UNSLOTH_OFFLOAD_OPTIMIZER_STATE=1).
-
-State lives in pinned host memory between steps and visits the GPU only inside optimizer.step,
-so peak memory is max(activations, optimizer state) instead of their sum. The step runs in chunks
-of UNSLOTH_OFFLOAD_OPTIMIZER_STATE_CHUNK_MB (default 1024) of state, so the step itself never holds
-all of it on device either (parameter-local optimizers only, see _CHUNK_SAFE_MODULES).
-"""
+"""UNSLOTH_OFFLOAD_OPTIMIZER_STATE=1: state on host, chunked to GPU in step; parameter-local only."""
import copy
import os
diff --git a/unsloth/tokenizers_v1.py b/unsloth/tokenizers_v1.py
index 4eb8c0f3431..a09b9dbac5e 100644
--- a/unsloth/tokenizers_v1.py
+++ b/unsloth/tokenizers_v1.py
@@ -1,20 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023-present Daniel Han-Chen & the Unsloth team. All rights reserved.
-"""Opt-in encoding through the ``tokenizers`` 1.0 release candidate.
-
-transformers requires ``tokenizers<0.24`` and builds its tokenizers from the 0.x component API,
-which the RC drops, so the RC cannot replace 0.x. Instead it is installed beside it:
-
- pip install --pre --no-deps --target ~/.cache/unsloth/tokenizers_v1 "tokenizers>=1.0.0rc2"
- UNSLOTH_TOKENIZERS_V1=1 python train.py # UNSLOTH_TOKENIZERS_V1_PATH overrides the directory
-
-and loaded under another module name. The fast tokenizer's 0.x backend is then wrapped: plain
-encodes (str input, no pair, no pre-split words; padding and truncation included) run on the RC,
-everything else goes to 0.x unchanged. Each RC copy is built from the backend's own JSON and must
-match 0.x on a probe set first, else the backend stays on 0.x. Fields the RC's ``Encoding`` lacks
-(offsets, tokens, word ids, special tokens mask, ...) are recomputed by 0.x on first access.
-"""
+"""Opt-in tokenizers 1.0 RC (UNSLOTH_TOKENIZERS_V1=1): plain encodes only; a backend failing the
+probe against 0.x stays on 0.x."""
import contextlib
import copy
diff --git a/unsloth/utils/flash_impl.py b/unsloth/utils/flash_impl.py
index 375396e07cd..891ddf15f8b 100644
--- a/unsloth/utils/flash_impl.py
+++ b/unsloth/utils/flash_impl.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Run torch's flash kernels as FA4 / FA3 while a packed / padding-free trainer trains.
-
-torch (2.11+) swaps the flash impl process-wide, and FA4 raises (not falls back) on dropout and missing
-head dims and costs ~0.2 ms per launch, so it is on only inside ``trainer.train()``, with no dropout,
-supported head dims, and a probe matching torch's bundled flash.
-UNSLOTH_FLASH_ATTENTION_IMPL = auto (default: FA4 on sm100; on sm90 FA3 then FA4, only for models with
-hidden_size >= _HOPPER_AUTO_MIN_HIDDEN) | fa4 | fa3 | off.
-"""
+"""FA4/FA3 flash only inside trainer.train(), with no dropout, supported head dims and a probe
+matching torch flash (FA4 raises, not falls back); UNSLOTH_FLASH_ATTENTION_IMPL selects."""
import contextlib
import functools
diff --git a/unsloth/utils/hf_packed_attention.py b/unsloth/utils/hf_packed_attention.py
index 86677d5b6ac..bf9f47af261 100644
--- a/unsloth/utils/hf_packed_attention.py
+++ b/unsloth/utils/hf_packed_attention.py
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Packed rows on the transformers modeling path run a varlen flash kernel (torch's, else xformers /
-flash-attn) instead of SDPA over a dense block-causal mask; heads past flash's 256 (Gemma-4 global
-layers, 512) and shapes an FA4 / FA3 impl refuses run SDPA's memory-efficient kernel over the same
-cu_seqlens. Anything else reaches the wrapped "sdpa"."""
+"""Packed rows use varlen flash; heads past 256 and shapes FA4/FA3 refuses use SDPA mem-efficient;
+anything else goes to the wrapped sdpa."""
import contextlib
import inspect
diff --git a/unsloth/utils/mfu.py b/unsloth/utils/mfu.py
index 6940f327065..97688914761 100644
--- a/unsloth/utils/mfu.py
+++ b/unsloth/utils/mfu.py
@@ -1,38 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Opt-in achieved TFLOPs and MFU logging with LoRA-aware FLOP counts.
-
-Turn on with `UNSLOTH_LOG_MFU=1` before building the trainer, or call `add_mfu_callback(trainer)`.
-Each training log then gains `train_tflops_per_gpu` and `train_hw_tflops_per_gpu` and, when the
-GPU peak is known, `train_mfu` and `train_hfu`. Set `UNSLOTH_PEAK_TFLOPS` to the per GPU dense
-peak to override the table (for example a measured MAMF number).
-
-`train_mfu` excludes the checkpointing recompute (PaLM MFU); `train_hfu` includes it. They were
-one value (HFU) before the split; that value is now `train_hfu` / `train_hw_tflops_per_gpu`.
-
-Model FLOPs per non padding token, summed over every linear layer with n = in * out weights:
- forward 2n every linear, frozen or trainable
- backward input grads 2n every linear (gradients flow through frozen weights to LoRA)
- backward weight grads 2n only linears whose weight requires grad
- recompute 2n every linear except the output head, when checkpointing
- (hardware FLOPs / HFU only)
-Attention adds 4 * layers * heads * head_dim FLOPs per causal (query, key) pair in the forward
-(QK^T and AV), L * (L + 1) / 2 pairs for a sequence of length L (L * L when every attention
-layer is bidirectional), times 3 for forward plus backward (times 4 with checkpointing in the
-hardware count). The
-output head is charged only for the last `logits_to_keep` positions when the forward passes it.
-Only the active copy of a PEFT `modules_to_save` wrapper and the active LoRA adapters are
-counted. Experts held as `nn.Linear` in an `experts` ModuleList count top_k / num_experts of
-their weights; experts stored as 3D tensors (transformers 5), sliding windows, convolutions,
-embedding lookups and the vision / audio towers of multimodal models (only the text decoder and
-head are walked) are not counted, and layers shared across depth (ALBERT) are counted once, so
-those models report a lower bound. Only `layer_types` entries that are softmax attention get the
-pair term. Backward input grads are charged to every linear, so layouts whose lowest trainable
-parameter sits above a frozen block (head-only training, linear probing) are overstated by up to
-2n per frozen linear below it. Encoder-decoder models are not reported. A model split over
-several GPUs with `device_map` reports the average per participating GPU.
-"""
+"""Opt-in UNSLOTH_LOG_MFU=1: LoRA-aware TFLOPs and MFU logging; train_hfu counts checkpoint recompute."""
__all__ = [
"count_linear_flops_per_token",
diff --git a/unsloth/utils/mm_packing.py b/unsloth/utils/mm_packing.py
index 689dfa426bc..1d1fdb6f128 100644
--- a/unsloth/utils/mm_packing.py
+++ b/unsloth/utils/mm_packing.py
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Packed rows of multimodal documents: each collated alone, then concatenated with per-document
-``position_ids``, from which transformers masks image blocks to their own document."""
+"""Packed multimodal rows: docs collated alone, concatenated; position_ids confine images to own doc."""
from __future__ import annotations
diff --git a/unsloth/utils/padding_choice.py b/unsloth/utils/padding_choice.py
index 457fa8c9f52..885df578701 100644
--- a/unsloth/utils/padding_choice.py
+++ b/unsloth/utils/padding_choice.py
@@ -1,33 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Choose between padding-free and padded batches for SFT when the user left `padding_free` unset.
-
-Padding-free removes pad tokens, but its varlen batches skip the per-block compile, so each step
-launches more kernels from Python. Padded batches pay for their pad tokens on the GPU but run the
-compiled blocks. Which one is faster depends on whether a micro batch is bound by the host or by the
-GPU: measured on A100, L4, T4 and RTX PRO 6000 Blackwell with Qwen3 0.6B / 4B LoRA (16 bit and
-4 bit), padded + block compile was 5-17% faster only when a padded micro batch costs the GPU well
-under the ~0.25-0.4 s the host spends launching it, and up to 57% slower once the GPU is the
-bottleneck.
-
-Rule (all estimates, every unknown keeps padding-free, the old default):
- padded GPU time = (linear FLOPs per token * padded tokens + attention FLOPs per pair * pairs)
- / (datasheet 16 bit peak * _EFFICIENCY)
- pick padded iff padded GPU time < the measured threshold for the GPU's compute capability
- (_MAX_PADDED_GPU_S_BY_CAPABILITY; any other capability keeps padding-free)
- and the run has enough micro batches to repay the extra block compile
- (about 25 s in 16 bit, 100 s in 4 bit) at ~_SAVED_S_PER_MICROBATCH each.
-
-Only Linux + NVIDIA CUDA on a measured compute capability is ever switched: ROCm / HIP, Windows,
-XPU, MPS, CPU and unmeasured capabilities (H100 / H200 sm90, B200 / B300 sm100 / sm103 have
-datasheet peaks but no measurement yet) keep padding-free, unless `UNSLOTH_PADDING_CHOICE=padded`
-is set explicitly.
-
-`UNSLOTH_PADDING_CHOICE=padding_free` restores the previous behaviour (always padding-free),
-`=padded` forces padded batches, `=auto` (default) applies the rule. An explicit
-`padding_free=True/False` on the config always wins.
-"""
+"""Unset padding_free: padded only on Linux CUDA with a measured capability; explicit padding_free
+always wins; UNSLOTH_PADDING_CHOICE sets the mode."""
import logging
import math
diff --git a/unsloth/utils/prefix_grouper_kernel.py b/unsloth/utils/prefix_grouper_kernel.py
index 8140db7c591..7e3b514754b 100644
--- a/unsloth/utils/prefix_grouper_kernel.py
+++ b/unsloth/utils/prefix_grouper_kernel.py
@@ -10,39 +10,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-"""FlexAttention shared-prefix kernel for PrefixGrouper (GRPO shared-prompt dedup).
-
-In GRPO every prompt spawns ``G = num_generations`` completions that share the same
-prompt prefix. The full-row packed path forwards the identical prefix ``G`` times.
-PrefixGrouper stores the prefix ONCE and concatenates only the ``G`` suffixes, with an
-attention layout where each suffix token attends to ``[the single shared prefix] +
-[causal within its own suffix]``. This kernel expresses that one-prefix -> many-suffix
-fan-out via a ``torch.nn.attention.flex_attention`` block mask, so the masked-out
-cross-suffix / cross-group blocks are never computed and the ``P + G*R`` FLOP saving is
-realised (not merely a masked dense ``O(T^2)``).
-
-Mask semantics (identical to the certified SDPA oracle):
-
- keep(q_idx, kv_idx) = same_group(q, kv) AND
- ( is_prefix[kv_idx] # full prefix visibility
- OR ( suffix_of_kv[kv_idx] == suffix_of_kv[q_idx] # same suffix ...
- AND kv_idx <= q_idx ) ) # ... causal within it
-
-This module is self-contained (no dependency on any temp/ scratch dir) so PrefixGrouper
-works from the installed source after a fresh compile. It is only imported lazily from
-``attention_dispatch.run_attention`` when ``prefix_seg_info`` is present, which itself is
-only ever set when ``UNSLOTH_GRPO_PREFIX_GROUPER`` is on and grouping succeeded, so the
-default (off) path never touches this file.
-
-Provided entry points:
- * ``PrefixSegInfo`` : per-flat-token segment metadata + cache signature.
- * ``build_seg_info_multigroup``: build PrefixSegInfo for many groups packed flat.
- * ``build_seg_info_from_layout``: build PrefixSegInfo for ONE group (test helper).
- * ``get_block_mask`` : cached create_block_mask keyed on the signature.
- * ``flex_shared_prefix_attention(Q, K, V, prefix_seg_info)``
- Q/K/V of shape [1, T, n_heads, head_dim]; returns [1, T, n_heads, head_dim],
- IDENTICAL semantics to the SDPA oracle.
-"""
+"""GRPO PrefixGrouper FlexAttention kernel, prefix stored once; self-contained (no temp dir
+dependency); imported lazily only when prefix_seg_info is set, so default-off never imports it."""
from __future__ import annotations
diff --git a/unsloth/utils/token_budget.py b/unsloth/utils/token_budget.py
index 4f8de419403..1a14a73682d 100644
--- a/unsloth/utils/token_budget.py
+++ b/unsloth/utils/token_budget.py
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Opt-in token-aware SFT micro-batches, off unless their env var is set.
-
-UNSLOTH_TOKEN_BALANCE=1 spreads each optimizer step's rows over data-parallel ranks and
-accumulation slots with equal token counts; every step keeps its rows, so num_items_in_batch
-is unchanged. UNSLOTH_TOKEN_BUDGET=<tokens> runs a larger micro-batch as several passes over
-whole sequences, each divided by the same num_items_in_batch, so they sum to the unsplit loss.
-"""
+"""Opt-in token-aware SFT micro-batches: UNSLOTH_TOKEN_BALANCE=1 keeps num_items_in_batch unchanged;
+UNSLOTH_TOKEN_BUDGET passes sum to the unsplit loss."""
from __future__ import annotations
diff --git a/unsloth/utils/ulysses_hybrid.py b/unsloth/utils/ulysses_hybrid.py
index d4d6f263ca7..e742c05bb6f 100644
--- a/unsloth/utils/ulysses_hybrid.py
+++ b/unsloth/utils/ulysses_hybrid.py
@@ -1,13 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
-"""Ulysses context parallelism for hybrid models: Gated DeltaNet layers and Hugging Face attention.
-
-Linear attention scans run sequentially over the whole sequence, so a sequence shard cannot run its
-scan alone. Ulysses exchanges the projected q / k / v / beta / gate inputs from sequence shards to
-head shards, runs the short conv and the chunked scan over the full sequence for a subset of heads,
-and exchanges the output back before the gated norm and the output projection.
-"""
+"""Ulysses context parallelism for hybrid models: scans need the full sequence, so they run on heads."""
import functools
import inspect
diff --git a/unsloth_cli/_studio_deps.py b/unsloth_cli/_studio_deps.py
index 7cd280efd1b..9c3af6b7cd5 100644
--- a/unsloth_cli/_studio_deps.py
+++ b/unsloth_cli/_studio_deps.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Unsloth dependency checks shared by the CLI commands.
-
-The wheel ships studio/ and studio.backend*, so train / export / chat /
-inference / studio all work after a plain `pip install unsloth` right up to the
-point they import the backend. studio_backend_imports() turns the resulting
-traceback into one sentence and the two commands that fix it.
-
-Also loads studio/install_manifest.py for `unsloth studio verify-install`.
-"""
+"""Dependency checks: studio_backend_imports() explains import failures; loads install_manifest.py."""
from __future__ import annotations
diff --git a/unsloth_cli/_studio_stage.py b/unsloth_cli/_studio_stage.py
index 01b582eb82d..4e832ce4393 100644
--- a/unsloth_cli/_studio_stage.py
+++ b/unsloth_cli/_studio_stage.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""The passive half of the 805-807 background update contract.
-
-Those shells run the INSTALLED (old) CLI with `--stage`, which clones the venv, runs this
-package's setup inside the clone and on POSIX imports `finalize_for_activation` from the staged
-tree. This wheel stages nothing, but those names must stay: stdlib only, importable under -I.
-"""
+"""Stub for old CLI's --stage path: keep finalize_for_activation; stdlib only, importable under -I."""
from __future__ import annotations
diff --git a/unsloth_cli/_system_dir_guard.py b/unsloth_cli/_system_dir_guard.py
index b6799629a47..bd6ae7089fe 100644
--- a/unsloth_cli/_system_dir_guard.py
+++ b/unsloth_cli/_system_dir_guard.py
@@ -1,21 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Windows system-folder guard for the `unsloth` console script.
-
-C:\\Windows\\System32 is unwritable for a normal user, and cwd-relative paths
-(`./models`, `unsloth_compiled_cache`) would resolve inside the Windows tree.
-
-Two ways in. "Run as administrator" opens a terminal there, a mistake that still
-stops with an actionable error. And "Run Unsloth at login" starts the desktop
-from an HKCU Run value, which carries no working directory, so it and every CLI
-child inherit System32 (issue #8510). That one is not the user's mistake: the
-desktop's own commands take no paths from the user, so they move to ~/.unsloth
-rather than leaving a tray icon and no server.
-
-Imports stay at `os`: this runs before the command modules, which resolve
-STUDIO_HOME against the working directory.
-"""
+"""Windows System32 guard: login-started desktop's commands run in ~/.unsloth; imports are os only."""
import os as _os
diff --git a/unsloth_cli/_tool_policy.py b/unsloth_cli/_tool_policy.py
index d3ffcd5d450..50d2a18d1fa 100644
--- a/unsloth_cli/_tool_policy.py
+++ b/unsloth_cli/_tool_policy.py
@@ -1,10 +1,6 @@
# Copyright 2025-present the Unsloth AI Inc. team. All rights reserved.
-"""Pure resolver for `unsloth studio [run] --enable-tools/--disable-tools`.
-
-Kept as a standalone module so the truth table can be unit-tested
-without spinning up Typer or the studio venv.
-"""
+"""Pure resolver for --enable-tools/--disable-tools, kept free of Typer so it is unit-testable."""
import ipaddress
import socket
diff --git a/unsloth_cli/commands/_password_prompt.py b/unsloth_cli/commands/_password_prompt.py
index 1391f04d31c..741fc94aa73 100644
--- a/unsloth_cli/commands/_password_prompt.py
+++ b/unsloth_cli/commands/_password_prompt.py
@@ -1,15 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Masked terminal password prompt for the first-exposure password change.
-
-Mirror of ``studio/backend/auth/terminal_prompt.py`` -- keep the two in sync.
-The CLI parent cannot import the backend package outside the studio venv, so the
-reader is duplicated here (like the auth mirroring in ``commands/studio.py``).
-
-Input echoes one ``*`` per character (unlike ``getpass``). All output goes to
-stderr so redirected stdout stays clean.
-"""
+"""Masked password prompt, mirror of studio/backend/auth/terminal_prompt.py (keep in sync)."""
from __future__ import annotations
diff --git a/unsloth_cli/commands/doctor.py b/unsloth_cli/commands/doctor.py
index 1622523133a..3dc7f322030 100644
--- a/unsloth_cli/commands/doctor.py
+++ b/unsloth_cli/commands/doctor.py
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""`unsloth doctor --gpus`: a multi-GPU preflight to run before a distributed job.
-
-Reports the GPUs, versions and interconnect, checks that peer copies keep their
-data, runs a short all_reduce across every visible GPU, and ends with a verdict
-and the settings to try. torch is imported lazily so `unsloth --help` stays fast.
-"""
+"""unsloth doctor --gpus: multi-GPU preflight; torch imported lazily to keep --help fast."""
import os
import shutil
diff --git a/unsloth_cli/commands/mcp.py b/unsloth_cli/commands/mcp.py
index e1244cc5382..efc3f87568f 100644
--- a/unsloth_cli/commands/mcp.py
+++ b/unsloth_cli/commands/mcp.py
@@ -1,11 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""`unsloth mcp add <agent>` and the checks behind `unsloth doctor --mcp`.
-
-Agent configs only name the environment variable that holds the API key. `mcp add`
-never reads the key; doctor sends it to the server to test it and never prints it.
-"""
+"""mcp add never reads the API key (configs name only its env var); doctor tests it, never prints it."""
import copy
import difflib