From ccd827a0f4479c10441444ab4cf64f23ac7eaac3 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Tue, 17 Nov 2026 23:17:38 +0000 Subject: [PATCH 01/13] feat(fsdp): resolve a Diffusers component's class and folder from the checkpoint's modular index MiniMax-H3-Image keeps its Diffusers DiT in `transformer_diffusers/`, declared only in `modular_model_index.json`; its root `model_index.json` names the engine's native class in `transformer/`. The backend read only the root index and used the component's name as the folder. It now reads the modular index when the checkpoint ships one, as diffusers' modular loader does, and takes the folder from the component's loading spec. Weights still come from the checkpoint the run names, not from the repository a loading spec names. --- miles/backends/fsdp_utils/model_backend.py | 55 +++++++-- .../backends/fsdp_utils/test_model_backend.py | 111 ++++++++++++++++++ 2 files changed, 156 insertions(+), 10 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index ff470e54c..df786798e 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -20,11 +20,15 @@ import abc import functools import importlib +import json import logging +import os from dataclasses import replace import torch -from diffusers import DiffusionPipeline +from diffusers import DiffusionPipeline, ModularPipeline +from huggingface_hub import hf_hub_download +from huggingface_hub.errors import EntryNotFoundError from .models.parallel_plan import FSDPParallelPlan from .sequence_parallel.diffusers_dispatch import install_diffusers_usp_patch @@ -189,9 +193,9 @@ def load_component( master_dtype: torch.dtype, materialize_weights: bool, ) -> torch.nn.Module: - model_cls = self._resolve_component_class(checkpoint_path, component) + model_cls, subfolder = self._resolve_component(checkpoint_path, component) kwargs = { - "subfolder": component, + "subfolder": subfolder, "torch_dtype": master_dtype, "low_cpu_mem_usage": materialize_weights, } @@ -210,8 +214,13 @@ def load_component( model_cls._keep_in_fp32_modules = keep_in_fp32 @classmethod - def _resolve_component_class(cls, checkpoint_path: str, component: str): - """Resolve ``component``'s class from ``model_index.json``. + def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, str]: + """``component``'s class and its folder under ``checkpoint_path``, from the checkpoint's index. + + A checkpoint that ships ``modular_model_index.json`` is read from it, as diffusers' modular loader does: + its root ``model_index.json`` may describe another layout of the same weights (MiniMax-H3-Image's names the + engine's native classes). The folder is the one the component's loading spec names, else the component's + name. The repository a loading spec names is not followed: weights come from ``checkpoint_path``. Components load individually via ``cls.from_pretrained(subfolder=...)`` rather than through ``DiffusionPipeline.from_pretrained`` with the siblings passed as @@ -221,16 +230,42 @@ def _resolve_component_class(cls, checkpoint_path: str, component: str): loaded from disk anyway — on every rank, and with ``low_cpu_mem_usage=False`` it also trips diffusers' ``_keep_in_fp32_modules`` guard. """ - config = DiffusionPipeline.load_config(checkpoint_path) + index_name = ModularPipeline.config_name + config = cls._read_modular_index(checkpoint_path) + if config is None: + index_name = DiffusionPipeline.config_name + config = DiffusionPipeline.load_config(checkpoint_path) if component not in config: - raise ValueError(f"pipeline {checkpoint_path} has no component {component!r}") - component_cls = cls._component_class(config[component]) + raise ValueError(f"{index_name} of {checkpoint_path} has no component {component!r}") + spec = config[component] + component_cls = cls._component_class(spec) if component_cls is None: raise ValueError( f"cannot resolve the class for component {component!r} of {checkpoint_path} " - f"from spec {config[component]!r}; remote-code components are not supported" + f"from spec {spec!r}; remote-code components are not supported" ) - return component_cls + if len(spec) == 2: + return component_cls, component + subfolder = spec[2].get("subfolder") if isinstance(spec[2], dict) else None + if not isinstance(subfolder, str) or not subfolder: + raise ValueError(f"component {component!r} of {checkpoint_path} names no subfolder in its spec {spec!r}") + return component_cls, subfolder + + @staticmethod + def _read_modular_index(checkpoint_path: str) -> dict | None: + """``modular_model_index.json`` of a local or Hub checkpoint; None when it ships none.""" + if os.path.isdir(checkpoint_path): + index_file = os.path.join(checkpoint_path, ModularPipeline.config_name) + if not os.path.isfile(index_file): + return None + else: + try: + index_file = hf_hub_download(checkpoint_path, ModularPipeline.config_name) + # an unreachable Hub still raises + except EntryNotFoundError: + return None + with open(index_file) as f: + return json.load(f) @staticmethod def _component_class(spec): diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index ee653ff55..17b85b40a 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -10,11 +10,54 @@ import json +import diffusers +import pytest import torch +from huggingface_hub.errors import EntryNotFoundError +from miles.backends.fsdp_utils import model_backend from miles.backends.fsdp_utils.model_backend import BaseModelBackend, DiffusersModelBackend, MilesModelBackend from miles.backends.fsdp_utils.models.diffusers import load_fsdp_parallel_plan +# MiniMaxAI/MiniMax-H3-Image at 8ced6006: transformer/ holds the engine's native layout +_H3_IMAGE_INDEX = {"_class_name": "MiniMaxH3ImagePipeline", "transformer": ["diffusers", "MiniMaxH3DiTModel"]} +_H3_IMAGE_MODULAR_INDEX = { + "_class_name": "MiniMaxH3ImageModularPipeline", + "transformer": [ + "diffusers", + "MiniMaxH3ImageTransformer2DModel", + { + "type_hint": ["diffusers", "MiniMaxH3ImageTransformer2DModel"], + "pretrained_model_name_or_path": "MiniMaxAI/MiniMax-H3-Image", + "subfolder": "transformer_diffusers", + "variant": None, + "revision": None, + }, + ], +} +# MiniMaxAI/MiniMax-H3 at 42ed227e: both index files carry these entries +_H3_INDEX = { + "_class_name": "MiniMaxH3ModularPipeline", + "transformer_ref": [ + "diffusers", + "MiniMaxH3Transformer3DModel", + { + "type_hint": ["diffusers", "MiniMaxH3Transformer3DModel"], + "pretrained_model_name_or_path": "MiniMaxAI/MiniMax-H3", + "subfolder": "transformer_ref", + "variant": None, + "revision": None, + }, + ], +} + + +def _write_checkpoint(path, index, modular_index=None): + (path / "model_index.json").write_text(json.dumps(index)) + if modular_index is not None: + (path / "modular_model_index.json").write_text(json.dumps(modular_index)) + return str(path) + class _RecordingModel(torch.nn.Module): def __init__(self): @@ -83,3 +126,71 @@ def test_component_loads_from_its_own_role_checkpoint(self, tmp_path): "torch_dtype": torch.float32, "low_cpu_mem_usage": True, } + + @pytest.mark.parametrize( + ("index", "modular_index", "component", "expected"), + [ + ( + _H3_IMAGE_INDEX, + _H3_IMAGE_MODULAR_INDEX, + "transformer", + (diffusers.MiniMaxH3ImageTransformer2DModel, "transformer_diffusers"), + ), + (_H3_INDEX, _H3_INDEX, "transformer_ref", (diffusers.MiniMaxH3Transformer3DModel, "transformer_ref")), + ], + ids=["h3-image", "h3"], + ) + def test_modular_index_names_the_class_and_the_folder(self, tmp_path, index, modular_index, component, expected): + """MiniMax-H3-Image's root index names classes diffusers does not have, in a folder of another layout.""" + checkpoint = _write_checkpoint(tmp_path, index, modular_index) + + assert DiffusersModelBackend._resolve_component(checkpoint, component) == expected + + def test_component_loads_from_the_checkpoint_not_the_repository_its_spec_names(self, tmp_path): + """A local mirror or a fine-tuned copy keeps the release's index; following it would train the release.""" + spec = {"pretrained_model_name_or_path": "org/release", "subfolder": "transformer_diffusers"} + checkpoint = _write_checkpoint( + tmp_path, _H3_IMAGE_INDEX, {"transformer": [__name__, "_CheckpointComponent", spec]} + ) + + model = DiffusersModelBackend(None).load_component( + "transformer", checkpoint_path=checkpoint, master_dtype=torch.float32, materialize_weights=True + ) + + assert model.checkpoint_path == checkpoint + assert model.load_kwargs["subfolder"] == "transformer_diffusers" + + def test_loading_spec_without_a_subfolder_is_rejected(self, tmp_path): + checkpoint = _write_checkpoint( + tmp_path, _H3_IMAGE_INDEX, {"transformer": [__name__, "_CheckpointComponent", {"subfolder": None}]} + ) + + with pytest.raises(ValueError, match="names no subfolder"): + DiffusersModelBackend._resolve_component(checkpoint, "transformer") + + def test_hub_checkpoint_without_a_modular_index_reads_model_index(self, monkeypatch): + def raise_entry_not_found(repo_id, filename): + raise EntryNotFoundError(f"{repo_id} has no {filename}") + + monkeypatch.setattr(model_backend, "hf_hub_download", raise_entry_not_found) + monkeypatch.setattr( + model_backend.DiffusionPipeline, + "load_config", + lambda checkpoint_path: {"transformer": [__name__, "_CheckpointComponent"]}, + ) + + assert DiffusersModelBackend._resolve_component("org/classic", "transformer") == ( + _CheckpointComponent, + "transformer", + ) + + def test_hub_failure_reading_the_modular_index_is_not_taken_for_its_absence(self, monkeypatch): + """An outage read as "no modular index" would resolve the root index's layout instead.""" + + def raise_connection_error(repo_id, filename): + raise ConnectionError("hub unreachable") + + monkeypatch.setattr(model_backend, "hf_hub_download", raise_connection_error) + + with pytest.raises(ConnectionError): + DiffusersModelBackend._resolve_component("org/release", "transformer") From 6833be2a81e6d8764e3bc0057ae410baa5d6f8fa Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:35:54 +0000 Subject: [PATCH 02/13] fix(fsdp): read the root index when the Hub cannot serve an uncached modular index A classic checkpoint's cache never holds modular_model_index.json, so the probe has no cached copy to fall back to. Offline it already read as absent, but a gated repo without a token or a stale token raised, and a mistyped local path surfaced as a repo-id error: loads that worked before the probe failed at trainer start. All three now fall through to the root index, which loads from the cache or gives diffusers' own error. The class error names the index it read, so a root-index read of a partially cached modular checkpoint is visible. --- miles/backends/fsdp_utils/model_backend.py | 12 ++--- .../backends/fsdp_utils/test_model_backend.py | 53 ++++++++++++++++--- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index df786798e..a677611d1 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -28,7 +28,7 @@ import torch from diffusers import DiffusionPipeline, ModularPipeline from huggingface_hub import hf_hub_download -from huggingface_hub.errors import EntryNotFoundError +from huggingface_hub.errors import EntryNotFoundError, HfHubHTTPError, HFValidationError from .models.parallel_plan import FSDPParallelPlan from .sequence_parallel.diffusers_dispatch import install_diffusers_usp_patch @@ -241,8 +241,8 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, component_cls = cls._component_class(spec) if component_cls is None: raise ValueError( - f"cannot resolve the class for component {component!r} of {checkpoint_path} " - f"from spec {spec!r}; remote-code components are not supported" + f"cannot resolve the class for component {component!r} from {index_name} of {checkpoint_path}: " + f"spec {spec!r}; remote-code components are not supported" ) if len(spec) == 2: return component_cls, component @@ -253,7 +253,7 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, @staticmethod def _read_modular_index(checkpoint_path: str) -> dict | None: - """``modular_model_index.json`` of a local or Hub checkpoint; None when it ships none.""" + """``modular_model_index.json`` of a local or Hub checkpoint; None when neither the Hub nor the cache has one.""" if os.path.isdir(checkpoint_path): index_file = os.path.join(checkpoint_path, ModularPipeline.config_name) if not os.path.isfile(index_file): @@ -261,8 +261,8 @@ def _read_modular_index(checkpoint_path: str) -> dict | None: else: try: index_file = hf_hub_download(checkpoint_path, ModularPipeline.config_name) - # an unreachable Hub still raises - except EntryNotFoundError: + # no cached copy and no answer (offline, gated, not a repo id): the cached snapshot holds none + except (EntryNotFoundError, HfHubHTTPError, HFValidationError): return None with open(index_file) as f: return json.load(f) diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index 17b85b40a..27cb78e94 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -11,9 +11,11 @@ import json import diffusers +import httpx +import huggingface_hub import pytest import torch -from huggingface_hub.errors import EntryNotFoundError +from huggingface_hub.errors import EntryNotFoundError, GatedRepoError from miles.backends.fsdp_utils import model_backend from miles.backends.fsdp_utils.model_backend import BaseModelBackend, DiffusersModelBackend, MilesModelBackend @@ -184,13 +186,48 @@ def raise_entry_not_found(repo_id, filename): "transformer", ) - def test_hub_failure_reading_the_modular_index_is_not_taken_for_its_absence(self, monkeypatch): - """An outage read as "no modular index" would resolve the root index's layout instead.""" + def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monkeypatch, tmp_path): + """A classic checkpoint's cache never holds a modular index, so the probe has no copy to fall back to.""" + monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True) + monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_CACHE", str(tmp_path)) + monkeypatch.setattr( + model_backend.DiffusionPipeline, + "load_config", + lambda checkpoint_path: {"transformer": [__name__, "_CheckpointComponent"]}, + ) + + assert DiffusersModelBackend._resolve_component("org/classic", "transformer") == ( + _CheckpointComponent, + "transformer", + ) - def raise_connection_error(repo_id, filename): - raise ConnectionError("hub unreachable") + def test_cached_classic_checkpoint_resolves_when_the_hub_refuses_the_probe(self, monkeypatch): + """A gated repo answers 401 without a token, also for a file it does not have.""" - monkeypatch.setattr(model_backend, "hf_hub_download", raise_connection_error) + def raise_gated(repo_id, filename): + response = httpx.Response(401, request=httpx.Request("HEAD", f"https://huggingface.co/{repo_id}")) + raise GatedRepoError(f"{repo_id} is gated", response=response) - with pytest.raises(ConnectionError): - DiffusersModelBackend._resolve_component("org/release", "transformer") + monkeypatch.setattr(model_backend, "hf_hub_download", raise_gated) + monkeypatch.setattr( + model_backend.DiffusionPipeline, + "load_config", + lambda checkpoint_path: {"transformer": [__name__, "_CheckpointComponent"]}, + ) + + assert DiffusersModelBackend._resolve_component("org/gated", "transformer") == ( + _CheckpointComponent, + "transformer", + ) + + def test_missing_local_checkpoint_is_reported_as_a_missing_directory(self, tmp_path): + """A mistyped path is not a repo id; the probe must not turn it into a repo-id error.""" + with pytest.raises(OSError, match="not the path to a directory containing a model_index.json"): + DiffusersModelBackend._resolve_component(str(tmp_path / "missing"), "transformer") + + def test_unresolvable_class_names_the_index_it_was_read_from(self, tmp_path): + """With a partial cache the root index is read; its native class must not look like the modular one's.""" + checkpoint = _write_checkpoint(tmp_path, {"transformer": ["diffusers", "NoSuchNativeModel"]}) + + with pytest.raises(ValueError, match="from model_index.json of"): + DiffusersModelBackend._resolve_component(checkpoint, "transformer") From 212ad5cfa018a3b966d120dd33f7000a316b8d07 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:35:54 +0000 Subject: [PATCH 03/13] refactor(fsdp): name the index dict index and keep the per-component loading note with load_component --- miles/backends/fsdp_utils/model_backend.py | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index a677611d1..86b6d0ec2 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -193,6 +193,16 @@ def load_component( master_dtype: torch.dtype, materialize_weights: bool, ) -> torch.nn.Module: + """Load one component of a Diffusers checkpoint by itself. + + Components load individually via ``cls.from_pretrained(subfolder=...)`` rather + than through ``DiffusionPipeline.from_pretrained`` with the siblings passed as + ``None``: pipelines that declare a component optional with a ``None`` default + (e.g. ``WanPipeline.transformer``/``transformer_2``) drop it from + ``expected_modules``, so the ``None`` is silently ignored and the sibling is + loaded from disk anyway — on every rank, and with ``low_cpu_mem_usage=False`` + it also trips diffusers' ``_keep_in_fp32_modules`` guard. + """ model_cls, subfolder = self._resolve_component(checkpoint_path, component) kwargs = { "subfolder": subfolder, @@ -221,23 +231,15 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, its root ``model_index.json`` may describe another layout of the same weights (MiniMax-H3-Image's names the engine's native classes). The folder is the one the component's loading spec names, else the component's name. The repository a loading spec names is not followed: weights come from ``checkpoint_path``. - - Components load individually via ``cls.from_pretrained(subfolder=...)`` rather - than through ``DiffusionPipeline.from_pretrained`` with the siblings passed as - ``None``: pipelines that declare a component optional with a ``None`` default - (e.g. ``WanPipeline.transformer``/``transformer_2``) drop it from - ``expected_modules``, so the ``None`` is silently ignored and the sibling is - loaded from disk anyway — on every rank, and with ``low_cpu_mem_usage=False`` - it also trips diffusers' ``_keep_in_fp32_modules`` guard. """ index_name = ModularPipeline.config_name - config = cls._read_modular_index(checkpoint_path) - if config is None: + index = cls._read_modular_index(checkpoint_path) + if index is None: index_name = DiffusionPipeline.config_name - config = DiffusionPipeline.load_config(checkpoint_path) - if component not in config: + index = DiffusionPipeline.load_config(checkpoint_path) + if component not in index: raise ValueError(f"{index_name} of {checkpoint_path} has no component {component!r}") - spec = config[component] + spec = index[component] component_cls = cls._component_class(spec) if component_cls is None: raise ValueError( From 33dba708f37851624cf355640655a790dbb00f90 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:24:41 +0000 Subject: [PATCH 04/13] docs(fsdp): say when the modular index probe returns None --- miles/backends/fsdp_utils/model_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index 86b6d0ec2..07092eb8c 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -255,7 +255,7 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, @staticmethod def _read_modular_index(checkpoint_path: str) -> dict | None: - """``modular_model_index.json`` of a local or Hub checkpoint; None when neither the Hub nor the cache has one.""" + """``modular_model_index.json`` of a checkpoint; None when it ships none, or the Hub cannot be asked and no copy is cached.""" if os.path.isdir(checkpoint_path): index_file = os.path.join(checkpoint_path, ModularPipeline.config_name) if not os.path.isfile(index_file): @@ -263,7 +263,7 @@ def _read_modular_index(checkpoint_path: str) -> dict | None: else: try: index_file = hf_hub_download(checkpoint_path, ModularPipeline.config_name) - # no cached copy and no answer (offline, gated, not a repo id): the cached snapshot holds none + # 404, or no answer (offline, gated, not a repo id) and no cached copy: the load goes on from the root index except (EntryNotFoundError, HfHubHTTPError, HFValidationError): return None with open(index_file) as f: From 231023ca504f89af58492d29a62fc73750aba17e Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:36:35 +0000 Subject: [PATCH 05/13] docs(fsdp): say which index entries take their folder from the component's name --- miles/backends/fsdp_utils/model_backend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index 07092eb8c..4fecc611d 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -229,8 +229,9 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, A checkpoint that ships ``modular_model_index.json`` is read from it, as diffusers' modular loader does: its root ``model_index.json`` may describe another layout of the same weights (MiniMax-H3-Image's names the - engine's native classes). The folder is the one the component's loading spec names, else the component's - name. The repository a loading spec names is not followed: weights come from ``checkpoint_path``. + engine's native classes). The folder is the ``subfolder`` of the component's loading spec; an entry without + a loading spec uses the component's name. The repository a loading spec names is not followed: weights come + from ``checkpoint_path``. """ index_name = ModularPipeline.config_name index = cls._read_modular_index(checkpoint_path) From 8042436856391f5904b5b71e55114ffe272853a0 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:17:57 +0000 Subject: [PATCH 06/13] fix(fsdp): say why the modular index was not read, and what the class error found A probe the Hub could not answer (offline, gated, not a repo id) fell through to `model_index.json` without a trace, and the class error that follows for a checkpoint whose root index names another layout blamed remote code. The fall-through is logged with its cause, a 404 stays silent, the class error says the installed library does not provide the class, and the missing-subfolder error names the index it read. --- miles/backends/fsdp_utils/model_backend.py | 26 ++++++++++++++----- .../backends/fsdp_utils/test_model_backend.py | 5 ++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index 4fecc611d..c93d59775 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -28,7 +28,7 @@ import torch from diffusers import DiffusionPipeline, ModularPipeline from huggingface_hub import hf_hub_download -from huggingface_hub.errors import EntryNotFoundError, HfHubHTTPError, HFValidationError +from huggingface_hub.errors import EntryNotFoundError, HfHubHTTPError, HFValidationError, RemoteEntryNotFoundError from .models.parallel_plan import FSDPParallelPlan from .sequence_parallel.diffusers_dispatch import install_diffusers_usp_patch @@ -245,13 +245,17 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, if component_cls is None: raise ValueError( f"cannot resolve the class for component {component!r} from {index_name} of {checkpoint_path}: " - f"spec {spec!r}; remote-code components are not supported" + f"spec {spec!r} names a class the installed library does not provide (remote-code components are " + f"not supported)" ) if len(spec) == 2: return component_cls, component - subfolder = spec[2].get("subfolder") if isinstance(spec[2], dict) else None + loading_spec = spec[2] if isinstance(spec[2], dict) else {} + subfolder = loading_spec.get("subfolder") if not isinstance(subfolder, str) or not subfolder: - raise ValueError(f"component {component!r} of {checkpoint_path} names no subfolder in its spec {spec!r}") + raise ValueError( + f"component {component!r} names no subfolder in its spec {spec!r} in {index_name} of {checkpoint_path}" + ) return component_cls, subfolder @staticmethod @@ -264,8 +268,18 @@ def _read_modular_index(checkpoint_path: str) -> dict | None: else: try: index_file = hf_hub_download(checkpoint_path, ModularPipeline.config_name) - # 404, or no answer (offline, gated, not a repo id) and no cached copy: the load goes on from the root index - except (EntryNotFoundError, HfHubHTTPError, HFValidationError): + except RemoteEntryNotFoundError: + return None + # no answer (offline, gated, not a repo id) and no cached copy: the load goes on from the root index + except (EntryNotFoundError, HfHubHTTPError, HFValidationError) as error: + logger.info( + "%s of %s could not be read (%s: %s); reading %s", + ModularPipeline.config_name, + checkpoint_path, + type(error).__name__, + error, + DiffusionPipeline.config_name, + ) return None with open(index_file) as f: return json.load(f) diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index 27cb78e94..d07580885 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -15,7 +15,7 @@ import huggingface_hub import pytest import torch -from huggingface_hub.errors import EntryNotFoundError, GatedRepoError +from huggingface_hub.errors import GatedRepoError, RemoteEntryNotFoundError from miles.backends.fsdp_utils import model_backend from miles.backends.fsdp_utils.model_backend import BaseModelBackend, DiffusersModelBackend, MilesModelBackend @@ -172,7 +172,8 @@ def test_loading_spec_without_a_subfolder_is_rejected(self, tmp_path): def test_hub_checkpoint_without_a_modular_index_reads_model_index(self, monkeypatch): def raise_entry_not_found(repo_id, filename): - raise EntryNotFoundError(f"{repo_id} has no {filename}") + response = httpx.Response(404, request=httpx.Request("HEAD", f"https://huggingface.co/{repo_id}")) + raise RemoteEntryNotFoundError(f"{repo_id} has no {filename}", response=response) monkeypatch.setattr(model_backend, "hf_hub_download", raise_entry_not_found) monkeypatch.setattr( From d4bf0736221a1e8dbe8485afa6394ba699c1ebe7 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:17:57 +0000 Subject: [PATCH 07/13] test(fsdp): resolve a cached modular checkpoint while the Hub is offline The Hub tests covered only the fall-through to `model_index.json`. A repo id whose modular index is cached is the path a MiniMax-H3-Image run takes, and returning early when offline would break it with every test green. --- .../backends/fsdp_utils/test_model_backend.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index d07580885..080c061bb 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -202,6 +202,24 @@ def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monke "transformer", ) + def test_cached_modular_checkpoint_resolves_from_its_modular_index_while_the_hub_is_offline( + self, monkeypatch, tmp_path + ): + """Falling through to the root index here would name the engine's native classes for MiniMax-H3-Image.""" + snapshot = tmp_path / "models--org--modular" / "snapshots" / ("0" * 40) + snapshot.mkdir(parents=True) + (snapshot / "modular_model_index.json").write_text(json.dumps(_H3_IMAGE_MODULAR_INDEX)) + refs = tmp_path / "models--org--modular" / "refs" + refs.mkdir() + (refs / "main").write_text("0" * 40) + monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True) + monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_CACHE", str(tmp_path)) + + assert DiffusersModelBackend._resolve_component("org/modular", "transformer") == ( + diffusers.MiniMaxH3ImageTransformer2DModel, + "transformer_diffusers", + ) + def test_cached_classic_checkpoint_resolves_when_the_hub_refuses_the_probe(self, monkeypatch): """A gated repo answers 401 without a token, also for a file it does not have.""" From 4e6810e34fe58871454e64beae7b8efe94832e3e Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:17:57 +0000 Subject: [PATCH 08/13] fix(fsdp): refuse a loading spec that names a weight variant diffusers' modular loader passes a spec's `variant` to `from_pretrained`; the backend read only `subfolder`, so a checkpoint that names one would have loaded the repository's default weights of that component without a word. No index read so far names a variant, so the load is refused as untested instead of guessed. --- miles/backends/fsdp_utils/model_backend.py | 6 ++++++ tests/fast/backends/fsdp_utils/test_model_backend.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index c93d59775..c00e6636b 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -256,6 +256,12 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, raise ValueError( f"component {component!r} names no subfolder in its spec {spec!r} in {index_name} of {checkpoint_path}" ) + if loading_spec.get("variant") is not None: + raise ValueError( + f"component {component!r} names the weight variant {loading_spec['variant']!r} in its spec in " + f"{index_name} of {checkpoint_path}; loading a variant is untested, and loading without it could " + f"read other weights" + ) return component_cls, subfolder @staticmethod diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index 080c061bb..70fe29648 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -170,6 +170,14 @@ def test_loading_spec_without_a_subfolder_is_rejected(self, tmp_path): with pytest.raises(ValueError, match="names no subfolder"): DiffusersModelBackend._resolve_component(checkpoint, "transformer") + def test_loading_spec_with_a_weight_variant_is_rejected(self, tmp_path): + """Loading without the variant could read the repository's other weights of the same component.""" + spec = [__name__, "_CheckpointComponent", {"subfolder": "transformer", "variant": "fp16"}] + checkpoint = _write_checkpoint(tmp_path, _H3_IMAGE_INDEX, {"transformer": spec}) + + with pytest.raises(ValueError, match="weight variant 'fp16'"): + DiffusersModelBackend._resolve_component(checkpoint, "transformer") + def test_hub_checkpoint_without_a_modular_index_reads_model_index(self, monkeypatch): def raise_entry_not_found(repo_id, filename): response = httpx.Response(404, request=httpx.Request("HEAD", f"https://huggingface.co/{repo_id}")) From ded4e0285afd525ad52cc9d30e4d5b1c66d8ec08 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:17:57 +0000 Subject: [PATCH 09/13] docs(fsdp): name both index files that mark a Diffusers checkpoint --- miles/backends/fsdp_utils/models/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miles/backends/fsdp_utils/models/__init__.py b/miles/backends/fsdp_utils/models/__init__.py index 5828ad95f..0dd3e05dd 100644 --- a/miles/backends/fsdp_utils/models/__init__.py +++ b/miles/backends/fsdp_utils/models/__init__.py @@ -2,7 +2,8 @@ Onboarding a model family: -- **Diffusers checkpoint** (has ``model_index.json``): +- **Diffusers checkpoint** (has ``modular_model_index.json`` or ``model_index.json``; the modular one is read + when shipped): ``DiffusersModelBackend`` loads it; add ``models/diffusers//parallel_plan.py`` for its FSDP precision plan. From fda4223cb769358f9747967a21530fbe0c13d45a Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:51:25 +0000 Subject: [PATCH 10/13] fix(fsdp): word the class error for an entry that names no class "Names a class the installed library does not provide" is false for a null entry and for a type_hint-only one, which fail in the same place. --- miles/backends/fsdp_utils/model_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index c00e6636b..e8e46d3ff 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -245,7 +245,7 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, if component_cls is None: raise ValueError( f"cannot resolve the class for component {component!r} from {index_name} of {checkpoint_path}: " - f"spec {spec!r} names a class the installed library does not provide (remote-code components are " + f"spec {spec!r} does not name a class an installed library provides (remote-code components are " f"not supported)" ) if len(spec) == 2: From 30c0aa2c276029039d8cb2f29ee0c70d3de8a7b6 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:51:26 +0000 Subject: [PATCH 11/13] fix(fsdp): log the cause of an unanswered modular-index probe, not the Hub client's wrapper Offline mode, a refused connection and a timeout all reach the fall-through as one LocalEntryNotFoundError that tells the reader to check their connection; the reason is its cause. The log prints that, and the tests pin both halves of the split: a 404 logs nothing, an offline probe logs why. --- miles/backends/fsdp_utils/model_backend.py | 10 ++++++---- .../fast/backends/fsdp_utils/test_model_backend.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index e8e46d3ff..24d302758 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -28,7 +28,7 @@ import torch from diffusers import DiffusionPipeline, ModularPipeline from huggingface_hub import hf_hub_download -from huggingface_hub.errors import EntryNotFoundError, HfHubHTTPError, HFValidationError, RemoteEntryNotFoundError +from huggingface_hub.errors import HfHubHTTPError, HFValidationError, LocalEntryNotFoundError, RemoteEntryNotFoundError from .models.parallel_plan import FSDPParallelPlan from .sequence_parallel.diffusers_dispatch import install_diffusers_usp_patch @@ -277,13 +277,15 @@ def _read_modular_index(checkpoint_path: str) -> dict | None: except RemoteEntryNotFoundError: return None # no answer (offline, gated, not a repo id) and no cached copy: the load goes on from the root index - except (EntryNotFoundError, HfHubHTTPError, HFValidationError) as error: + except (LocalEntryNotFoundError, HfHubHTTPError, HFValidationError) as error: + # the Hub client wraps "no answer and nothing cached" in one fixed message; its cause says which + cause = error.__cause__ if isinstance(error, LocalEntryNotFoundError) and error.__cause__ else error logger.info( "%s of %s could not be read (%s: %s); reading %s", ModularPipeline.config_name, checkpoint_path, - type(error).__name__, - error, + type(cause).__name__, + cause, DiffusionPipeline.config_name, ) return None diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index 70fe29648..8cca0b3bc 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -9,6 +9,7 @@ register_cpu_ci(est_time=15, suite="stage-a-cpu", labels=[]) import json +import logging import diffusers import httpx @@ -178,7 +179,9 @@ def test_loading_spec_with_a_weight_variant_is_rejected(self, tmp_path): with pytest.raises(ValueError, match="weight variant 'fp16'"): DiffusersModelBackend._resolve_component(checkpoint, "transformer") - def test_hub_checkpoint_without_a_modular_index_reads_model_index(self, monkeypatch): + def test_hub_checkpoint_without_a_modular_index_reads_model_index(self, monkeypatch, caplog): + caplog.set_level(logging.INFO, logger=model_backend.__name__) + def raise_entry_not_found(repo_id, filename): response = httpx.Response(404, request=httpx.Request("HEAD", f"https://huggingface.co/{repo_id}")) raise RemoteEntryNotFoundError(f"{repo_id} has no {filename}", response=response) @@ -194,9 +197,12 @@ def raise_entry_not_found(repo_id, filename): _CheckpointComponent, "transformer", ) + # every classic checkpoint answers 404: a line per component load on each rank would say nothing + assert not caplog.records - def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monkeypatch, tmp_path): + def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monkeypatch, tmp_path, caplog): """A classic checkpoint's cache never holds a modular index, so the probe has no copy to fall back to.""" + caplog.set_level(logging.INFO, logger=model_backend.__name__) monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True) monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_CACHE", str(tmp_path)) monkeypatch.setattr( @@ -209,6 +215,9 @@ def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monke _CheckpointComponent, "transformer", ) + # the log names why the Hub was not asked, not the client's "check your connection" wrapper + [record] = caplog.records + assert "offline mode is enabled" in record.getMessage() def test_cached_modular_checkpoint_resolves_from_its_modular_index_while_the_hub_is_offline( self, monkeypatch, tmp_path From 27e0954d8747812ecf54ac726dddfdbfb5ec77c7 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:23:16 +0000 Subject: [PATCH 12/13] test(fsdp): assert the logged cause by its class, not by the Hub client's sentence --- tests/fast/backends/fsdp_utils/test_model_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index 8cca0b3bc..30f0890a5 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -217,7 +217,7 @@ def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monke ) # the log names why the Hub was not asked, not the client's "check your connection" wrapper [record] = caplog.records - assert "offline mode is enabled" in record.getMessage() + assert "OfflineModeIsEnabled" in record.getMessage() def test_cached_modular_checkpoint_resolves_from_its_modular_index_while_the_hub_is_offline( self, monkeypatch, tmp_path From 3e082dc688f078786ac4ebe6ad027bf80ef0a579 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:48:36 +0000 Subject: [PATCH 13/13] refactor(fsdp): read the checkpoint's index with diffusers' own load_config fall-through The hand-written probe (hf_hub_download, three Hub exception classes, the cause of a wrapped one) did what ModularPipeline.load_config followed by DiffusionPipeline.load_config does, which is how diffusers' modular loader picks the index. A fall-through logs one line whatever its cause, and a modular index that sits in a local directory and cannot be read raises instead of falling through. The three tests that patched the probe become one test of the offline fall-through and its log line. --- miles/backends/fsdp_utils/model_backend.py | 67 +++++-------------- .../backends/fsdp_utils/test_model_backend.py | 51 ++------------ 2 files changed, 22 insertions(+), 96 deletions(-) diff --git a/miles/backends/fsdp_utils/model_backend.py b/miles/backends/fsdp_utils/model_backend.py index 24d302758..0a0a6d66b 100644 --- a/miles/backends/fsdp_utils/model_backend.py +++ b/miles/backends/fsdp_utils/model_backend.py @@ -20,15 +20,12 @@ import abc import functools import importlib -import json import logging import os from dataclasses import replace import torch from diffusers import DiffusionPipeline, ModularPipeline -from huggingface_hub import hf_hub_download -from huggingface_hub.errors import HfHubHTTPError, HFValidationError, LocalEntryNotFoundError, RemoteEntryNotFoundError from .models.parallel_plan import FSDPParallelPlan from .sequence_parallel.diffusers_dispatch import install_diffusers_usp_patch @@ -227,17 +224,17 @@ def load_component( def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, str]: """``component``'s class and its folder under ``checkpoint_path``, from the checkpoint's index. - A checkpoint that ships ``modular_model_index.json`` is read from it, as diffusers' modular loader does: - its root ``model_index.json`` may describe another layout of the same weights (MiniMax-H3-Image's names the - engine's native classes). The folder is the ``subfolder`` of the component's loading spec; an entry without - a loading spec uses the component's name. The repository a loading spec names is not followed: weights come - from ``checkpoint_path``. + The index is the one diffusers' modular loader reads: ``modular_model_index.json`` when the checkpoint has + one, else ``model_index.json``. Weights load from ``checkpoint_path``, not from the repository a loading + spec names. """ - index_name = ModularPipeline.config_name - index = cls._read_modular_index(checkpoint_path) - if index is None: - index_name = DiffusionPipeline.config_name - index = DiffusionPipeline.load_config(checkpoint_path) + try: + index, index_name = ModularPipeline.load_config(checkpoint_path), ModularPipeline.config_name + except OSError as error: + if os.path.isfile(os.path.join(checkpoint_path, ModularPipeline.config_name)): + raise + index, index_name = DiffusionPipeline.load_config(checkpoint_path), DiffusionPipeline.config_name + logger.info("%s: read %s; no %s (%s)", checkpoint_path, index_name, ModularPipeline.config_name, error) if component not in index: raise ValueError(f"{index_name} of {checkpoint_path} has no component {component!r}") spec = index[component] @@ -245,53 +242,23 @@ def _resolve_component(cls, checkpoint_path: str, component: str) -> tuple[type, if component_cls is None: raise ValueError( f"cannot resolve the class for component {component!r} from {index_name} of {checkpoint_path}: " - f"spec {spec!r} does not name a class an installed library provides (remote-code components are " - f"not supported)" + f"spec {spec!r} names no class an installed library provides; remote-code components are not supported" ) if len(spec) == 2: return component_cls, component loading_spec = spec[2] if isinstance(spec[2], dict) else {} - subfolder = loading_spec.get("subfolder") - if not isinstance(subfolder, str) or not subfolder: + subfolder, variant = loading_spec.get("subfolder"), loading_spec.get("variant") + if not subfolder: raise ValueError( - f"component {component!r} names no subfolder in its spec {spec!r} in {index_name} of {checkpoint_path}" + f"component {component!r} names no subfolder in {index_name} of {checkpoint_path}: {spec!r}" ) - if loading_spec.get("variant") is not None: + if variant is not None: raise ValueError( - f"component {component!r} names the weight variant {loading_spec['variant']!r} in its spec in " - f"{index_name} of {checkpoint_path}; loading a variant is untested, and loading without it could " - f"read other weights" + f"component {component!r} names the weight variant {variant!r} in {index_name} of {checkpoint_path}; " + f"loading a variant is untested" ) return component_cls, subfolder - @staticmethod - def _read_modular_index(checkpoint_path: str) -> dict | None: - """``modular_model_index.json`` of a checkpoint; None when it ships none, or the Hub cannot be asked and no copy is cached.""" - if os.path.isdir(checkpoint_path): - index_file = os.path.join(checkpoint_path, ModularPipeline.config_name) - if not os.path.isfile(index_file): - return None - else: - try: - index_file = hf_hub_download(checkpoint_path, ModularPipeline.config_name) - except RemoteEntryNotFoundError: - return None - # no answer (offline, gated, not a repo id) and no cached copy: the load goes on from the root index - except (LocalEntryNotFoundError, HfHubHTTPError, HFValidationError) as error: - # the Hub client wraps "no answer and nothing cached" in one fixed message; its cause says which - cause = error.__cause__ if isinstance(error, LocalEntryNotFoundError) and error.__cause__ else error - logger.info( - "%s of %s could not be read (%s: %s); reading %s", - ModularPipeline.config_name, - checkpoint_path, - type(cause).__name__, - cause, - DiffusionPipeline.config_name, - ) - return None - with open(index_file) as f: - return json.load(f) - @staticmethod def _component_class(spec): # Classic pipelines write ``[library, class_name]``; modular ones append a diff --git a/tests/fast/backends/fsdp_utils/test_model_backend.py b/tests/fast/backends/fsdp_utils/test_model_backend.py index 30f0890a5..c41766421 100644 --- a/tests/fast/backends/fsdp_utils/test_model_backend.py +++ b/tests/fast/backends/fsdp_utils/test_model_backend.py @@ -12,11 +12,9 @@ import logging import diffusers -import httpx import huggingface_hub import pytest import torch -from huggingface_hub.errors import GatedRepoError, RemoteEntryNotFoundError from miles.backends.fsdp_utils import model_backend from miles.backends.fsdp_utils.model_backend import BaseModelBackend, DiffusersModelBackend, MilesModelBackend @@ -179,29 +177,10 @@ def test_loading_spec_with_a_weight_variant_is_rejected(self, tmp_path): with pytest.raises(ValueError, match="weight variant 'fp16'"): DiffusersModelBackend._resolve_component(checkpoint, "transformer") - def test_hub_checkpoint_without_a_modular_index_reads_model_index(self, monkeypatch, caplog): - caplog.set_level(logging.INFO, logger=model_backend.__name__) - - def raise_entry_not_found(repo_id, filename): - response = httpx.Response(404, request=httpx.Request("HEAD", f"https://huggingface.co/{repo_id}")) - raise RemoteEntryNotFoundError(f"{repo_id} has no {filename}", response=response) - - monkeypatch.setattr(model_backend, "hf_hub_download", raise_entry_not_found) - monkeypatch.setattr( - model_backend.DiffusionPipeline, - "load_config", - lambda checkpoint_path: {"transformer": [__name__, "_CheckpointComponent"]}, - ) - - assert DiffusersModelBackend._resolve_component("org/classic", "transformer") == ( - _CheckpointComponent, - "transformer", - ) - # every classic checkpoint answers 404: a line per component load on each rank would say nothing - assert not caplog.records - - def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monkeypatch, tmp_path, caplog): - """A classic checkpoint's cache never holds a modular index, so the probe has no copy to fall back to.""" + def test_checkpoint_without_a_readable_modular_index_reads_model_index_and_logs_it( + self, monkeypatch, tmp_path, caplog + ): + """A cached classic checkpoint must still resolve offline, and the fall-through must not be silent.""" caplog.set_level(logging.INFO, logger=model_backend.__name__) monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True) monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_CACHE", str(tmp_path)) @@ -215,9 +194,8 @@ def test_cached_classic_checkpoint_resolves_while_the_hub_is_offline(self, monke _CheckpointComponent, "transformer", ) - # the log names why the Hub was not asked, not the client's "check your connection" wrapper [record] = caplog.records - assert "OfflineModeIsEnabled" in record.getMessage() + assert "model_index.json" in record.getMessage() and "modular_model_index.json" in record.getMessage() def test_cached_modular_checkpoint_resolves_from_its_modular_index_while_the_hub_is_offline( self, monkeypatch, tmp_path @@ -237,25 +215,6 @@ def test_cached_modular_checkpoint_resolves_from_its_modular_index_while_the_hub "transformer_diffusers", ) - def test_cached_classic_checkpoint_resolves_when_the_hub_refuses_the_probe(self, monkeypatch): - """A gated repo answers 401 without a token, also for a file it does not have.""" - - def raise_gated(repo_id, filename): - response = httpx.Response(401, request=httpx.Request("HEAD", f"https://huggingface.co/{repo_id}")) - raise GatedRepoError(f"{repo_id} is gated", response=response) - - monkeypatch.setattr(model_backend, "hf_hub_download", raise_gated) - monkeypatch.setattr( - model_backend.DiffusionPipeline, - "load_config", - lambda checkpoint_path: {"transformer": [__name__, "_CheckpointComponent"]}, - ) - - assert DiffusersModelBackend._resolve_component("org/gated", "transformer") == ( - _CheckpointComponent, - "transformer", - ) - def test_missing_local_checkpoint_is_reported_as_a_missing_directory(self, tmp_path): """A mistyped path is not a repo id; the probe must not turn it into a repo-id error.""" with pytest.raises(OSError, match="not the path to a directory containing a model_index.json"):