Skip to content

Commit 84ff061

Browse files
authored
[Modular] Save Modular Pipeline weights to Hub (#13168)
* update * update * update * update * update * update
1 parent 3fd14f1 commit 84ff061

20 files changed

+2112
-27
lines changed

.claude/CLAUDE.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Build, Lint, and Test Commands
6+
7+
```bash
8+
# Install in development mode
9+
pip install -e ".[dev]"
10+
11+
# Run full test suite (requires beefy machine)
12+
make test
13+
# Or directly:
14+
python -m pytest -n auto --dist=loadfile -s -v ./tests/
15+
16+
# Run a single test file
17+
python -m pytest tests/<TEST_FILE>.py
18+
19+
# Run slow tests (downloads many GBs of models)
20+
RUN_SLOW=yes python -m pytest -n auto --dist=loadfile -s -v ./tests/
21+
22+
# Format code (ruff + doc-builder)
23+
make style
24+
25+
# Check code quality without modifying
26+
make quality
27+
28+
# Fast fixup for modified files only (recommended before commits)
29+
make fixup
30+
31+
# Fix copied code snippets and dummy objects
32+
make fix-copies
33+
34+
# Check repository consistency (dummies, inits, repo structure)
35+
make repo-consistency
36+
```
37+
38+
## Code Architecture
39+
40+
Diffusers is built on three core component types that work together:
41+
42+
### Pipelines (`src/diffusers/pipelines/`)
43+
- End-to-end inference workflows combining models and schedulers
44+
- Base class: `DiffusionPipeline` (in `pipeline_utils.py`)
45+
- Follow **single-file policy**: each pipeline in its own directory
46+
- Loaded via `DiffusionPipeline.from_pretrained()` which reads `model_index.json`
47+
- Components registered via `register_modules()` become pipeline attributes
48+
- ~99 pipeline implementations (Stable Diffusion, SDXL, Flux, etc.)
49+
50+
### Models (`src/diffusers/models/`)
51+
- Configurable neural network architectures extending PyTorch's Module
52+
- Base classes: `ModelMixin` + `ConfigMixin` (in `modeling_utils.py`)
53+
- **Do NOT follow single-file policy**: use shared building blocks (`attention.py`, `embeddings.py`, `resnet.py`)
54+
- Key subdirectories:
55+
- `autoencoders/`: VAEs for latent space compression
56+
- `unets/`: Diffusion model architectures (UNet2DConditionModel, etc.)
57+
- `transformers/`: Transformer-based models (Flux, SD3, etc.)
58+
- `controlnets/`: ControlNet variants
59+
60+
### Schedulers (`src/diffusers/schedulers/`)
61+
- Guide denoising process during inference
62+
- Base class: `SchedulerMixin` + `ConfigMixin` (in `scheduling_utils.py`)
63+
- Follow **single-file policy**: one scheduler per file
64+
- Key methods: `set_num_inference_steps()`, `step()`, `timesteps` property
65+
- Easily swappable via `ConfigMixin.from_config()`
66+
- ~55 scheduler algorithms (DDPM, DDIM, Euler, DPM-Solver, etc.)
67+
68+
### Supporting Systems
69+
70+
- **Loaders** (`src/diffusers/loaders/`): Mixins for LoRA, IP-Adapter, textual inversion, single-file loading
71+
- **Quantizers** (`src/diffusers/quantizers/`): BitsAndBytes, GGUF, TorchAO, Quanto support
72+
- **Hooks** (`src/diffusers/hooks/`): Runtime optimizations (offloading, layer skipping, caching)
73+
- **Guiders** (`src/diffusers/guiders/`): Guidance algorithms (CFG, PAG, etc.)
74+
75+
## Configuration System
76+
77+
All components use `ConfigMixin` for serialization:
78+
- Constructor arguments stored via `register_to_config(**kwargs)`
79+
- Instantiate from config: `Component.from_config(config_dict)`
80+
- Save/load as JSON files
81+
82+
## Key Design Principles
83+
84+
1. **Usability over Performance**: Models load at float32/CPU by default
85+
2. **Simple over Easy**: Explicit > implicit; expose complexity rather than hide it
86+
3. **Single-file policy**: Pipelines and schedulers are self-contained; models share building blocks
87+
4. **Copy-paste over abstraction**: Prefer duplicated code over hasty abstractions for contributor-friendliness
88+
89+
## Code Style
90+
91+
- Uses `ruff` for linting and formatting (line length: 119)
92+
- Documentation follows [Google style](https://google.github.io/styleguide/pyguide.html)
93+
- Use `# Copied from` mechanism for sharing code between similar files
94+
- Avoid lambda functions and advanced PyTorch operators for readability
95+
96+
## Testing
97+
98+
- Tests use `pytest` with `pytest-xdist` for parallelization
99+
- Slow tests gated by `RUN_SLOW=yes` environment variable
100+
- Test dependencies: `pip install -e ".[test]"`

_modular_model_index.json

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"_blocks_class_name": "SequentialPipelineBlocks",
3+
"_class_name": "Flux2ModularPipeline",
4+
"_diffusers_version": "0.36.0.dev0",
5+
"scheduler": [
6+
"diffusers",
7+
"FlowMatchEulerDiscreteScheduler",
8+
{
9+
"repo": "hf-internal-testing/tiny-flux2",
10+
"revision": null,
11+
"subfolder": "scheduler",
12+
"type_hint": [
13+
"diffusers",
14+
"FlowMatchEulerDiscreteScheduler"
15+
],
16+
"variant": null
17+
}
18+
],
19+
"text_encoder": [
20+
"transformers",
21+
"Mistral3ForConditionalGeneration",
22+
{
23+
"repo": "hf-internal-testing/tiny-flux2",
24+
"revision": null,
25+
"subfolder": "text_encoder",
26+
"type_hint": [
27+
"transformers",
28+
"Mistral3ForConditionalGeneration"
29+
],
30+
"variant": null
31+
}
32+
],
33+
"tokenizer": [
34+
"transformers",
35+
"AutoProcessor",
36+
{
37+
"repo": "hf-internal-testing/Mistral-Small-3.1-24B-Instruct-2503-only-processor",
38+
"revision": null,
39+
"subfolder": "",
40+
"type_hint": [
41+
"transformers",
42+
"AutoProcessor"
43+
],
44+
"variant": null
45+
}
46+
],
47+
"transformer": [
48+
"diffusers",
49+
"Flux2Transformer2DModel",
50+
{
51+
"repo": "hf-internal-testing/tiny-flux2",
52+
"revision": null,
53+
"subfolder": "transformer",
54+
"type_hint": [
55+
"diffusers",
56+
"Flux2Transformer2DModel"
57+
],
58+
"variant": null
59+
}
60+
],
61+
"vae": [
62+
"diffusers",
63+
"AutoencoderKLFlux2",
64+
{
65+
"repo": "hf-internal-testing/tiny-flux2",
66+
"revision": null,
67+
"subfolder": "vae",
68+
"type_hint": [
69+
"diffusers",
70+
"AutoencoderKLFlux2"
71+
],
72+
"variant": null
73+
}
74+
]
75+
}

0 commit comments

Comments
 (0)