IOPaint/iopaint/tests/test_model_switch.py

71 lines
1.7 KiB
Python
Raw Normal View History

2023-12-19 06:16:30 +01:00
import os
2024-01-05 08:19:23 +01:00
from iopaint.schema import InpaintRequest
2023-12-19 06:16:30 +01:00
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
import torch
2024-01-05 08:19:23 +01:00
from iopaint.model_manager import ModelManager
2023-12-19 06:16:30 +01:00
def test_model_switch():
model = ModelManager(
name="runwayml/stable-diffusion-inpainting",
2023-12-28 03:48:52 +01:00
enable_controlnet=True,
controlnet_method="lllyasviel/control_v11p_sd15_canny",
2023-12-19 06:16:30 +01:00
device=torch.device("mps"),
disable_nsfw=True,
sd_cpu_textencoder=True,
cpu_offload=False,
)
model.switch("lama")
def test_controlnet_switch_onoff(caplog):
name = "runwayml/stable-diffusion-inpainting"
model = ModelManager(
name=name,
2023-12-28 03:48:52 +01:00
enable_controlnet=True,
controlnet_method="lllyasviel/control_v11p_sd15_canny",
2023-12-19 06:16:30 +01:00
device=torch.device("mps"),
disable_nsfw=True,
sd_cpu_textencoder=True,
cpu_offload=False,
)
model.switch_controlnet_method(
2023-12-30 16:36:44 +01:00
InpaintRequest(
2023-12-19 06:16:30 +01:00
name=name,
2023-12-28 03:48:52 +01:00
enable_controlnet=False,
2023-12-19 06:16:30 +01:00
)
)
assert "Disable controlnet" in caplog.text
2023-12-28 03:48:52 +01:00
def test_switch_controlnet_method(caplog):
2023-12-19 06:16:30 +01:00
name = "runwayml/stable-diffusion-inpainting"
old_method = "lllyasviel/control_v11p_sd15_canny"
new_method = "lllyasviel/control_v11p_sd15_openpose"
model = ModelManager(
name=name,
2023-12-28 03:48:52 +01:00
enable_controlnet=True,
controlnet_method=old_method,
2023-12-19 06:16:30 +01:00
device=torch.device("mps"),
disable_nsfw=True,
sd_cpu_textencoder=True,
cpu_offload=False,
)
model.switch_controlnet_method(
2023-12-30 16:36:44 +01:00
InpaintRequest(
2023-12-19 06:16:30 +01:00
name=name,
2023-12-28 03:48:52 +01:00
enable_controlnet=True,
2023-12-19 06:16:30 +01:00
controlnet_method=new_method,
)
)
assert f"Switch Controlnet method from {old_method} to {new_method}" in caplog.text