Skip to content
Back to skills

Diffusers Library Expert

ASecurity

HF diffusers - pipelines, schedulers, IP-Adapter loading, LoRA loading, custom model loading. Use when working with multimodal AI (images, audio, video) using diffusers library.

  • 9 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 8, 2026
developmentpythonrustgoc++nodegit

Security analysis

A100/100

Scanned September 8, 2026

npx -y skills add anubhavg-icpl/vibe --skill diffusers-library-expert --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Diffusers Library Expert?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Diffusers Library Expert
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/anubhavg-icpl-diffusers-library-expert/badge)](https://www.skillsdirectory.com/skills/anubhavg-icpl-diffusers-library-expert)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: diffusers-library-expert
description: HF diffusers - pipelines, schedulers, IP-Adapter loading, LoRA loading, custom model loading. Use when working with multimodal AI (images, audio, video) using diffusers library.
license: CC-BY-NC-SA-4.0
metadata:
  risk: unknown
  source: community
  kind: mode
  category: multimodal-ai
  tags: [multimodal, image-gen, diffusers, huggingface, lora, ip-adapter]
---

# HuggingFace Diffusers Library Expert Mode

You are an expert in the `diffusers` Python library - the canonical reference implementation for diffusion model inference and training. You know every pipeline class, scheduler swap, adapter loader, memory optimization, and how to ship custom pipelines.

## Core Capabilities

- Pipeline classes for SD1.5, SDXL, SD3, Flux, video (CogVideoX, Mochi, SVD), audio (Stable Audio).
- Scheduler swapping for quality/speed trade-offs.
- LoRA / IP-Adapter / Textual Inversion / ControlNet adapter loading.
- Memory optimization: cpu_offload, sequential_offload, attention slicing, VAE tiling.
- Custom pipelines and `from_single_file` for community checkpoints.

## Pipeline Class Map

| Task | Pipeline class | Example model |
|---|---|---|
| SDXL t2i | StableDiffusionXLPipeline | sd-xl-base-1.0 |
| SDXL i2i | StableDiffusionXLImg2ImgPipeline | refiner |
| SDXL inpaint | StableDiffusionXLInpaintPipeline | sdxl-inpainting |
| SDXL ControlNet | StableDiffusionXLControlNetPipeline | + ControlNetModel |
| SD3.5 t2i | StableDiffusion3Pipeline | sd-3.5-large |
| Flux t2i | FluxPipeline | FLUX.1-dev |
| Flux ControlNet | FluxControlNetPipeline | + FluxControlNetModel |
| AnimateDiff | AnimateDiffPipeline | + MotionAdapter |
| SVD | StableVideoDiffusionPipeline | SVD-XT |
| CogVideoX | CogVideoXPipeline | CogVideoX-5b |
| Mochi | MochiPipeline | mochi-1-preview |
| Stable Audio | StableAudioPipeline | stable-audio-open-1.0 |

## Implementation Patterns

### Standard load + generate

```python
import torch
from diffusers import StableDiffusionXLPipeline, AutoPipelineForText2Image

# Generic auto-detect (recommended for unknown checkpoints)
pipe = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    torch_dtype=torch.float16, variant="fp16", use_safetensors=True,
).to("cuda")
img = pipe("a cat astronaut").images[0]
```

### Loading single-file checkpoints (Civitai, .safetensors)

```python
pipe = StableDiffusionXLPipeline.from_single_file(
    "models/juggernaut_xl_v9.safetensors",
    torch_dtype=torch.float16,
).to("cuda")
```

### Scheduler swap

```python
from diffusers import (DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler,
                       DDIMScheduler, LCMScheduler, FlowMatchEulerDiscreteScheduler)

# Quality default
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
    pipe.scheduler.config, use_karras_sigmas=True, algorithm_type="dpmsolver++",
)
# Flow matching for Flux/SD3 (already default but tweakable)
pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config(pipe.scheduler.config, shift=3.0)
# LCM/turbo
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
```

### LoRA loading (PEFT-backed)

```python
# Single LoRA
pipe.load_lora_weights("user/style-lora", weight_name="style.safetensors")
pipe.fuse_lora()                                 # bake in for speed (irreversible without unload)

# Multiple LoRAs with weighting
pipe.load_lora_weights("artist/style", adapter_name="style")
pipe.load_lora_weights("char/face",   adapter_name="face")
pipe.set_adapters(["style", "face"], adapter_weights=[0.7, 0.9])
pipe.disable_lora()                              # turn off without unload
pipe.unload_lora_weights()                       # remove entirely
```

### IP-Adapter loading

```python
pipe.load_ip_adapter(
    "h94/IP-Adapter", subfolder="sdxl_models",
    weight_name="ip-adapter-plus_sdxl_vit-h.safetensors",
)
pipe.set_ip_adapter_scale(0.6)
img = pipe(prompt=p, ip_adapter_image=ref_pil).images[0]
```

Order matters when combining: load IP-Adapter **before** LCM-LoRA / Lightning LoRA.

### Textual Inversion

```python
pipe.load_textual_inversion("sd-concepts-library/cat-toy", token="<cat-toy>")
img = pipe("a <cat-toy> on the moon").images[0]
```

### ControlNet

```python
from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline
cn = ControlNetModel.from_pretrained("xinsir/controlnet-canny-sdxl-1.0", torch_dtype=torch.float16)
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", controlnet=cn, torch_dtype=torch.float16,
).to("cuda")
out = pipe(prompt=p, image=canny_img, controlnet_conditioning_scale=0.8).images[0]
```

## Memory Optimization

```python
pipe.enable_attention_slicing("auto")            # -10% memory, slight slowdown
pipe.enable_vae_slicing()                         # -VAE memory
pipe.enable_vae_tiling()                          # for large images / video
pipe.enable_model_cpu_offload()                   # -50% VRAM, swaps modules to CPU
pipe.enable_sequential_cpu_offload()              # max savings, biggest slowdown
pipe.unet.to(memory_format=torch.channels_last)   # ~10% speedup on Ampere+

# torch.compile (PyTorch 2.x) - ~30-50% speedup after warmup
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
pipe.vae.decode = torch.compile(pipe.vae.decode, mode="reduce-overhead", fullgraph=True)

# 8-bit text encoders for SD3/Flux
from transformers import T5EncoderModel, BitsAndBytesConfig
t5 = T5EncoderModel.from_pretrained(model_id, subfolder="text_encoder_3",
    quantization_config=BitsAndBytesConfig(load_in_8bit=True))
```

## Custom Pipelines

```python
# Load community pipeline (e.g., long-prompt weighting)
pipe = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16,
    custom_pipeline="lpw_stable_diffusion_xl",
)
img = pipe(prompt="(masterpiece:1.4), (best quality:1.3), ...").images[0]
```

Write your own subclass of `DiffusionPipeline` for novel research workflows.

## Common Pitfalls

- Wrong VAE precision -> black images. Use `madebyollin/sdxl-vae-fp16-fix` or `force_upcast=False`.
- Loading SD1.5 LoRA into SDXL pipeline silently broken; check arch.
- `enable_xformers_memory_efficient_attention()` deprecated - PyTorch SDPA is default.
- `.to("cuda")` after `enable_model_cpu_offload()` defeats the point.
- `torch.compile` first call is slow (compilation); warm up with a dummy gen.
- Updating `diffusers` minor version can change LoRA conversion behavior - pin in production.

## Hardware / Cost

- SDXL fp16 on RTX 4090: ~3 s for 1024x1024, 28 steps.
- Flux dev bf16 on H100 with offload: ~10 s for 1024x1024.
- CPU-offload doubles latency vs full GPU resident.
- torch.compile: ~30% speedup but +30 s warmup per model load.

## When to Use

- Reference implementation, all major models -> diffusers.
- Production node graphs / non-coders -> ComfyUI on top of diffusers.
- Rust / C++ inference -> sdcpp, candle, mistral.rs.
- Single-file Civitai checkpoint -> `from_single_file`.

## Sources

- https://huggingface.co/docs/diffusers/index
- https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters
- https://huggingface.co/docs/diffusers/en/tutorials/using_peft_for_inference
- https://huggingface.co/docs/diffusers/using-diffusers/ip_adapter
- https://github.com/huggingface/diffusers

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.