feat: add Anima block remapping for Base/2.9B/3.8B LoRAs - #1104
Open
okingjo wants to merge 1 commit into
Open
Conversation
- Added anima_remap.py: block-index detection and remapping logic - Added expansion manifests for 28→40 and 40→52 block transformations - Integrated automatic remapping into LoRA loading workflow - Added anima_remap toggle to LoraTextLoaderLM node - Supports chained mapping (28→40→52) for Base LoRAs on 3.8B models - Safe for non-Anima models (no-op when block counts don't match known manifests)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Feature Request] Add Anima Block-Index Remap Support to LoRA Loaders
Summary
Anima image-generation models use an interleaved layer-expansion architecture across generations:
New blocks are inserted between existing blocks rather than appended. This means applying a LoRA trained on Anima Base directly to a 2.9B or 3.8B model causes every block index after the first insertion point to land on the wrong layer — producing broken, scribble-level output.
This PR adds automatic block-index remapping to the LoRA Manager's loader nodes, so that:
block_remapinput toggle — no behavior change for existing workflowsMotivation
There are hundreds of community LoRAs trained on Anima Base. With Anima 3.8B now released, users want to reuse their existing LoRA collections on the newer, larger models. Currently the only options are:
ComfyUI-Anima-Remap) and replace LoRA Manager's loadersNeither option plays nicely with LoRA Manager's workflow integration — users lose trigger words, recipe support, and the
<lora:...>tag syntax they already use.Adding remap support directly into LoRA Manager's loaders would make this seamless.
Proposed Changes
1. New file:
py/nodes/anima_remap.pyCore remapping utilities — detection, manifest loading, and key rewriting:
2. New manifest files
Place under
py/nodes/anima_manifests/:expand_manifest_28_40.json(from official Anima-2.9B):{ "old_block_count": 28, "new_block_count": 40, "insertion_positions": [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47], "inserted_to_source": { "3": 2, "7": 5, "11": 8, "15": 11, "19": 14, "23": 17, "27": 20, "31": 23, "35": 26, "39": 29, "43": 32, "47": 35 } }expand_manifest_40_52.json(reconstructed from Anima 3.8B checkpoint metadata):{ "old_block_count": 40, "new_block_count": 52, "insertion_positions": [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47], "inserted_to_source": { "3": 2, "7": 5, "11": 8, "15": 11, "19": 14, "23": 17, "27": 20, "31": 23, "35": 26, "39": 29, "43": 32, "47": 35 } }3. Modify
py/nodes/lora_loader.pyIntegrate remap into
_apply_entries(). Changes are minimal — only the standardcomfy.sd.load_lora_for_modelspath is affected:Optionally, add a toggle to let users opt out:
class LoraLoaderLM: @classmethod def INPUT_TYPES(cls): return { "required": { ... }, "optional": { + "block_remap": ("BOOLEAN", { + "default": True, + "tooltip": "Auto-remap LoRA block indices for Anima model family (Base→2.9B→3.8B)", + }), }, }Then guard the remap call:
Impact
Design Decisions
Opt-in by default for Anima, no-op for everything else: The remap only fires when the LoRA's block count is strictly less than the model's AND a matching manifest exists. For SD1.5/SDXL/Flux/etc. models, none of these conditions are met, so there's zero behavioral change.
Composed mappings: Instead of shipping a separate manifest for every pair of generations, the 28→52 mapping is composed at runtime from 28→40 and 40→52. This makes it trivial to add future Anima generations — just drop a new
expand_manifest_N_M.json.No cache files: Unlike
ComfyUI-Anima-Remap, this implementation remaps in-memory on every run. The overhead is negligible (a dict key rewrite over ~200 tensors). This avoids cache invalidation headaches and keeps the code simpler.llm_adapterandconnectorkeys excluded: These sub-structures have their own separate block numbering and are never touched by remapping — matching the behavior of established remap implementations.Alternatives Considered
<lora:...>syntax integration.Testing
Tested with:
References