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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio diffusion: a numbered shard without its index is not a complete snapshot (#16418)
Daniel Hane02bc9eaa784
diff --git a/studio/backend/core/inference/diffusion_small_host.py b/studio/backend/core/inference/diffusion_small_host.pyindex 73b909da39e..d47005e70a0 100644--- a/studio/backend/core/inference/diffusion_small_host.py+++ b/studio/backend/core/inference/diffusion_small_host.py@@ -7,6 +7,7 @@ from __future__ import annotationsimport jsonimport os+import reimport sysimport uuidfrom dataclasses import dataclass, field@@ -268,8 +269,7 @@ def snapshot_weights_complete(skip: Any = (),variant: Optional[str] = None,) -> bool:- """False when a ``model_index.json`` component lacks weights or index-listed shards; True without an index.- ``skip`` names caller-supplied components; ``variant`` checks only that layout's files."""+ """Check pipeline weights for the requested variant, excluding caller-supplied components."""try:root = Path(snapshot)index = json.loads((root / "model_index.json").read_text(encoding = "utf-8"))@@ -293,6 +293,7 @@ def snapshot_weights_complete(]if not files and (sub / "config.json").is_file():return False # a model folder without weights; tokenizer / scheduler folders have no config.json+ indexed_shards = set()for shard_index in shard_indexes:try:shards = set(@@ -304,6 +305,14 @@ def snapshot_weights_complete(return Falseif any(not (sub / shard).is_file() for shard in shards):return False+ indexed_shards.update(shards)+ # All numbered shards still need the index the loader opens.+ if any(+ re.search(r"-\d{5}-of-\d{5}(?:\.[^.]+)?\.(?:safetensors|bin)$", f.name)+ and f.name not in indexed_shards+ for f in files+ ):+ return Falsereturn Truediff --git a/studio/backend/tests/test_diffusion_small_host.py b/studio/backend/tests/test_diffusion_small_host.pyindex b3841a27994..5d8aa506cf9 100644--- a/studio/backend/tests/test_diffusion_small_host.py+++ b/studio/backend/tests/test_diffusion_small_host.py@@ -580,7 +580,9 @@ def _header_only((sub / filename).write_bytes(struct.pack("<Q", len(raw)) + raw)[email protected]("cached", ["configs_only", "vae_only", "one_dit_shard"])+ "cached", ["configs_only", "vae_only", "one_dit_shard", "one_dit_shard_no_index"]+)def test_a_partially_cached_snapshot_downloads_before_the_decision(tmp_path, monkeypatch, cached):"""An interrupted download leaves some weights cached; sizing them alone hides the large denoiser."""from core.inference import diffusion as dif@@ -604,10 +606,16 @@ def test_a_partially_cached_snapshot_downloads_before_the_decision(tmp_path, mon_header_only(full, "vae", 161)if cached == "vae_only":_header_only(partial, "vae", 161)- if cached == "one_dit_shard":+ if cached in ("one_dit_shard", "one_dit_shard_no_index"):_header_only(partial, "transformer", 4096, "diffusion_pytorch_model-00001-of-00005.safetensors")+ if cached == "one_dit_shard_no_index":+ _header_only(partial, "text_encoder", 1000, "model.safetensors")+ _header_only(partial, "vae", 161)+ for name in ("transformer", "text_encoder", "vae"):+ (partial / name / "config.json").write_text("{}")+ if cached == "one_dit_shard":(partial / "transformer" / "diffusion_pytorch_model.safetensors.index.json").write_text(json.dumps({@@ -640,6 +648,46 @@ def test_a_partially_cached_snapshot_downloads_before_the_decision(tmp_path, monassert d.engaged and d.int8_spill+ "stem,extension,variant",+ [+ ("diffusion_pytorch_model", "safetensors", None),+ ("model", "safetensors", None),+ ("pytorch_model", "bin", None),+ ("diffusion_pytorch_model", "safetensors", "fp16"),+ ],+)+def test_numbered_shards_require_an_index_covering_them(tmp_path, stem, extension, variant):+ (tmp_path / "model_index.json").write_text(+ json.dumps({"transformer": ["diffusers", "X"], "vae": ["diffusers", "Y"]})+ )+ mark = f".{variant}" if variant else ""+ _header_only(tmp_path, "vae", 1, f"diffusion_pytorch_model{mark}.safetensors")+ sub = tmp_path / "transformer"+ sub.mkdir()+ (sub / "config.json").write_text("{}")+ names = [f"{stem}{mark}-{i:05d}-of-00002.{extension}" for i in (1, 2)]+ (sub / names[0]).touch()+ assert not sh.snapshot_weights_complete(tmp_path, variant = variant)+ assert sh.snapshot_weights_complete(tmp_path, skip = ("transformer",), variant = variant)+ (sub / names[1]).touch()+ assert not sh.snapshot_weights_complete(tmp_path, variant = variant)+ shard_index = sub / f"{stem}.{extension}.index{mark}.json"+ orphan = f"{stem}{mark}.{extension}"+ (sub / orphan).touch()+ for content in (+ "{",+ "{}",+ json.dumps({"weight_map": {"other": orphan}}),+ ):+ shard_index.write_text(content)+ assert not sh.snapshot_weights_complete(tmp_path, variant = variant)+ shard_index.write_text(json.dumps({"weight_map": {f"w{i}": n for i, n in enumerate(names)}}))+ assert sh.snapshot_weights_complete(tmp_path, variant = variant)+ (sub / names[1]).unlink()+ assert not sh.snapshot_weights_complete(tmp_path, variant = variant)++def test_a_complete_snapshot_with_a_supplied_component_skips_the_download(tmp_path):index = {"transformer": ["diffusers", "X"],