diff options
Diffstat (limited to 'src/mcp_sd15/pipeline_factory.py')
| -rw-r--r-- | src/mcp_sd15/pipeline_factory.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mcp_sd15/pipeline_factory.py b/src/mcp_sd15/pipeline_factory.py index b0525ea..02fe882 100644 --- a/src/mcp_sd15/pipeline_factory.py +++ b/src/mcp_sd15/pipeline_factory.py @@ -38,11 +38,16 @@ class PipelineFactory: ) vae_path = self.config.model.vae_path() if vae_path is not None: + # from_single_file needs a Diffusers config directory to avoid + # network access. Reuse the VAE config that the base pipeline + # already resolved from the local huggingface cache. + vae_config_dir = self._vae_config_dir(cache_dir) pipeline.vae = diffusers.AutoencoderKL.from_single_file( str(vae_path), torch_dtype=torch.float16, local_files_only=True, cache_dir=cache_dir, + config=vae_config_dir, ) if getattr(pipeline, "vae", None) is None: raise ConfigError( @@ -156,3 +161,19 @@ class PipelineFactory: except KeyError as exc: raise ConfigError(f"unsupported scheduler: {name}") from exc return scheduler_class.from_config(current.config) + + @staticmethod + def _vae_config_dir(cache_dir: str) -> str: + """Find the VAE config.json inside the local huggingface cache.""" + snapshots = ( + Path(cache_dir) / "models--stable-diffusion-v1-5--stable-diffusion-v1-5" / "snapshots" + ) + if not snapshots.is_dir(): + raise ConfigError( + "cannot locate VAE config: huggingface cache snapshots directory not found" + ) + for snapshot in snapshots.iterdir(): + vae_dir = snapshot / "vae" + if (vae_dir / "config.json").is_file(): + return str(vae_dir) + raise ConfigError("cannot locate VAE config.json in the local huggingface cache") |
