1
0
mirror of https://github.com/huggingface/diffusers.git synced 2026-10-24 20:59:27 +03:00

6973 Commits

Author SHA1 Message Date
DN6
9adb089d80 [CLI] Add --tensor-parallel to diffusers-cli run and fix per-rank device placement
- Shard the transformer with `TensorParallelConfig` on CUDA, TPU and Neuron, with
  remote-code transformers loaded via `--trust-remote-code`.
- Require `--seed`; reject `--device-map`, `--cpu-offload`, `--lora`,
  `--context-parallel` and modular pipelines.
- Wrap `--remote` runs in torchrun.
- Load standard pipelines without an indexed `device_map` (e.g. `cuda:<LOCAL_RANK>`)
  and place components after loading, fixing `--context-parallel` on ranks > 0.
2026-10-21 13:03:11 +05:30
Jingya HUANG
1d5d056ecf [TPU] TorchTPU backend integration - eager / torch.compile / tp (#14039)
* feat: add torchtpu

* feat:draft TorchTPU support

* fix: wan overflow issue + compile mode error on sdxl

* doc: enhance with TorchTPU doc

* doc: enhance with TorchTPU doc

* style: remove unused imports flagged by ruff

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs: remove Debug Eager and Fused Eager sections from tpu.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: add TP for TPU

* style: fix import sorting in TPU test scripts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* style: ruff format TPU test scripts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: style

* fix: test for native 4 devices

* fix: propagate TPU device fixes to Flux/Flux2/Wan-family copies; register tpu.md; drop redundant execution_device check

- Propagate the text_encoder.device-based fix (introduced for TPU CPU-offload
  support) from FluxPipeline/Flux2KleinPipeline/WanPipeline into their
  `# Copied from` copies (flux/*, flux2_klein_inpaint, visualcloze, anyflow,
  chronoedit, lucy_edit, skyreels_v2/*). SDXL-family copies of
  StableDiffusionXLPipeline.encode_prompt are intentionally left untouched;
  they'll be handled in a follow-up PR that fixes device placement for every
  pipeline component (not just text encoders).
- Register docs/source/en/optimization/tpu.md in _toctree.yml (was breaking
  the docs build: "not present in the table of contents").
- Remove the redundant "prefer non-CPU, non-meta component" loop from
  DiffusionPipeline._execution_device: PR #14383 already fixed this in
  DiffusionPipeline.device, which _execution_device falls back to. Verified
  on TPU hardware that _execution_device still resolves correctly for a
  split-placement pipeline after the removal.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* tests: cleanup

* fix: fix compile mode

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* test: remove flux2 e2e test

* doc: apply suggestions

* doc: apply suggestions

* review: remove monkey patch

* review: revert neuron-specific changes in the tests

* review: apply suggestions

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* doc: add tpu to tp doc

* review: remove unnecessary for tpu

* test: assert every _tp_plan parameter is sharded after a TP load

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* removal: delete redundant tp shard helpers

* removal: drop TPU workarounds no longer needed after recent main changes

* doc: keep the FLUX.2-dev text encoder off a single TPU chip in the TP example

* doc: encode the prompt on CPU in the TPU TP example so it runs end to end

* test: tighten TPU TP tolerance and simplify the TPU TP worker

* doc: use enable_model_cpu_offload() in the TPU eager example

* doc: shard both FLUX.2-dev text encoder and transformer in the TPU TP example

* doc: run the text encoders on TPU in the compiled example

* test: drop the redundant TPU sync in the TP worker

* test: trim comments in the TPU TP tests

* test: run the TPU TP test with mp.spawn like the CUDA one

* test: pin the TPU TP test to 4 chips

* Update docs/source/en/optimization/tpu.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* doc: use DistributedConfig and dtype, and drop the torch_tpu import in the TPU examples

* test: skip the TPU TP test for models without a _tp_plan

* doc: correct the warning of recompilation

* fix: clone the SD3 timestep so torch.compile doesn't recompile every step, thus we can use it for the tpu.md compile mode snippet

* doc: update advice for compile mode when one chip doesn't fit

* test: pass the TPU TP tolerances as test arguments

* review: apply suggestions to the doc

* review: view compilation patch for tpu-only

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: JingyaHuang <huang_jingya@outlok.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-09 16:16:23 +05:30
Christopher
78bf2c6266 [LoRA] add LoKr adapter support (Z-Image, Flux2/Klein) (#14163)
* [LoRA] add LoKr adapter support (Z-Image, Flux2/Klein)

Adds loading of LoKr (LyCORIS Kronecker product) adapters:

- `load_lora_adapter` detects `lokr_` keys and injects a peft `LoKrConfig`,
  inferred from the tensor shapes via `_create_lokr_config` (decompose
  factor, per-module rank/alpha patterns).
- State dict conversions for the formats in the wild: ai-toolkit Z-Image
  (dotted diffusers paths under `diffusion_model.`), ai-toolkit BFL Flux2
  (fused qkv), LyCORIS underscore format, and bare dotted diffusers paths.
- BFL fused-QKV LoKr cannot be split exactly into separate Q/K/V Kronecker
  factors, so `Flux2LoraLoaderMixin.load_lora_weights` fuses the model's
  QKV projections and maps the adapter 1:1 (exact).
- Alpha follows the LyCORIS convention: scaling applies only to
  rank-decomposed factors and is baked into the weights at conversion.

Fixes #13221

* [LoRA] LoKr review follow-ups: adapter-agnostic error message, refuse fused-QKV load over an unfused adapter

- "Invalid adapter checkpoint. We currently support LoRA and LoKr." replaces the
  message that still said "LoRA checkpoint" and described the substring check.
- Loading a fused-QKV LoKr checkpoint now refuses when an adapter is already
  injected on to_q/to_k/to_v or add_{q,k,v}_proj: fuse_qkv_projections() would
  replace those modules and orphan it. Covered by a test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [LoRA] rename the LoKr tests to test_lokr_conversion.py

The file exercises checkpoint conversion and loading for LoKr adapters, not LoRA.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [LoRA] LoKr review follow-ups: scope to Z-Image/Flux2, model-level fused QKV, LoKrTesterMixin

- Only the Z-Image and Flux2 loader mixins accept LoKr checkpoints, the two that
  convert them; the other mixins are back to their LoRA-only check.
- The fused-QKV handling moves to `_maybe_fuse_qkv_projections_for_lokr` in
  peft_utils, called from `load_lora_adapter`, so the model fuses its projections
  whichever entry point loads the adapter. The quantized-model error explains why.
- `_bake_lokr_alpha` becomes `_bake_lokr_alpha_` as it edits the dict in place.
- The BFL Flux2 converter no longer accepts expanded diffusers block names under
  `diffusion_model.`: no LoKr checkpoint uses that layout; diffusers-named
  checkpoints have no prefix and take the generic converter.
- The LyCORIS converter names the keys it does not recognize.
- Tests move from tests/lora to a `LoKrTesterMixin` in tests/models/testing_utils,
  with the checkpoint formats tested on the Flux2 and Z-Image model test classes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [LoRA] mark ZImageLoraLoaderMixin.load_lora_weights as copied from Flux2

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-09 12:56:56 +05:30
Sayak Paul
d7d0b9c2c7 [ci] consolidate labeling on PRs. (#14911)
consolidate labeling on PRs.

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
2026-10-09 10:49:19 +05:30
Patrick Ribbsaeter
d961a388fd fix(image_processor): maintain 3-tuple return contract in InpaintProcessor.preprocess when mask is None (#14481)
fix(image_processor): preserve 3-tuple return contract when mask is None (#14470)

Ensure InpaintProcessor.preprocess returns (image, None, postprocessing_kwargs) when mask is None, preserving the expected 3-tuple return contract and signature consistency across all preprocess branches. Consolidate unit tests into a parameterized test covering with-mask, without-mask, and crop configurations.
2026-10-07 22:24:47 -10:00
Subodh
e0415c41f8 Fix active adapter detection for text encoders (#14961)
* Fix active adapter detection for text encoders

Signed-off-by: Subodh Bansode <subodh171011@gmail.com>

* test: move text encoder adapter regression test

Signed-off-by: Subodh Bansode <subodh171011@gmail.com>

---------

Signed-off-by: Subodh Bansode <subodh171011@gmail.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-08 11:57:28 +05:30
Steven Liu
122b1e11fd [docs] Community methods (#14973)
* freeu

* cachedit
2026-10-07 08:04:42 -07:00
Steven Liu
c6df88a511 [docs] Jobs guide (#14926)
hf jobs

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-06 12:04:08 -07:00
Pauline Bailly-Masson
71774d9bc8 Bump doc-builder workflow pin (#14957)
* Bump doc-builder pin to 9fc8a41 in build_documentation.yml

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Bump doc-builder pin to 9fc8a41 in build_pr_documentation.yml

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Bump doc-builder pin to 9fc8a41 in upload_pr_documentation.yml

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-06 19:51:32 +05:30
Sayak Paul
bc5e3bd9c5 Kandinsky6 (#14949)
* implement Kandinsky 6
 - add TI2VA and SR pipelines
 - additonally implement PiflowScheduler and MMAudioVAE

* update docs for Kandinsky 6

* remove redundant bigvgan code and manual checkpoint loading inside model
code

* add missing _no_split_modules

* use attention processor in SR

* fix unguarded dependencies
 - removed: einops, pydantic
 - lazy: torchvision, av, librosa

* remove dead manual weight loading code; flattent MMAudioVAE structure

* move attention processors to transformer files

* remove duplicate code in K6 latent_upscaler

* address 1st batch of comments

* patch transformer k6

* patch SR

* patch pipeline style

* replace TimestepEmbedding and fix batching

* refactor ti2va dit and pipeline

* refactor piflow scheduler

* refactor SR

* patch sr transformer autocast

* major refactor

* untrack notebooks directory

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* patch mmaudio VAE

* patch mmaudio VAE

* fix inits

* fix flex attn

* refactoring

* remove __all__

* separate MMAudio VAE and Vocoder

* fix naming

* refactor checkpointing, magcache, transformer, sr vae for K6

* refactor

* address apply_scale_shift_norm problem

* update docs

* apply style chanes

* address review feedback on transformer, SR VAE, and flex attention

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* address comments

* fix critical bugs

* Revert checkpoint-breaking module renames from 28c5326da

Commit 28c5326da (today, 14:03 +0300) renamed Kandinsky6FusedTransformerDecoderBlock's
videoT/audioT submodules to video_dec_block/audio_dec_block, and replaced both
Kandinsky6TimeEmbeddings and Kandinsky6SRTimeEmbeddings's hand-rolled in_layer/out_layer
with diffusers' Timesteps/TimestepEmbedding, purely for naming clarity. No checkpoint
conversion was re-run to match, so every published K6 checkpoint (unchanged since Sep 27,
confirmed via identical blob SHA256 across recent Hub commits) still ships the old names.

Verified against kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers and
kandinskylab/Kandinsky-6.0-VSR-5s-Diffusers: this was silently dropping ~65% of the main
transformer's weights (every visual_transformer_blocks.*.{video,audio}T.* parameter) and
the SR transformer's time embeddings, then crashing with "Cannot copy out of meta tensor"
on enable_model_cpu_offload(). After this revert, all checkpoint keys match exactly
(4471/4471 for the main transformer, 459/459 for the SR transformer).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Revert checkpoint-breaking latent-upscaler renames from 372f29088

Same class of regression as 9ae71f0d0, this time in Kandinsky6SRLatentUpscalerX2Branch
and Kandinsky6SRLatentUpscalerOutputHead: today's "address comments" commit (18:48 +0300)
dropped the private_ prefix from private_mid_blocks/private_upsample/private_blocks/
private_output_proj, and converted OutputHead from nn.Sequential to a plain nn.Module with
named norm/activation/conv submodules, again without a matching checkpoint re-conversion.

Verified against kandinskylab/Kandinsky-6.0-VSR-5s-Diffusers's latent_upscaler: this left
every Kandinsky6SRLatentUpscalerX2Branch parameter (and the OutputHead-based output_proj
used standalone by the x2/x4 branches) unfilled on the meta device, crashing
enable_model_cpu_offload() the same way as the main transformer did before 9ae71f0d0.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* move vocoder and LU

* add coppied from resolve i2v cond mode

* rename variables

* fix lu rename bug

* Update src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py

Co-authored-by: YiYi Xu <yixu310@gmail.com>

* Update src/diffusers/models/transformers/transformer_kandinsky6.py

Co-authored-by: YiYi Xu <yixu310@gmail.com>

* address yiyixuxu's comments

* fix audio channels bug

* fix tests

* Fix CI failures on the Kandinsky6 PR

- tests/others/test_utils.py: assert the caller file path without assuming the checkout directory is named `diffusers`.
- .github/workflows/pr_tests.yml: raise PYTEST_TIMEOUT to 300 s for the example and pipeline CPU steps. Both run several workers with four threads each on an 8-vCPU runner, and the checkpointing example tests run several training subprocesses in sequence.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Avoid staging LFS dedup race in the org push test

The second push in TestModelPushToHub.test_push_to_hub_in_organization sent the same model bytes as the first push. The staging server can deduplicate those bytes against the first push's LFS object and then reject the commit with "LFS pointer pointed to a file that does not exist". Change the weights before the second push so its bytes differ.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Revert "Avoid staging LFS dedup race in the org push test"

This reverts commit 35e6cc4ef.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Revert "Fix CI failures on the Kandinsky6 PR"

This reverts commit 60cad4341.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Apply suggestion from @yiyixuxu

* Apply suggestion from @yiyixuxu

* Apply batched suggestions from code review

Co-authored-by: YiYi Xu <yixu310@gmail.com>

* remove review-only files from the Kandinsky6 PR

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS

* Apply suggestion from @yiyixuxu

* restore .gitignore to match main

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS

* simplify the mono audio handling in _write_audio

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS

* remove the no-op set_attention_backend calls from the Kandinsky6 docs

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS

* give the Kandinsky6 transformer its own output class instead of reusing LTX-2's

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS

* fix the stale pipeline exports and add return annotations for the Kandinsky6 pipelines

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS

* address feedback from @leffff

---------

Co-authored-by: Denis Koposov <denis.koposov@phystech.edu>
Co-authored-by: leffff <levnovitskiy@gmail.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Lev Novitskiy <57654885+leffff@users.noreply.github.com>
Co-authored-by: YiYi Xu <yixu310@gmail.com>
2026-10-06 17:34:58 +05:30
YiYi Xu
36438e2ee4 fix https://github.com/huggingface/diffusers/issues/14461 (#14956)
* keep explicit timesteps in FlowMatchEulerDiscreteScheduler.set_timesteps and warn when they come without sigmas
2026-10-05 22:42:25 -10:00
Sayak Paul
771779849b [tests] remove test_pipelines_common.py (#14669)
* migrate imports

* migrate stable diffusion adapter tests

* up

* move last remaining bits.

* simplify test policy wording

* move around

* move flux ip adapter testing stuff to flux module of test

* fix(ci): harden GitHub Actions workflows (#14669) (#14787)

fix(ci): harden workflow files flagged on #14669

Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>

* clarify comment.

* remove name from batch_input

---------

Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>
2026-10-06 11:43:52 +05:30
Sayak Paul
899c9f3fd0 [chore] remove force_upcast from autoencoder flux2 (#14946)
* remove force_upcast attribute from autoencoder flux2

* remove script.
2026-10-06 07:32:00 +05:30
naykun
da1d3829cf Configure fixed sampling sigmas on QwenImage21Pipeline (#14950)
* feat(qwenimage21): configure sampling sigmas on the pipeline

* docs(qwenimage21): clarify default and runtime sampling sigmas
2026-10-05 09:11:49 -10:00
Sayak Paul
c2798cc785 [tests] refactor the pipeline-level attention processor tests (#14701)
* refactor the pipeline-level attention processor tests

* simplify stuff.

* remove utils.py
2026-10-05 15:38:23 +05:30
Sayak Paul
cff9dafbbf [modular] Echo team joy future academy jd echo by @Gelercatty (#14941)
* Add Echo modular pipeline

* Address Echo modular pipeline review feedback

* Inline Echo input list normalization

* Align Echo latent boundaries and batch expansion

* Polish Echo documentation per review

* Load official Echo checkpoint and separate block tests

* consolidate testing.

* formatting

---------

Co-authored-by: Yanwen Ma <gelercat117@gmail.com>
2026-10-05 14:04:27 +05:30
Aritra Roy Gosthipaty
9aababd755 Fix: Deprecating Siglip2ImageProcessorFast (#14781)
remove fast processor

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-05 13:53:28 +05:30
YiYi Xu
8b33bfc04b agent docs: support only what released checkpoints use (#14750)
* agent docs: support only what released checkpoints use

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Apply suggestion from @stevhliu

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Apply suggestion from @stevhliu

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Apply suggestion from @stevhliu

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Apply suggestion from @stevhliu

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Apply suggestion from @stevhliu

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Apply suggestion from @yiyixuxu

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-10-02 13:59:22 -10:00
yzhautouskay
357f8738cd [Bugfix] Fix Cosmos3 FP8 tensor parallelism (#14921)
Fix Cosmos3 FP8 tensor parallelism
2026-10-02 09:49:42 -10:00
TB
41566305ce Tag Krea 2 text encoder outputs as denoiser_input_fields (#14925) 2026-10-02 09:17:50 -10:00
Dhruv Nair
578c9b2c66 Add single file support for Krea 2 (#14914)
update
2026-10-01 16:37:20 +05:30
Sayak Paul
7997e4eabb chore: add one additional copied from in qwenimage 2.1 vae (#14810)
* add one additional copied from in qwenimage 2.1 vae.

* formattinmg
2026-09-30 22:21:28 -10:00
Dhruv Nair
acbabca385 Consolidate torch device backend dispatch (#14792)
* introduce TorchDeviceBackend

* update

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-01 13:41:30 +05:30
Dhruv Nair
4de185d6ec Add single file support for Minimax H3 (#14839)
update

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-01 13:14:41 +05:30
Dhruv Nair
a91ff967f5 [Modular] Avoid downloading weights when loading from an existing local path (#14797)
* avoid redownload from local path

* update

* update

* update

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-01 11:13:15 +05:30
Jingya HUANG
863092ffec [core] Shard tensor-parallel checkpoints on load and save (#14544)
* [core] Shard tensor-parallel checkpoints on load and save

Stream each rank's slice of a tensor-parallel checkpoint straight off disk
instead of materializing the full checkpoint on every rank and resharding it
afterwards, and gather the shards back on save.

- `from_pretrained(..., parallel_config=TensorParallelConfig(...))` resolves
  the shard specs on the still-meta model, then slices each safetensors tensor
  before the dtype cast, so host memory peaks at ~1/tp_degree of the checkpoint.
- `save_pretrained` all-gathers the DTensors into an ordinary checkpoint, or
  writes a distributed checkpoint with `dcp=True` so no full tensor is ever
  formed. The writing `tp_degree` is recorded, since a packed weight's stored
  layout is interleaved by it.
- Factor the plan interpretation out of the Neuron pre-shard path into shared
  `TPShardSpec` / `resolve_tp_shard_specs` / `_local_shard` / `_hooks_only_styles`
  helpers, so both backends and both the load and save paths shard identically.

* Raise when tensor parallelism is combined with quantization, offloading or LoRA

Addresses the remaining two items of the review on #13718: tensor parallelism was rejected
alongside quantization and `device_map` only on the `from_pretrained` streaming path, while
`enable_parallelism` — which the quantization error message itself recommended — accepted a
quantized, offloaded or adapter-injected model and sharded it anyway.

- Add `_check_tp_model_state`, called from `apply_tensor_parallel`, the one chokepoint every TP
  entry point funnels through. It rejects a model that is quantized, group-offloaded, placed by
  accelerate (`device_map` or CPU offload), or has PEFT layers injected. Placed before the
  device-type check so the reported reason is the useful one.
- Guard the reverse order too: `enable_group_offload`, the two pipeline CPU-offload methods, and
  `load_lora_adapter` now refuse a tensor-parallel model.
- `save_pretrained` refuses a quantized tensor-parallel model. Previously the `dcp=True` branch
  returned before the quantizer's serialization step, writing shards with no quantization
  metadata and no error.
- The DCP load guard checked the `quantization_config` kwarg only, so a pre-quantized checkpoint
  directory loaded silently; check the config's own entry too, and add the missing `_tp_plan`
  check that otherwise surfaced as a raw `AttributeError`.
- Correct the `from_pretrained` message and the doc sentence that pointed at `enable_parallelism`
  as a way to shard a quantized model.

The new tests are the first tensor-parallel tests that need neither an accelerator nor more than
one rank: every case asserts a raise before any collective, so they run single-process on gloo.

* review: remove tp save/ dcp related

* review: add a new helper .

* review: moved the TP checks into enable_parallelism

* review: move the warning under caution block

* review: add loading time numbers

* review: move tp size dividende check

* review: delete test

* review: consolidate tp checks

* review: consolidate the tp checks, all in tensor_parallel.py

* review: improve conditionals

* review: debug info

* review: check weights format before instantiating the model

* review: restore duplicated _find_mismatched_keys since irrelevant

* revert: delete duplicated helper

* review: update doc for loading benchmark of flux2-dev

* review: improve the raising check

* review: add an args section

* Test tensor-parallel loading from sharded checkpoints

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-10-01 10:16:29 +05:30
Steven Liu
c60830ee36 [fix] Add return types (#14874)
* add return types

* add return blocks

* style

* modular pipelines

* add a test to validate

* feedback - skip deprecated stuff
2026-09-30 08:59:23 -07:00
yzhautouskay
78405ec9a1 [Cosmos3] Fix Transfer SeaCache artifacts with control CFG (#14897)
* Fix Cosmos 3 Transfer SeaCache indicators

* Clarify SeaCache indicator guidance; tests refactor

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-30 21:23:20 +05:30
Dhruv Nair
a12c38a689 Remove deprecated code paths (#14838)
update
2026-09-30 17:38:01 +05:30
Sayak Paul
031b2798ad spit output to stderr when extracting GPU tests for PRs (#14847)
* update

* don't use xdist during gpu tests in PRs.

* Revert "update"

This reverts commit 0906d05c8b.

* fix(ci): harden GitHub Actions workflows (#14847) (#14849)

fix(ci): harden workflow files flagged on #14847

Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>

* redirect to stderr

---------

Co-authored-by: DN6 <dhruv.nair@gmail.com>
Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>
2026-09-30 10:47:09 +05:30
Sayak Paul
56aa3cd669 [docs] document release philosophy (#14904)
* document release philosophy

* Update docs/source/en/conceptual/contribution.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/conceptual/contribution.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/conceptual/contribution.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* clarify how folks can reach out to coordinate a release.

---------

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-09-30 09:53:59 +05:30
Sayak Paul
fef717ffb0 [core] propagate sage attention updates. (#14584)
* propagate sage attention updates.

* add sage blackwell.

* up

* style.

* address feedback

* style.
2026-09-29 18:47:23 +05:30
Sayak Paul
4ac08e9408 [diffusers-cli] add a dockerfile for diffusers cli hf jobs (#14550)
* add a dockerfile for diffusers cli hf jobs

* up

* up

* use diffusers from pypi

* fix(ci): harden GitHub Actions workflows (#14550) (#14851)

fix(ci): harden workflow files flagged on #14550

Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>

* Apply batched suggestions from code review

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* lower bound for tokenizers.

---------

Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
2026-09-29 16:50:36 +05:30
BeyondBirthday07
5ff8e59ff9 Fix LoRA loading for flattened CLIP text encoders (#14872)
Co-authored-by: Aznix07 <sruhilmodi13@gmail.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-28 19:47:16 +05:30
Christopher
8f0ad34299 [LoRA] convert Z-Image LoRAs that only carry the fused qkv and bare out attention keys (#14875)
* [LoRA] convert Z-Image LoRAs that only carry the fused `qkv` and bare `out` attention keys

A LoRA trained on Z-Image's original module names (musubi-tuner, LyCORIS)
has `attention.qkv` and `attention.out` and nothing else. The non-diffusers
converter dropped both on the assumption that split `to.q/k/v` and `to_out.0`
keys are also present (the Anime-Z layout), which emptied such a LoRA and then
raised on its leftover `.alpha` keys. Split the fused key into to_q/to_k/to_v
like the single-file converter does and map bare `out` to `to_out.0` when no
split keys exist; the Anime-Z case keeps skipping the redundant keys.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [LoRA] review follow-ups: shorter comment with the layout's origin, drop the private-method test

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: christopher5106 <christopher@scenario3d.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-28 17:52:38 +05:30
Pranav Negi
8315c5d6dc [realfill] Fix the LR scheduler when num_train_epochs is passed in a distributed training env (#14885)
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-28 14:13:27 +05:30
Álvaro Somoza
51a454be9a [MInimax H3] Fix VAE decode (#14754)
* intiial fix

* fix code quality

* fix failing pr test

* fix gpu test

* don't override the requested dtype

* add test

* apply review

---------

Co-authored-by: YiYi Xu <yixu310@gmail.com>
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
2026-09-28 10:55:14 +05:30
Sammy Tourani
e0abab83b5 downcast MiniMax-H3 position_ids at the device transfer on fp64-less backends (#14767)
Both layout steps build position_ids in float64 on CPU and then move it to
the execution device with a plain .to(device), which raises on MPS. Pass the
dtype through maybe_adjust_dtype_for_device so the transfer lands as float32
on mps/npu/neuron and is unchanged everywhere else. The fp64 construction is
untouched, and MiniMaxH3RotaryPosEmbed.forward already casts position_ids to
float32, so no device sees different rotary angles.

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-26 08:12:16 +05:30
Hidemitsu Ikeda
bdc2bea37a Fix TaylorSeer cache crash when the feature shape changes between steps (#14831)
* Fix TaylorSeer cache crash when the feature shape changes between steps

* Add QwenImage 2.1 x TaylorSeer tests covering the KV-cache prefill shape change

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-25 12:34:07 +05:30
Steven Liu
4295ee3ec5 [docs] Adapters (#14842)
* lora

* legacy adapters

* ip adapter

* controlnet

* feedback
2026-09-24 09:11:42 -07:00
Linoy Tsaban
e0118ade2f [LoRA] add LoRA training for Qwen Image 2.1 (#14808)
* [LoRA] add LoRA training for Qwen Image 2.1

Add DreamBooth LoRA training for Qwen-Image 2.1, text-to-image and
image-to-image, with fast tests and a README section.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* default rank and alpha to 16 and document the ratio

`--rank` and `--lora_alpha` are independent arguments, so raising the rank
alone leaves the update scaled by `lora_alpha / rank`. Default both to 16,
which keeps the scale at 1, and add a README section explaining the ratio.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* fix validation when embeddings are precomputed or only the final pass runs

Two fixes from review:

`QwenImage21ValidationPipeline` substituted the cached image-pad mask after
calling the base `encode_prompt`, but that call raises for a missing mask when
it is handed `prompt_embeds` together with a condition image, so the
substitution never ran and image-to-image validation failed. Pass the mask in
before the call instead.

`--final_validation_prompt` was accepted by the final-inference guard, but the
prompt embeddings were only built under `--validation_prompt`, so the final pass
reached a pipeline whose text encoder is `None` with no prompt at all. Build the
embeddings for whichever prompt is set.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* fix encoding under --offload without --cache_latents

`vae.encode` sat outside the `offload_models` block, so the context manager had
already moved the VAE back to the CPU by the time it ran, while the prepared
dataloader hands the batch over on the accelerator:

    RuntimeError: Input type (torch.cuda.FloatTensor) and weight type
    (torch.FloatTensor) should be the same

Move the call inside the block and cover that flag combination, which is the
only path that encodes pixels inside the training loop. The image-to-image
trainer already had it right.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* add LoRA tests for the Qwen-Image 2.1 pipeline

Follow the Flux layout and reuse `LoraTesterMixin` and `LoraMemoryTesterMixin`,
so the adapters these trainers produce are covered by the pipeline's own
loading, fusing and memory-offload tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* fix caching a prompt mask that `encode_prompt` returns as None

`encode_prompt` drops the prompt mask when nothing in the batch is padded,
which is the common case for `--caption_column` datasets since captions in a
bucket often tokenize to the same length. The cache is filled per sample, so
slicing that `None` raised during latent caching:

    prompt_embeds_mask_cache[idx] = prompt_embeds_mask[i : i + 1]
    TypeError: 'NoneType' object is not subscriptable

Materialize the mask before filling the cache, and cover the path with a test:
none of the existing ones passed `--caption_column`, which is why this only
showed up on a real dataset.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* pass rank and alpha explicitly in the README dog example

The dog example was written for the old 4/4 defaults; now that both default
to 16, spell out 4/4 so the documented command keeps training the size it
was tuned for.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* drop copy-paste leftovers from other trainers

`--output_dir` defaulted to `hidream-dreambooth-lora`, the weight-decay help
mentioned UNet params, and the VAE cast comment talked about the Flux VAE.
All three were inherited verbatim from the trainer this was derived from.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* lower the README dog example to lr 1e-4

At 2e-4 the example memorizes the five training images: prompted scenes
collapse to the training backdrop rather than following the prompt. 1e-4
is what the image-to-image example already uses.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qnMKe5MVc7B4XXHGPvXuZ

* skip the LoRA scale test for the Qwen-Image 2.1 dummy

Halving the LoRA scale moves this dummy transformer's output by less than the
tolerance the assertion allows, so the two outputs compare equal and the test
fails on CPU. Skip it with the measurement recorded rather than loosening a
tolerance shared with every other pipeline's LoRA tests.

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-24 08:33:09 +05:30
hf-security-analysis[bot]
0377f0c1b3 Pin GitHub Actions to commit SHAs (#14853)
A tag is mutable: whoever controls the action's repository can move
`v4` to different code, and the next run picks it up with no diff to
review. Pinning to the commit SHA freezes the code that runs today.

Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>
2026-09-23 16:05:59 +02:00
hf-security-analysis[bot]
256e9fbc0b Scope GITHUB_TOKEN permissions per job (#14852)
A job with no `permissions:` block inherits whatever the repository
hands out. Each block added here grants what that job's own steps
need and nothing more.

Co-authored-by: hf-security-analysis[bot] <265538906+hf-security-analysis[bot]@users.noreply.github.com>
2026-09-23 14:39:08 +02:00
Sayak Paul
0121a91f9d test and docs for xet dedup based file sharing. (#14835)
* test and docs for xet dedup based file sharing.

* up[
2026-09-23 10:20:11 +05:30
Dhruv Nair
f2edf6ea30 Add single file support for Qwen 2.1 (#14836)
update
2026-09-23 09:49:51 +05:30
Nianze Wu
8b3c707ebd Fix Wuerstchen LoRA scheduler steps for distributed epochs (#14748)
Fix Wuerstchen LoRA scheduler step scaling

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-22 14:26:27 +05:30
Lucain
fbf49e7f35 [docs] Fix legacy hf CLI references (diffusers) (#14830)
Use hf auth login in the LPL example error message

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-22 08:23:13 +05:30
Steven Liu
7263f3317f [docs] Using diffusion pipelines (#14805)
* refactor

* more refactor

* improve diagram, fix link

* legacy ckpts
2026-09-21 09:52:06 -07:00
Ch Revanth reddy
93d88c1898 [docs] Fix docstring arguments that don't match the signatures (#14778)
- TransformerSpatioTemporalModel.forward: no num_frames parameter
- get_2d_rotary_pos_embed_lumina: parameters are len_h / len_w, not grid
- AutoencoderKLHunyuanImageRefiner / AutoencoderKLHunyuanVideo15.tiled_decode:
  no return_dict parameter; they return a plain tensor

Co-authored-by: revanth-045 <revanthreddych159@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 08:44:04 -07:00
Aritra Roy Gosthipaty
71f7c96a47 [docs] typo with hyperlink (#14826)
typo with link
2026-09-21 08:19:24 -07:00