Diffusers
English
stable-diffusion
stable-diffusion-diffusers
inpainting
art
artistic
anime
absolute-realism
Instructions to use diffusers/tools with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use diffusers/tools with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("diffusers/tools", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
| #!/usr/bin/env python3 | |
| from diffusers import StableDiffusionControlNetPipeline, ControlNetModel | |
| import requests | |
| import torch | |
| from PIL import Image | |
| from io import BytesIO | |
| url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" | |
| response = requests.get(url) | |
| init_image = Image.open(BytesIO(response.content)).convert("RGB") | |
| init_image = init_image.resize((512, 512)) | |
| path = "runwayml/stable-diffusion-v1-5" | |
| run_compile = False # Set True / False | |
| controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16) | |
| pipe = StableDiffusionControlNetPipeline.from_pretrained( | |
| path, controlnet=controlnet, torch_dtype=torch.float16 | |
| ) | |
| pipe = pipe.to("cuda:0") | |
| pipe.unet.to(memory_format=torch.channels_last) | |
| pipe.controlnet.to(memory_format=torch.channels_last) | |
| if run_compile: | |
| print("Run torch compile") | |
| pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) | |
| pipe.controlnet = torch.compile(pipe.controlnet, mode="reduce-overhead", fullgraph=True) | |
| prompt = "ghibli style, a fantasy landscape with castles" | |
| for _ in range(3): | |
| image = pipe(prompt=prompt, image=init_image).images[0] | |