Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[core] Refactor condition embedders (and others) modules from pipelines#13781

Open
sayakpaul wants to merge 27 commits into
mainfrom
refactor/condition-embedders-submodule
Open

[core] Refactor condition embedders (and others) modules from pipelines#13781
sayakpaul wants to merge 27 commits into
mainfrom
refactor/condition-embedders-submodule

Conversation

@sayakpaul

@sayakpaul sayakpaul commented May 21, 2026

Copy link
Copy Markdown
Member

What does this PR do?

We have a bunch of model-level components under src/diffusers/pipelines module. This PR factors them out of the pipelines module and places them under src/diffusers/models module strategically.

The main changes are in src/pipelines/pipeline_loading_utils.py which basically remaps to the components that were moved to src/diffusersmodels/. Open to other ways of handling it.

For reviewers

Main changes can be summarized as follows:

  • Move an existing model-level module (e.g., audio_tokenizer_ace_step.py) to src/diffusers/models and deprecate gracefully.
  • I have used my best judgment to determine which model gets to either of autoencoders and condition_embedders. When I wasn't sure, I simply placed them under others. No strong opinions here.
  • scripts/smoke_test_relocated_pretrained.py is for transient testing until the PR is merged. Will delete it after. I have run the tests and models and pipelines load as expected.
  • There is a tests/models/test_relocated_class_loading.py which will check if deprecation warnings are raised and will also help to remove those deprecation paths once the cycle is over.
  • Similarly, there is a tests/pipelines/test_relocated_class_loading.py. It ensures that no deprecation warnings for the refactored modules are raised when loading the affected pipelines.

@github-actions github-actions Bot added size/L PR with diff > 200 LOC models tests utils pipelines and removed size/L PR with diff > 200 LOC labels May 21, 2026
@github-actions github-actions Bot added the size/L PR with diff > 200 LOC label May 21, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

# See the License for the specific language governing permissions and
# limitations under the License.

import torch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to suggestions on where to place these other than others.

@@ -0,0 +1,476 @@
# Copyright 2025 The ACE-Step Team and The HuggingFace Team. All rights reserved.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going by the implementation of the module, it encodes into a tokenized representation (not the existing sense of tokenization done in language models). So, decided keep them under autoencoders.

@@ -0,0 +1,192 @@
# Copyright 2025 Lightricks and The HuggingFace Team. All rights reserved.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to moving them elsewhere. Since upsampling could be interpreted as decoding to a higher resolution, I thought of keeping them under autoencoders.

@sayakpaul sayakpaul marked this pull request as ready for review May 22, 2026 06:24
@sayakpaul sayakpaul requested a review from yiyixuxu May 22, 2026 07:55
@sayakpaul sayakpaul requested review from dg845 and yiyixuxu and removed request for yiyixuxu May 22, 2026 07:55

# Reroutes pretrained loads past pipeline-local deprecation shims onto the canonical
# top-level diffusers export.
_RELOCATED_PIPELINE_CLASSES: dict[tuple[str, str], tuple[str, str]] = {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that we don't hit deprecation warnings.

@sayakpaul

sayakpaul commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@dg845 @yiyixuxu a gentle ping (because of the conflicts).

@@ -0,0 +1,93 @@
import sys

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be deleted.

@sergereview sergereview Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤗 Serge says:

Overall

This is a well-structured refactoring that moves model-level components out of pipelines/ into models/. The deprecation shim pattern (subclass with __new__ warning) is clean and preserves backward compatibility. However, there are a few issues worth addressing.

Correctness

  • Incomplete _RELOCATED_PIPELINE_CLASSES mapping. The remap dict in pipeline_loading_utils.py only covers 6 of the relocated classes. The remaining ones (LTX2VocoderWithBWE, AceStepConditionEncoder, AceStepAudioTokenizer, AceStepAudioTokenDetokenizer, CLIPImageProjection, StableUnCLIPImageNormalizer, ReduxImageEncoder, ShapERenderer, and the LTX latent upsamplers) are missing. When a user loads a pipeline whose model_index.json references these classes via the old pipeline module name (e.g. ["ace_step", "AceStepConditionEncoder"]), the loader will resolve them through the deprecation shim and emit spurious deprecation warnings during normal pipeline usage. The remap dict should include all relocated classes so that from_pretrained on a pipeline bypasses the shim entirely. (This is visible in the full PR but the dict definition is not in this chunk — noting for completeness.)

  • Pre-existing bug in vocoder_ltx2.py line 263: act_fn = nn.LeakyReLU(...) should be act = nn.LeakyReLU(...). This reassigns the string parameter act_fn to an nn.Module and leaves act undefined in the else branch. This is a bug carried over from the original file, not introduced by this PR, but since the code is being relocated this is a good opportunity to fix it.

Style / Minor

  • vocoder_ltx2.py and text_connector_ltx2.py are missing license headers, while all other new files in this PR have them. Likely carried over from the originals.

Ephemeral content

  • scripts/smoke_test_relocated_pretrained.py — the PR description says this will be deleted after merge. That's fine, but make sure it doesn't land on main.

Dead code analysis (advisory)

The ResBlock class in vocoder_ltx2.py (line 214) shadows the ResBlock in latent_upsampler_ltx.py / latent_upsampler_ltx2.py within the same autoencoders package. They are different classes (1D conv vs 2D/3D conv). This is not a bug since they live in separate modules, but the name collision could confuse readers browsing the autoencoders package. The latent_upsampler_ltx2.py version is already annotated with # Copied from which helps.

Note: review finished early after hitting the input-token budget; 3 remaining diff chunk(s) were not reviewed.

model: claude-opus-4-6 · 25 LLM turns · 31 tool calls · 148.2s · 2093370 in / 6527 out tokens

Comment thread src/diffusers/models/autoencoders/vocoder_ltx2.py
Comment thread src/diffusers/models/autoencoders/vocoder_ltx2.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants