mirror of
https://github.com/huggingface/diffusers.git
synced 2026-03-13 12:07:57 +08:00
Compare commits
1 Commits
diffusers-
...
fix-sdxl-a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e0578c0dc |
@@ -37,8 +37,10 @@ from diffusers import (
|
|||||||
EulerDiscreteScheduler,
|
EulerDiscreteScheduler,
|
||||||
LCMScheduler,
|
LCMScheduler,
|
||||||
StableDiffusionPipeline,
|
StableDiffusionPipeline,
|
||||||
|
StableDiffusionXLAdapterPipeline,
|
||||||
StableDiffusionXLControlNetPipeline,
|
StableDiffusionXLControlNetPipeline,
|
||||||
StableDiffusionXLPipeline,
|
StableDiffusionXLPipeline,
|
||||||
|
T2IAdapter,
|
||||||
UNet2DConditionModel,
|
UNet2DConditionModel,
|
||||||
)
|
)
|
||||||
from diffusers.utils.import_utils import is_accelerate_available, is_peft_available
|
from diffusers.utils.import_utils import is_accelerate_available, is_peft_available
|
||||||
@@ -2175,7 +2177,7 @@ class LoraSDXLIntegrationTests(PeftLoraLoaderMixinTests, unittest.TestCase):
|
|||||||
self.assertTrue(np.allclose(images, expected, atol=1e-3))
|
self.assertTrue(np.allclose(images, expected, atol=1e-3))
|
||||||
release_memory(pipeline)
|
release_memory(pipeline)
|
||||||
|
|
||||||
def test_canny_lora(self):
|
def test_controlnet_canny_lora(self):
|
||||||
controlnet = ControlNetModel.from_pretrained("diffusers/controlnet-canny-sdxl-1.0")
|
controlnet = ControlNetModel.from_pretrained("diffusers/controlnet-canny-sdxl-1.0")
|
||||||
|
|
||||||
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
||||||
@@ -2199,6 +2201,34 @@ class LoraSDXLIntegrationTests(PeftLoraLoaderMixinTests, unittest.TestCase):
|
|||||||
assert np.allclose(original_image, expected_image, atol=1e-04)
|
assert np.allclose(original_image, expected_image, atol=1e-04)
|
||||||
release_memory(pipe)
|
release_memory(pipe)
|
||||||
|
|
||||||
|
def test_sdxl_t2i_adapter_canny_lora(self):
|
||||||
|
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-lineart-sdxl-1.0", torch_dtype=torch.float16).to(
|
||||||
|
"cpu"
|
||||||
|
)
|
||||||
|
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
|
||||||
|
"stabilityai/stable-diffusion-xl-base-1.0",
|
||||||
|
adapter=adapter,
|
||||||
|
torch_dtype=torch.float16,
|
||||||
|
variant="fp16",
|
||||||
|
)
|
||||||
|
pipe.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors")
|
||||||
|
pipe.enable_model_cpu_offload()
|
||||||
|
pipe.set_progress_bar_config(disable=None)
|
||||||
|
|
||||||
|
generator = torch.Generator(device="cpu").manual_seed(0)
|
||||||
|
prompt = "toy"
|
||||||
|
image = load_image(
|
||||||
|
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/t2i_adapter/toy_canny.png"
|
||||||
|
)
|
||||||
|
|
||||||
|
images = pipe(prompt, image=image, generator=generator, output_type="np", num_inference_steps=3).images
|
||||||
|
|
||||||
|
assert images[0].shape == (768, 512, 3)
|
||||||
|
|
||||||
|
image_slice = images[0, -3:, -3:, -1].flatten()
|
||||||
|
expected_slice = np.array([0.4284, 0.4337, 0.4319, 0.4255, 0.4329, 0.4280, 0.4338, 0.4420, 0.4226])
|
||||||
|
assert numpy_cosine_similarity_distance(image_slice, expected_slice) < 1e-4
|
||||||
|
|
||||||
@nightly
|
@nightly
|
||||||
def test_sequential_fuse_unfuse(self):
|
def test_sequential_fuse_unfuse(self):
|
||||||
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
||||||
|
|||||||
@@ -672,34 +672,6 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
|
|||||||
gc.collect()
|
gc.collect()
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
|
|
||||||
def test_canny_lora(self):
|
|
||||||
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-lineart-sdxl-1.0", torch_dtype=torch.float16).to(
|
|
||||||
"cpu"
|
|
||||||
)
|
|
||||||
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
|
|
||||||
"stabilityai/stable-diffusion-xl-base-1.0",
|
|
||||||
adapter=adapter,
|
|
||||||
torch_dtype=torch.float16,
|
|
||||||
variant="fp16",
|
|
||||||
)
|
|
||||||
pipe.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors")
|
|
||||||
pipe.enable_model_cpu_offload()
|
|
||||||
pipe.set_progress_bar_config(disable=None)
|
|
||||||
|
|
||||||
generator = torch.Generator(device="cpu").manual_seed(0)
|
|
||||||
prompt = "toy"
|
|
||||||
image = load_image(
|
|
||||||
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/t2i_adapter/toy_canny.png"
|
|
||||||
)
|
|
||||||
|
|
||||||
images = pipe(prompt, image=image, generator=generator, output_type="np", num_inference_steps=3).images
|
|
||||||
|
|
||||||
assert images[0].shape == (768, 512, 3)
|
|
||||||
|
|
||||||
image_slice = images[0, -3:, -3:, -1].flatten()
|
|
||||||
expected_slice = np.array([0.4284, 0.4337, 0.4319, 0.4255, 0.4329, 0.4280, 0.4338, 0.4420, 0.4226])
|
|
||||||
assert numpy_cosine_similarity_distance(image_slice, expected_slice) < 1e-4
|
|
||||||
|
|
||||||
def test_download_ckpt_diff_format_is_same(self):
|
def test_download_ckpt_diff_format_is_same(self):
|
||||||
ckpt_path = (
|
ckpt_path = (
|
||||||
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
|
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
|
||||||
|
|||||||
Reference in New Issue
Block a user