Skip to content

Commit 998a3da

Browse files
authored
Merge branch 'main' into refactor-flux2-pipeline-tests
2 parents a610a74 + 191984b commit 998a3da

83 files changed

Lines changed: 1764 additions & 708 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ai/AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Strive to write code as simple and explicit as possible.
3737
Task-specific guides live in `.ai/skills/` and are loaded on demand by AI agents. Available skills include:
3838

3939
- [model-integration](./skills/model-integration/SKILL.md) (adding/converting pipelines)
40+
- [custom-blocks](./skills/custom-blocks/SKILL.md) (packaging a `ModularPipelineBlocks` subclass for the Hub)
41+
- [diffusers-cli](./skills/diffusers-cli/SKILL.md) (running pipelines, inspecting schemas, and using the Diffusers CLI)
4042
- [self-review](./skills/self-review/SKILL.md) (pre-PR self-review against the project rules)
4143

4244
## Self-review before a PR

.ai/modular.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@ OutputParam(
235235

236236
If a template's predefined description doesn't fit (e.g. the `"latents"` output template means "Denoised latents", which is wrong for the noisy latents out of a prepare-latents step) — drop the template and declare the field directly with an accurate description. See gotcha #5.
237237

238+
**Declare defaults in the `InputParam`, not inside `__call__`.**
239+
240+
```python
241+
# yes
242+
InputParam(name="num_frames", type_hint=int, default=189)
243+
244+
# no — works, but the assembled pipeline is not aware of it
245+
if block_state.num_frames is None:
246+
block_state.num_frames = 189
247+
```
248+
249+
A declared default is part of the block's contract, so the assembled pipeline is aware of it: the generated docstring shows it and `default_call_parameters` reports it. Resolved inside the body instead, the input renders as `*optional*` with no default, and nothing at the pipeline level can report what the block will actually do. Don't worry about branches of a conditional blockset declaring different defaults for the same input — each branch resolves its own at runtime. Resolve inside `__call__` only when the default is *computed* — derived from other inputs or component config (`height = components.default_sample_size * components.vae_scale_factor`). And when several blocks in a sequence share an input, declare the same default on each (or only on the first block that reads it): in a sequence the input is one shared value, so disagreeing declarations are silently resolved first-block-wins.
250+
238251
## ComponentSpec patterns
239252

240253
```python
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: New Model Request Reply
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
reply:
9+
name: Point new model requests at Modular Diffusers
10+
# Match the heading the issue form renders for its first field rather than a label: template
11+
# labels are applied after the issue is created, so `github.event.issue.labels` is empty here.
12+
# Keep this string in sync with .github/ISSUE_TEMPLATE/new-model-addition.yml.
13+
if: >-
14+
github.repository == 'huggingface/diffusers' &&
15+
contains(github.event.issue.body, '### Model/Pipeline/Scheduler description')
16+
runs-on: ubuntu-latest
17+
permissions:
18+
issues: write
19+
steps:
20+
- name: Post Modular Diffusers guidance
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
GH_REPO: ${{ github.repository }}
24+
ISSUE_NUMBER: ${{ github.event.issue.number }}
25+
BODY: |
26+
Thanks for the request!
27+
28+
**How new model support works in Diffusers**
29+
30+
We're a small team, and our review queue shouldn't be what decides whether a model is usable in Diffusers. With [Modular Diffusers](https://huggingface.co/docs/diffusers/modular_diffusers/overview), a pipeline can live as remote code in any Hub repo and load straight from there with `from_pretrained`.
31+
32+
🛠️ **Want to bring this model to Diffusers?**
33+
34+
Please start with a Hub repo — you don't need anything from us to do that, and people can use it immediately. From there we decide how to support it: we might work with the authors, upstream an existing community version, or just point people at the one on the Hub. The pipelines we integrate are usually the ones people are already running.
35+
36+
Tag `@asomoza` when you have something to share — we'll give feedback on the implementation, help get it in front of people, and add the ones we like to our hand-picked [Modular Pipelines](https://huggingface.co/collections/diffusers/modular-pipelines) collection. Tell us where you hit friction along the way, too: confusing APIs, missing docs, bugs. That feedback is worth as much to us as the pipeline.
37+
38+
👋 **Are you an author of the model?** We'd love to hear from you — comment here and we'll help you pick the path that fits.
39+
40+
📚 [Quickstart](https://huggingface.co/docs/diffusers/modular_diffusers/quickstart) · [Building custom blocks](https://huggingface.co/docs/diffusers/modular_diffusers/custom_blocks) — template repo, and how to publish to the Hub · [Modular Pipelines](https://huggingface.co/collections/diffusers/modular-pipelines) and [Custom Blocks](https://huggingface.co/collections/diffusers/modular-diffusers-custom-blocks) — examples to crib from
41+
42+
*This is an automated message.*
43+
run: gh issue comment "$ISSUE_NUMBER" --body "$BODY"

docs/source/en/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@
184184
title: NVIDIA ModelOpt
185185
- local: quantization/autoround
186186
title: AutoRound
187+
- local: quantization/sdnq
188+
title: SDNQ
187189
title: Quantization
188190
- isExpanded: false
189191
sections:

docs/source/en/api/quantization.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Quantization techniques reduce memory and computational costs by representing we
3838

3939
[[autodoc]] quantizers.quantization_config.QuantoConfig
4040

41+
## SDNQConfig
42+
43+
[[autodoc]] quantizers.quantization_config.SDNQConfig
44+
4145
## TorchAoConfig
4246

4347
[[autodoc]] quantizers.quantization_config.TorchAoConfig

docs/source/en/conceptual/contribution.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ specific language governing permissions and limitations under the License.
1212

1313
# How to contribute to Diffusers 🧨
1414

15+
> [!TIP]
16+
> If you use an AI agent to contribute, make sure you read the [AI-assisted and agentic contributions](#ai-assisted-and-agentic-contributions) section for our expectations and guidelines.
17+
1518
We ❤️ contributions from the open-source community! Everyone is welcome, and all types of participation –not just code– are valued and appreciated. Answering questions, helping others, reaching out, and improving the documentation are all immensely valuable to the community, so don't be afraid and get involved if you're up for it!
1619

1720
Everyone is encouraged to start by saying 👋 in our public Discord channel. We discuss the latest trends in diffusion models, ask questions, show off personal projects, help each other with contributions, or just hang out ☕. <a href="https://Discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a>
@@ -329,6 +332,11 @@ Good second issues are usually more difficult to get merged compared to good fir
329332

330333
### 9. Adding pipelines, models, schedulers
331334

335+
> [!TIP]
336+
> If you are the model's author, please get in touch so we can coordinate the integration with you: open a feature request, or drop a comment if one is already open.
337+
>
338+
> If you are a community contributor, please also let us know you're interested under the feature request, and start with a Hub repo at the same time. See the [Modular Diffusers](../modular_diffusers/overview) guide to get started, and [custom blocks](../modular_diffusers/custom_blocks) or [custom models](../using-diffusers/automodel) for publishing as remote code on the Hub.
339+
332340
Pipelines, models, and schedulers are the most important pieces of the Diffusers library.
333341
They provide easy access to state-of-the-art diffusion technologies and thus allow the community to
334342
build powerful generative AI applications.
@@ -589,13 +597,17 @@ The repository keeps AI-agent configuration in [`.ai/`](https://github.com/huggi
589597

590598
### AI-assisted and agentic contributions
591599

600+
AI agents are welcome for contributing to Diffusers. We encourage you to set up your agent with the Diffusers [agent guide](https://github.com/huggingface/diffusers/blob/main/.ai/AGENTS.md) and use the relevant task-specific skills, such as `model-integration` and `self-review`. Run `make codex` or `make claude` to use the skills with your agent, then follow the guide to scope, implement, test, and review your contribution. You remain responsible for understanding, testing, and maintaining the changes in your PR.
601+
592602
AI-assisted contributions are welcome, but they must be coordinated, scoped, and verified to keep review load manageable. PRs that do not follow these guidelines may be closed without detailed review.
593603

594604
- **Coordinate before opening a PR.** Find or open an issue, review similar PRs (open and recently closed), and wait for an explicit acknowledgment from a maintainer on that issue before opening a PR. This gives us a chance to discuss scope, avoid duplicate work, and confirm the approach.
595-
- **Fix patterns, not one-offs.** If you spot an recurring issue, search the codebase for similar instances and open a *single* issue with a clear, systematic scope (e.g. "fix mutable defaults across all schedulers") rather than many issues or PRs for individual instances.
605+
- **Fix patterns, not one-offs.** If you spot an recurring issue, search the codebase for similar instances and open a *single* issue with a clear, systematic scope (e.g. "fix mutable defaults across all schedulers") rather than many issues or PRs for individual instances.
596606
- **Self-review before opening.** Run the [`self-review`](https://github.com/huggingface/diffusers/blob/main/.ai/skills/self-review/SKILL.md) skill — it reviews your diff against [`.ai/review-rules.md`](https://github.com/huggingface/diffusers/blob/main/.ai/review-rules.md), the same rubric the `@claude` CI reviewer uses — and address what it reports — it's a helper, not authoritative, and can be wrong. Focus on the blocking issues that make sense to you, and clean up dead/unused code as much as possible. If you disagree with a suggestion, it's fine to leave it for the reviewer to discuss after the PR is opened — the notes you share (see below) tell the reviewer it was a deliberate call.
597607
- **Share your self-review notes.** Please post the final self-review report — the round that reflects the diff you're submitting — on the PR, in the description or as a comment, including findings you intentionally did not fix and why. It helps the reviewer see what has already been checked and which calls were deliberate, and usually saves a few rounds of back-and-forth.
598608
- **Include in the PR description:**
599609
- A **coordination link** to the issue or discussion where a maintainer acknowledged the work.
600610
- The **test commands you ran** and their results (paste relevant output, not just "tests pass").
601611
- Your **self-review notes** (or a link to the PR comment containing them), as described above.
612+
613+
If you are a model author or part of a team that officially maintains a model, we encourage you to use agents for a new model integration. Follow the repository's [recommended setup](https://github.com/huggingface/diffusers/blob/main/.ai/AGENTS.md) and use the [`model-integration`](https://github.com/huggingface/diffusers/blob/main/.ai/skills/model-integration/SKILL.md) skill. Coordinate the scope with maintainers before opening a PR — see [Adding pipelines, models, schedulers](#9-adding-pipelines-models-schedulers).

docs/source/en/optimization/attention_backends.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ with attention_backend("_flash_3_hub"):
8282
> [!TIP]
8383
> Most attention backends support `torch.compile` without graph breaks and can be used to further speed up inference.
8484
85+
## Trusting remote kernels
86+
87+
Hub backends and other kernel-backed features (such as [GGUF](../quantization/gguf) and [Nunchaku Lite](../quantization/nunchaku)) download compute kernels from the Hub with [`kernels`](https://github.com/huggingface/kernels) and execute their code locally.
88+
89+
By default, `kernels` only loads a kernel when its publisher is a trusted kernel publisher on the Hub. Kernels published under the [`kernels-community`](https://huggingface.co/kernels-community) organization are trusted, so Diffusers loads them without any additional configuration. The `_flash_3_hub`, `flash_hub`, `sage_hub`, and the other Hub attention backends all resolve to `kernels-community` repositories.
90+
91+
Kernels from any other publisher are not vetted. Loading one downloads and runs code that Diffusers cannot vouch for, so Diffusers keeps it disabled unless you explicitly opt in with the `DIFFUSERS_TRUST_REMOTE_KERNELS` environment variable. When set, Diffusers forwards `trust_remote_code=True` to `kernels` so it loads kernels from untrusted publishers too.
92+
93+
```bash
94+
export DIFFUSERS_TRUST_REMOTE_KERNELS=true
95+
```
96+
97+
Only enable this after inspecting the kernel repository, since it grants the downloaded code the ability to run on your machine. Without it, loading a kernel from an untrusted publisher raises an error. Diffusers performs this check itself, so it also applies to `kernels<0.14.0`, which predates the `trust_remote_code` argument. Setting `DIFFUSERS_DISABLE_REMOTE_CODE=true` disables remote code globally and takes precedence over `DIFFUSERS_TRUST_REMOTE_KERNELS`.
98+
8599
## Checks
86100

87101
The attention dispatcher includes debugging checks that catch common errors before they cause problems.

docs/source/en/quantization/gguf.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pip install -U kernels
6363

6464
Once installed, set `DIFFUSERS_GGUF_CUDA_KERNELS=true` to use optimized kernels when available. Note that CUDA kernels may introduce minor numerical differences compared to the original GGUF implementation, potentially causing subtle visual variations in generated images. To disable CUDA kernel usage, set the environment variable `DIFFUSERS_GGUF_CUDA_KERNELS=false`.
6565

66+
The GGUF kernels are downloaded from the [`Isotr0py/ggml`](https://huggingface.co/Isotr0py/ggml) repository, whose publisher is not a trusted kernel publisher on the Hub. Loading it downloads and executes code from the Hub, so Diffusers requires you to explicitly opt in by setting `DIFFUSERS_TRUST_REMOTE_KERNELS=true`. See [Trusting remote kernels](../optimization/attention_backends#trusting-remote-kernels) for details.
67+
6668
## Supported Quantization Types
6769

6870
- BF16

docs/source/en/quantization/nunchaku.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The kernels package supplies the optimized CUDA kernels, which load automaticall
2727
pip install -U kernels
2828
```
2929

30+
Nunchaku Lite loads its kernels from the [`rootonchair/nunchaku-lite-kernels`](https://huggingface.co/rootonchair/nunchaku-lite-kernels) repository, whose publisher is not a trusted kernel publisher on the Hub. Loading it downloads and executes code from the Hub, so Diffusers requires you to explicitly opt in by setting `DIFFUSERS_TRUST_REMOTE_KERNELS=true`. See [Trusting remote kernels](../optimization/attention_backends#trusting-remote-kernels) for details.
31+
3032
## Load a quantized pipeline
3133

3234
Load the prequantized pipeline with [`~DiffusionPipeline.from_pretrained`], which reads the quantization

docs/source/en/quantization/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ The following backends support loading prequantized checkpoints out of the box.
149149
| [AutoRound](./autoround) | Only loading is supported; quantize first with the AutoRound CLI or Python API. |
150150
| [Nunchaku Lite](./nunchaku) | Config is saved in `config.json`; requires the `kernels` package. Only loading is supported. |
151151
| [ModelOpt](./modelopt) | Only loading prequantized models is supported. |
152+
| [SDNQ](./sdnq) | Supports both quantizing on the fly and loading prequantized models; requires the `sdnq` package. |
152153

153154
## Resources
154155

0 commit comments

Comments
 (0)