|
1 | 1 | import json |
2 | 2 | import os |
3 | 3 | from enum import Enum |
| 4 | +from pathlib import Path |
4 | 5 | from typing import Literal, Optional |
5 | 6 |
|
6 | 7 | from omegaconf import OmegaConf |
7 | 8 | from pydantic import Field |
8 | 9 |
|
| 10 | +from invokeai.app.services.config import InvokeAIAppConfig |
| 11 | +from invokeai.backend.model_management.detect_baked_in_vae import has_baked_in_sdxl_vae |
| 12 | +from invokeai.backend.util.logging import InvokeAILogger |
| 13 | + |
9 | 14 | from .base import ( |
10 | 15 | BaseModelType, |
11 | 16 | DiffusersModel, |
@@ -116,17 +121,20 @@ def convert_if_required( |
116 | 121 | # The convert script adapted from the diffusers package uses |
117 | 122 | # strings for the base model type. To avoid making too many |
118 | 123 | # source code changes, we simply translate here |
| 124 | + if Path(output_path).exists(): |
| 125 | + return output_path |
| 126 | + |
119 | 127 | if isinstance(config, cls.CheckpointConfig): |
120 | 128 | from invokeai.backend.model_management.models.stable_diffusion import _convert_ckpt_and_cache |
121 | 129 |
|
122 | 130 | # Hack in VAE-fp16 fix - If model sdxl-vae-fp16-fix is installed, |
123 | | - # then we bake it into the converted model. |
124 | | - from invokeai.app.services.config import InvokeAIAppConfig |
125 | | - |
126 | | - kwargs = dict() |
| 131 | + # then we bake it into the converted model unless there is already |
| 132 | + # a nonstandard VAE installed. |
| 133 | + kwargs = {} |
127 | 134 | app_config = InvokeAIAppConfig.get_config() |
128 | 135 | vae_path = app_config.models_path / "sdxl/vae/sdxl-vae-fp16-fix" |
129 | | - if vae_path.exists(): |
| 136 | + if vae_path.exists() and not has_baked_in_sdxl_vae(Path(model_path)): |
| 137 | + InvokeAILogger.get_logger().warning("No baked-in VAE detected. Inserting sdxl-vae-fp16-fix.") |
130 | 138 | kwargs["vae_path"] = vae_path |
131 | 139 |
|
132 | 140 | return _convert_ckpt_and_cache( |
|
0 commit comments