Skip to content
This repository was archived by the owner on Oct 25, 2026. It is now read-only.

feat: add Anima 2.9B 40-block training compatibility - #11

Merged
LingyeSoul merged 2 commits into
LingyeSoul:mainfrom
buxinzi2233:codex/anima29-training-compat
Aug 15, 2026
Merged

LingyeSoul merged 2 commits into
LingyeSoul:mainfrom
buxinzi2233:codex/anima29-training-compat

Conversation

@buxinzi2233

Copy link
Copy Markdown

Summary

  • add a header-only Anima checkpoint inspector with strict 28/40-block layout validation, prefix normalization, shard validation, and deterministic base hashes
  • construct the DiT from the detected layout and run one shared compatibility preflight before datasets, caches, Accelerator, or model allocation
  • isolate adapters and resume state by Anima architecture, block count, model channels, and exact base checkpoint hash
  • add validated 40-block channel calibration data and select it at runtime from the detected model layout
  • expose detected model/profile/blockers in the WebUI and record the architecture identity in snapshots, manifests, progress events, and adapter metadata
  • keep legacy 28-block adapters and training behavior compatible while rejecting uncertified 40-block feature combinations before launch

40-block support policy

The shared preflight accepts only:

  • Plain LoRA
  • T-LoRA + OrthoLoRA

REPA, VR loss, ConvRot, Hydra, LoKr/LoHa/GLoKr, ControlNet/EasyControl, Turbo, SPD, BYG, text-encoder training, and other unvalidated combinations are reported together and rejected before cache/model startup. The certified base identity is the Anima 2.9B preview-v1 checkpoint (0b3020d1b906155f7eb30667622723e87160632c8c7a5f1c93bdce685f2a346d). Other structurally valid 40-block derivatives are detected but remain uncertified.

Validation

  • clean origin/main focused suite: 76 passed
  • broader local regression suite: 1706 passed, 15 skipped
  • WebUI production build: 449 modules transformed, built successfully
  • fatal Ruff rules: passed
  • artifact/metadata audit: passed, including 28/40 adapter identities and all 40 channel-stat tensors
  • 28-block Plain LoRA and T-LoRA regression, save/resume, adapter inference, merge, and merged inference: passed
  • V100 16 GB 40-block Plain LoRA: 1 step, 3 steps, save/resume, adapter inference, merge, merged inference, and 50-step stability run passed; peak allocation was about 7271 MiB

Hardware certification limits

  • V100 16 GB T-LoRA + OrthoLoRA passed one optimizer step, but swaps 16/20/24 all OOMed on the second optimizer step. No V100 2.9B preset is added and this path is not claimed as supported.
  • SM80+ BF16/Flash/compile hardware validation has not been run, so this PR provides the compatibility implementation without claiming a completed all-platform release gate.

The remaining failures from the raw full local pytest run are pre-existing environment/baseline failures involving optional pystray, a missing default VAE file, stale documentation links, Torch 2.10 golden-number drift, and an existing stage-test mock.

Comment thread library/anima/compat.py
"use_byg": "BYG",
"pgraft": "P-GRAFT",
"train_llm_adapter": "train_llm_adapter",
"network_train_text_encoder_only": "text-encoder-only training",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟠 High: Joint text-encoder training bypasses the 40-block gatennThis catches text-encoder-only mode, but network_train_unet_only=false enables joint DiT/text-encoder training and still passes. That combination is explicitly outside the certified 40-block policy, so it must add a blocker too.

Comment thread library/inference/models.py Outdated
return None
dit_path = str(resolve_under_home(dit))
cached = getattr(args, "_anima_inference_identity", None)
if cached is not None and cached[0] == dit_path and cached[1] == adapters:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟡 Medium: Path-only cache can skip adapter identity revalidationnnReplacing an adapter at the same path leaves this cache key unchanged, so the new file is loaded without checking its base/model identity. Include stable file fingerprints such as resolved path, size, timestamps, and file identity in the key.

block_prefixes: set[str] = set()

for path in files:
with MemoryEfficientSafeOpen(str(path)) as handle:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🔴 Critical: Unbounded safetensors header length can exhaust memorynnMemoryEfficientSafeOpen trusts the first 8 bytes and allocates/reads that declared header size. A corrupt checkpoint can declare a multi-GB header and OOM WebUI preflight or training before validation. Bound the header and verify it fits inside the file before reading.

Comment thread library/anima/checkpoint.py Outdated
)


@lru_cache(maxsize=32)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟠 High: Metadata-keyed SHA cache can retain stale certificationnnA checkpoint replaced with same-size content and a preserved mtime can reuse the previous certified SHA. That stale identity then propagates to adapter checks and metadata. Certification hashes should be recomputed from content rather than trusted from (path, size, mtime).

Comment thread library/anima/compat.py Outdated
down_init = str(options.get("down_init", "kaiming") or "kaiming").lower()
if not timestep_mask and not use_ortho and down_init == "kaiming":
profile = "plain_lora"
elif timestep_mask and (

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟠 High: Plain SVD-Down T-LoRA is mislabeled as certified OrthoLoRAnndown_init=weight_svd with use_ortho=false stays on LoRAModule per networks/lora_anima/config.py; it is not OrthoLoRA. This branch therefore admits an architecture outside the stated allowlist. Require use_ortho=true with the compatible kaiming initialization.

Comment thread scripts/distill_mod/distill.py Outdated
"method": "distill_mod",
"network_module": "networks.lora_anima",
}
checkpoint_layout, base_sha256, _compatibility = preflight_anima_training(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟡 Medium: Dry-run now scans and requires the full DiTnnThis preflight runs before the dry_run return, so a model-free collation check now fails on a missing checkpoint or hashes multiple GB unnecessarily. Move it below the dry-run path; the identical ordering in scripts/distill_spd.py needs the same change.

"--dit in your argparse."
)

checkpoint_layout = inspect_anima_checkpoint(dit_path)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟠 High: Preflight bypasses repository-relative model path resolutionnnload_anima_model resolves relative paths under ANIMA_HOME, but this new inspection runs first against the process CWD. build_anima() therefore fails outside the repo for otherwise valid default paths. Resolve dit_path once with resolve_under_home() before all three operations.


from library.io.safetensors import MemoryEfficientSafeOpen, get_split_weight_filenames

_KEY_PREFIXES = ("net.", "model.diffusion_model.", "")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟠 High: Inspector and loader normalize different checkpoint prefixesnnThis newly accepts model.diffusion_model.blocks.*, but the loader strips only net.. Such a checkpoint passes preflight and then loads under the wrong keys. Normalize every prefix accepted here in the loader too.

@LingyeSoul
LingyeSoul merged commit 0fc46db into LingyeSoul:main Aug 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants