Skip to content

Commit

Permalink
Update models and model paths #195
Browse files Browse the repository at this point in the history
- installer now uses .safetensors version of clip-vision
- use new models/ipadapter path instead of legacy custom node path
- keep backwards compatibility to old models/paths for now
- update docker image to v1.10.0
  • Loading branch information
Acly committed Dec 12, 2023
1 parent 1b3f00f commit a06a4a7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
16 changes: 12 additions & 4 deletions ai_diffusion/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class ModelResource(NamedTuple):
folder: Path
filename: str
url: str
alternatives: list[Path] | None = None # for backwards compatibility


required_models = [
Expand All @@ -128,8 +129,9 @@ class ModelResource(NamedTuple):
ResourceKind.clip_vision,
SDVersion.all,
Path("models/clip_vision/SD1.5"),
"pytorch_model.bin",
"https://huggingface.co/h94/IP-Adapter/resolve/main/models/image_encoder/pytorch_model.bin",
"model.safetensors",
"https://huggingface.co/h94/IP-Adapter/resolve/main/models/image_encoder/model.safetensors?download=true",
alternatives=[Path("models/clip_vision/SD1.5/pytorch_model.bin")],
),
ModelResource(
"NMKD Superscale model",
Expand Down Expand Up @@ -159,17 +161,23 @@ class ModelResource(NamedTuple):
"IP-Adapter (SD1.5)",
ResourceKind.ip_adapter,
SDVersion.sd15,
Path("custom_nodes/ComfyUI_IPAdapter_plus/models"),
Path("models/ipadapter"),
"ip-adapter_sd15.safetensors",
"https://huggingface.co/h94/IP-Adapter/resolve/main/models/ip-adapter_sd15.safetensors",
alternatives=[
Path("custom_nodes/ComfyUI_IPAdapter_plus/models/ip-adapter_sd15.safetensors")
],
),
ModelResource(
"IP-Adapter (SDXL)",
ResourceKind.ip_adapter,
SDVersion.sdxl,
Path("custom_nodes/ComfyUI_IPAdapter_plus/models"),
Path("models/ipadapter"),
"ip-adapter_sdxl_vit-h.safetensors",
"https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter_sdxl_vit-h.safetensors",
alternatives=[
Path("custom_nodes/ComfyUI_IPAdapter_plus/models/ip-adapter_sdxl_vit-h.safetensors")
],
),
ModelResource(
"LCM-LoRA (SD1.5)",
Expand Down
23 changes: 13 additions & 10 deletions ai_diffusion/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ def check_install(self):
]
self.missing_resources += missing_nodes

def find_missing(
folder: Path, resources: list[ModelResource], ver: SDVersion | None = None
):
return [
res.name
for res in resources
if (not ver or res.sd_version is ver)
and not (folder / res.folder / res.filename).exists()
]

self.missing_resources += find_missing(
self.comfy_dir, resources.required_models, SDVersion.all
)
Expand Down Expand Up @@ -590,6 +580,19 @@ def _decode_utf8_log_error(b: bytes):
return result


def find_missing(folder: Path, resources: list[ModelResource], ver: SDVersion | None = None):
def resource_exists(res: ModelResource):
return (folder / res.folder / res.filename).exists() or (
res.alternatives and any((folder / alt).exists() for alt in res.alternatives)
)

return [
res.name
for res in resources
if (not ver or res.sd_version is ver) and not resource_exists(res)
]


def rename_extracted_folder(name: str, path: Path, suffix: str):
if path.exists() and path.is_dir() and not any(path.iterdir()):
path.rmdir()
Expand Down
7 changes: 4 additions & 3 deletions scripts/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

version = f"v{ai_diffusion.__version__}"
docker_root = Path(__file__).parent / "docker"
download_folder = docker_root / "downloads"


def clean(models):
expected = set(m.folder / m.filename for m in models)
for path in (docker_root / "models").glob("**/*"):
if path.is_file() and path.relative_to(docker_root) not in expected:
for path in (download_folder).glob("**/*"):
if path.is_file() and path.relative_to(download_folder) not in expected:
print(f"- Deleting {path}")
path.unlink()

Expand All @@ -27,7 +28,7 @@ async def main():
clean(all_models())

print("Downloading new models")
await download_models(docker_root)
await download_models(download_folder)

print("Preparation complete.\n\nTo build run:")
print(f" docker build -t aclysia/sd-comfyui-krita:{version} scripts/docker")
Expand Down
4 changes: 2 additions & 2 deletions scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /ComfyUI/custom_no
git clone https://github.com/Acly/comfyui-tooling-nodes /ComfyUI/custom_nodes/comfyui-tooling-nodes && \
pip3 install -r /ComfyUI/custom_nodes/ComfyUI-Manager/requirements.txt && \
pip3 install -r /ComfyUI/custom_nodes/comfyui_controlnet_aux/requirements.txt && \
pip3 cache purge
pip3 cache purge && \
echo v1.10.0 > .krita-ai-diffusion.version

# Copy models
RUN mkdir -p models
COPY downloads/models/ /models/
COPY downloads/custom_nodes/ComfyUI_IPAdapter_plus/models/* /ComfyUI/custom_nodes/ComfyUI_IPAdapter_plus/models/
COPY extra_model_paths.yaml /ComfyUI/

# Install Jupyter
Expand Down
1 change: 1 addition & 0 deletions scripts/docker/extra_model_paths.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ runpod:
embeddings: embeddings
hypernetworks: hypernetworks
controlnet: controlnet
ipadapter: ipadapter

0 comments on commit a06a4a7

Please sign in to comment.