HuggingFace - Diffuser Workshop
===
- GitHub: https://github.com/huggingface/diffusers
- Blog: https://huggingface.co/blog/stable_diffusion
# Diffusion Models
Hugging Face: https://huggingface.co/models

# Sample Code
[Google Colab Sample](https://colab.research.google.com/drive/1vc4lJSM-U-wMotnVGaG85S4z4GigHv7x?usp=sharing)
## Package
```python=
# package to install
!pip install torch diffusers transformers accelerate
```
## Windows with GPU / Apple Silicon
### Windows
```python=
# if you have a GPU
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipeline.to("cuda")
pipeline("An image of a squirrel in Picasso style").images[0]
```
### Apple Silicon
Refer to this document: [How to use Stable Diffusion in Apple Silicon](https://huggingface.co/docs/diffusers/optimization/mps)
```python=
# if using Apple Silicon (M1/M2)
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("mps")
# Recommended if your computer has < 64 GB of RAM
pipe.enable_attention_slicing()
prompt = "An image of a squirrel in Picasso style"
image = pipe(prompt).images[0]
image
```