---
source: https://iinventedlight.com/library/notes/hf-diffusers-memory.md
title: "Reducing diffusers memory: offloading, device_map, VAE slicing"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (huggingface/transformers, huggingface_hub, diffusers docs; LICENSE verified in each repo); prose restates cited source lines in own words"
license_family: hf-apache
attribution: "Summary by iinventedlight (AI-assisted). Sources: Hugging Face docs, Reduce memory usage, Apache-2.0 (huggingface docs repos); Hugging Face docs, Quickstart, Apache-2.0 (huggingface docs repos)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-09
status: published
checked_on: 2026-11-09
as_of: 2026-11-09
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Hugging Face"
tags: [hugging-face, diffusers, memory, offloading]
client: Librarian
sources:
  - id: S1
    title: "Reduce memory usage"
    publisher: Hugging Face docs
    url: https://huggingface.co/docs/diffusers/optimization/memory
    accessed: 2026-11-09
    license: "Apache-2.0 (huggingface docs repos)"
  - id: S2
    title: "Quickstart"
    publisher: Hugging Face docs
    url: https://huggingface.co/docs/diffusers/quicktour
    accessed: 2026-11-09
    license: "Apache-2.0 (huggingface docs repos)"
---
# Reducing diffusers memory: offloading, device_map, VAE slicing

**Answer:** Large diffusion models often exceed GPU memory; use more than one GPU, offload pipeline components to the CPU, or load in 4-bit.

## Multiple GPUs

- The `balanced` device placement strategy evenly splits the pipeline across all available devices; inspect it with `hf_device_map`.
- Sharded checkpoints load one shard at a time; sharding is recommended when the fp32 checkpoint is greater than 5GB.
- Use `reset_device_map` to reset the `device_map` before calling `.to()` or offload methods on a device-mapped pipeline.

## Offloading on one GPU

- CPU offloading moves weights from the GPU to the CPU; it dramatically reduces memory but is extremely slow.
- Model offloading moves entire models to the GPU, a faster alternative; enable it with `enable_model_cpu_offload`.

## VAE

VAE slicing decodes one image at a time instead of all images in a batch at once. VAE tiling divides an image into smaller overlapping tiles.

## Quantization

Load in 4-bit with bitsandbytes to use less memory.

## Artifacts

- [Topic packet: huggingface](https://iinventedlight.com/library/packets/huggingface.json)

## See also

- [hf-diffusers-pipeline-loading](https://iinventedlight.com/library/notes/hf-diffusers-pipeline-loading/)
- [hf-transformers-big-model-loading](https://iinventedlight.com/library/notes/hf-transformers-big-model-loading/)

## Claims

- id: C1
  claim: balanced splits a pipeline evenly across devices.
  source: S1
  evidence: "strategy evenly splits the pipeline across all available devices."

- id: C2
  claim: CPU offloading is extremely slow.
  source: S1
  evidence: "but it is also **extremely slow**"

- id: C3
  claim: Model offloading is the faster alternative.
  source: S1
  evidence: "makes model offloading a faster alternative."

- id: C4
  claim: 4-bit bitsandbytes reduces memory.
  source: S2
  evidence: "To use less memory, load in 4-bit with bitsandbytes."

## Sources

- [S1] Reduce memory usage. Hugging Face docs. https://huggingface.co/docs/diffusers/optimization/memory . License: Apache-2.0 (huggingface docs repos). Accessed 2026-11-09.

- [S2] Quickstart. Hugging Face docs. https://huggingface.co/docs/diffusers/quicktour . License: Apache-2.0 (huggingface docs repos). Accessed 2026-11-09.


License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Hugging Face docs (huggingface/transformers, huggingface/huggingface_hub, huggingface/diffusers on GitHub), Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0). Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
