Views
No views yet
1import torch
2from diffusers import StableDiffusionPipeline
3from peft import PeftModel
4
5pipe = StableDiffusionPipeline.from_pretrained(
6 "runwayml/stable-diffusion-v1-5",
7 torch_dtype=torch.float16,
8 safety_checker=None,
9)
10
11# Merge the adapter at 0.6 strength (see "Adapter strength" below)
12peft_unet = PeftModel.from_pretrained(pipe.unet, "MayankTamakuwala/sd15-wikiart-impressionism-lora")
13for module in peft_unet.modules():
14 if hasattr(module, "scaling") and isinstance(module.scaling, dict):
15 for name in module.scaling:
16 module.scaling[name] *= 0.6
17pipe.unet = peft_unet.merge_and_unload()
18pipe = pipe.to("cuda")
19
20image = pipe(
21 "an Impressionism painting, landscape, by Claude Monet",
22 num_inference_steps=30,
23 guidance_scale=7.5,
24).images[0]
25image.save("output.png")an Impressionism painting, {genre}, by {artist}an Impressionism painting, landscape, by Claude Monet. Free-form prompts also work; the style transfers to novel
compositions.| Model | FID ↓ | CLIP ↑ |
|---|---|---|
| Base SD 1.5 | 106.50 | 0.3141 |
| + this LoRA @ 1.0 | 102.55 | 0.3037 |
| + this LoRA @ 0.6 | 100.38 | 0.3092 |
| Base model | runwayml/stable-diffusion-v1-5 |
| Dataset | huggan/wikiart, Impressionism, 5,000 images |
| LoRA rank / alpha | 16 / 16 |
| Target modules | to_q, to_k, to_v, to_out.0 |
| Trainable params | 3,188,736 (0.37% of 862,709,700) |
| Epochs / steps | 6 / 3,750 |
| Effective batch | 8 |
| Optimizer | AdamW, lr 1e-4, cosine schedule |
| Precision | bf16 |
| Hardware | 1× NVIDIA H200, 12m41s |