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

1341 Commits

Author SHA1 Message Date
Dhruv Nair
3681e65996 Restructure skill files and reference guides for CLI based installation. (#14454)
* restructure guides as skill references

* reorganize AGENTS.md and references

* clean up

* clean up

* clean up

* fix AGENTS.md references and add check_ai to Makefile

* clean up

* update paths

* clean up
2026-08-20 18:16:49 +05:30
Atharva Joshi
4e0466f3e5 fix: image preprocessing for cosmos3 (#14519)
fix: preserve Cosmos3 conditioning image aspect ratio
2026-08-19 08:43:50 -10:00
Jingya HUANG
7d2e86a85a [core] Support tensor parallelism for model inference (CUDA, Neuron) (#13718)
* draft:add neuron as a legit backend

* feat: neuron-specific changes in the pipeline

* tests: eager tests

* draft: start with tp for flux2

* fix: style

* fix:apr_02 beta

* feat:add wan

* fix:pixart

* fix: rewrite flux swiglu activation to avoid gather op in neuron IR

* test: pixart compile mode on neuron

* cleanup & fix style

* merge: another change

* review: cleanup+suggestions

* fix: CIs style

* tests: add test units for tp

* fix: in case of text-encoder(s) on CPU

* review:cleanup+add test

* fix: style

* doc: remove it for now

* Add from_single_file support for SkyReelsV2 and ChronoEdit transformers (#13946)

SkyReels-V2 and ChronoEdit are both built on Wan, and their transformers have
the same keys as WanTransformer3DModel, so they reuse
convert_wan_transformer_to_diffusers (like WanVACE / WanAnimate). This lets the
community GGUF builds load directly.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* multi-GPU VAE Fix for Cosmos 3 (#13924)

fix(cosmos3): pin VAE latent norm buffers to encode output device

Under sharded placement (device_map="balanced"), vae.encode() runs on the
VAE's own device while the mean/inv_std buffers were pinned to x.device,
causing a cross-device RuntimeError. Compute raw_mu first, then pin the
normalization buffers to its device so all tensors share one device.

Co-authored-by: Atharva Joshi <atjoshi@smc521ge-0036.ipp2a2.colossus.nvidia.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* docs: fix repeated word typo in set_timesteps docstring (#13876)

* docs: fix repeated word typo in set_timesteps docstring

Removed the duplicate word "schedule" from the docstring for the sigmas argument in EulerDiscreteScheduler.set_timesteps.

* Update scheduling_euler_discrete.py

* Apply style fixes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* clean some stuff to simplify code.

* clean more to remove permutation related shenanigans.

* revert: put torch.chunk back

* Update docs/source/en/training/distributed_inference.md

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* Address Sayak's TP review nits (docstrings + stale comments)

- _modeling_parallel: fix stale comment claiming attention processors read
  tp_degree at runtime (no longer true after the PackedColwise/Rowwise
  refactor; processors are TP-agnostic via head_dim).
- tensor_parallel: single backticks instead of double in docstrings, add
  input/output examples to _blocks_to_block_sizes and _resolve_tp_plan, and
  drop the stale "applies the Flux2 fused-weight permutations" line from
  apply_tensor_parallel (permuters were removed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Fix stale permuter reference in Flux2ParallelSelfAttnProcessor comment

The proportional QKV/MLP slice is now guaranteed by PackedColwiseParallel
block-by-block sharding, not the removed fused-weight permuter.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Derive TP backend inside apply_tensor_parallel from the mesh device type

Drops the `backend` parameter: apply_tensor_parallel already holds the TP
mesh, so it derives neuron-vs-default from `config._mesh.device_type` itself.
The caller no longer computes it. Documents why torch_device can't be used
(Neuron reports as "cpu" via torch's accelerator API). Removes the now-unused
is_torch_neuronx_available import from modeling_utils.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Simplify TP backend derivation to the mesh device type alone

Drop the redundant is_torch_neuronx_available() guard: a DeviceMesh("neuron", ...)
only exists when running on Neuron, so tp_mesh.device_type is the single source
of truth.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Remove incorrect "Neuron reports as cpu" rationale from TP backend docstring

Verified on the current native torch_neuronx drop that Neuron does surface as
the torch accelerator (torch._C._get_accelerator().type == "neuron",
get_device() == "neuron"); the old "reports as cpu" claim was stale. The
mesh-device-type derivation is unchanged — it's the device being sharded onto.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Drop stale "XLA" labels from Neuron device/runtime comments

Neuron is a native torch backend now (not XLA-routed): remove the "(XLA)"
parenthetical from the randn-on-CPU note in torch_utils and the "XLA runtime"
mention from the Neuron TP test docstring. Behavior unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* make style: reflow tensor_parallel docstrings

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Revert "revert: put torch.chunk back"

This reverts commit 7ea75f771a.

* fix: sharding for neuron + validate flux 1

* fix: change for check_repository_consistency

* feat: support qwen image as well

* Update docs/source/en/training/distributed_inference.md

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

* review: keep bria and nucleusmoe out

* review: keep bria and nucleusmoe out

* review: keep bria and nucleusmoe out

* review: address agent review

* review: apply suggestions

* Update docs/source/en/training/distributed_inference.md

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* review: change example tp size to 4

* review: add flux tp test

* review: address comments

* review: improve the doc

* review:apply qwen rotary_emb per device

* review:remove redundant device def after PR #14383

* review: doc title suggestion

* review: restore copy comment

* review: remove cp divisibility explanation from doc on parallelism guide

* fix style

---------

Co-authored-by: Hz_Zhang <47402297+HaozheZhang6@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Atharva Joshi <atjoshi@nvidia.com>
Co-authored-by: Atharva Joshi <atjoshi@smc521ge-0036.ipp2a2.colossus.nvidia.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: Ramkumar R <ramkumarashvanth09@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-08-19 16:20:59 +05:30
Buffett Liu
360bef8074 Feat -- Stable Audio 3 (#14119)
* Stable Audio 3 First Version Commit, require model dict loading on GPUs

* Fixing bugs for sa3 VAE

* Make quality fix

* Fix the unit test failure

* Fix SA3 pipeline noise: learned text-padding embedding + no cross-attn mask

The diffusers Stable Audio 3 pipeline produced noise instead of music because
the cross-attention conditioning was built differently from the reference:

- The reference text conditioner uses padding_mode="learned": padded text
  positions (~245 of 256 for a short prompt) are filled with a trained
  `padding_embedding`, and the DiT attends to *all* positions (its
  cross-attention mask is intentionally disabled). Our pipeline instead zeroed
  padded positions and masked them out, wiping ~95% of the conditioning signal.

Changes:
- transformer_stable_audio3: add learned `prompt_padding_embedding`; in forward,
  replace masked text positions with it (in cond_token_dim space, before
  to_cond_embed) then attend to the full context, matching the reference.
- pipeline_stable_audio_3: stop zeroing padded positions (the DiT now handles
  them); default `silence_padding_duration` to 6.0 (reference headroom default).
- convert_..._to_diffusers: convert
  `conditioner.conditioners.prompt.padding_embedding` into the DiT.
- scheduling_ping_pong: pin schedule endpoints (sigmas[0]=1.0, sigmas[-1]=0.0)
  to match the reference LogSNRShift endpoint preservation.
- run_..._inference: coerce float16->float32 on CPU.
- tests: update transformer state-dict expectations (523 tensors, add
  prompt_padding_embedding) and ping-pong sigma endpoint assertions.

Verified against the reference with identical noise + identical conditioning:
full 8-step ping-pong trajectories agree to 4e-6 (final latent). Removed the
dev-only parity scripts (verify_*_dit_parity, verify_*_vae_parity) from the tree.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Style fix

* Autopipeline available

* Adding document description for testing examples.

* Solving fix for serge review bot suggestion

* Design review comments fix

* CI/CD Fix for ping pong scheduler md file

* Fix doc build: remove autodoc for nonexistent StableAudio3EulerSchedulerOutput

* Fix doc build: qualify non-exported autodoc references with module paths

* Fix details in scheduler and some nits

* suggestion fix

* fix-copies: propagate prepare_latents dtype fix to audio2audio/inpaint pipelines

---------

Co-authored-by: Buffett Liu <jengliu@linkedin.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
2026-08-18 22:09:32 -07:00
Dhruv Nair
f3175baf6a [CLI] Clean up and improvements to diffusers CLI (#14381)
* [CLI] Clean up and improvements to `diffusers-cli`

Modular pipelines:
- `custom_blocks` also writes `modular_model_index.json`, so a packaged repo is
  loadable by `ModularPipeline.from_pretrained` (and runnable by `run`), not just
  importable as blocks.
- Add `--cpu-offload auto`, which offloads through the pipeline's
  `ComponentsManager`, plus `--offload-margin` to set its `memory_reserve_margin`.
- Add `--workflow` passthrough; warn and ignore it on standard pipelines.
- Route `model_index.json` repos whose `_class_name` is modular to the modular path.

Output saving:
- Resolve every media field on the output object (`images`, `frames`, `audios`,
  `audio`) instead of the first match, keeping the batch dimension. Fixes video
  output being misrouted through the image branch and LTX2's audio being dropped.
- Fix the `output_type="pt"` video transpose: `postprocess_video` returns
  `(B, F, C, H, W)`, not `(B, C, F, H, W)`.
- Save `(B, C, samples)` waveforms as multi-channel wavs (StableAudio).
- Write each video's frames to `<stem>-frames/<NNNN>.png`. Frames need no video
  backend, so they replace the `.pt` fallback when `export_to_video` fails.
- Report frame directories as a single path so hundreds of frames don't flood the
  terminal; `--push-to` and the sandbox download preserve subfolder structure.
- Raise on unrecognized payloads instead of dumping JSON/pickle.

Remote:
- Add `imageio`, `imageio-ffmpeg`, and `peft` to the default sandbox deps.
- Raise sandbox `start_timeout` to 600s; the 120s default expires while a cold node
  pulls the pytorch base image.

* Apply suggestion from @sayakpaul

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* update

* update

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-08-19 09:55:26 +05:30
iridescentWen
59c47446f2 docs: fix typos in Kandinsky 5.0 video docs (#14345)
- `qualty` -> `quality`
- `infered` -> `inferred` (x3)
- `bakend` -> `backend` (x3, in the trailing `# <--- Set attention
  bakend to Flex` comments; the actual `set_attention_backend` calls
  were already spelled correctly)
- `wothout` -> `without`

Prose and comments only, no code or behavior changes.
2026-08-18 08:55:22 -07:00
Kashif Rasul
d6bfaa71b8 Fix batched DiffusionGemma adaptive stopping (#14386)
* Fix DiffusionGemma stopping

* Test batched stopping

* Style DiffusionGemma docs

* Address DiffusionGemma review

* Update DiffusionGemma review

---------

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
2026-08-18 11:12:21 +02:00
YiYi Xu
a00d536450 Drop the experimental warning from Modular Diffusers (#14525)
Modular Diffusers is no longer experimental: remove the import-time warning
and the docstring warnings from ModularPipeline, the block base classes, and
every model's modular pipeline, and drop it from the docs overview.

ComponentsManager and the Mellon integration are still moving, so they keep
a warning — added one to the ComponentsManager docs page and to
mellon_node_utils, which had none.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 09:28:43 +02:00
BADAOUI Abdennacer
8222302f03 [FA2] Use kernels-community/aiter-flash-attn-ck Hub kernel for ROCm FlashAttention (drop aiter dependency) (#14436)
Use  Hub kernel

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-08-14 10:39:23 +02:00
apolinário
8c3dcd6da1 Add LoRA loading support for MiniMax-H3 (#14408)
* Add LoRA support for MiniMax-H3

* Address review: Copied-from loader, LoRA badge, docstring caveats, drop generic scale test

* Move the MiniMax-H3 LoRA tests to tests/lora

* Support the remaining published MiniMax-H3 LoRA layouts

Three more published H3 LoRAs did not load. Two were key-layout gaps and the
third was the reason neither was noticed: a layout that reaches no module at
all used to return without an exception.

- musubi-tuner writes one flattened `lora_unet_` name per module. It is
  un-flattened against the H3 module vocabulary, since `qkv_proj`,
  `token_refiner`, `final_layer` and the output heads carry underscores that
  are not path separators, and then goes through the existing kohya path.
- one producer publishes its own converter's output: diffusers module names
  with peft's `.default.` infix left in and no component prefix. The infix is
  dropped and the prefix added.
- a state dict that filters to nothing in both partitions now warns instead of
  loading as a silent no-op, in the wording `load_lora_adapter` uses for the same
  situation.

A fourth loaded, but at the wrong strength. One producer ships no `.alpha` scalars
and records the alpha it trained with in the file's own `__metadata__` instead,
under `alpha`. Its 8-step turbo LoRA pairs that entry's 8 with rank 128, an
effective scale of 0.0625, so synthesizing `alpha == rank` applied the adapter 16x
too strong. That entry is now read as the uniform network alpha. Per-module scalars
still win when a file carries both, since the converter has already folded them into
the weights, and a non-numeric value is warned about and ignored. `__metadata__` only
exists on a file, so `_fetch_state_dict` hands it back on request.

* Simplify the MiniMax-H3 LoRA comments

* Trim the MiniMax-H3 LoRA tests to loading and effectiveness

* Reference the alpha convention in the MiniMax-H3 LoRA docstring

* Drop a redundant format comment

* Test only diffusers-written state dicts

* Rely on get_peft_kwargs for alpha-less files

* Drop the peft version guards after the main cleanup

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-08-14 09:50:12 +02:00
apolinário
2da7040be1 Add MiniMax Music 3 (#14456)
* Add MiniMax Music 3 transformer, pipeline sub-models, and conversion script

* Add MiniMax Music 3 pipeline, tests, and docs

* Wire example docstring, point diffusers-format references at MiniMaxAI/MiniMax-Music-3

* Use MiniMaxAI/MiniMax-Music3 as the official diffusers weights repo id

* Apply doc-builder style

* Use dtype in examples, demonstrate the structured prompt format

* Use soundfile in examples like the other audio pipelines

* Convert to a modular pipeline and move models under src/diffusers/models

Per review: the conditioner moves to models/condition_embedders, the RVQ depth
decoder and vocoder to models/transformers and models/autoencoders, and the
standard pipeline is replaced by MiniMaxMusic3ModularPipeline (anima-style
blocks, helios-style chunk loop, guider-abstracted CFG with a zeros
unconditional branch). Index configs now reference all components under the
diffusers library. Also applies the transformer review suggestions
(Transformer2DModelOutput, inlined rotary forward, explicit processor default).

* Point modular index loading specs at the Hub repo in the converter

* Apply doc-builder style to the modular blocks docstrings

* Address review-bot comments: overlap comment accuracy, single pipeline-level progress bar, zero-frame duration guard, import ordering, docstring cross-reference

* Support CPU offloading in the AR step: trigger offload hooks before submodule calls (minimax_h3 workaround), clear error when the AR models cannot co-reside

* Docs: PR-install tip and memory-usage section with measured offloading numbers

* Address review comments on the block assembly

Take the individual models rather than `components` in `_generate_depth_codes` and
`_embed_audio_frame`; `num_codebooks` / `audio_vocab_size` come off the depth decoder's
config, so the two pipeline properties that existed only for them are gone.

Assemble the blockset as three top-level children, each owning models and runnable on its
own — generate the semantics once and denoise it with different settings:

    semantic_generator  MiniMaxMusic3SemanticGenerationStep  [tokenize, generate]
    denoise             MiniMaxMusic3CoreDenoiseStep         [prepare_chunks, denoise]
    decode              MiniMaxMusic3VocoderDecodeStep

`MiniMaxMusic3TextEncoderStep` is renamed `MiniMaxMusic3TokenizeStep` (it only tokenizes)
and the autoregressive leaf `MiniMaxMusic3AutoregressiveStep`, freeing its old name for
the sequential.

Point the tests at `hf-internal-testing/tiny-minimax-music3-modular-pipe`; the previous
fixture repo's component specs pointed at a local path, so nothing loaded off that machine.
Drop the PR-branch install tip from the docs.

20s and 60s generations are bit-identical to before these changes.

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

---------

Co-authored-by: yiyixuxu <yixu310@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-13 13:47:57 -10:00
Vinh H. Pham
788e80206a docs: document fused-kernel performance in Nunchaku Lite guide (#14458)
* docs: document fused-kernel performance in Nunchaku Lite guide

* Apply suggestions from code review

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

* Apply suggestion from @rootonchair

---------

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-08-13 09:00:17 -07:00
YiYi Xu
3a2f35d4ef Wan-Animate-2 (authored by @kelseyee) (#14413)
* support wan-animate-2

---------

Co-authored-by: kelseyee <971704395@qq.com>
Co-authored-by: yiyi@huggingface.co <yiyi@huggingface.co>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: sayakpaul <spsayakpaul@gmail.com>
2026-08-12 08:48:05 -10:00
Funtowicz Morgan
175fe6b241 docs: add installation instructions for NVIDIA Spark (ARM64) devices (#14448) 2026-08-11 12:17:59 -10:00
Sayak Paul
7564fb016d Ltx 2.5 (#14447)
* Add LTX-2.4 support to the LTX2 transformer, pipelines, and conversion script

LTX-2.4 reuses the existing LTX2 model and pipeline classes. The delta over
2.3 is a small set of additive config flags plus a Gemma 3 -> Gemma 4 text
encoder swap, so no new model or pipeline classes are introduced.

- transformer_ltx2.py: add `ff_bias`/`audio_ff_bias` (2.4's video FFN drops
  its bias) and `use_prompt_adaln_single` (toggles timestep-dependent prompt
  cross-attention modulation; when off, cross-attention K/V becomes
  timestep-independent and cacheable across denoising steps for a given
  prompt). Both default to their 2.3 behavior. The flag is read back from
  `self.config` rather than mirrored onto an instance attribute, and all
  three new constructor args are documented.

- pipeline_ltx2.py / pipeline_ltx2_image2video.py: add an optional
  `prompt_enhancer` component to both pipelines (previously T2V-only).
  LTX-2.4's fine-tuned text encoder is conditioning-only, so enhancement
  uses a separate off-the-shelf google/gemma-4-E2B-it checkpoint with its
  own message format and decoding recipe -- unlike LTX-2.0/2.3, where one
  checkpoint serves both roles. `enhance_prompt()` resolves the format and
  `.generate` kwargs from whichever model is active, and frees a dedicated
  enhancer from GPU memory right after use (guarded so it does not interfere
  with accelerate's offload hooks), mirroring the existing text_encoder
  handling.

  Both `__call__`s gain `enable_prompt_enhancement: bool | None = None`,
  which resolves to `True` when a dedicated `prompt_enhancer` is configured
  (LTX-2.4) or when `system_prompt` was passed explicitly (matching prior
  LTX-2.0/2.3 behavior exactly), and `False` otherwise. Explicit `False`
  disables enhancement even on 2.4. When enabled with no `system_prompt` on
  a 2.4 pipeline, the matching default system prompt is injected.

  `max_new_tokens`/`seed` keep their literal defaults (512/10)
  unconditionally: greedy decoding consumes no randomness, so `seed` is
  inert for the dedicated-enhancer case, and 512 tokens comfortably covers
  the target caption length. No public API or default changes were needed
  for LTX-2.0/2.3.

  Validation of the enhancement arguments happens in `check_inputs`, so an
  unsatisfiable request fails before the prompt is encoded rather than
  partway through generation. Text encoder, tokenizer, processor and
  enhancer type hints name the concrete Gemma classes they accept.

- utils.py: add a `PromptEnhancementConfig` dataclass plus
  `GEMMA3_PROMPT_ENHANCEMENT_CONFIG`/`GEMMA4_PROMPT_ENHANCEMENT_CONFIG` as
  the single source of truth for each model's message prefix and `.generate`
  kwargs, shared by both pipelines. Add the validated "capstyle_plus"
  LTX2_4_T2V/I2V_DEFAULT_SYSTEM_PROMPT strings, marked `docstyle-ignore` so
  `doc-builder style` cannot re-wrap them -- the prompts must stay
  byte-for-byte identical to the reference, newlines included.

- convert_ltx2_to_diffusers.py: add a "2.4" branch to all five
  get_ltx2_*_config functions. Transformer/VAE/vocoder configs are
  structurally identical to 2.3 (verified against the checkpoint's own
  safetensors metadata); only `ff_bias=False` differs. Connector
  `caption_channels`/`text_proj_in_factor` are now derived from the live
  Gemma text config rather than hardcoded, since 2.4's text encoder is not
  pinned to a single checkpoint the way Gemma-3-12B is for 2.0/2.3. Swap
  `Gemma3ForConditionalGeneration`/`Gemma3Processor` for
  `AutoModelForImageTextToText`/`AutoProcessor` so one path covers Gemma 3
  and Gemma 4. Raise a clear error when --version 2.4 is requested without
  pointing --text_encoder_model_id at a Gemma 4 (gemma4_unified) checkpoint,
  and add --prompt_enhancer_model_id, required whenever --version 2.4 is
  combined with --add_processor, since falling back to
  --text_encoder_model_id (correct for 2.0/2.3) would pair 2.4 with the
  wrong enhancement model. Also fixes a pre-existing vocoder
  class-selection bug that only checked for "2.3", and `processor` never
  being passed into the --full_pipeline LTX2Pipeline(...) construction.

- docs/source/en/api/pipelines/ltx2.md: add an "LTX-2.4" section covering
  what carries over from 2.3 unchanged (guidance recommendations, aside
  from a different STG block index) and what does not (a single-stage
  checkpoint only, with no two-stage or distilled workflow yet), plus the
  corrected prompt-enhancement recipe and its enabled-by-default behavior
  for both LTX2Pipeline and LTX2ImageToVideoPipeline.

* Fix resolution-dependent timestep shift being a no-op in all LTX2 pipelines

Every LTX2Pipeline variant's `mu = calculate_shift(...)` call passed the
scheduler's `max_image_seq_len` config value as the `image_seq_len`
argument instead of the current generation's actual packed sequence
length. Since calculate_shift's formula is a line through
(base_seq_len, base_shift) and (max_seq_len, max_shift), passing
image_seq_len == max_seq_len always evaluates to exactly max_shift --
so `mu` was pinned to a constant (2.05 for the LTX-2.4 scheduler config)
regardless of height/width/num_frames, even though `use_dynamic_shifting:
true` is set specifically to make this resolution-dependent.

Found while benchmarking LTX-2.4 diffusers output against the reference
pipeline with bit-identical starting noise: the reference computes this
shift from the real video token count (ltx_core's LTX2Scheduler.execute),
which diverges substantially from the constant diffusers was using at
any resolution other than exactly the checkpoint's max-anchor token
count. For a 768x512, 121-frame video (6144 tokens), the reference lands
on mu ~= 2.78 versus diffusers' constant 2.05.

Fixed by passing the current call's actual packed video latent length
(`latents.shape[1]`) as `image_seq_len`, matching the pattern already
used correctly in pipeline_flux.py (the source this was copied from).
Applies to all 5 LTX2 pipeline variants, each with their own independent
`__call__` (not linked via `# Copied from` for this method).

* Add LTX-2.4 duration head for automatic num_frames prediction

LTX-2.4 checkpoints ship a small regression head (~1.9M params) that predicts
the natural duration of the shot implied by a caption, from the same text
connector output the transformer is conditioned on. With it converted, a caller
can let the model choose the video length instead of picking `num_frames`.

- duration_head.py: `LTX2DurationHead` (a `ModelMixin` optional pipeline
  component) plus the `LTX2AutoDuration` request object. Modality-specific
  projections map the video and audio connector streams into a shared pooler
  dim, learnable modality embeddings tag them, one learnable query cross-attends
  the concatenation, and a small MLP regresses a log-duration. `forward` returns
  seconds as a tensor; `predict_num_frames` clamps to bounds and snaps to the
  VAE's causal temporal grid.

  The attention pooler uses explicit to_q/to_k/to_v/to_out with
  `dispatch_attention_fn` rather than `torch.nn.MultiheadAttention`, which both
  reference implementations use because that is the layout the checkpoint ships.
  `nn.MultiheadAttention` is documented in diffusers as breaking
  `enable_sequential_cpu_offload`; the split form also gets backend dispatch.

  Two details are load-bearing for numerical parity: the GELU must be
  tanh-approximated (the exact GELU gives different numbers against the
  JAX-trained head), and the clamp must precede the grid snap (a clamped frame
  count is not necessarily grid-aligned). Where narrow bounds convert to a frame
  window containing no grid point -- at 24 fps [1.0s, 1.02s] rounds to [24, 24],
  and 24 is not 8k + 1 -- the nearest grid point is used and a warning logged,
  rather than refusing to generate over a rounding artifact.

  The output MLP's config argument is `mlp_hidden_dim`, not the reference's
  `mlp_hidden`: the submodule keeps the checkpoint's `mlp_hidden` name, and
  `ModelMixin.__getattr__` resolves config keys ahead of submodules, so the two
  colliding would shadow the `nn.Linear` with an `int`.

- pipeline_ltx2.py / pipeline_ltx2_image2video.py: `num_frames` becomes
  `int | LTX2AutoDuration | None`. Omitting it auto-predicts when the checkpoint
  ships a head and keeps the legacy 121 otherwise, mirroring the reference --
  whose CLI also defaults to auto-prediction -- and matching the resolution
  these pipelines already do for `enable_prompt_enhancement`, which likewise
  switches on the presence of an optional LTX-2.4 component. Pre-2.4 pipelines
  have no head, so nothing changes for them.

  The prediction runs immediately after the connectors and before `num_frames`
  is first read. Only the positive half of the CFG-concatenated batch is used,
  and rows past the first are `num_videos_per_prompt` duplicates.

  Auto-duration is rejected from `check_inputs` -- before prompt enhancement and
  encoding, so a bad request costs nothing -- when there is no head, and when
  more than one prompt is supplied: the batch carries a single temporal
  dimension, so prompts with different natural lengths cannot share one frame
  count. Batched prompts with an explicit integer `num_frames` are unaffected.

- convert_ltx2_to_diffusers.py: `--duration_head` (with
  `--duration_head_prefix`) alongside the other per-component flags. The head's
  keys sit at the checkpoint top level rather than under the DiT prefix, so the
  existing prefix helper handles them. The checkpoint's fused `in_proj_weight`
  is split into separate q/k/v, and dimensions are read back from weight shapes
  since checkpoint metadata carries no duration_head config; only
  `num_pooler_heads` is not recoverable and is fixed at 4. Pre-2.4 checkpoints
  yield no keys and are skipped rather than failing.

Verified against ltx_core on the real 2.4 checkpoint: fed the reference's
recorded connector tokens, the converted head predicts 12.9375s (video only),
2.671875s (audio only) and 3.515625s (both) -- bit-identical to the reference --
and the same frame counts through the clamp/snap path at 24/25/30/8 fps. The
snapping arithmetic matches the reference `seconds_to_clamped_num_frames` across
260 combinations of duration, frame rate and bounds.

* Add LTX-2 modular video and audio decoder blocks

Add the first blocks of the LTX-2 modular pipeline under
modular_pipelines/ltx2/decoders.py:

- LTX2VaeDecoderStep: unpacks and decodes video latents (or returns
  latents for output_type="latent"), applying the optional decode-time
  noise on normalized latents before denormalizing, matching the
  standard LTX2Pipeline decode stage.
- LTX2AudioDecoderStep: unpacks and decodes audio latents into a
  waveform via the audio VAE and vocoder in a single block.

Pack/unpack/denormalize helpers are redefined at module level rather
than imported, since modular blocks must not import from
diffusers.pipelines.* (the vocoder class is imported from the pipelines
path for now, flagged for relocation to models/).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add LTX-2 modular pipeline (t2v + i2v) and parity harnesses

Add the LTX-2 modular pipeline package under modular_pipelines/ltx2/,
covering the joint video+audio text-to-video and image-to-video
workflows for LTX-2.4:

- encoders.py: dedicated Gemma-4 prompt enhancer (t2v/i2v), Gemma text
  encoder, text connectors, and the i2v image VAE encoder.
- before_denoise.py: text-input expansion, flow-match timesteps (with a
  deep-copied audio scheduler), video/audio latent prep, and RoPE coords.
- denoise.py: the joint video+audio denoise loop with manual guidance
  (CFG + spatio-temporal + modality-isolation), shared across t2v/i2v.
- decoders.py: video VAE decode and audio VAE + vocoder decode.
- modular_blocks_ltx2.py: LTX2Blocks (t2v), LTX2ImageToVideoBlocks (i2v),
  and LTX2AutoBlocks (both, default), plus the auto/conditional wrappers.
- modular_pipeline.py: LTX2ModularPipeline with the compression-ratio and
  patch-size properties the blocks read.

Wire up lazy imports and register the pipeline (top-level diffusers
exports, modular_pipelines __init__, MODULAR_PIPELINE_MAPPING, and dummy
objects).

Also add integrations/ (temporary, for-visibility) parity harnesses that
compare the modular t2v/i2v blocksets against the standard LTX-2
pipelines by sharing the same loaded components. This directory is meant
to be removed before the final integration.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add script to create tiny LTX-2.4 test pipeline ckpt (under assumption that it inherits all configs from LTX-2.3)

* make fix-copies

* Run modular connector once on CFG-concatenated batch for bitwise parity

Run the LTX-2 text connector once on the CFG-concatenated `[uncond, cond]`
batch (as `LTX2Pipeline` does) instead of once per branch, then split the
outputs back into uncond/cond. The connector is applied per batch element, so
both forms are mathematically equivalent, but its GEMM/attention kernels round
identically for a given row only at batch >= 2; running the branches separately
diverged from the standard pipeline by ~1e-6 at `num_videos_per_prompt=1`. The
modular path is now bitwise-identical to the standard pipeline at any batch size.

Also extend the T2V/I2V parity harnesses with a `--num_videos_per_prompt`
argument and a `--check_tensor_stats` flag for per-output min/mean/std/max.

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

* Use tiny LTX2VocoderWithBWE in the LTX-2.4 test checkpoint

Swap the placeholder LTX2Vocoder for a scaled-down LTX2VocoderWithBWE that
mirrors LTX-2.3's vocoder (snakebeta + antialiasing, no final activation/bias,
16kHz -> 48kHz bandwidth extension) while keeping the same in/out channel
shapes. Dimensions are reduced but the shape invariants the two-stage forward
requires are preserved: in_channels = audio_vae.output_channels * mel_bins,
bwe_in_channels = out_channels * num_mel_channels, filter_length == window_length,
and prod(bwe_upsample_factors) == (output_sr // input_sr) * hop_length so the BWE
residual and the resampled stage-1 skip line up.

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

* Match LTX-2.4 transformer flags in the test checkpoint

Only `ff_bias=False` is a transformer-level delta from LTX-2.3 per the
authoritative LTX-2.4 config in `scripts/convert_ltx2_to_diffusers.py`;
`audio_ff_bias` and `use_prompt_adaln_single` keep their `True` defaults.
The test checkpoint was incorrectly overriding both to `False`, so drop
those two overrides. T2V/I2V modular-vs-standard parity remains bitwise.

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

* Add CPU offload flag to parity scripts to be able to load full checkpoints

* Support dynamic timestep shift and duration head in LTX-2 modular pipeline

Track two recent additions to the standard LTX-2.4 pipelines in the
modular blocks (t2v + i2v):

- Resolution-aware timestep shift: LTX2SetTimestepsStep now computes `mu`
  from the actual packed video sequence length (derived from
  height/width/num_frames and the transformer patch sizes) instead of a
  constant, matching the standard pipeline's `latents.shape[1]`-based
  shift. Uses the compute-from-dims approach (like LTX-1 / Flux2), so no
  block reordering is needed.

- Optional duration head: add LTX2DurationStep, which predicts a concrete
  `num_frames` from the connector text conditioning via the `duration_head`
  component when `num_frames` is an `LTX2AutoDuration` request, and
  re-emits it. Wrapped in the LTX2AutoDurationStep conditional (skipped for
  an integer `num_frames`) and wired into all three blocksets after the
  connector step, so `num_frames` is resolved before the shift and latent
  prep run.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add duration predictor support for tiny checkpoint and parity scripts

* Refactor LTX-2 modular guidance into video/audio guiders

Replace the manual multi-term guidance in `LTX2LoopDenoiser` with a
`LTX2Guidance` guider (in `guider.py`), instantiated once as the video
`guider` and once as the `audio_guider`. Each combines CFG + spatio-temporal
guidance (STG) + modality-isolation via the delta formulation in x0 space; the
denoiser owns a `plan_guidance_passes` union plan across the two guiders, runs
each transformer pass, converts velocity->x0, and delegates the per-modality
combine to the guiders. Guidance scales are now guider config, not `__call__`
kwargs. Parity harnesses updated to configure the guiders accordingly.

Parity investigation (not yet resolved):
- The refactor runs every guidance pass as its own single-batch transformer
  forward, whereas the standard `LTX2Pipeline` batches the cond+uncond CFG pair
  into one forward and runs STG/modality-isolation as separate single-batch
  passes. STG and modality already match (single-batch in both).
- The change is mathematically equivalent, not a logic bug: in fp32 the
  denoised latents match to ~8e-6 mean abs diff (sparse outliers up to
  ~3.5e-4), and disabling STG does not move the diff.
- But GPU matmul is not batch-invariant, so cond computed alone differs from
  cond computed inside a batch-of-2. Negligible in fp32 (~1e-6/op); ~1e-2/op in
  bf16, where amplification by the CFG delta and accumulation over sampler steps
  drives the modular vs. standard bf16 latents to ~10% mean-relative divergence.
- Net: numerical, but the modular pipeline does NOT reproduce the standard
  pipeline bitwise in bf16 (the real inference dtype). Restoring parity would
  require re-batching the cond+uncond pair into a single forward to match the
  reference execution, keeping STG/modality single-batch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Batch cond+uncond CFG forward to mirror standard LTX-2 pipeline

Restore fp32 bitwise parity with `LTX2Pipeline` in the modular denoiser by
running the cond+uncond CFG pair as a single batched transformer forward
(`torch.cat([latents] * 2)` + `.chunk(2)`), keeping STG and modality-isolation
as separate single-batch conditional forwards -- matching the reference
op-for-op (batch sizes, repeated coords, cache-context names).

`plan_guidance_passes` now emits forward-groups (`identifiers` / `conditioning`
aligned lists + `flags` + `cache_context`) instead of one entry per pass; the
denoiser runs each group once and chunks the CFG forward back into its
`[uncond, cond]` identifiers. The `LTX2Guidance` combine is unchanged -- only
how the four x0 tensors are obtained changed.

Parity results:
- fp32: bitwise (0.0 max abs diff), verified at full-checkpoint scale including
  under CPU offload. This is the authoritative parity gate.
- bf16: the previous single-batch-per-pass design diverged ~10% mean-relative
  from the standard pipeline (GPU matmul is not batch-invariant: cond alone vs.
  cond in a batch-of-2). Batching the CFG pair removes that gap; a smaller
  ~1% (tiny) / ~5% (full) bf16 gap remains. It is not a logic difference (fp32
  is bitwise across scale and offload); it is a bf16-kernel effect -- coarser
  mantissa amplifying non-associative accumulation order, plus bf16 using
  different kernels than fp32 (tensor-core GEMM algorithm selection, fused
  attention). bf16 is therefore a close-but-not-bitwise check, not a gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Drive LTX-2 modular guidance through the guider API (per-pass inputs)

Replace the batched-CFG denoiser with one that runs each guidance pass as its
own single-batch transformer forward, driven end-to-end through the standard
guider API. `LTX2Guidance.prepare_inputs(guider_inputs)` builds one identifier-
tagged batch per active pass from a dict whose values are 4-tuples indexed by
pass [cond, uncond, stg, modality]; the per-pass model flags
(`spatio_temporal_guidance_blocks`, `isolate_modalities`) ride in those tuples
alongside the encoder inputs, so a pass fully describes its own forward. The
denoiser unions both guiders' passes by identifier, runs each once (storing
video+audio x0 on the batch), and combines each modality via its guider's
`forward`/`__call__`, filtered to that guider's active passes so the batch count
matches `num_conditions`.

Removes the bespoke `plan_guidance_passes` union helper and the empty-dict
`prepare_inputs_from_block_state` call: the plan is now expressed as the
`guider_inputs` tuples + `active_predictions()`, so guidance logic lives behind
the guider API rather than in the denoiser.

Parity trade vs. the previous batched-CFG design:
- Batched CFG matched the standard pipeline op-for-op and was fp32-bitwise.
  Running every pass single-batch is mathematically equivalent but, since GPU
  matmul is not batch-invariant, cond computed alone differs from cond inside a
  batch-of-2: ~1e-4 mean-relative in fp32 on a full checkpoint (sparse outliers
  up to ~3.5e-4 max), ~10% mean-relative in bf16.
- This is numerical, not a logic difference, and fp32-within-tolerance (not
  bitwise) is the modular-ecosystem norm. The trade buys end-to-end guider-API
  usage (swappable within the LTX-2 guidance family, per-pass flags carried the
  same way as encoder inputs) at the cost of the bitwise guarantee.

Parity harnesses: gate on magnitude-aware stats (mean abs diff relative to mean
magnitude, plus a loose max-abs ceiling) instead of assert_close's near-bitwise
fp32 defaults, which no single-batch design can clear. fp32 is the authoritative
gate (1e-3/1e-3); bf16 is a loose sanity check (0.15/0.5). `--atol`/`--rtol`
become `--mean_rel_tol`/`--max_abs_tol`; motivation documented in-file.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Drive LTX-2 modular guidance via prepare_inputs_from_block_state

Move `LTX2LoopDenoiser` onto the standard Wan/Z-Image guider idiom: the
denoiser now owns a `guider_input_fields` map (transformer arg -> per-pass
block-state attribute names, indexed [cond, uncond, stg, modality]) and calls
`guider.prepare_inputs_from_block_state(block_state, guider_input_fields)`
instead of hand-building a literal `guider_inputs` dict in `__call__`. This
lifts the cond/uncond/stg/modality field mapping to a construction-time arg
(swappable per workflow) and resolves the connector_*->encoder_hidden_states
name mismatch via the map keys.

The two per-pass model flags (`spatio_temporal_guidance_blocks`,
`isolate_modalities`) are pass-identity constants, not block-state
conditioning, so they can't ride the name-referenced field map; the denoiser
sets them on each batch by identifier after preparation, via a
`pass_flags.get(identifier, (None, False))` lookup. The plain-conditional
default keeps this correct for any guider that emits a subset of passes (e.g.
a swapped-in `ClassifierFreeGuidance` -> just pred_cond/pred_uncond gets no STG
and no modality isolation).

`LTX2Guidance` gains `prepare_inputs_from_block_state` (names, via the base
`_prepare_batch_from_block_state` helper); `prepare_inputs` (literals) is
retained so both halves of the guider data-prep API are implemented. Pass
structure and numerics are unchanged (still four single-batch forwards), so the
fp32/bf16 parity story is untouched; user-confirmed parity OK.

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

* Route LTX-2 batch-invariant denoiser kwargs via denoiser_input_fields

Tag the three upstream-produced, batch-invariant transformer kwargs
(`audio_num_frames` from the audio-latents step; `video_coords` / `audio_coords`
from the coords step) with `kwargs_type="denoiser_input_fields"`, and have
`LTX2LoopDenoiser` collect them from `block_state.denoiser_input_fields` filtered
against the transformer's forward signature (à la qwenimage/cosmos3) instead of
listing them as explicit inputs. This drops three explicit `InputParam`s in favor
of one `denoiser_input_fields` template input.

Per-pass conditioning (cond/uncond/stg/modality) stays on the guider field map --
the tag only delivers a flat dict, so it can't do the cond/uncond split or the
connector_*->encoder_hidden_states rename. The locally-computed latent dims
(num_frames/height/width/fps) are still supplied in-denoiser: they aren't upstream
outputs and their names would clash with the pixel-space values in state.

Parity unchanged (validated T2V + multi-frame I2V): the tagged values reach the
transformer identically; the first-forward capture shows them bitwise-equal.

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

* Fix LTX-2 parity harnesses: guidance overrides reach both pipelines

The CLI guidance flags (`--guidance_scale`, etc.) only fed the modular guiders;
the standard pipeline was always called with the hardcoded GUIDANCE dict. So
`--guidance_scale 1.0` disabled CFG on the modular side only, comparing
standard-with-full-CFG (batch-2) against modular-no-CFG (batch-1) -- an
apples-to-oranges run that manifested as a huge (but spurious) I2V mismatch.

Add `_resolve_guidance(args)` (CLI overrides on top of GUIDANCE) and drive BOTH
the standard call and `_make_guiders` from the one resolved dict, in both the t2v
and i2v harnesses. With CFG correctly disabled on both sides, multi-frame I2V is
bitwise-ish (~5e-6 mean-rel), confirming the default-guidance ~8e-3 divergence is
the documented cond/uncond batch-invariance (amplified by I2V's per-token masked
timestep + clean anchor frame), not a logic bug.

Also:
- i2v: loosen the fp32 gate to (2e-2, 1.5e-1) to fit that amplified-but-numerical
  multi-frame divergence, with a comment pointing at the CFG-off run as the tight
  bug-catching gate.
- i2v: add `--debug_forward`, which diffs the first transformer forward
  (inputs + outputs) between the two runs via a forward hook -- the diagnostic
  that pinpointed the batch-shape mismatch above.

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

* Document denoiser_input_fields standalone-run caveat for LTX-2 denoiser

`audio_num_frames` / `video_coords` / `audio_coords` reach `LTX2LoopDenoiser`
via the `denoiser_input_fields` tag, not as named inputs. Note in the docstring
that a standalone run (without the upstream tagging blocks) must pass them
through `denoiser_input_fields={...}`; plain named kwargs are silently ignored
(modular.md's kwargs_type standalone gotcha).

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

* Address LTX-2 modular self-review: fix dead enhancer trigger + docstrings

Blocking fix: `enable_prompt_enhancement` was declared only as a
`block_trigger_inputs` entry / `select_block` param, never as an `InputParam`,
so it was not an accepted pipeline input -- `pipe(enable_prompt_enhancement=True)`
was dropped as "unexpected" and the prompt enhancer could never run. Declare it
on both enhancer sub-blocks so it reaches `select_block` (mirrors how the `image`
trigger is declared).

Also from the self-review:
- Regenerate the modular auto-docstrings: the guidance knobs (guidance_scale,
  stg_scale, ...) that moved onto the guider no longer show as block inputs, and
  the enhancer trigger now appears.
- Add descriptions to the 16 `InputParam`s that rendered as "TODO: Add
  description." in the generated docstrings (conversion checklist requires none).
- Drop the defensive `getattr(tokenizer, "padding_side", "left")` (a declared
  tokenizer always has it; gotcha #7).
- Rewrite two ephemeral comments (the connector-output "reconcile when denoise.py
  is written" NOTE, now resolved; the guider "batched-CFG variant in git history"
  pointer) into standing rationale.

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

* Fix stale I2V parity-harness --help text for the loosened fp32 gate

The `--mean_rel_tol` / `--max_abs_tol` help strings still advertised the old
fp32 defaults (1e-3, 1e-3); the I2V gate is now (2e-2, 1.5e-1). Update the help
to match the actual DTYPE_TOLERANCES so `--help` doesn't misreport the gate.

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

* make style and make quality

* Add the LTX-2.4 diffusion VAE decoder with a native-parity harness

* Add a converter for the LTX-2.4 diffusion VAE decoder

* Initialise use_slicing and document the diffusion VAE decisions

* Record real-weight parity against the reference decoder

* Add model-level tests for the LTX-2.4 diffusion VAE decoder

The generated test file needed three decisions rather than fill-ins: the class had no forward() for the
mixins to call, the decoder denoises so forward has to take a generator for any output comparison to mean
anything, and MemoryTesterMixin.test_group_offloading reused one inputs_dict across four forwards without
re-seeding it. The last is fixed in the mixin, reusing the helper test_group_offloading_with_disk already
had for the same reason, now module-level and reading the signature off the class (offloading replaces
model.forward with a *args wrapper).

* Fold the diffusion VAE converter into convert_ltx2_to_diffusers.py

--diffusion_vae now sits beside --vae instead of shipping a second script. It also drops the standalone
script's --encoder-vae: the encoder is in the same checkpoint and goes through the conv VAE's own rename
rules, with its config pinned in get_ltx2_diffusion_video_vae_config. Output verified bitwise identical to
the standalone script's on the rc2 checkpoint, 491/491 tensors and the same config.json.

* Make the diffusion decoder work through LTX2Pipeline

The documented usage -- LTX2Pipeline.from_pretrained(repo, vae=diffusion_vae) -- had never been run: every
real-weight run so far called vae.decode() directly. Through the pipeline it raised on
vae.config.timestep_conditioning, which this decoder has no reason to carry, and would have bound the
positional decode timestep to the decoder's generator. The decode step now branches on the decoder type,
skipping the decode_timestep pre-noising and passing the generator instead, which also makes decoding
seed-reproducible; two full runs from one seed agree bitwise. The conv path's own statements are unchanged.

* Make the diffusion decoder work through the modular decode step

Same fix as the standard pipeline, in LTX2VaeDecoderStep: skip the decode_timestep pre-noising and pass the
generator instead of a timestep. Verified on rc2 weights by injecting the decoder into
LTX2Blocks().init_pipeline() with update_components, the route the modular parity harness already uses -- two
runs at 320x448x17 from one seed agree bitwise, so no modular_model_index.json repo was needed to run this.

* Note that the pipeline decode block predates the LTX-2.4 integration PR

* Address diffusers self-review on the diffusion VAE decoder

Four things the project's own rules catch:

- models.md forbids unconditional torch.float64 in a model (MPS/NPU/Neuron cannot run it). The RoPE
  frequency base now goes through maybe_adjust_dtype_for_device, the helper flux/flux2/wan use for exactly
  this. Measured cost of the downcast where it applies: 1.5e-08 on the frequencies, 1e-06 on the angles.
- rope_dim_split was threaded through five classes but was never a config entry, so it was always None and
  always fell back to the default split. Removed, and the default-split helper inlined into its one caller.
- FromOriginalModelMixin was declared with no SINGLE_FILE_LOADABLE_CLASSES entry, so from_single_file raised
  rather than working. Dropped; single-file support can come with its own mapping later.
- set_attention_backend() overwrites the processor's _attention_backend, which handed the neighborhood
  BlockMask to backends that cannot read it. Guarded like AnyFlowCausalAttnProcessor does.

Also runs make fix-copies, which was missing the dummy object for the new class.

* Add the API doc page for AutoencoderKLLTX2VideoDiffusionDecoder

* Mark the parity harness transient and drop the notes doc from the diff

Matches the header the other integrations/ harnesses on this branch already carry, and states that the file
imports the native reference package. The notes doc goes to the PR description instead: the self-review skill
is explicit that it never ships in the diff.

* Accept the diffusion decoder in the image-to-video pipeline too

Same branch as the text-to-video pipeline: skip the decode_timestep pre-noising and pass the generator instead
of a timestep. The remaining LTX2 pipelines that share this decode block (condition, hdr_lora, ic_lora,
latent_upsample) are deliberately left for later, so the surface stays the two pipelines this PR actually
exercises.

* Reorganize LTX-2 modular blocks into coarser component-aligned phases

Regroup the top-level LTX-2 block assemblies so each direct child of
LTX2AutoBlocks is a coherent, component-aligned phase, mirroring Flux 2's
[text_encoder, vae_encoder, denoise, decode] shape:

- New LTX2TextConditioningStep wraps [text_encoder, text_input, connectors] as
  one "text_encoder" phase (LTX-2's text conditioning is genuinely a three-step
  model chain; text_input must precede connectors for batch-invariant parity, so
  the whole chain lives here rather than pushing text_input into denoise).
- New LTX2DecoderStep wraps [video_decode, audio_decode] as one "decode" phase.
- duration stays a top-level child: it is component-aligned (duration_head) and a
  ConditionalPipelineBlocks that self-skips for concrete num_frames, so it is a
  cleanly optional phase alongside prompt_enhancer / vae_encoder -- keeping it
  out of the (mandatory) denoise block.

Top-level children become:
  t2v:  [text_encoder, duration, denoise, decode]
  i2v:  [text_encoder, duration, vae_encoder, denoise, decode]
  auto: [prompt_enhancer, text_encoder, duration, vae_encoder, denoise, decode]

Also reorder the class definitions to follow this flow, keeping the core-denoise
trio (LTX2CoreDenoiseStep, LTX2Image2VideoCoreDenoiseStep, LTX2AutoCoreDenoiseStep)
contiguous instead of split by LTX2AutoVaeEncoderStep.

Pure re-grouping: no block bodies change and intermediate outputs still propagate,
so t2v/i2v parity is bit-identical to before (user-confirmed at 17 frames).
Docstrings regenerated.

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

* Enable LTX-2 prompt enhancement by default when the enhancer is loaded

Mirror the standard pipeline's tri-state prompt-enhancement default
(pipeline_ltx2.py:559-560), where `enable_prompt_enhancement` defaults to
auto-on when a `prompt_enhancer` component is present (LTX-2.4) and off
otherwise, and wire the enhancer into the t2v/i2v assemblies.

- Both enhancer sub-blocks: default `enable_prompt_enhancement=None` (tri-state).
  Resolve `None` against component presence inside `__call__` -- select_block
  cannot see components, so the gate dispatches for None/True and the sub-block
  decides. `None` + no enhancer -> pass the prompt through unchanged (the
  Cosmos3 optional-component pattern); explicit `True` + no enhancer -> a clear
  ValueError instead of the previous cryptic `NoneType` crash from within the
  enhance helper.
- LTX2AutoPromptEnhancerStep.select_block: skip only on an explicit `False`.
- Add LTX2AutoPromptEnhancerStep to LTX2Blocks and LTX2ImageToVideoBlocks so all
  three assemblies share the prompt_enhancer-first shape (previously only
  LTX2AutoBlocks had it; passing the flag to the others was silently ignored).
- Parity harnesses: force `enable_prompt_enhancement=False` on the modular run
  too (the modular sets now carry an enhancer), and fix the now-stale
  "contains no enhancer block" docstrings.

Only the dedicated-enhancer (LTX-2.4) path is wired; the standard pipeline's
text_encoder-as-enhancer fallback for LTX-2.0/2.3 remains a follow-up. Parity
unchanged (both pipelines run with enhancement disabled in the harnesses).
Docstrings regenerated.

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

* Rename LTX-2.4 product identifiers to LTX-2.5.

Update conversion --version, model ids, system-prompt constant names, and docs/comments to the public 2.5 name. Behavior is unchanged in this commit.

* Add image-conditioning H.264 CRF matching Lightricks training.

Resolve CRF 18 for LTX-2.5 (Gemma 4) and 33 for earlier generations, and apply the PyAV re-compress path for I2V and single-frame Condition/IC keyframes.

* Align LTX-2 pipelines with the Lightricks reference behavior.

Extract shared prompt-enhancement and check_inputs mixins; enable Condition duration+enhancement and IC enhancement (HDR remains encode-only); match enhancement recipe and LTX-2.3/2.5 sampling defaults.

* Update LTX-2 docs for 2.5 naming, defaults, and opt-in enhancement.

Document LTX_2_3/2.5 sampling defaults, STG block 28, and enable_prompt_enhancement=True as the opt-in path.

* Replace LTX2AutoDuration with min_seconds/max_seconds call args.

Drop the dataclass wrapper and expose duration bounds directly on the T2V, I2V, and Condition pipelines.

* Align LTX-2 modular blocks with the merged standard-pipeline changes

The standard LTX-2 pipelines moved to shared `LTX2PromptEnhancementMixin` /
`LTX2CheckInputsMixin`, dropped `LTX2AutoDuration`, adopted the Lightricks
reference defaults, and gained H.264 CRF re-compression of image
conditionings. Port all of that to the modular blocks.

- Prompt enhancement: re-derive `_enhance_prompt` from the new mixin -- the
  `user prompt:` / `User Raw Input Prompt:` templates, 896px long-side image
  prep, left-padding to a multiple of 8 for Flash Attention, `clean_response`
  on the decoded output, and `max_new_tokens=None` resolving to the Gemma-4
  budget of 600.
- Revert `enable_prompt_enhancement` to a plain `False` opt-in, matching the
  reference pipelines (the tri-state auto-on default is gone upstream). The
  friendly error for `True` with no enhancer loaded is kept.
- Auto-duration: trigger on an omitted `num_frames` instead of an
  `LTX2AutoDuration` sentinel, with `min_seconds`/`max_seconds` as call args.
  `LTX2DurationStep` raises when no `duration_head` is loaded rather than
  silently falling back to 121 frames.
- Every `num_frames` InputParam default becomes `None`: input defaults are
  seeded into the pipeline state before any block runs, so a default of 121
  would leave the auto-duration branch permanently unreachable.
- Defaults sweep: `num_inference_steps` 40 -> 30, `use_cross_timestep`
  False -> True, and the video/audio guider ComponentSpec configs updated to
  the reference guidance stack.
- `LTX2VaeEncoderStep` gains `image_crf` and re-compresses the conditioning
  image before preprocess, declaring `text_encoder` only to resolve the model
  default CRF.
- Rename LTX-2.4 -> LTX-2.5 throughout, following the upstream product rename.

Parity harnesses updated for the new duration arguments, plus an `--image_crf`
flag on the i2v harness defaulting to 0 so the comparison isolates block logic
from the PyAV codec round-trip. Verified against a real checkpoint: t2v, i2v at
`--image_crf 0`, and i2v at `--image_crf -1` all pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Evaluate the decoder's SwiGLU in token tiles

Decode-only peak VRAM at 121 frames and 512x768 was 24.6 GiB, and 17.0 GiB of that was one transient
inside the first stage-5 block: `w_gate(x)` and `w_up(x)` are both hidden-width and their product makes
a third, so the whole video's worth of hidden activations was live three times over. At that size each
one is 2,973,696 tokens x 1024 x 2 bytes = 5.67 GiB.

The MLP is pointwise across tokens, so tiling it is exact -- it changes only how many hidden-width
elements exist at once. Measured on a full-size decode: peak 24.8 -> 19.4 GiB (-22%), wall clock 2.79 ->
2.84 s (+1.6%), output bit-identical (max abs diff 0.000e+00). That also puts the diffusion decoder
below the conv decoder, which needs 23.8 GiB at the same size.

Tile size 16384 tokens is the reference decoder's own default (`DEFAULT_SWIGLU_TILE_SIZE`). Bounding a
token count rather than a number of tiles keeps peak memory independent of resolution.

This is the first of the two transients the reference's default decode mode avoids; the other is the
full-volume QKV projection plus RoPE's fp32 upcast, which it addresses by chunking attention along
width. That one is not bit-exact (it reassociates NATTEN's accumulation), so it is left for a follow-up
rather than changed here.

* Declare _no_split_modules on the diffusion decoder

Both block types close over a residual add that combines outputs from different children, which is the
case models.md says has to stay co-located, so neither can be split across devices.

Unskips three memory tests that were gated on the attribute: the file goes from 35 passed / 7 skipped to
38 passed / 4 skipped, and the three (test_cpu_offload, test_disk_offload_with_safetensors,
test_disk_offload_without_safetensors) pass.

* Match the encoder defaults to the published LTX-2.4 config

block_out_channels was (256, 512, 1024, 2048) and layers_per_block was (4, 6, 6, 2, 2); both were
inherited from the 2.0 conv VAE. The published vae_diffusion/config.json has (256, 512, 1024, 1024) and
(4, 6, 4, 2, 2). Real loads were unaffected because the config sets these explicitly, but the defaults
described a model that does not exist.

All 27 __init__ defaults that appear in the published config now match it.

* Cover the token-tiled SwiGLU path in the tests

The dummy video is 9x48x48, so its stage-5 grid is 5184 tokens against a 16384-token tile size: every
other test in the file takes the untiled branch and the tiling loop ran nowhere in CI. This shrinks the
tile size to force ~41 tiles and requires torch.equal against the untiled evaluation, since the MLP is
pointwise across tokens and tiling must be exact rather than close.

Checked the test is not vacuous: sabotaging the tiled branch alone (silu on w_up instead of w_gate)
fails it at 8.83e-01.

* Let the parity harness run against the LTX-2.5 reference too

The harness only spoke LTX-2.4's decoder API and died on `forward_pre_diffusion` against 2.5, so it could
not check the release the port is now targeted at. Three shims absorb the differences:

* 2.5 selects a decode pathway by swapping `__class__` on every block, so an as-constructed decoder has no
  `forward_combined`. Install the COMBINED pathway explicitly, uncompiled, since that is the pathway this
  port implements.
* stages 1-4 split into `forward_stages_1_to_3` + `forward_stage_4`, so the chunked pathway can defer
  stage 4.
* the trailing NATTEN ghost pad moved out to the caller while its crop stayed behind
  `forward_stage_4(pad_trailing=True)`; the two have to be paired or the context loses real frames (3 of
  17 survive at this config, which is how the mismatch first showed up).

Same numbers against both references -- context 5.367e-04, step 7.337e-04 -- which is the check that the
shims are semantically right and not just shape-compatible.

* Add LTX-2.X modular condition blocks

Ports LTX2ConditionPipeline to the modular pipeline system, including the
LTX-2.5 additions (per-condition CRF, conditions-sourced prompt enhancement,
auto-duration, the Lightricks reference defaults).

New blocks:
  - encoders.py: LTX2ConditionEncoderStep (resize/center-crop, single-frame
    H.264 re-compression at the model CRF, temporal trim, VAE encode) and
    LTX2ConditionPromptEnhancerStep (grounds the rewrite in the first PIL
    frame found in `conditions`, text-only otherwise).
  - before_denoise.py: LTX2ConditionPrepareLatentsStep (first-frame overwrite
    + keyframe token append with their own RoPE coords, emitting
    conditioning_mask / clean_latents / appended_coords / base_token_count),
    LTX2ConditionSetTimestepsStep, LTX2ConditionPrepareAudioLatentsStep,
    LTX2ConditionPrepareCoordsStep, and the _prepare_keyframe_coords helper.
  - denoise.py: LTX2ConditionLoopBeforeDenoiser (mask-scaled per-token video
    timestep), LTX2ConditionLoopAfterDenoiser (x0 blend against the clean
    condition latents, then a full-sequence scheduler step),
    LTX2ConditionDenoiseStep.
  - decoders.py: LTX2TrimConditionTokensStep.
  - modular_blocks_ltx2.py: LTX2ConditionAutoPromptEnhancerStep,
    LTX2ConditionCoreDenoiseStep, LTX2ConditionDecoderStep, LTX2ConditionBlocks.

LTX2LoopDenoiser is reused unchanged: the two LTX2Guidance guiders already
express the whole CFG + STG + modality-isolation stack the condition pipeline
uses, and the transformer takes the longer packed sequence with the base
num_frames/height/width exactly as the standard pipeline does. The standard
pipeline's CFG batch duplication (conditioning mask, coords) has no modular
counterpart, since each guidance pass is its own single-batch forward.

Block ordering: prepare-latents runs *before* set-timesteps, unlike the
text-to-video and image-to-video core denoise steps. The resolution-aware
shift `mu` is computed from the packed latent sequence length, which here
includes the appended keyframe tokens, so the latents must exist first. This
mirrors LTX2ConditionPipeline (its section 4 precedes section 5). The
text-to-video and image-to-video blocksets are unaffected: with no appended
tokens the grid-derived sequence length already equals latents.shape[1].

Two subtleties the parity harness surfaced:

  - The condition pipeline samples audio noise directly in packed shape
    [B, L, C * M], while the text-to-video and image-to-video pipelines sample
    unpacked [B, C, L, M] and pack afterwards. Both draw the same number of
    values from the generator but lay them out differently, so reusing the
    shared LTX2PrepareAudioLatentsStep silently desynchronizes the audio noise
    and, through the joint attention, the video too (1.4 mean-rel on audio,
    0.13 on video before the fix). Hence a standalone condition audio block.

  - `noise_scale` means different things across workflows: 0.0 for
    text-to-video/image-to-video, `None -> sigmas[0] or 1.0` for conditions.
    A blockset keeps the first non-None default across its blocks, so a 0.0
    would have shadowed the condition resolution and left the latents
    unnoised. Both condition-path blocks declare None; prepare-latents
    resolves once and writes the value back for the audio step.

Keyframe tokens, masks and coords are expanded to the generation batch (the
pattern the in-context pipeline already uses for reference tokens). The
standard pipeline builds them at batch 1 and cats them onto a batch-B
sequence, so it raises for num_videos_per_prompt > 1 with any condition at
latent index > 0; the modular blocks handle that case.

Verification: integrations/ltx2_condition_parity.py (transient, removed before
merge) compares LTX2ConditionBlocks against LTX2ConditionPipeline on shared
component objects. Eight cases on a tiny checkpoint -- first-frame only,
keyframe only, both plus a multi-frame video condition, two keyframes, no
conditions, --crf -1, --predict_duration, num_videos_per_prompt=2 -- all pass
at 3e-7 to 1.3e-6 mean-rel. On a full checkpoint at 768x512x17 with two
conditions through the CRF path: video 8.7e-04 mean-rel / 1.1e-02 max-abs,
audio 1.5e-04 / 2.1e-03, in line with the image-to-video figures at the same
frame count.

make style, make quality and make fix-copies are clean; auto-docstrings
regenerated with no TODO placeholders.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Add LTX-2.X modular in-context (IC-LoRA) blocks

Ports LTX2InContextPipeline to the modular pipeline system on top of the
condition blocks, and fixes two bugs in the standard in-context pipeline that
the parity harness surfaced.

New blocks:
  - encoders.py: LTX2ReferenceEncoderStep (preprocess, VAE-encode and pack each
    reference video, compute the coords that map its tokens into the target
    space, and build the per-token cross-attention strengths), plus the
    _downsample_mask_to_latent helper.
  - before_denoise.py: LTX2InContextPrepareLatentsStep (frame conditions as in
    the condition step, then the reference tokens appended last) and
    LTX2BuildVideoSelfAttentionMaskStep.
  - modular_blocks_ltx2.py: LTX2AutoReferenceEncoderStep,
    LTX2AutoBuildVideoSelfAttentionMaskStep, LTX2InContextCoreDenoiseStep,
    LTX2InContextBlocks.

LTX2ConditionDenoiseStep is reused unchanged: with the blend gate fixed below,
reference tokens are pinned by exactly the same x0 blend as frame conditions,
matching the reference implementation where VideoConditionByReferenceLatent and
VideoConditionByKeyframeIndex produce the same (denoise_mask, clean_latent) pair
and post_process_latent runs unconditionally. The condition encoder, timesteps,
audio-latents, coords and decoder blocks are shared as well.
video_self_attention_mask reaches the transformer through the
denoiser_input_fields tag, so LTX2LoopDenoiser needed no change.

`reference_conditions` is optional, matching LTX2InContextPipeline: IC-LoRAs
that carry their behavior in the adapter weights (camera control, style) take
no reference video, which is the shape of the standard pipeline's own docstring
example. The reference encoder and the attention-mask step are both skipped when
it is absent. There is no duration step (the in-context pipeline ships without a
duration_head), so LTX2ConditionEncoderStep now raises a concise error if
`num_frames` is still None by the time the conditions are encoded.

Per-reference token counts come from the encoder rather than an equal split of
the total, so references of differing lengths (a reference video shorter than
num_frames) get the right strengths.

Standard-pipeline fixes in pipeline_ltx2_ic_lora.py:

  - The x0 blend was gated on `has_conditions` alone, so with reference
    conditions and no frame conditions the reference tokens were seeded clean
    and given a zeroed timestep but never re-pinned. Their x0 prediction error,
    divided by sigma each step, then accumulated and drifted them away from the
    encoded reference. Now gated on `has_conditions or num_ref_tokens > 0`, in
    line with the surrounding gates and the reference implementation.

  - video_self_attention_mask was rebound in the loop rather than expanded into
    a per-pass local. The main pass expanded it to the CFG-doubled batch, after
    which the STG pass's expand() to `latents.shape[0]` raised
    "RuntimeError: The expanded size of the tensor (1) must match the existing
    size (2)". Any run combining an attention mask with STG or modality
    guidance -- i.e. the default guidance settings -- died on the first step.

Also removed the unused has_appended_tokens local and replaced the "# - TODO"
placeholder above the attention-mask construction with the block structure,
which the reference confirms.

Verification: integrations/ltx2_in_context_parity.py (transient, removed before
merge). Twelve cases on a tiny checkpoint -- reference only, reference at
partial strength, scalar attention strength, pixel-space attention mask,
downscale factor 2, references plus first-frame and keyframe conditions, two
references, the CRF path, and four reference-free variants -- all pass at 3.4e-7
to 1.3e-6 mean-rel. The seven-case condition suite still passes. On a full
checkpoint at 768x512x17 with a reference plus two conditions: video 4.4e-05
mean-rel / 5.6e-04 max-abs, audio 3.2e-05 / 2.4e-04.

Known limitation, not addressed here: transformer_ltx2.py converts the
multiplicative [0, 1] self-attention mask to an additive bias linearly, as
(1 - mask) * -10000, whereas the reference uses log space (bias = log(mask),
finfo.min at zero). Intermediate strengths therefore saturate to "fully masked",
making conditioning_attention_strength effectively binary and spatially varying
masks inert beyond their zero/non-zero pattern. Parity is unaffected -- both
pipelines feed the same mask into the same transformer -- but the feature does
not currently work as documented.

make style, make quality and make fix-copies are clean; auto-docstrings
regenerated with no TODO placeholders.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Make the diffusion decoder a decode pipeline instead of a VAE

Addresses the review: a full diffusion model should not be an AutoencoderKL that hides its denoising
behind `.decode()`, and it should not have to be threaded into every LTX-2 pipeline as a `vae`.

AutoencoderKLLTX2VideoDiffusionDecoder becomes LTX2VideoDiffusionDecoderModel, a plain ModelMixin with
no encoder. Encoding stays with AutoencoderKLLTX2Video, whose latent space this consumes unchanged, so
latents remain interchangeable between the two decoders. Dropping the encoder also removes the
converter's awkwardness of sourcing encoder weights and the real block_out_channels from the conv
`vae/` folder: ten encoder-only config keys are gone.

LTX2VideoDiffusionDecodePipeline drives it, shaped like LTX2LatentUpsamplePipeline: run any LTX-2
pipeline with output_type="latent", then decode. `vae` is an optional component, since it is only ever
consulted for the latent statistics, and the decoder carries its own `latents_mean` / `latents_std`
buffers to fall back on. That means a decode-only workflow never loads a second autoencoder.

The `vae=` path is removed accordingly: the isinstance branches in LTX2Pipeline,
LTX2ImageToVideoPipeline and the modular decode step are gone, along with the fixtures that built a
diffusion decoder to pass as `vae`. The model's slicing/tiling test class went with them, since
enable_tiling was an AutoencoderMixin concern and this is no longer an autoencoder.

Tests: 37 passed / 3 skipped on the model, 83 passed / 2 skipped across the t2v and i2v pipelines.

Still to come: mapping the 2.5 checkpoint to a blockset that selects the diffusion decode block, and
the KandinskyCombinedPipeline pattern for running the two-step flow by default in the standard API.

* Add a modular decode block for the LTX-2 diffusion decoder

The previous commit removed the `isinstance(vae, ...)` branch that let the diffusion decoder stand in
as the modular `vae`, which was the right call twice over: it is what the review objected to, and
modular.md says a new case gets a new block rather than a branch inside an existing one. But removing
it without a replacement left modular with no route to the diffusion decoder at all.

LTX2DiffusionVaeDecoderStep is that replacement. It declares the decoder as its own
`diffusion_decoder` component rather than borrowing the `vae` slot, and passes a generator instead of
a decode timestep, since this decoder draws the noise it denoises. `LTX2VaeDecoderStep` is untouched,
so the convolutional path is unaffected.

What is still missing is the wiring: a blockset using this block, and an `_ltx2_map_fn` so a
checkpoint that ships the diffusion decoder selects it automatically instead of the user choosing.
That lands in modular_blocks_ltx2.py, which #12 is reorganizing, so it needs sequencing against that
PR rather than racing it.

* Test the diffusion decode pipeline, and give it a video-only output

The decode pipeline had no coverage: it was never actually run. Writing the tests immediately turned
up a bug, which is that it returned `LTX2PipelineOutput`, whose `audio` field is required. This
pipeline decodes video only, so it now returns a video-only `LTX2VideoDecodeOutput` instead of
passing a meaningless `audio=None`.

Four tests: decode with no `vae` (the fallback to the decoder's own latent statistics), decode with a
`vae` supplied (its statistics take precedence, checked by making the two disagree rather than
asserting a shape), reproducibility under a seeded generator plus divergence under a different seed,
and `denormalize=False` actually skipping the statistics. The decoder's stat buffers are set to
non-trivial values in the fixture so a run that silently skipped denormalization could not pass by
coincidence.

* Fix the decode example: output_type="latent" is already denormalized

The example in the docs and the pipeline docstring both showed `output_type="latent"` feeding straight
into the decode pipeline on its defaults. That path denormalizes twice: `LTX2Pipeline` applies the
latent statistics before returning latents (pipeline_ltx2.py), and the decode pipeline applies them
again because `denormalize` defaults to True. Every channel ends up scaled by its own std a second
time, so e.g. channel 0 (std 0.238) comes out roughly 4x too small.

Passing `denormalize=False` in the example and saying so in both docstrings. Caught by running the
flow end to end on real rc4 weights, which is also where the two decoders agree at 0.9978 once the
statistics are applied only once.

Whether the *default* should flip, or `output_type="latent"` should stop denormalizing instead, is a
contract question across both pipelines and is still open.

* Fix IC-LoRA video self-attention mask grouping

The video self-attention mask deviated from the reference implementation
(`ltx_core.conditioning.mask_utils.build_attention_mask`) in two ways. Both
predate the modular blocks and applied to `LTX2InContextPipeline` as well; the
modular block had ported the same construction.

1. Keyframe conditions cross-attended with reference tokens. `num_noisy_tokens`
   was derived as `latents.shape[1] - num_ref_tokens`, which folds the appended
   keyframe tokens into the noisy group, so they received the reference cross
   mask. The reference takes `num_noisy_tokens` from the target latent shape --
   generated-video tokens only -- and tracks the extras offset separately, so
   keyframe <-> reference is 0.0. Split the two quantities apart:
   `_build_video_self_attention_mask` now takes `num_prefix_tokens` alongside
   `num_noisy_tokens`.

2. Multiple reference conditions fully attended to each other. All references
   were passed as a single attention group with a 1.0 self-block. The reference
   wraps each `LTX2ReferenceCondition` in its own
   `ConditioningItemAttentionStrengthWrapper`, building the mask once per item,
   so reference_i <-> reference_j is 0.0. The call site now splits
   `ref_cross_mask` into one group per reference before building the mask.

Threading per-reference token counts out of `_encode_reference_conditions` also
removes the equal-split assumption in `prepare_latents` and
`prepare_reference_latents`, which assigned the wrong per-token strengths when
references encoded to different token counts (reachable when a reference video
is shorter than `num_frames`).

API impact
----------

`prepare_latents` returns a 7-tuple instead of a 6-tuple, adding
`ref_token_counts` (`list[int]`) as the new final element. Elements 1-6 keep the
types they have on `main`; in particular `ref_cross_mask` remains the
concatenated `[1, num_ref_tokens]` tensor. Callers that unpack the tuple fail
immediately with a `ValueError` rather than silently receiving a changed type.

`_encode_reference_conditions` (private) likewise gains `reference_token_counts`
as a fourth return element. `prepare_reference_latents` keeps its documented
4-tuple unchanged.

Verification
------------

Correctness against the reference. Both the standard helper and the modular
block were checked for exact tensor equality (`torch.equal`) against
`build_attention_mask`, driven the way `ic_lora.py` drives it -- one
`ConditioningItemAttentionStrengthWrapper` per reference, so the reference
builds iteratively with `existing_mask` carried forward. Five layouts, all
matching, exercised through the same concatenate-then-split path the call site
uses:

  - references only, 1 reference
  - keyframes + 1 reference          (exercises fix 1)
  - keyframes + 2 references         (exercises fixes 1 and 2)
  - 2 references of unequal length   (exercises fix 2 and the token counts)
  - no keyframes, 3 references       (exercises fix 2)

Standard/modular parity on a real checkpoint, 512x512x17, fp32, via
`integrations/ltx2_in_context_parity.py`. Video latents (1, 128, 3, 16, 16),
audio latents (1, 8, 18, 16); gates are mean-rel 2e-2 and max-abs 1.5e-1:

  --reference 1.0 9 --condition 2 0.5 9 --conditioning_attention_strength 0.5
    video: max abs 4.822e-05, mean rel 7.851e-06
    audio: max abs 1.875e-04, mean rel 1.773e-05

  --reference 1.0 9 --reference 0.8 9 --conditioning_attention_strength 0.5
    video: max abs 1.953e-04, mean rel 9.101e-05
    audio: max abs 9.251e-05, mean rel 1.026e-05

The first case is the layout where `num_prefix_tokens != num_noisy_tokens`; a
wrong prefix/base split would have placed the group blocks at the wrong offsets
with valid shapes, surfacing as a parity mismatch. The returned video shape also
unpacks from exactly 768 base tokens (3 x 16 x 16), confirming
`base_token_count` is the quantity now fed as `num_noisy_tokens`.

Scope of the parity runs: both sides share this construction, so parity shows
they did not desynchronize, not that either matches the reference -- that rests
on the equality test above. Both references in the second case are 9 frames and
so encode to equal token counts, meaning the equal-split and per-count paths
coincide; the token-count change is not discriminated by these runs. A reference
pair of differing lengths (e.g. `--reference 1.0 9 --reference 0.8 17`, giving
512 vs 768 tokens) would separate them, and would have failed parity before this
commit since the modular block already used per-reference counts while the
standard pipeline split evenly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Add LTX25AutoBlocks and LTX25ModularPipeline

Following the review: LTX-2.5 is a new checkpoint, so it gets its own blockset and pipeline rather
than a config flag inside the LTX-2 ones.

LTX25AutoBlocks subclasses LTX2AutoBlocks and overrides exactly one entry, `video_decode`, to
LTX2DiffusionVaeDecoderStep. Every other leaf block is reused, so the two blocksets have identical
block_names and cannot drift apart. That makes the diffusion decoder the default for LTX-2.5, which
matches what the checkpoint ships natively, without the user having to pass a decoder at all.

Going the other way stays a one-line swap rather than a second official blockset:

    blocks.sub_blocks["video_decode"] = LTX2VaeDecoderStep()

LTX25ModularPipeline carries `default_blocks_name = "LTX25AutoBlocks"` and a new "ltx2.5" key in
MODULAR_PIPELINE_MAPPING, so a repo shipping `modular_model_index.json` routes straight to the new
blockset.

The condition and in-context workflows belong in this blockset too, but those blocks live in the
modular condition/IC PR, so folding them in belongs there rather than as a competing change here.

* Drop the encoder half in the diffusion decoder converter

The converter still assembled the whole VAE checkpoint, encoder included, and handed it to a strict
`load_state_dict`. That was correct while the class was an autoencoder; after it became decoder-only
the ~84 `encoder.*` keys have nowhere to land and the load raises. Nothing caught it because no test
converts anything and every other check loads pre-converted weights, where unexpected keys are only
warned about.

Now the encoder is discarded rather than remapped, keeping the `decoder.` half and the per-channel
statistics that become `latents_mean` / `latents_std`. `strict=True` stays, since it is what guards
against a botched rename rule.

Verified by actually running it: pulled the 395 `vae.*` tensors out of the native rc4 checkpoint by
byte range, converted, and diffed against the already-published folder. 407/407 parameters, max abs
difference 0.000e+00, so the fix changes nothing about the weights it produces.

Also added a regression test, since the absence of any converter coverage is why this slipped.

* Share the neighborhood attention mask and parameterise the AdaLN chunk count

Two of the resolved review threads. Both are internal to the decoder modules and are unaffected by
the pipeline-vs-model question still open on the thread above them.

Build the FlexAttention mask once per stage instead of once per block. The mask depends only on the
grid and the kernel, both fixed within a stage, so 24 builds collapse to 5; measured at 768x512x121
that is 582ms to 132ms. build_block_mask returns None for NATTEN, which encodes the window in its
kernel. That is not merely an optimisation: create_block_mask materialises O(N^2) uncompiled, so a
69x64x96 stage would ask for 167 GiB and stage 5 for 8.2 TiB, and the mask must never be built for a
path that would not read it.

Make the AdaLN chunk count a constructor argument, num_chunks on the shared AdaLN and num_mod_params
on the diffusion block, with the decoder passing shared_adaln.num_chunks through so the two cannot
drift. num_mod_params is already the name LTX2AdaLayerNormSingle uses. The block's forward still
destructures exactly seven chunks and reads four of them, which is the reference's shape.

Decoding the test fixture is bitwise identical to before (max abs diff 0.000e+00). 39 passed, 4
skipped.

* Export the LTX-2.5 modular classes from the top-level namespace

`ModularPipeline.from_pretrained` resolves a repo's `_class_name` with
`getattr(importlib.import_module("diffusers"), class_name)`, so a class that is only reachable from
`diffusers.modular_pipelines.ltx2` cannot be selected by a checkpoint. `LTX25ModularPipeline` and
`LTX25AutoBlocks` were exported there but not from `diffusers` itself, which left the whole
checkpoint-to-blockset mapping dead: loading a repo whose index names them raised
`AttributeError: module diffusers has no attribute LTX25ModularPipeline`.

Exported alongside `LTX2ModularPipeline` / `LTX2AutoBlocks`, which is how the loader already finds
those. Verified against a real repo: `ModularPipeline.from_pretrained(...)` now resolves
LTX25ModularPipeline -> LTX25AutoBlocks -> LTX2DiffusionVaeDecoderStep, with the decoder supplied by
the repo index and nothing passed by hand.

Found by loading an actual checkpoint rather than constructing the blocks directly; calling
`LTX25AutoBlocks().init_pipeline(repo)` goes blocks-to-pipeline and never exercises the lookup.

* Name the diffusion decoder LTX-2.5 and save it to diffusion_decoder/

Two naming fixes, one of them load-bearing.

The converter wrote the decoder to a `vae_diffusion/` subfolder, a leftover from when the class was an
autoencoder. The folder name matters now: `DiffusionPipeline.from_pretrained` resolves each component
from the subfolder named after it, so `LTX2VideoDiffusionDecodePipeline` (component name
`diffusion_decoder`, same as the modular `ComponentSpec`) can never load itself out of a repo whose
folder is called `vae_diffusion`. The converter now saves to `diffusion_decoder/`, matching the layout
the LTX-2.5 weight repos already use, and the docs example loads from that name.

The docstrings also called it the LTX-2.4 decoder. The diffusion decoder ships with LTX-2.5; the
converter handles those checkpoints under the `--version 2.4` architecture family, which the version
guard's message now spells out instead of misattributing the feature.

Verified by re-running the converter on the rc4 distilled checkpoint after the change: the output lands
in `diffusion_decoder/` and is bit-identical (sha256) to the pre-change conversion, so this renames and
redocuments without touching what is produced. The converter regression test passes.

* Move the LTX-2 text-input expansion into the core denoise step

`LTX2TextInputStep` expanded the prompt embeddings to the effective batch
size inside `LTX2TextConditioningStep`, so running the text-conditioning
stage on its own baked `num_videos_per_prompt` into its outputs. Feeding
them to `LTX2CoreDenoiseStep` with a different `num_videos_per_prompt`
meant re-running the text stage or reshaping its outputs by hand.

`LTX2TextInputStep` now expands the connector conditioning (the tensors
the denoiser actually reads through `guider_input_fields`) instead of the
raw Gemma embeds, and runs as the first block of both core denoise steps.
The raw `prompt_embeds` expansion is dropped -- it only existed to feed
the connector at the expanded batch. `batch_size` / `dtype` move up to
`LTX2TextEncoderStep`, since `LTX2DurationStep` needs `batch_size` before
the denoise stage.

Two behavior notes:
- The connectors now run at one row per prompt rather than
  `num_videos_per_prompt` rows. They are applied per batch element, so
  this is mathematically identical (verified to ~3.6e-7, float32
  rounding) and N times cheaper, but not bitwise identical to
  `LTX2Pipeline` when `num_videos_per_prompt > 1`.
- Expansion uses `repeat_interleave` for the masks as well as the embeds.
  The previous code (inherited from the standard pipeline) interleaved
  the embeds but tiled the masks, which misaligned them whenever both
  `batch_size > 1` and `num_videos_per_prompt > 1`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Describe the connector inputs on LTX2TextInputStep

`LTX2TextInputStep` declares the connector conditioning tensors and now
runs first in the denoise sequence, so its declarations -- not
`LTX2LoopDenoiser`'s -- are the ones the docstring generator picks up.
They carried no `description`, which left `TODO: Add description.`
placeholders on the three core denoise blocks.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Build the condition and in-context workflows from LTX2AutoBlocks

`LTX2AutoBlocks` covered text-to-video and image-to-video only; the
condition and in-context (IC-LoRA) workflows were reachable solely
through their own blocksets. Fold them into the auto blockset so all
four are selected from the inputs, the way t2v and i2v already were.

- Merge `LTX2ConditionAutoPromptEnhancerStep` into
  `LTX2AutoPromptEnhancerStep`, which now picks the condition, image or
  text enhancer off `conditions` / `image`.
- Add `LTX2AutoConditionEncoderStep`, triggered by `conditions` or
  `reference_conditions` so a reference-only in-context run still gets
  the empty per-condition lists `LTX2InContextPrepareLatentsStep`
  requires.
- Extend `LTX2AutoCoreDenoiseStep` to four branches and add
  `LTX2AutoDecoderStep`, which trims the appended keyframe/reference
  tokens whenever `base_token_count` is present.

Two fixes this exposed:

- `noise_scale` means an interpolation factor (t2v/i2v, 0.0) in one
  workflow and an initial noise level (condition/in-context, `None` ->
  `sigmas[0]` or 1.0) in another. A blockset keeps the first non-`None`
  default across its blocks, so sharing one blockset published 0.0 and
  silently zeroed the noise for condition workflows that omitted the
  argument. `LTX2PrepareLatentsStep` and `LTX2PrepareAudioLatentsStep`
  now declare `None` and resolve to 0.0 in the block, mirroring what the
  condition steps already do.
- `LTX2AutoBuildVideoSelfAttentionMaskStep.select_block` compared
  `conditioning_attention_strength` against 1.0, but
  `get_execution_blocks` passes unset trigger inputs as an explicit
  `None`, so resolving any in-context workflow raised `TypeError`.

The parity harnesses passed `noise_scale=None` explicitly, which took
the argument-present path and hid the shadowing bug; `--omit_noise_scale`
drops the key entirely so the default is exercised.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Run the text-input step in the condition and in-context denoise steps

`LTX2TextInputStep` is the only block that expands the connector text
conditioning by `num_videos_per_prompt`, and it was missing from
`LTX2ConditionCoreDenoiseStep` and `LTX2InContextCoreDenoiseStep`. The
prepare-latents/audio/coords steps all build their tensors at
`batch_size * num_videos_per_prompt`, so the video latents arrived at the
transformer at batch B*N while `encoder_hidden_states` was still at B —
a shape error in cross-attention for any `num_videos_per_prompt > 1`.

The step goes at the head of both sequences, before prepare-latents, so
the prepare-latents-before-set-timesteps ordering these workflows need
(`mu` is read off the full packed sequence length) is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Broadcast keyframe and reference conditioning across the generation batch

Frame conditions are VAE-encoded at batch 1, but `latents`,
`conditioning_mask` and `clean_latents` are built at
`batch_size * num_videos_per_prompt`. Appending a keyframe condition
(latent index > 0) therefore failed in `prepare_latents` with
"Sizes of tensors must match except in dimension 1" whenever the batch
was greater than 1. First-frame conditions were unaffected because they
are applied by indexed assignment, which broadcasts.

Expand the keyframe tokens, mask and coords to `batch_size` before the
concatenation, and do the same for the IC-LoRA reference coords, which
feed the same `appended_coords` block that is later concatenated onto
batch-`batch_size` `video_coords`. This is what the modular LTX-2 blocks
already do, and matches the `[B, 3, ...]` shape both docstrings promise.

Also picks up a pending `make style` docstring rewrap in the same file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* feat: use natten for processing. (#15)

* feat: use natten for processing.

* address dhruv's comments.

* remove unneeded test

* remove integration file

* make vae properties accessible without loading it. (#17)

* Address review: replace LTX2 mixins with Copied-from pipeline methods.

Inline check_inputs/enhance_prompt on LTX2Pipeline and sync I2V/Condition/InContext via # Copied from, and update docs for shared 2.5 defaults.

(cherry picked from commit c183923cdd9c951f9694f9f6cd903714330cff03)

* Point the modular enhance-prompt comment at LTX2Pipeline

`LTX2PromptEnhancementMixin` was inlined into the pipelines in c183923cd,
so the mirrored-from reference no longer names an existing class.

* Remove the integrations/ dev scripts

The LTX-2 parity harnesses and the tiny-checkpoint builder were local
development scaffolding and are not part of the shipped library.

* moular tests (#19)

* Keep LTX-2.5.1 keyframes_abs_pos_embedding through convert. (#20)

Distilled 2.5.1 monoliths ship this (1, inner_dim) buffer with
use_keyframes_abs_pos_embedding=True; store it on the transformer for
load/save without wiring it into the regular distilled forward yet.

* remove test_ltx2_keyframes_abs_pos_embedding_load_and_forward

* Update the LTX-2.5 docs: two stage generation, distilled default, repo id (#21)

* feat: implement tiling for the diffusion decoder. (#22)

* add a note on tiling (#23)

* fix documentation.

---------

Co-authored-by: aartyomov <aartyomov@lightricks.com>
Co-authored-by: Daniel Gu <daniel.gu@huggingface.co>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: linoytsaban <linoy.tsaban@gmail.com>
Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
Co-authored-by: DN6 <dhruv.nair@gmail.com>
Co-authored-by: Linoy Tsaban <57615435+linoytsaban@users.noreply.github.com>
2026-08-11 07:10:00 -10:00
Sayak Paul
53e5b00d99 [tests] implement todos in the modular tests for H3 followup (#14404)
* remove doc placeholder.

* fix remaining tests

* empty

* empty
2026-08-07 13:47:04 +08:00
apolinário
9c6a68c32b Point the MiniMax-H3 docs install note at main (#14401) 2026-08-06 05:49:48 -10:00
apolinário
f53d552036 Add MiniMax-H3 (#14355)
* Add MiniMax-H3

* Keep the MiniMax-H3 VAEs in float32 under torch_dtype casts

* Make MiniMax-H3 modular only

* Assert the VAE float32 pin as a positive contract

* Point the modular tests at the hf-internal-testing tiny repo

* Document performance recipes per hardware class

* Slim hardware loading snippets and PR install note

* Use pinnable int8 config and freeze quantized components

* Scope load time quantization and disable low cpu mem usage under streamed offload

* Minimax h3 follow up (review & refactor) (#14371)

review & refactor

* Regenerate the modular auto docstrings and restyle the H3 docstrings

`make modular-autodoctrings` and `make quality` both failed on CI. The nine
`# auto_docstring` blocks in `modular_blocks_minimax_h3.py` were stale, and the
docstrings of eleven files had not been through `doc-builder style`.

Nothing but docstrings and comments changes here.

One trap worth recording: `utils/modular_auto_docstring.py` shells out to
`ruff` and degrades silently when it is not on `PATH` ("Warning: tool not
found ... Skipping formatting"), which makes it rewrite 42 unrelated pipelines
instead of the one that is stale.

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

* Fix the H3 fast tests against the refactored state contract

`condition_latents` is the VAE encoder block's own output — a list of one latent
per condition — and the after-denoise step unpacks `latents` and drops the
conditioning rows, so neither is meaningful once a request has come back. The
end-to-end tests no longer reach for them; a new standalone test runs
`MiniMaxH3KeyframeVaeEncoderStep` on its own, which is where the list is real.

Three other tests were failing for reasons of their own:

- `test_check_inputs_references` was missing its `@parametrize` and errored at
  collection. Added four cases that hit real validation.
- The duration ceiling had drifted between the two blocks that check it.
  `before_denoise` warned and reassigned before validating, so it reported `got
  362` — a count the caller never passed, right after warning it had rounded
  their 346. It now validates first, like `before_encoder` already did, and both
  messages read `got 346 (rounded up to 362)`.
- `height` without `width` raised `TypeError: unsupported operand type(s) for %:
  'NoneType' and 'int'` on `t2va`, and died inside the resize on `fl2va`. Both
  blocks now raise the same error `MiniMaxH3Ref2VASetupStep` already raised.

58 passed -> 71 passed, 5 failed, no errors. What is left: `output_type="latent"`
has no opt-out in the video decode block, `reference_image_short_edge` is a
constructor argument so it does not survive save/reload, an image reference is
PIL-only where the test expects three layouts, and `test_float16_inference`,
which fails on the base branch too.

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

* Stop claiming `num_inference_steps` is optional in the H3 tests

The block declares it `InputParam.template("num_inference_steps", required=True)`
and `expected_workflow_defaults` lists it under `required_inputs` for all three
workflows, so `optional_params` said the opposite in the same file. It was
inherited from the mixin's default set and never examined.

Nothing enforces the requirement today: `_check_inputs` substitutes the declared
default before it tests `required`, and the template carries `default=50`, so
omitting the input runs 50 steps rather than raising. That is not specific to
H3 — 14 call sites on main are in the same position — and it is tracked in #14388.

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

* Fix the two-card recipe, and stop accepting `output_type="latent"`

The two-card section did not run, on this branch or on the base one. A pipeline
resolves a single execution device for all of its components, so the documented
shape — one pipeline whose conditioner is `device_map`ped to the second card and
whose denoiser is moved to the first — built the rotary positions on `cuda:1` and
handed them to a transformer on `cuda:0`:

    transformer_minimax_h3.py, in Rope.forward
    RuntimeError: Expected all tensors to be on the same device, but found at
    least two devices, cuda:1 and cuda:0!

Reproduced against `abc5e9bf7` too, so it is not something the refactor broke;
the section went in as a plausible recipe that was never executed.

The split is therefore between pipelines rather than inside one: pop the text
encoder block into a conditioner of its own, give each pipeline a
`ComponentsManager` pinned to a card, and pass the state from one call to the
other. The managers' hooks are what align `prompt_embeds` onto the denoiser's
card; placing the components by hand instead works too, but then that one tensor
has to be moved explicitly. Verified end to end against the tiny fixture.

`output_type="latent"` is separate. It is not an output format — a request that
wants latents runs a pipeline without the decode blocks — and it used to run the
whole VAE decode before dying inside `postprocess_video` with "latent does not
exist", which does not say what to do instead. The video decode block now rejects
anything it cannot postprocess, before decoding. `test_output_type` covers the
three formats it does accept, and the rejection is a `test_check_inputs` case.

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

* Skip the workflow tests whose tiny repositories cannot serve them

`test_from_pretrained_workflow`, `test_load_components_workflow` and
`test_unload_components` build a pipeline from `pretrained_model_name_or_path`
and compare it against the test class's own blocks. Three fixtures cannot answer
that, in three different ways, and none of them is about the pipelines' code:

- `tiny-anima-modular-pipe` has no `modular_model_index.json`. Anima assembles
  its dummy components in `get_pipeline` and never loads from a repository, so
  the path it declares had never been exercised.
- `tiny-flux2-klein-modular` names `Flux2KleinBaseAutoBlocks` while its
  `_class_name` and `is_distilled` both say distilled. `from_pretrained` honours
  `_blocks_class_name`, so it builds base blocks, which declare a `guider` the
  distilled ones do not.
- `tiny-qwenimage-edit-modular` names `QwenImageModularPipeline`, so
  `from_pretrained` falls back to `QwenImageAutoBlocks`, which declares no
  `image_conditioned` workflow.

Skipped with a TODO each, since the fixes are Hub-side. The klein and qwenimage
ones are a single key in `modular_model_index.json`; Anima needs a repository
published.

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

* Declare `reference_image_short_edge` as pipeline config

`MiniMaxH3Ref2VASetupStep` resolves three pieces of released-checkpoint geometry
— the canvas short edge, the canvas area cap, and the separate short edge an
image reference is encoded at — and declared only the first two as `ConfigSpec`s.
The third was a constructor argument, so it did not survive a save and reload:
the reloaded pipeline rebuilt the block from the repository, took the 2048
default instead of the 64 the tests configure, resized reference images at a
different resolution, and landed 0.398 away from the original output.

All three now sit together, which is also what lets the test fixture stop
reaching into the block tree to swap in a configured copy — the shrunken
geometry is one `update_components` call next to the canvas rule it belongs
with, and `test_reference_image_geometry` exercises the released default rather
than constructing the block with an explicit 2048.

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

* Accept a reference image in the three layouts a video reference takes

`MiniMaxH3VideoReference.frames` takes a list of images, a channels-last array
or a channels-first tensor; `MiniMaxH3ImageReference.image` took a PIL image
only, and the two array layouts failed on `entry.image.size` — an element count
on numpy, a bound method on torch — with `TypeError: 'int' object is not
subscriptable`.

Passing an array through as-is would have been worse than the crash. The resize
would silently drop to `F.interpolate`'s nearest-neighbour where a PIL image
gets LANCZOS, and the VAE encode does `np.array(image).permute(2, 0, 1)`, which
fixes the axes of an image and scrambles those of a channels-first tensor. So
the layouts are normalized onto a PIL image before any of that, through the
processor component the block already declares: `pt_to_numpy` for the channel
axis and `numpy_to_pil` for the array. Neither converts dtype, and
`numpy_to_pil` scales by 255, so `uint8` is normalized on the original object
first — after `pt_to_numpy` a `uint8` tensor is floats over `[0, 255]` and a
later dtype check would miss it.

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

* Read the model's constants off the pipeline rather than the module

`before_denoise.py` imported `MINIMAX_H3_AUDIO_CHANNELS`, `MINIMAX_H3_AUDIO_TAG`
and `MINIMAX_H3_VIDEO_TAG` and read them inside its layout builders, even though
two of the three were already exposed as pipeline properties and used that way
everywhere else. They are arguments now, passed from `components.*` at the two
`__call__` sites; `audio_tag` needed the property `text_tag` and `video_tag`
already had, which is presumably why it was the one still reaching for the
global.

Same treatment where a helper cannot see a pipeline: `resolve_canvas_size` and
`audio_latent_num_frames` take the constants as default arguments instead of
closing over them, and `_normalize_video_condition` takes the rate it resamples
onto, so `before_encoder.py` imports none of them at all. What is left of the
constants is their definitions, the properties that expose them, and default
argument values.

Two helpers with a single caller each are inlined at it: the two rotary-time
sums, which are a parity contract — the reference sums the same series pairwise
in one place and sequentially in the other, and the orders differ in the last
ulp from 16 latent frames onwards. Both inlined sums are bit-identical to the
functions they replace across 1..399 latent frames, and the two still disagree
on 373 of those counts. `_frame_position_grid` stays, and `build_packed_sequence`
now calls it rather than repeating its five lines.

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

* Reject a reference video too short for the conditioner to read

The conditioner reads a reference video at 2 fps and Qwen3-VL merges the sampled
frames in groups of two, so anything under 13 frames at 24 fps samples down to a
single frame and dies inside transformers:

    image_processing_glm4v.py
    ValueError: t:1 must be larger than temporal_factor:2

which names neither the reference nor the rate that produced it, and only fires
on the versions carrying that check — it passed locally and failed on CI.
`_sample_video_condition_frames` now rejects it where the sampling happens, with
the bound derived from the rates rather than hardcoded: "must run at least 13
frames at 24 fps (0.54 seconds), got 4".

`test_reference_media_layouts` was building exactly such a reference, four
frames, which is what surfaced this. It uses a second of video now, like
`test_reference_combinations` already did.

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

* Drop the padded-layout attention mask

`forward` built a boolean attention mask whenever a row carried a negative
modality tag, reproducing the reference implementation's `cu_seqlens = [0, used,
S]` split of the padding tail it adds for FlashAttention. Nothing in this port
ever produces such a row: both packers partition `[0, sequence_length)` and write
only the text, audio and video tags, so the branch was unreachable and the mask
was never built. The `clamp(min=0)` that kept a `-1` from indexing the AdaLN
table backwards goes with it.

Removing it is not only dead-code removal. `if bool(is_pad.any())` is a
data-dependent branch, which has no fullgraph representation, and it was the
reason whole-model `fullgraph=True` compilation and `torch.export` were skipped:

    4 passed, 1 skipped     tests -k "compile or export or aot"

Both now run. The model tests go from 40 passed / 4 skipped to 41 passed /
2 skipped, against the same 8 pre-existing memory-offload failures.

`attention_mask` stays on the processor, attention and block signatures — it is
the signature every other processor in diffusers has, and a custom one may want
it — but the model itself never passes anything but `None`, so attention runs
unmasked over the one document and every backend stays available.

Two of the four documentation examples have been re-run against this and come
back bit-identical, frames and audio: `t2va` at the full 768x1344 canvas and
`fl2va`. The two `ref2va` ones are still to run.

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

* Apply suggestions from code review

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

---------

Co-authored-by: YiYi Xu <yixu310@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-08-05 07:00:38 -10:00
YiYi Xu
6f2010e8bb Auto-reply to new model requests with remote code guidance (#14343)
* Auto-reply to new model requests with Modular Diffusers guidance

Points new model/pipeline/scheduler requests at building a Hub-hosted
modular pipeline instead of waiting on a core PR, and asks requesters to
tag @asomoza when they have something to share.

Gates on the `### Model/Pipeline/Scheduler description` heading the issue
form renders rather than on a label: the label the template declares does
not exist in this repo, so GitHub never applies it, and template labels
land after issue creation anyway.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Apply suggestion from @yiyixuxu

* Tighten the new model request reply

Lead with starting on the Hub and frame what follows as a support
decision (work with the authors, upstream a community version, or point
people at the Hub one) rather than a soft no to PRs. Trims the message
by collapsing the author section and the resource list.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Link the Modular Pipelines collection in the reply

Community-built model pipelines belong in the Modular Pipelines
collection rather than Custom Blocks, so point the "we'll add the ones we
like" line there and keep both collections in the resource list.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Recommend starting on the Hub for new models

Adds a callout to the contribution guide asking model authors to get in
touch on a feature request, and community contributors to coordinate
there and start with a Hub repo at the same time.

Points agents the same way: default to publishing a modular pipeline as
remote code rather than opening a PR against src/diffusers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Apply suggestion from @yiyixuxu

* Apply suggestion from @yiyixuxu

* Update .github/workflows/new_model_request_reply.yml

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

* Consolidate the Hub-first guidance into one place

stevhliu noted the new callout in "Adding pipelines, models, schedulers"
overlapped the last two paragraphs of the AI-assisted contributions
section. Drop the community-contributor paragraph there — it is general
contribution policy rather than agent-specific guidance — and point the
model-author paragraph at the callout instead. Carry the custom models
link over so the non-modular Hub path stays covered.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-08-03 06:40:38 -10:00
Sayak Paul
3533886987 [kernels] download kernels when users request for it. (#14298)
* download kernels when users request for it.

* address review feedback
2026-08-03 23:28:24 +08:00
Álvaro Somoza
8b33b47332 [quantization] SDNQ core loading (#14277)
* initial

* fix code quality

* dependency test fix

* apply review suggestions

* add extras and version check

* fix gating and prefer local cache for modular

* simplify transformers registration and make the version warning silenceable

* remove pipeline level test

* only model level testing

* layers to quantizze, change em dashes

* env flag for transformers

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-07-30 13:09:11 +05:30
Steven Liu
9e969b6cf0 [docs] update agentic contribution guidelines (#14312)
* docs

* feedback
2026-07-29 13:43:07 -07:00
Steven Liu
05dde2f200 [docs] remove image generation benchmarks (#14310)
* remove

* remove
2026-07-29 08:00:24 -07:00
Steven Liu
351de3a6fe [docs] deprecate torch_dtype for dtype (#14313)
* docs

* update

* Revert "docs"

This reverts commit 04ca80543f.

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-07-29 08:20:06 +05:30
Sayak Paul
1c6aaa7678 [docs] minor corrections in the overview of quantization table (#14301)
minor corrections in the overview of quantization table
2026-07-29 08:06:41 +05:30
Sayak Paul
d4ec49f7cf [docs] add a warning note about device_map='cuda' usage. (#14261)
* add a warning note about device_map='cuda' usage.

* Apply suggestions from code review

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

---------

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-07-29 08:06:30 +05:30
Atharva Joshi
6ad357395d Cosmos3 Model Parallelism (#14054)
* feat(cosmos3): multi-GPU inference — context + tensor parallelism

Cosmos 3 cannot use diffusers' declarative `_cp_plan` CP path: it is grouped-query
attention (the shared Ulysses kernel assumes K/V share the query head count), its
understanding (causal) and generation (full) streams are separate packed sequences
(gen attends to cat(und, gen)), and per-pathway lengths are ragged. The model carries
no parallelism logic -- it exposes only small, CP-agnostic seams; all sharding lives
outside it, in a reusable example module.

Model (transformer_cosmos3.py): adds two default-None `forward` seams -- `_cp_shard_fn`
(shards und/gen + rotary before the decoder layers) and `_cp_gather_fn` (gathers/unpads
after the final norm) -- and extracts `Cosmos3AttnProcessor._run_attention` as an
override point. The non-parallel path is unchanged.

Helpers (examples/cosmos3/cosmos_parallel.py): one importable module, two orthogonal
and composable axes:
  * Context parallelism (Ulysses) -- `enable_cosmos3_context_parallel`. Shards the
    sequence; brackets the two attention pathways with all-to-all (DTensor redistribute),
    repeats GQA KV heads, pads ragged lengths and masks padded generation keys.
  * Tensor parallelism (Megatron) -- `enable_cosmos3_tensor_parallel`. Column/row-shards
    the attention + MLP weights so a checkpoint that does not fit one GPU (Super, ~120 GB)
    loads across several; weights load to CPU then shard layer by layer.
Both expand KV heads to the query-head count and call SDPA with enable_gqa=False so it
dispatches to the flash kernel; enable_gqa=True forces the math path, which materializes
the full [S, S] score matrix and OOMs on long videos. A dense `Cosmos3FlashAttnProcessor`
(`enable_cosmos3_flash_attention`) provides the same for TP without CP.

CLI (examples/cosmos3/inference_cosmos3.py): imports these helpers, so any modality
(text-to-image/video, image-to-video, sound, action) runs single- or multi-GPU via
`--tp-degree` / `--cp-degree` (their product must equal --nproc_per_node). Single-GPU
behavior is unchanged.

Docs + example README updated. Verified: CP attention core is bit-exact vs non-CP in
fp32 (max|d|=0), and a full 36-layer forward matches CP-on vs CP-off to ~1e-6 in fp32
(bf16 differs only by floating-point rounding).

* refactor(cosmos3): make CP/TP attention processors standalone

Address review feedback on PR #14054: the parallel attention processors no
longer subclass Cosmos3AttnProcessor, so the model file needs no override seam.

- transformer_cosmos3.py: revert Cosmos3AttnProcessor to inline the attention
  in __call__ (remove the _run_attention seam); restores it to its base version.
- cosmos_parallel.py: Cosmos3CPAttnProcessor and Cosmos3FlashAttnProcessor each
  get their own full __call__, sharing a _project_qkv_with_rope prologue helper.

Verified behavior-preserving on 4x RTX PRO 6000: cp_unit_test (fp32) passes at
1e-4; cp_numeric_check is byte-identical to the pre-refactor code; the end-to-end
CLI passes in CP-only, TP-only, and TP+CP modes.

* fix(cosmos3): support modular multi-GPU inference
2026-07-23 22:56:44 -10:00
Cedric Perauer
623213d29f Krea2 Modular Pipeline Support, Documentation, Test Cases (#14083)
* towards krea2 modular

* add test cases

* self-review fixes: test model id to hf internal, guider change

* remove pnd

* modular autodoc

* modular autodoc

* Update src/diffusers/modular_pipelines/krea2/modular_blocks_krea2.py

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* Update src/diffusers/modular_pipelines/krea2/before_denoise.py

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* Update docs/source/en/api/pipelines/krea2.md

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* input params, dim multiple of scale factor * patch

* docs for krea2 turbo modular

* docs fix

* Update tests/modular_pipelines/krea2/test_modular_pipeline_krea2.py

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* Update src/diffusers/modular_pipelines/krea2/before_denoise.py

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* modular blocks krea2 turbo fix

* Update docs/source/en/api/pipelines/krea2.md

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

* Update src/diffusers/modular_pipelines/krea2/before_denoise.py

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

* fix default height/width and inference time steps

* Apply suggestions from code review

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

* Regenerate stale krea2 auto docstrings

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

---------

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
Co-authored-by: YiYi Xu <yixu310@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 07:27:48 -10:00
Dhruv Nair
6afdfd9f4e Update diffusers-cli for agentic use (#13966)
* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* pdate

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-07-22 17:02:44 +05:30
Dhruv Nair
80bfe77b57 Remove JAX/Flax (#14169)
* Remove JAX/Flax support

Deletes all Flax models, schedulers, pipelines, and loading utilities,
the from_flax loading path, flax/jax packaging extras, Flax CI filters,
Flax training examples, and Flax content in translated docs.

Hub compatibility is preserved: Flax class names in old model_index.json
files are still stripped to their PyTorch equivalents, and *.msgpack
files in repos are still ignored during download.

* Drop Flax class-name remapping from model_index.json loading

Flax-saved checkpoint metadata is no longer recognized: class names like
FlaxStableDiffusionPipeline in model_index.json now fail to resolve
instead of being remapped to their PyTorch equivalents. *.msgpack files
in hub repos are still ignored during download.

* Restore Flax training examples

The example scripts are standalone and still work with diffusers<=0.39.x.
A warning note is added to each Flax README section pointing out the
version requirement now that the library itself no longer ships Flax.

* update

* Repoint scheduler default-config tests off the Flax fixture

* Repoint example training tests off the Flax fixture
2026-07-21 13:12:27 +05:30
Chenyang Zhu
9f6fc2c136 Add ace step lora support (#14193)
* feat: add LoRA support to AceStepPipeline

Add standard diffusers LoRA API (load_lora_weights, set_adapters,
fuse_lora, save_lora_weights) for AceStepPipeline, targeting the
transformer (AceStepTransformer1DModel) only.

Includes automatic conversion of ACE-Step-1.5 original PEFT format
LoRA weights (q_proj/k_proj/v_proj/o_proj naming) to diffusers format
(to_q/to_k/to_v/to_out.0 naming) during loading.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use HuggingFace Hub ID for tokenizer in AceStep LoRA test and apply ruff formatting

- Replace hardcoded local path with "Qwen/Qwen3-Embedding-0.6B" so tests
  run on CI
- Apply ruff formatting fix (slice spacing)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: override test_lora_fuse_nan instead of skipping it

The base test hardcodes block attribute names (transformer_blocks,
blocks, etc.) but AceStep uses 'layers'. Override with AceStep-specific
block access path instead of skipping.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add joint_attention_kwargs to AceStepPipeline for per-step LoRA scale

- Add @apply_lora_scale("joint_attention_kwargs") decorator and
  joint_attention_kwargs param to AceStepTransformer1DModel.forward
- Add joint_attention_kwargs param to AceStepPipeline.__call__ and wire
  it through to all three transformer calls
- Un-skip 4 LoRA scale tests that now pass (39 passed, 13 skipped)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: override test_lora_fuse_nan instead of skipping it

The base test hardcodes block attribute names (transformer_blocks,
blocks, etc.) but AceStep uses 'layers'. Override with AceStep-specific
block access path instead of skipping.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add joint_attention_kwargs to AceStepPipeline for per-step LoRA scale

- Add @apply_lora_scale("joint_attention_kwargs") decorator and
  joint_attention_kwargs param to AceStepTransformer1DModel.forward
- Add joint_attention_kwargs param to AceStepPipeline.__call__ and wire
  it through to all three transformer calls
- Un-skip 4 LoRA scale tests that now pass (39 passed, 13 skipped)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: use attention_kwargs instead of joint_attention_kwargs, use torch_device in test

- Rename joint_attention_kwargs to attention_kwargs in transformer
  forward and pipeline __call__ for consistency with the diffusers
  naming convention for new pipelines
- Add docstring for the attention_kwargs parameter
- Use torch_device instead of hardcoded "cpu" in test_lora_fuse_nan

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Apply style fixes

* docs: document ACE-Step attention kwargs

* docs: document ACE-Step LoRA loader mixin

---------

Co-authored-by: zcy <zhuchenyang.zcy@alibaba-inc.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-07-18 15:03:55 +05:30
yzhautouskay
8eac6ad1c4 Cosmos3 Distilled support (#14177)
* Cosmos3 distilled support (dedicated modular pipeline + blocks)

* Address review comments

* Refactor unit test to use ModularPipelineTesterMixin

* Docs fix

* Tests refactor

* Pass generator to SDE scheduler  for reproducibility

* Apply suggestion from @yiyixuxu

* Distilled text encoder step bugfix

---------

Co-authored-by: YiYi Xu <yixu310@gmail.com>
2026-07-17 08:35:41 -10:00
Sayak Paul
bc7aebc20a [core] deprecate dduf (#14141)
* deprecate dduf (re-apply after accidental revert on main).

* up
2026-07-16 13:24:12 +05:30
YiYi Xu
662a6a354f ask to share self-review notes (#14185)
* Require sharing self-review notes on PRs

The PR template's self-review checkbox is unverifiable on its own — make the
notes a required, shareable artifact:

- self-review skill: new step to save each round's report and post all rounds
  on the PR (description or comment)
- contribution guide: sharing the notes is part of the AI-assisted
  contribution workflow; a checked box without notes counts as not done
- PR template: checkbox for having shared the notes
- .ai/AGENTS.md: mention the notes-sharing step in the self-review section

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

* Share only the final self-review round, not all rounds

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

* Mention self-review notes in the PR template intro comment

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

* Soften notes-sharing ask; skill iterates until ready then reminds to share

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

* Apply suggestion from @yiyixuxu

* Point checkbox and guide at the self-review skill directly

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

* Note human review comments as a source for agent doc gaps

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

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 18:10:30 -10:00
yzhautouskay
e29a9ce631 Transfer support for Cosmos3 ModularPipeline (#14150)
* Add transfer support to the Cosmos3 modular pipeline

* Convention matches fixes

* Align Cosmos3 transfer blocks with modular conventions

* Move Cosmos3TransferSetupStep to before_encoder.py

* Decouple Cosmos3 transfer blocks from task-pipeline internals

* Temporarily disable standalone transfer workflow

* Auto docstring run fix

* Apply style fixes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-07-14 07:07:43 -10:00
Vinh H. Pham
60ec6f7242 Add Nunchaku Lite single-file quantization (#14100)
* Add Nunchaku Lite single-file quantization

* Support config-backed Nunchaku Lite loading

* Remove Nunchaku runtime manifest metadata loading

* Simplify Nunchaku compact config loading

* Add Nunchaku Lite quantization tests

* Document Nunchaku Lite checkpoint loading

* Refine Nunchaku Lite quantization docs

* Remove unused Nunchaku smooth factor original weights

* Update docs/source/en/quantization/nunchaku.md

Co-authored-by: sergereview[bot] <283583894+sergereview[bot]@users.noreply.github.com>

* Update src/diffusers/quantizers/nunchaku/utils.py

Co-authored-by: sergereview[bot] <283583894+sergereview[bot]@users.noreply.github.com>

* Update src/diffusers/quantizers/nunchaku/nunchaku_quantizer.py

Co-authored-by: sergereview[bot] <283583894+sergereview[bot]@users.noreply.github.com>

* Address Nunchaku Lite review feedback

* Update Nunchaku Lite quantizer

* Rename Nunchaku Lite fp4 precision to nvfp4

* Allow torch_dtype to override Nunchaku compute dtype

* Keep Nunchaku replacement modules on meta during loading

* Require kernels when importing Nunchaku runtime utils

* Use kernels requirement decorators for Nunchaku tests

* Validate Nunchaku CUDA capability requirements

* Apply suggestions from code review

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* docs: update nunchaku quantization guide

* test: remove nunchaku quantization tests

* fix: reject hopper for nunchaku lite

* Apply suggestion from @rootonchair

* docs: update nunchaku lite compile example

* Apply style fixes

* Apply suggestions from code review

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Vinh H. Pham  <phamvinh257@gmail.com>

* update doc to be more reasonable

* fix import that requires kernels

---------

Co-authored-by: sergereview[bot] <283583894+sergereview[bot]@users.noreply.github.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-07-14 10:09:08 +05:30
yzhautouskay
284419b352 Cosmos3 ModularPipeline (#14110)
* Cosmos3 ModularPipeline initial commit

* Fix from_pretrained for modular pipleine without modular_model_index.json

* Isolate text prep inside Cosmos3TextEncoderStep; add Cosmos3ActionTextStep

* Cosmos3 modular encode/decode flow

* Drop device/dtype required InputParams; use components._execution_device and model dtype

* Add lazy pipeline properties and requires_safety_checker-based safety gating

* Drop callback_on_step_end from Cosmos3 denoise loop

* Move container/auto blocks into modular_blocks

* Move action_gen check, remove unused params

* Declare video_processor as ComponentSpec; drop unused pipeline state

* Split VAE encode block by modality (image and video)

* Remove Cosmos3AssembleResultStep; add Cosmos3ExportStep

* Remove unused action_mode

* Refactor Cosmos3 modular denoising by modality

* Document Cosmos3 modular output selection

* Address Cosmos3 modular review feedback

* Remaining local-variable device cleanup

* Address Cosmos3 modular review feedback

* Address final Cosmos3 modular feedback

---------

Co-authored-by: Atharva Joshi <atjoshi@nvidia.com>
2026-07-09 08:26:24 -10:00
Sayak Paul
b8905b9b0f Revert "deprecate dduf."
This reverts commit b3545f9c57.
2026-07-08 07:21:41 +00:00
Sayak Paul
b3545f9c57 deprecate dduf. 2026-07-08 07:20:40 +00:00
Sayak Paul
c56add8081 post release v0.39.0 (#14116)
* post release v0.39.0

* style.

* remove deprecated code path.

* remove deprecated method.
2026-07-08 10:48:49 +05:30
tangyanf
408ce8db29 feat: add JoyImage edit plus (#14032)
* feat: add image edit plus

* refactor: remove debug code

* fix: address review issues for JoyImage Edit Plus

    - Remove einops dependency: replace rearrange with reshape/permute
    - Remove sglang-specific code from transformer forward
    - Remove unused import inspect from transformer
    - Fix hardcoded device_type="cuda" to use device.type
    - Simplify scheduler sigma math: delegate to retrieve_timesteps
    - Remove unused enable_denormalization parameter
    - Fix callback latents variable binding
    - Fix output_type="pt" to return stacked tensor
    - Set return_dict default to True in transformer forward
    - Add dummy objects for JoyImageEditPlus classes
    - Add transformer and pipeline test files

* fix: add missing newline at end of pipeline_output.py

* fix: add missing newline at end of pipeline_output.py

* doc: add joyimage-edit-plus doc

* refactor: update code format

* refactor: update code formate

* refactor: merge edit-plus conversion script into convert_joyimage_edit_to_diffusers.py

	JoyImage Edit and Edit Plus share identical VAE and transformer weight
      layouts — only the target model class differs. Consolidate both into a
      single script with a --model_type flag (edit | edit_plus) instead of
      maintaining two nearly-duplicate files.

* revert: remove unnecessary attention_mask change from transformer_joyimage.py

* Apply style fixes

* fix: remove stale Copied-from annotations that diverged from source

* fix: address CI check failures for edit-plus PR

  - Add missing Returns section to JoyImageEditPlusTransformer3DModel.forward docstring
  - Fix alphabetical ordering of dummy classes in dummy_pt_objects.py

* fix: use VAE dtype instead of float32 cast in edit-plus pipeline

   Replace `torch.autocast(dtype=torch.float32)` + `.float()` with
   `.to(self.vae.dtype)` for both VAE encode and decode calls.

   The previous approach caused dtype mismatch (float32 input vs bfloat16
   bias) on CPU where autocast does not automatically cast conv weights,
   breaking the CI `test_layerwise_casting_inference` test.

* refactor: address dg845 review comments on edit-plus

  Transformer:
  - Simplify RoPE by removing dead txt_freqs path
  - Fix patch_size type hint to list[int]
  - Use self.config.xxx instead of explicit attributes

  Pipeline:
  - Merge VaeImageProcessor into JoyImageEditImageProcessor
  - Inline normalize/denormalize latents at call sites
  - Use image_processor.preprocess() for reference images
  - Remove duplicate resize_center_crop in prepare_latents
  - Rename padded_latents to latents in __call__
  - Support pre-computed latents parameter
  - Remove redundant padding token zeroing (attention mask suffices)
  - Use image_processor.postprocess() for output conversion
  - Return (image,) tuple when return_dict=False

* fix: guard against division-by-zero in CFG norm rescaling

  Add .clamp_min(1e-6) to noise_norm to prevent NaN when comb_pred
  is all-zeros (e.g. padded patches), matching pipeline_joyimage_edit.py.

* style: run ruff format on edit-plus pipeline

* refactor: address dg845 second-round review comments

  - Fix vae_image_processor -> image_processor in docs
  - Remove empty __init__ from AttnProcessor
  - Restore # Copied from on retrieve_timesteps and sync with source
  - Add check_inputs method for basic input validation
  - Remove unnecessary test skip for test_from_save_pretrained_dtype_inference

* Apply style fixes

---------

Co-authored-by: tangyanfei.8 <tangyanfei.8@jd.com>
Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-07-07 17:45:06 -07:00
Sayak Paul
4f37263ab7 [chore] update to 2026 finally. (#14079)
update to 2026 finally.
2026-06-29 20:20:44 -04:00
Kashif Rasul
1f9c201083 Add doc pages for the DiffusionGemma schedulers (#14092)
* add doc pages for the discrete ddim and entropy bound schedulers

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

* fix the cited paper titles to match the linked papers

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

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 22:10:42 +02:00
Kashif Rasul
21ba39457d [discrete diffusion] Add DiffusionGemma pipeline and schedulers (#13986)
* Add discrete DDIM and entropy bound schedulers and a uniform mode for block refinement

* Add DiffusionGemma block-diffusion pipeline

* Add DiffusionGemma pipeline tests and docs

* Put DiffusionGemma docs under the Text pipelines section

* Add static cache and fullgraph-compiled decoder path to DiffusionGemma pipeline

* Compile decoder externally for the static cache path instead of a pipeline flag

* Prefill the encoder once into a reusable cache and sync default denoising steps

* Support image prompts by forwarding pixel_values to the encoder prefill

* Restyle docstrings to satisfy doc-builder

* Sort the new scheduler and pipeline exports

* Let any of the three schedulers drive the pipeline

* Document the schedulers and updated defaults in the pipeline docs

* Sort the scheduler dummy objects

* Set scheduler sampling knobs on the scheduler config, not the pipeline call

* Accept raw prompt/image/messages instead of pre-tokenized model inputs

* Add leave-one-out predictor-corrector to DiscreteDDIM scheduler

Adds optional Gibbs corrector sweeps after each predictor step for
uniform diffusion, recovering the LOO denoiser in closed form so it
works on the released checkpoint with no retraining.

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

* Forward PEFT adapter API on the DiffusionGemma pipeline

The denoiser is a Transformers model, so adapters (LoRA, DoRA, ...) load
through its native PEFT integration rather than the diffusers LoRA loader.
Also dispatch the predictor-corrector by scheduler capability instead of class.

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

* Fix callback kwargs gathering on Python < 3.12

Build callback_kwargs with a loop instead of a dict comprehension, whose
own scope hides locals() on pre-3.12 (PEP 709), causing KeyError: 'canvas'.

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

* Speed up diffusion gemma sampling to match transformers

Add adaptive stopping (stop a block once its prediction is stable and
confident) and make the decoder compile cudagraph-safe via
cudagraph_mark_step_begin + logits clone. ~175 -> ~372 tok/s. Also align
the decoder mask with the new transformers#46654 layout.

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

* Enable adaptive stopping by default

Default confidence_threshold to 0.005 to match the released checkpoint
and transformers, so the speedup is on out of the box.

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

* Fold corrector sweeps into the step budget

Run fewer predictor steps and spend the freed forwards on the corrector,
so predictor-corrector sampling costs the same total forwards as plain
ancestral (~2x faster), matching the paper.

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

* Commit the converged prediction on adaptive stop

Ancestral schedulers like DiscreteDDIM only clean the canvas on the final
step, so stopping early left noise tokens. Use the denoiser argmax instead,
which is the converged answer and matches the canvas for commit schedulers.

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

* anneal sampling temperature and fix static cache decoder mask

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

* Update src/diffusers/pipelines/diffusion_gemma/pipeline_diffusion_gemma.py

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* Update src/diffusers/schedulers/scheduling_entropy_bound.py

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* Update src/diffusers/pipelines/diffusion_gemma/pipeline_diffusion_gemma.py

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>

* address dg845 review comments

* fix entropy scheduler temperature scaling

* update decoder mask for new transformers

* self-condition on the temperature-shaped logits

* move temperature annealing into EntropyBoundScheduler

* self-condition on the entropy scheduler's shaped logits

* show torch.compile + static cache in the usage example

* removed wrong commit

* Update src/diffusers/pipelines/diffusion_gemma/pipeline_diffusion_gemma.py

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>

* address review comments

* expose pred_logits on all schedulers

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-06-25 08:22:16 +02:00
apolinário
3993de59e3 Krea 2 LoRA DreamBooth trainer (#14046)
* Add Krea 2 LoRA DreamBooth trainer + Krea2 LoRA loader

Adds examples/dreambooth/train_dreambooth_lora_krea2.py and the
Krea2LoraLoaderMixin (Krea2Pipeline now inherits it) so LoRA adapters
can be saved/loaded for the Krea 2 transformer. The transformer/pipeline
forward now accept attention_kwargs for runtime LoRA scaling.

Co-Authored-By: linoytsaban <linoy.tsaban@gmail.com>

* inline _pack/_unpack_latents in trainer (pipeline methods are instance methods)

* add Krea2LoraLoaderMixin to LoRA loaders docs

* remove mu from validation call to align with pipeline on main

---------

Co-authored-by: linoytsaban <linoy.tsaban@gmail.com>
Co-authored-by: Linoy Tsaban <57615435+linoytsaban@users.noreply.github.com>
2026-06-23 17:39:27 +05:30
YiYi Xu
7104cb43c3 Add Krea 2 (K2) text-to-image pipeline and transformer (#14045)
Adds Krea2Transformer2DModel and Krea2Pipeline: a flow-matching
text-to-image MMDiT with grouped-query attention, Qwen3-VL text
conditioning, and the Qwen-Image VAE.

Co-authored-by: Elea Zhong <elea@krea.ai>
Co-authored-by: Naga Sai Abhinay Devarinti <devarintinagasaiabhinay@gmail.com>
2026-06-22 16:59:24 -04:00
Linoy Tsaban
3467efa65a Add Ideogram4LoraLoaderMixin (LoRA loading for Ideogram4) (#13921)
* add Ideogram4LoraLoaderMixin

* Support loading non-diffusers Ideogram4 LoRA checkpoints (#13919)

support loading non-diffusers Ideogram4 LoRAs

* add Ideogram4 LoRA loader tests

* support call-time LoRA scaling via attention_kwargs in Ideogram4

* fix and un-skip Ideogram4 LoRA loader tests

* document attention_kwargs in Ideogram4 forward and pipeline

* style Ideogram4 attention_kwargs docstrings

* fix Ideogram4 LoRA loader CI test failures

- pipeline: run the text encoder on its parameters' current device, then
  move features to the execution device, so encode_prompt works under
  enable_model_cpu_offload. The pipeline calls the text encoder's submodules
  directly to tap intermediate layers, which bypasses accelerate's onload
  hook, so the weights stay on CPU while inputs are on the execution device.
  Fixes test_lora_loading_model_cpu_offload.
- tests: override test_lora_fuse_nan to corrupt a weight under Ideogram4's
  `layers` tower (the base test probes transformer_blocks/blocks/etc.).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* address review nits on Ideogram4 LoRA loader

- pipeline: clarify the te_device comment (per review) — explain the CpuOffload hook
  attaches to forward, why submodule calls bypass it, and that te_device is the offload
  device under enable_model_cpu_offload.
- tests: drop the unused `import sys` and `sys.path.append(".")`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
2026-06-17 17:39:52 +03:00
David Bertoin
a487e2f131 Add PRXPixelPipeline: pixel-space PRX text-to-image pipeline (#13928)
Adds a pixel-space variant of PRX that denoises raw RGB directly
(no VAE), conditioned on a Qwen3-VL text encoder:

- PRXTransformer2DModel: new optional config args `bottleneck_size`
  (two-layer img_in projection for large patch dims) and
  `resolution_embeds` (PRXResolutionEmbedder conditions the timestep
  modulation on the latent resolution)
- PRXPipeline: support for subclass-tuned tokenizer max length, light
  text cleaning, x-prediction flow matching (x0 -> velocity conversion),
  and non-unit initial noise scale
- PRXPixelPipeline: thin subclass wiring the above together
  (vae optional/None, vae_scale_factor=1, 1024px default)
- conversion script support for the pixel checkpoint format
- registration in __init__ files + dummy objects, docs autodoc entry,
  fast pipeline tests

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-16 21:14:54 -07:00
yzhautouskay
bcbfcd43da Add Cosmos3 video2video generation support (#13896)
* Init v2v cosmos3 commit

* Add user quide; prompt upsampling is TBD

* Apply style fixes

---------

Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-06-15 21:08:36 -07:00
YiYi Xu
12fc496d3c keep the agent symlinks (#13968)
* Commit root AGENTS.md/CLAUDE.md symlinks so agents auto-load conventions

Track the root AGENTS.md/CLAUDE.md symlinks (-> .ai/AGENTS.md) instead of
generating them via `make claude`/`make codex`, so a fresh clone auto-loads
the agent guide with no setup step (matching transformers). The make targets
now only wire up skills; .ai/AGENTS.md, the contribution doc, and the PR
template are updated to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add documentation-impact check to PR review rules

During review, scan related usage docs and agent docs and flag (advisory)
any that should be updated based on the PR — outdated/missing usage docs, or
a rule/pattern/gotcha worth recording in the agent guides.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 16:20:28 -10:00