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.

studio: trim comments in header sizes (#13610)

Daniel Han14f35a882af1
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py
index 0aa189c7145..29a58a19d1b 100644
--- a/studio/backend/core/inference/diffusion.py
+++ b/studio/backend/core/inference/diffusion.py
@@ -11945,7 +11945,6 @@ def _pipeline_components_from_index(
if explicit_components is None:
from .diffusion_component_sizes import manifest_entry_loaded
- # the same predicate the size planner reads the manifest with
selected = {
str(name) for name, spec in payload.items() if manifest_entry_loaded(name, spec)
}
diff --git a/studio/backend/core/inference/diffusion_component_sizes.py b/studio/backend/core/inference/diffusion_component_sizes.py
index 29633526194..279b3f4916f 100644
--- a/studio/backend/core/inference/diffusion_component_sizes.py
+++ b/studio/backend/core/inference/diffusion_component_sizes.py
@@ -18,10 +18,7 @@ from typing import Any, Callable, Iterable, Optional
logger = logging.getLogger(__name__)
MAX_HEADER_BYTES = 256 * 1024 * 1024
-# Bits per element of every floating dtype safetensors names. Float8 / float6 / float4 / MX scales count as float:
-# loaded at bf16 they occupy 2 bytes per parameter. Sub-byte types are packed: the header ``shape`` is the logical
-# element count and the byte span is numel * bits / 8 (an F4 [4, 16] tensor spans 32 bytes), so parameters are
-# counted as bytes * 8 / bits.
+# Float bits per element; sub-byte types are packed, so parameters = bytes * 8 / bits (loaded at 2 bytes each).
FLOAT_BITS = {
"F64": 64,
"F32": 32,
@@ -96,8 +93,7 @@ class ComponentSize:
nonfloat_bytes: int
bytes_by_dtype: tuple[tuple[str, int], ...] = field(default_factory = tuple)
files: tuple[str, ...] = field(default_factory = tuple)
- # Of the totals above: tensors under the LTX loader's connector key prefixes bundled into a denoiser folder. The
- # loader splits them off (video_ltx2._checkpoint_group) and the pack prices them as its own connectors/ folder.
+ # LTX connector tensors bundled in a denoiser folder; the loader splits them off (video_ltx2._checkpoint_group).
bundled_connector_float_params: int = 0
bundled_connector_nonfloat_bytes: int = 0
@@ -124,12 +120,9 @@ class ComponentSizes:
components: dict
source: str = "local"
revision: Optional[str] = None
- # Component names model_index.json declares (None when it was not read).
manifest: Optional[frozenset] = None
- # Folders holding weights whose size could not be read (a .bin checkpoint, an unreadable header or index).
unknown: frozenset = frozenset()
- # Stored bytes of the weight files in each ``unknown`` folder (an upper bound of its bf16-resident size for any
- # checkpoint stored at >= 2 bytes per parameter), when known.
+ # Stored bytes per ``unknown`` folder: an upper bound of its bf16 size when stored at >= 2 bytes/param.
unknown_bytes: tuple = ()
def get(self, name: str) -> Optional[ComponentSize]:
@@ -224,8 +217,7 @@ _TRANSFORMERS_FOLDER_RE = re.compile(r"^(?:text_encoder|image_encoder|prompt_enh
def _stem_order(folder: str) -> tuple[str, ...]:
"""LTX-2's text_encoder/ ships both stems; only the preferred one loads. ``pytorch_model`` is the legacy stem."""
if _TRANSFORMERS_FOLDER_RE.match(folder or ""):
- # transformers' PreTrainedModel.from_pretrained reads model.safetensors / its index, else pytorch_model.bin
- # (not sized here, so the folder is unknown); never diffusion_pytorch_model.* or pytorch_model.safetensors
+ # transformers reads model.safetensors / its index, else pytorch_model.bin (unknown here)
return ("model",)
return ("diffusion_pytorch_model", "model", "pytorch_model")
@@ -248,8 +240,7 @@ def select_weight_files(
return [f"{stem}.safetensors"]
if any(_SHARD_RE.match(n) and n.startswith(stem + "-") for n in names):
return []
- # Nothing else is selected: from_pretrained reads only these stems (Studio passes no variant, so a
- # diffusion_pytorch_model.fp16.safetensors twin is not read either), never e.g. adapter_model.safetensors.
+ # Only these stems load (Studio passes no variant, so .fp16 twins are not read either).
return []
@@ -295,9 +286,7 @@ def _pick_files(
"""Only the loader's PREFERRED index counts (it never falls back to a stale second one); unreadable or
naming a missing shard makes the component unknown, never a smaller subset."""
names = list(names)
- # Same-stem order follows the loader: transformers (5.5 modeling_utils._get_resolved_checkpoint_files) takes an
- # unsharded model.safetensors before the index; diffusers (ModelMixin.from_pretrained, _fetch_index_file) takes
- # the index first.
+ # Loader order: transformers takes unsharded model.safetensors before the index; diffusers the index first.
unsharded_first = bool(_TRANSFORMERS_FOLDER_RE.match(folder or ""))
for stem in _stem_order(folder):
index = f"{stem}.safetensors.index.json"
@@ -710,7 +699,6 @@ def _read_hub_sizes(
unknown_bytes: dict = {}
try:
for folder, files in sorted(by_folder.items()):
- # Studio-attached extras are never in the manifest; the caller only asks for them when attached
if (
manifest is not None
and folder not in manifest
@@ -799,8 +787,7 @@ def component_sizes(
if local is not None and all(c in local.components for c in need):
if not allow_hub or snap is None or hub_disabled():
return local
- # online: the cached snapshot answers only while the ref still points at it (TTL-cached resolve)
- # an unresolved ref (head None) is not a match: probe the Hub, and keep the local sizes only if that fails too
+ # online: the snapshot answers only while the ref still points at it; unresolved -> probe the Hub first
head = resolve_ref(str(repo_or_dir), token = token)
if head is not None and head == snap.name:
return local
@@ -818,8 +805,7 @@ VIDEO_ROLE_VAE = ("vae", "audio_vae", "vocoder", "connectors")
VIDEO_EXTRA_VAE_ROLE: dict[str, tuple[str, ...]] = {"ltx-2.5": ("latent_upsampler",)}
# Studio attaches these itself, so model_index.json never names them (LTX-2.5's latent_upsampler/).
_LOADED_OUTSIDE_MANIFEST = frozenset(f for roles in VIDEO_EXTRA_VAE_ROLE.values() for f in roles)
-# Companion folders and when a family loads them; one that is present is counted only when its family rule says so
-# or model_index.json names it (a leftover folder in a repo is not a loaded component).
+# A present companion counts only by family rule or model_index.json (leftover folders are not loaded).
VIDEO_COMPANION_RULES: dict[str, Callable[[Any], bool]] = {
"audio_vae": lambda fam: bool(getattr(fam, "has_audio", False)),
"vocoder": lambda fam: bool(getattr(fam, "has_audio", False)),
@@ -900,7 +886,6 @@ def video_loaded_roles(
def video_required_roles(fam: Any) -> tuple[str, ...]:
"""Connectors, vocoder, upsampler, a second text encoder are optional: never a reason to go to the Hub."""
denoiser = getattr(fam, "denoiser_attr", None) or "transformer"
- # an MoE's second expert is not required: see _second_expert_loaded
roles = [denoiser]
roles += ["text_encoder", "vae"]
if bool(getattr(fam, "has_audio", False)):
@@ -1122,7 +1107,6 @@ def video_components_gb(
),
*VIDEO_ROLE_TEXT,
*VIDEO_ROLE_VAE,
- # only the extras this load attaches: a dev / single-stage load never probes the latent upsampler
*attached_extras(fam, dev),
)
sizes = component_sizes(
diff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.py
index bf853372331..604a78e92a8 100644
--- a/studio/backend/core/inference/video.py
+++ b/studio/backend/core/inference/video.py
@@ -6364,12 +6364,10 @@ class VideoBackend:
components = video_components_gb(
fam,
- # a GGUF / single-file load takes its companions from the resolved base (a caller-supplied base_repo
- # included), not the family default
+ # GGUF / single-file: companions come from the resolved base, not the family default
repo_id if kind == "pipeline" else base,
allow_hub = not local_files_only,
token = hf_token,
- # a dev (single-stage) LTX-2.5 load attaches no latent upsampler, so it is not a loaded role
dev = _ltx25_dev_load(fam, kind, gguf_filename, repo_id, display_repo_id),
)
mib_per_gb = 1000.0**3 / (1024.0 * 1024.0)
@@ -9908,15 +9906,12 @@ class VideoBackend:
offload_policy = state.offload_policy,
device = state.device,
)
- # The step-cache mode THIS request runs: an AUTO decision is re-taken per request below
- # (maybe_toggle_step_cache), so the key uses the same rule now and is corrected after the
- # runner-aware toggle if that disagrees.
+ # Key on the cache mode this request runs; corrected after the runner-aware toggle.
if state.cache_auto:
from .diffusion_cache import auto_step_cache_mode
request_cache_mode = auto_step_cache_mode(steps)
else:
request_cache_mode = getattr(state, "transformer_cache", None)
- # This request's peak sizes the next request of its size (refusal below, Wan residency fit).
calibration = video_stream_residency.calibration_key(
fam.name,
getattr(state, "repo_id", None),
@@ -9937,7 +9932,6 @@ class VideoBackend:
memory_mode = getattr(state, "memory_mode", None),
transformer_quant = getattr(state, "transformer_quant", None),
text_encoder_quant = getattr(state, "text_encoder_quant", None),
- # fps (audio length), keyframes / references (extra latents) and CFG all move the peak
fps = out_fps if getattr(fam, "has_audio", False) else None,
conditioning = conditioning,
first_frame = first_pil is not None,
@@ -9967,7 +9961,6 @@ class VideoBackend:
logger = logger,
)
else:
- # the fit arms its own measurement; every other family is armed here
video_stream_residency.arm_request(
state.pipe,
key = calibration,
diff --git a/studio/backend/tests/test_diffusion_component_sizes.py b/studio/backend/tests/test_diffusion_component_sizes.py
index d974ef99295..8642c23f733 100644
--- a/studio/backend/tests/test_diffusion_component_sizes.py
+++ b/studio/backend/tests/test_diffusion_component_sizes.py
@@ -948,7 +948,6 @@ def test_transformer_2_counts_only_for_moe(tmp_path):
assert dcs.video_header_terms(_fam("wan2.2-t2v-a14b"), sizes)[0] == pytest.approx(4.0)
-# ---- review round 4 ----
def test_pytorch_model_stem_and_its_index_are_recognised(tmp_path):
@@ -1106,7 +1105,6 @@ def test_sub_byte_floats_count_parameters_by_bit_width(tmp_path):
assert dcs.FLOAT_BITS["F4"] == 4 and dcs.FLOAT_BITS["F6_E2M3"] == dcs.FLOAT_BITS["F6_E3M2"] == 6
-# ---- review round 5 ----
def test_unresolved_ref_probes_the_hub_and_falls_back_to_local(tmp_path, monkeypatch):
@@ -1177,7 +1175,6 @@ def test_same_stem_order_follows_the_loader(tmp_path):
assert sizes.get("transformer").files == ("diffusion_pytorch_model-00001-of-00001.safetensors",)
-# ---- review round 6 ----
def test_hub_skips_folders_the_manifest_does_not_load(monkeypatch):
@@ -1291,7 +1288,6 @@ def test_local_index_read_is_capped(tmp_path, monkeypatch):
assert sizes is None and "diffusion_pytorch_model.safetensors.index.json" not in reads
-# ---- review round 7 ----
def test_snapshot_missing_a_loaded_role_is_incomplete(tmp_path, monkeypatch):
@@ -1350,7 +1346,6 @@ def test_index_fetch_is_bounded_by_the_deadline_while_a_peer_trickles():
release.set()
-# ---- review round 8 ----
def test_ltx_bundled_connector_tensors_leave_the_denoiser_term(tmp_path):
@@ -1444,7 +1439,6 @@ def test_moe_second_expert_is_optional_unless_shipped(tmp_path):
] == pytest.approx(28.6)
-# ---- review round 9 ----
def test_partial_term_keeps_its_known_sum_as_a_lower_bound(tmp_path, monkeypatch):
@@ -1580,7 +1574,6 @@ def test_calibration_key_carries_the_revision():
assert a != vsr.calibration_key("ltx-2", "r", "group", "cuda:0", revision = "b" * 40)
-# ---- review round 10 ----
def test_manifest_predicate_matches_the_loader(tmp_path):
@@ -1674,7 +1667,6 @@ def test_retagged_peak_is_recorded_under_the_mode_that_ran(monkeypatch):
assert vsr.measured_extra_mib(predicted, 64) is None
-# ---- review round 11 ----
def test_pre_download_plan_threads_the_dev_flag():