Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(anima): cast the whole semantic connector under FP8 Storage

Alexander Eichhorn8c6729540485
diff --git a/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx b/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx
index 706c57b5a1..83275ec83f 100644
--- a/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx
@@ -70,6 +70,9 @@ iterations per second at 832×1216 on an RTX 4090), and its Qwen3.5 encoder adds
is encoded. **Reset all to model defaults** sets 40 steps at CFG 6, the settings of the author's reference
workflow.
+[FP8 Storage](/configuration/optimization/fp8-storage/) changes Anima-3.8B's images more than Anima's: at
+the same seed the composition can change, where Anima keeps it and only details differ.
+
Only the v1.1 checkpoint of Anima-3.8B is supported. The earlier v1.0 transformer needs a separate adapter
file and is refused at install with a message that says so.
@@ -80,7 +83,7 @@ LoRAs and ControlNet-LLLite adapters address the transformer's blocks by positio
insert their extra blocks between the original ones. Invoke moves an adapter trained on Anima to the
blocks the finetune kept from Anima, and one trained on Anima-2.9B to its blocks in Anima-3.8B.
Anima-2.9B keeps Anima's blocks unchanged, so Anima adapters work there as on Anima itself.
-Anima-3.8B trained most of them further, so expect weaker or different results there.
+Anima-3.8B changed them slightly and adds the semantic connector, so results there can differ more.
:::
## Generation settings
diff --git a/invokeai/backend/anima/anima_transformer.py b/invokeai/backend/anima/anima_transformer.py
index 231ecbc315..f7cc928306 100644
--- a/invokeai/backend/anima/anima_transformer.py
+++ b/invokeai/backend/anima/anima_transformer.py
@@ -1049,14 +1049,12 @@ class AnimaTransformer(MiniTrainDIT):
from invokeai.backend.anima.semantic_connector import AnimaSemanticConnector
# Named as in the Anima-3.8B bundle (`net.anima_v2_connector.*`), so its keys load as-is.
+ # FP8 Storage casts all of it. Keeping its timestep path (`time_mlp`, `time_modulation`, 159M
+ # params) in bf16 by analogy with `t_embedder` was measured and changes nothing: 30 steps, three
+ # seeds, PSNR against bf16 8.4/10.3/9.6 dB with that exception and 8.4/10.2/9.6 dB without, and
+ # 8.3/10.1/9.6 dB with the whole connector in bf16. FP8 Storage moves Anima-3.8B's composition
+ # through the DiT blocks, not the connector; Anima base stays at 14-16 dB.
self.anima_v2_connector = AnimaSemanticConnector(semantic_connector)
- # The resampler's timestep path plays the role `t_embedder` plays for the DiT: its output
- # modulates every resampler block. Kept out of FP8 Storage on that analogy -- unmeasured.
- # Declared on the instance so a model without the connector does not carry dead patterns.
- self._skip_layerwise_casting_patterns = [
- *type(self)._skip_layerwise_casting_patterns,
- r"^anima_v2_connector\.semantic_resampler\.(time_mlp|blocks\.\d+\.time_modulation)",
- ]
@property
def has_semantic_connector(self) -> bool:
diff --git a/tests/backend/anima/test_semantic_connector.py b/tests/backend/anima/test_semantic_connector.py
index 2b7b2277f1..6c39cf5f4d 100644
--- a/tests/backend/anima/test_semantic_connector.py
+++ b/tests/backend/anima/test_semantic_connector.py
@@ -85,26 +85,22 @@ def test_transformer_built_from_the_bundle_takes_every_key() -> None:
assert result.missing_keys == []
-def test_only_a_transformer_with_the_connector_declares_its_skip_pattern() -> None:
+def test_fp8_storage_casts_the_whole_connector() -> None:
+ """No connector module is kept out of FP8 Storage: keeping its timestep path in bf16 was measured to change
+ nothing (see `AnimaTransformer.__init__`), so a model with the connector declares the same patterns as one
+ without."""
with accelerate.init_empty_weights():
- plain = AnimaTransformer(**ANIMA_TRANSFORMER_CONFIG)
expanded = AnimaTransformer(**ANIMA_TRANSFORMER_CONFIG, semantic_connector=AnimaSemanticConnectorConfig())
- assert not plain.has_semantic_connector
- assert plain._skip_layerwise_casting_patterns is AnimaTransformer._skip_layerwise_casting_patterns
- skipped = {
+ assert expanded.has_semantic_connector
+ assert expanded._skip_layerwise_casting_patterns is AnimaTransformer._skip_layerwise_casting_patterns
+ kept = [
name
for name, module in expanded.named_modules()
- if isinstance(module, torch.nn.Linear)
- and any(
- re.search(p, name)
- for p in expanded._skip_layerwise_casting_patterns[len(plain._skip_layerwise_casting_patterns) :]
- )
- }
- assert skipped == {
- "anima_v2_connector.semantic_resampler.time_mlp.0",
- "anima_v2_connector.semantic_resampler.time_mlp.2",
- *(f"anima_v2_connector.semantic_resampler.blocks.{i}.time_modulation" for i in range(6)),
- }
+ if name.startswith("anima_v2_connector.")
+ and isinstance(module, torch.nn.Linear)
+ and any(re.search(p, name) for p in expanded._skip_layerwise_casting_patterns)
+ ]
+ assert kept == []
class TestMaskedSdpa: