Skip to content

fix(lora): reject diffusers LoRAs of other DiTs by Anima's attention widths - #10223

Open
Pfannkuchensack wants to merge 3 commits into
invoke-ai:mainfrom
Pfannkuchensack:fix/anima-lora-width-check
Open

Pfannkuchensack wants to merge 3 commits into
invoke-ai:mainfrom
Pfannkuchensack:fix/anima-lora-width-check

Conversation

@Pfannkuchensack

@Pfannkuchensack Pfannkuchensack commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Diffusers-named LoRAs of other DiTs use the same module names as Anima's diffusers layout (transformer_blocks.N.attn1 / attn2), so the Anima probe accepted them by name alone. They installed as Anima and failed only at generation (Unsupported diffusers Anima LoRA layer, or skipped layers on shape mismatch).

The Anima probe now also checks the input width of those attention projections, read from low-rank, LoHA, full and LoKR (factor product) layers:

  • attn1.to_q/k/v/out.0, attn2.to_q, attn2.to_out.0: 2048
  • attn2.to_k/v (text context): 1024

These widths hold for every Anima variant (base, 2.9B, 3.8B v1.1; checked against the checkpoints). A mismatch raises NotAMatchError naming the layer and its width, so such files now end up as unknown instead of the wrong family. Kohya and native blocks.N. layouts are not affected. A layer that carries no width (a lone DoRA magnitude) does not count.

The width reader used by the Qwen-Image-2.1 detection now takes the projection pattern as a parameter, so both probes share it. Qwen-Image behavior is unchanged.

Issue repro, before → after:

case before after
LTX-2 video-only, transformer. anima unknown
LTX-2 video-only, base_model.model. anima unknown
LTX-2 video+audio, base_model.model. anima unknown
LTX-2 video+audio, transformer. ltx-2 ltx-2
Anima-shaped diffusers LoRA anima anima

Related Issues / Discussions

Closes #10081

Follow-up to #10076. LTX-2's own gaps for these prefixes (e.g. video+audio under base_model.model. still landing on unknown) are #10080.

QA Instructions

CPU only, no models needed.

  • uv run --no-sync pytest tests/backend/model_manager/configs/ tests/model_identification/test_identification.py (LFS fixtures checked out): 1751 passed, 1 skipped.
  • New cases in test_anima_diffusers_lora_config.py: realistic Anima fixture (with attn2.to_k = 1024) under four prefixes. Video-only LTX-2 and CogView4, Mochi, CogVideoX 2B/5B, PixArt-Σ, Sana 600M/1600M and LTX-Video, with widths from their diffusers configs, all come out unknown. SD 3.5 Medium stays SD 3. LoKR with matching and mismatching factor products. A width-less DoRA key. A Kohya regression case.
  • test_ltx2_lora_probe_independence.py: the Anima probe rejects a video-only LTX-2 LoRA under every prefix it accepts.
  • test_sd3_lora_probe_independence.py: the CogView4 test expected the diffusers spelling to be claimed by Anima, which it called a known misidentification. It now expects no probe to claim it.
  • ruff@0.11.2 check and format --check clean.

Review

Review asked for the docs to state the remaining ambiguity precisely and for the format support page to note the change; both are done. Remaining limit: an LTX-Video LoRA without cross-attention key/value layers (attn2.to_k, attn2.to_v) is still identified as Anima. Its other attention layers are 2048 wide like Anima's, so neither names nor widths separate them.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Meaningful regression coverage added / updated where needed; obsolete tests/code removed
  • Persisted-state and API changes include required migrations / compatibility validation
  • Relevant performance/efficiency opportunities considered; material claims have evidence
  • Material review findings resolved and relevant checks rerun
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…widths

Diffusers-named LoRAs of LTX-2, LTX-Video, CogView4, Mochi, CogVideoX,
PixArt and Sana share Anima's `transformer_blocks.N.attn1/attn2` names and
were identified as Anima by name alone, failing only at generation. The
Anima probe now checks the input width of those attention projections:
2048 for self-attention and the cross-attention query/output, 1024 for the
cross-attention key/value, the same in every Anima variant. Kohya and
native layouts are unaffected.

Closes invoke-ai#10081
@github-actions github-actions Bot added python PRs that change python files backend PRs that change backend files python-tests PRs that change python tests docs PRs that change docs labels Nov 10, 2026

@joshistoast joshistoast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No material runtime regression found. The approach is focused, checks shapes without tensor computation, and improves installation behavior by rejecting incompatible adapters earlier. Native/Kohya handling appears preserved.

Comment on lines +169 to +170
Diffusers LoRAs of other transformers that use the same layer names (for example LTX-2, LTX-Video, CogView4,
PixArt, Sana) are not recognized as Anima, because their attention widths do not match Anima's.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P3] Documentation overstates protection.

Says LTX-Video LoRAs are not recognized as Anima. Self-attention-only LTX-Video LoRAs still pass because both use width 2048. Qualify this claim and explain the remaining ambiguity.

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.

Fixed in 2e0c5d1. LTX-Video is out of the example list. The page now says that its self-attention is as wide as Anima's, that a LoRA training the cross-attention is refused, and that one training only the self-attention still installs as Anima.

An LTX-Video LoRA that trains only self-attention has Anima's widths and still installs as Anima.
Comment on lines +171 to +172
self-attention is as wide as Anima's, so only its cross-attention tells them apart. An LTX-Video LoRA that trains
the cross-attention is refused; one that trains only the self-attention installs as Anima.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P3] Cross-attention rejection claim is still too broad.

The text says LTX-Video adapters that train cross-attention are refused. Adapters targeting only cross-attention query or output layers still pass: their input width matches Anima’s. Only key/value layers expose the mismatch. Clarify that adapters without cross-attention key/value layers can still install as Anima. The detection limitation already existed; the misleading wording is new.

Separately, backend guidance requires updating 03.model-format-support.mdx when identification acceptance changes. That update remains missing.

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.

Both fixed in 20acceb.

  • The family page now names the layers that differ: only the cross-attention key and value layers (attn2.to_k, attn2.to_v) read a wider text embedding in LTX-Video. An LTX-Video LoRA with those layers is not recognized as Anima. One without them, including one that trains only the cross-attention query or output, still installs as Anima.
  • 03.model-format-support.mdx gets a paragraph under the LoRA table. It says that Anima's Diffusers PEFT LoRAs are told apart by their attention widths, that other files install as unknown models, and it states the same LTX-Video limit with a link to the family page. 02.model-families.mdx names no Anima LoRA format, so it stays as is.

Only the cross-attention key/value layers differ in width; the format support page now notes the width check.

@joshistoast joshistoast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some suggested re-wording, otherwise looks good.

Comment on lines +236 to +237
Sana and others). A file whose attention widths are not Anima's is not recognized as Anima and installs as an
unknown model. LTX-Video LoRAs without cross-attention key and value layers have Anima's widths and still install as

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P3] Rejected by Anima does not always mean “unknown”.

The new wording says adapters with different attention widths install as unknown. Supported LTX-2 adapters containing video and audio layers still identify correctly as LTX-2. This could mislead users into thinking those adapters are unsupported.

Suggested wording: “These files are not recognized as Anima. If no other supported model family matches, they install as unknown.”

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend PRs that change backend files docs PRs that change docs python PRs that change python files python-tests PRs that change python tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Diffusers LoRAs of other DiTs (LTX-2, CogView4, SD 3.5 M, Mochi, …) are identified as Anima by key names alone

2 participants