repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
InvokeAI | tests/backend/model_manager/load/test_flux2_state_dict_utils.py | .py | """Unit tests for the FLUX.2 BFL->diffusers state-dict converters.
Fixtures are captured from real single-file checkpoints (see the fixture module docstrings).
The meta-device tests instantiate the actual diffusers architectures with `init_empty_weights`
(no real weights, no GPU) and assert that every converted key is... | 102 | 4,850 |
InvokeAI | tests/backend/model_manager/load/test_z_image_state_dict_utils.py | .py | """Unit tests for the Z-Image GGUF/ComfyUI -> diffusers state-dict converter."""
import torch
from invokeai.backend.model_manager.load.model_loaders.z_image import _convert_z_image_gguf_to_diffusers
from tests.backend.model_manager.load.state_dicts.utils import keys_to_mock_state_dict
from tests.backend.model_manager... | 67 | 3,586 |
InvokeAI | tests/backend/model_manager/load/test_krea2_state_dict_utils.py | .py | """Unit tests for the Krea-2 loader state-dict helpers.
These cover the pure key/tensor transforms that the single-file, GGUF and Qwen3-VL encoder loaders
run before ``load_state_dict`` (prefix stripping, native<->diffusers key conversion, scaled-fp8
dequantization, encoder key remapping) plus the shared ``_reject_inc... | 379 | 19,021 |
InvokeAI | tests/backend/model_manager/load/test_shared_weight_adoption.py | .py | """Tests for load-time adoption of shared CPU weights (multi-GPU RAM-spike fix).
When a second device loads a model that another device already holds, the loader deep-copies the
empty (meta-weight) structural shell the first device registered and assigns the canonical CPU
weights into it — instead of re-reading the mo... | 189 | 7,629 |
InvokeAI | tests/backend/model_manager/load/test_anima_state_dict_utils.py | .py | """Unit tests for the Anima single-file prefix-stripping helper."""
import torch
from invokeai.backend.model_manager.load.model_loaders.anima import (
_filter_non_model_keys,
_strip_anima_bundle_prefix,
)
from tests.backend.model_manager.load.state_dicts.anima_comfyui_keys import state_dict_keys as anima_keys... | 75 | 2,611 |
InvokeAI | tests/backend/model_manager/load/test_load_default_helpers.py | .py | """Two invariants that belong to model loading in general, not to any one loader.
Both were repeatedly got wrong per-loader, so they now live at the single choke point every loader
passes through (`put_in_eval_mode`) or in one shared resolver (`resolve_submodel_path`).
"""
from pathlib import Path
from types import S... | 131 | 5,549 |
InvokeAI | tests/backend/model_manager/load/test_mistral_tokenizer_ladder.py | .py | """The local-directory rungs of the Mistral tokenizer ladder must try `AutoTokenizer`, not just
`AutoProcessor`.
With transformers 5.5.4, `AutoProcessor.from_pretrained` on a directory whose `config.json` says
`model_type: "mistral3"` — the BFL-style standalone-encoder layout these rungs exist for — resolves
to a *mul... | 296 | 14,336 |
InvokeAI | tests/backend/model_manager/load/test_wan_loader.py | .py | """Tests for Wan loader helpers (native -> diffusers key conversion)."""
from contextlib import nullcontext
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import gguf
import pytest
import torch
from invokeai.backend.model_manager.load.model_loaders.wan import (
WanGGUFCheckpointMode... | 215 | 8,307 |
InvokeAI | tests/backend/model_manager/load/test_wan_vae_loader.py | .py | """Tests for the Wan VAE single-file loader helper.
Covers the bug where ``AutoencoderKLWan`` was always instantiated with the A14B
defaults (base_dim=96, out_channels=3, no patchify), causing the TI2V-5B VAE
checkpoint to fail state_dict loading with shape mismatches throughout the
encoder + decoder. The fix routes z... | 93 | 3,999 |
InvokeAI | tests/backend/model_manager/load/test_gemma2_encoder_gguf_loader.py | .py | """Tests for the native GGMLTensor Gemma-2 GGUF encoder loader.
The loader keeps the large 2D projection weights quantized (as GGMLTensor, dequantized on demand by the
model cache) and materializes only the embedding and RMSNorm weights, so a GGUF Gemma-2 encoder no longer
costs the same VRAM as the unquantized model.... | 287 | 13,173 |
InvokeAI | tests/backend/model_manager/load/test_load_default_cpu_only.py | .py | """Tests for `ModelLoader._get_execution_device` — the helper that forces a model onto the CPU
when its config requests `cpu_only`.
A VAE (or text encoder) configured with `cpu_only=True` must load onto the CPU so its weights
never occupy VRAM. The loader signals this by returning `torch.device("cpu")` from
`_get_exec... | 50 | 2,168 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_model_cache_timeout.py | .py | """Tests for model cache keep-alive timeout functionality."""
import logging
import time
from unittest.mock import MagicMock
import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.model_cache import ModelCache
@pytest.fixture
def mock_logger():
"""Create a mock logger."""
logger = ... | 127 | 3,593 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_shared_weights_gpu.py | .py | """Real-GPU validation of cross-device CPU-weight sharing.
These require two CUDA (incl. ROCm/HIP) devices. They prove the properties the CPU-only unit tests
cannot: that a module re-pointed at shared canonical CPU weights (a) loads onto its GPU and produces
correct inference output, and (b) survives two GPUs loading/... | 235 | 9,208 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_model_cache_shared_weights.py | .py | """End-to-end test of CPU-weight sharing through ModelCache.put()/eviction.
Simulates the multi-GPU topology — one ModelCache per device, all sharing a single
SharedCpuWeightsStore — and asserts that the same model loaded into both caches keeps exactly one
CPU copy, with RAM freed only when the last device evicts it. ... | 142 | 5,681 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_model_cache_ram_budget.py | .py | """End-to-end tests of the global RamBudget driving eviction across per-device caches.
Validates that the budget counts a shared model once (not once-per-GPU), counts non-deduplicated
models per-instance, and that eviction is made against the global deduplicated total — including the
case where a cache cannot free RAM... | 1,635 | 73,029 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_model_cache_integrated_gpu.py | .py | """ModelCache behaviour on an Intel integrated GPU, whose "VRAM" is system RAM.
Two things follow from that topology and are asserted here: a RAM copy of the weights is not
kept (it would double every model's footprint against the same DRAM), and partial loading stays
on so device residency remains bounded. Both are d... | 277 | 11,546 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_shared_cpu_weights.py | .py | import threading
import torch
from invokeai.backend.model_manager.load.model_cache.shared_cpu_weights import SharedCpuWeightsStore
def _state_dict() -> dict[str, torch.Tensor]:
return {
"a": torch.ones(10, 10, dtype=torch.float32), # 400 bytes
"b": torch.ones(5, dtype=torch.float32), # 20 byte... | 186 | 6,283 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_ram_budget.py | .py | import torch
from invokeai.backend.model_manager.load.model_cache.ram_budget import RamBudget
from invokeai.backend.model_manager.load.model_cache.shared_cpu_weights import SharedCpuWeightsStore
def test_total_in_use_sums_store_and_non_shared():
store = SharedCpuWeightsStore()
store.acquire("k", {"a": torch.... | 49 | 1,726 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_model_cache_cached_model_keys.py | .py | """Tests for ModelCache.cached_model_keys(), which feeds the session queue's device-affinity
heuristic and must therefore (a) report only model-key-shaped keys and (b) never block."""
import logging
import threading
import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.model_cache import Mo... | 71 | 2,514 |
InvokeAI | tests/backend/model_manager/load/model_cache/test_model_cache_drop_model.py | .py | """Tests for `ModelCache.drop_model` — used by the model_manager API to invalidate cached
entries when a setting that changes how a model loads (e.g. `fp8_storage`, `cpu_only`) is
toggled. Without this, the toggle is silently a no-op until the entry is evicted by other
means (clear cache, eviction under memory pressure... | 225 | 7,803 |
InvokeAI | tests/backend/model_manager/load/model_cache/torch_module_autocast/test_torch_module_autocast.py | .py | import os
import gguf
import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import (
apply_custom_layers_to_model,
remove_custom_layers_from_model,
)
from tests.backend.quantization.gguf.test_ggml_tensor import quantize_tensor
try:
fro... | 133 | 4,606 |
InvokeAI | tests/backend/model_manager/load/model_cache/torch_module_autocast/custom_modules/test_all_custom_modules.py | .py | import copy
from collections.abc import Callable
import gguf
import pytest
import torch
from invokeai.backend.flux.modules.layers import RMSNorm
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import (
AUTOCAST_MODULE_TYPE_MAPPING,
AUTOCAST_MODULE_TYPE_MAPPING_... | 799 | 30,922 |
InvokeAI | tests/backend/model_manager/load/model_cache/torch_module_autocast/custom_modules/test_custom_invoke_linear_nf4.py | .py | from unittest.mock import patch
import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import (
wrap_custom_layer,
)
if not torch.cuda.is_available():
pytest.skip("CUDA is not available", allow_module_level=True)
else:
from invokeai.bac... | 109 | 4,635 |
InvokeAI | tests/backend/model_manager/load/model_cache/torch_module_autocast/custom_modules/test_custom_flux_rms_norm.py | .py | import torch
from invokeai.backend.flux.modules.layers import RMSNorm
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.custom_modules.custom_flux_rms_norm import (
CustomFluxRMSNorm,
)
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import ... | 32 | 1,223 |
InvokeAI | tests/backend/model_manager/load/model_cache/torch_module_autocast/custom_modules/test_custom_invoke_linear_8_bit_lt.py | .py | import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import (
wrap_custom_layer,
)
if not torch.cuda.is_available():
pytest.skip("CUDA is not available", allow_module_level=True)
else:
from invokeai.backend.model_manager.load.model_cac... | 83 | 3,291 |
InvokeAI | tests/backend/model_manager/load/model_cache/cached_model/test_cached_model_with_partial_load.py | .py | import itertools
import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.cached_model.cached_model_with_partial_load import (
CachedModelWithPartialLoad,
)
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import (
apply_custom_layers_to_m... | 342 | 13,701 |
InvokeAI | tests/backend/model_manager/load/model_cache/cached_model/test_repair_required_tensors.py | .py | import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.cached_model.cached_model_with_partial_load import (
CachedModelWithPartialLoad,
)
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import (
apply_custom_layers_to_model,
)
class Mo... | 48 | 1,715 |
InvokeAI | tests/backend/model_manager/load/model_cache/cached_model/utils.py | .py | import os
import pytest
import torch
class DummyModule(torch.nn.Module):
def __init__(self):
super().__init__()
self.linear1 = torch.nn.Linear(10, 32)
self.linear2 = torch.nn.Linear(32, 64)
self.register_buffer("buffer1", torch.ones(64))
# Non-persistent buffers are not in... | 42 | 1,321 |
InvokeAI | tests/backend/model_manager/load/model_cache/cached_model/test_cached_model_only_full_load.py | .py | import torch
from invokeai.backend.model_manager.load.model_cache.cached_model.cached_model_only_full_load import (
CachedModelOnlyFullLoad,
)
from tests.backend.model_manager.load.model_cache.cached_model.utils import (
DummyModule,
parameterize_keep_ram_copy,
parameterize_mps_and_cuda,
)
class NonT... | 144 | 4,987 |
InvokeAI | tests/backend/model_manager/load/model_cache/cached_model/test_cached_model_shared_weights.py | .py | """Tests for sharing a single canonical CPU copy of model weights across per-device cached models.
These exercise the multi-GPU RAM-dedup path: two cached models built for the same cache key (as
would happen on two GPUs) must end up aliasing one set of CPU tensors instead of holding two
copies. They run on CPU — the w... | 129 | 5,642 |
InvokeAI | tests/backend/model_manager/load/state_dicts/qwen_vl_encoder_comfyui_keys.py | .py | """Representative key layout of a ComfyUI single-file Qwen2.5-VL encoder checkpoint.
Captured from `qwen_2.5_vl_7b_fp8_scaled.safetensors` (Qwen2.5-VL-7B, ComfyUI fp8_scaled).
The full checkpoint has 1446 tensors (32 visual blocks, 28 language layers); this
fixture keeps every top-level/structural key plus block 0 of ... | 78 | 3,933 |
InvokeAI | tests/backend/model_manager/load/state_dicts/utils.py | .py | """Shared helpers for model-loader state-dict fixtures.
Mirrors `tests/backend/patches/lora_conversions/lora_state_dicts/utils.py`: a fixture module
exports `state_dict_keys: dict[str, list[int]]` (key name -> shape, captured from a real
checkpoint) and tests expand it to a mock state dict with `keys_to_mock_state_dic... | 14 | 569 |
InvokeAI | tests/backend/model_manager/load/state_dicts/anima_comfyui_keys.py | .py | """Representative key layout of an official Anima transformer single-file checkpoint.
Captured from `anima-base-v1.0.safetensors`. The full checkpoint has 685 tensors under the
`net.` prefix; this fixture keeps `net.blocks.0.*` plus all non-block `net.*` keys. Used to
exercise `_strip_anima_bundle_prefix` (the `net.` ... | 156 | 9,541 |
InvokeAI | tests/backend/model_manager/load/state_dicts/flux2_vae_bfl_keys.py | .py | """BFL-format key layout of a FLUX.2 VAE single-file checkpoint (full, 251 keys).
Captured from `flux2-vae.safetensors` (standard FLUX.2 VAE, block_out_channels=(128,256,512,512)).
The full key set is kept (the VAE is small), so `convert_flux2_vae_bfl_to_diffusers` can be
validated for *complete* coverage against `Aut... | 267 | 15,435 |
InvokeAI | tests/backend/model_manager/load/state_dicts/flux2_transformer_bfl_keys.py | .py | """Representative BFL-format key layout of a FLUX.2 transformer single-file checkpoint.
Captured from `flux-2-klein-9b-kv.safetensors` (FLUX.2 Klein 9B, bf16). The full
checkpoint has 201 tensors (8 double blocks, 24 single blocks); this
fixture keeps every top-level key plus block 0 of the double/single stacks, which... | 42 | 2,171 |
InvokeAI | tests/backend/model_manager/load/state_dicts/z_image_transformer_comfyui_keys.py | .py | """Representative ComfyUI key layout of a Z-Image transformer single-file checkpoint.
Captured from `zimageTurboBadmilk_v10.safetensors` (Z-Image Turbo) after stripping the
`model.diffusion_model.` prefix -- this is exactly the input `_convert_z_image_gguf_to_diffusers`
receives (the converter runs on both the checkpo... | 70 | 3,551 |
InvokeAI | tests/backend/model_manager/model_loading/test_model_load.py | .py | """
Test model loading
"""
from pathlib import Path
from invokeai.app.services.model_manager import ModelManagerServiceBase
from invokeai.backend.textual_inversion import TextualInversionModelRaw
def test_loading(mm2_model_manager: ModelManagerServiceBase, embedding_file: Path):
store = mm2_model_manager.store
... | 26 | 904 |
InvokeAI | tests/backend/model_manager/util/test_hf_model_select.py | .py | from pathlib import Path
from typing import List
import pytest
from invokeai.backend.model_manager.taxonomy import ModelRepoVariant
from invokeai.backend.model_manager.util.select_hf_files import filter_files
# This is the full list of model paths returned by the HF API for sdxl-base
@pytest.fixture
def sdxl_base_f... | 406 | 16,931 |
InvokeAI | tests/backend/model_manager/configs/test_lora_default_settings.py | .py | import pytest
from pydantic import ValidationError
from invokeai.backend.model_manager.configs.lora import LoraModelDefaultSettings
def test_accepts_none_for_all_fields() -> None:
settings = LoraModelDefaultSettings()
assert settings.weight is None
assert settings.weight_min is None
assert settings.w... | 113 | 4,267 |
InvokeAI | tests/backend/model_manager/configs/test_wan_t5_encoder_config.py | .py | """Tests for the WanT5Encoder config probe (UMT5-XXL diffusers folder)."""
import json
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import MagicMock
import pytest
from invokeai.backend.model_manager.configs.identification_utils import NotAMatchError
from invokeai.backend.model_... | 110 | 4,471 |
InvokeAI | tests/backend/model_manager/configs/test_sdnq_flux2_identification.py | .py | """Tests for SDNQ FLUX.2 single-file model identification.
A single-file SDNQ FLUX.2 transformer must identify as ``Main_SDNQ_Flux2_Config`` (base=flux2),
not as ``Main_SDNQ_FLUX_Config`` (base=flux) and not as unknown.
The only supported single-file layout is *bare diffusers* (``transformer_blocks.*`` /
``context_em... | 108 | 5,136 |
InvokeAI | tests/backend/model_manager/configs/test_sdnq_pipeline_submodel_discovery.py | .py | """Tests that SDNQ pipeline submodel discovery recognizes the compatible Qwen encoder/tokenizer
classes the loader can actually load.
_get_submodels() must record the TextEncoder / Tokenizer submodels for the text-only Qwen causal-LM
classes and the slow/fast Qwen2 tokenizer classes; otherwise a valid SDNQ pipeline wh... | 627 | 28,843 |
InvokeAI | tests/backend/model_manager/configs/test_qwen3_encoder_sdnq_single_file_identification.py | .py | """Tests that Qwen3Encoder_SDNQ_Config (single-file) only accepts a real Qwen3 encoder.
A single-file SDNQ Qwen checkpoint has no config.json, so identification must key on the state dict.
`_has_qwen3_keys` alone is generic across Qwen2 / Qwen3 / Qwen-VL (same `model.layers.*` /
`model.embed_tokens.weight` layout). Be... | 87 | 4,129 |
InvokeAI | tests/backend/model_manager/configs/test_krea2_main_config.py | .py | """Tests for Krea-2 main-model identification and variant detection.
Krea-2-Turbo (distilled) and Krea-2-Raw (Base, undistilled) share the IDENTICAL transformer
architecture, so a single-file/GGUF checkpoint cannot be told apart from its weights. Detection:
1. Explicit ``variant`` in override_fields always wins.
2. D... | 250 | 11,942 |
InvokeAI | tests/backend/model_manager/configs/test_qwen_image_gguf_variant_detection.py | .py | """Tests for GGUF Qwen Image variant detection.
Detection precedence:
1. Explicit `variant` in override_fields wins.
2. Presence of the `__index_timestep_zero__` tensor in the state dict marks an Edit model.
3. Otherwise fall back to a filename heuristic ("edit" in the stem → Edit).
4. Otherwise default to Generate.
"... | 123 | 6,585 |
InvokeAI | tests/backend/model_manager/configs/test_qwen3_encoder_config.py | .py | """Regression tests for Qwen3 Encoder config probing.
See https://github.com/invoke-ai/InvokeAI/issues/9090
`Qwen2.5-1.5B-Instruct` (a standalone causal LM) was being misidentified as a
`Qwen3Encoder` because the diffusers-style config check matched any directory with
`config.json` at the root and a Qwen* class name.... | 148 | 6,355 |
InvokeAI | tests/backend/model_manager/configs/test_anima_model_identification.py | .py | import pytest
from invokeai.backend.model_manager.configs.main import _has_anima_keys
def _make_state_dict(prefixes: list[str], keys: list[str]) -> dict[str, object]:
"""Build a minimal fake state dict with the given prefixes applied to the given keys."""
return {f"{prefix}{key}": None for prefix in prefixes... | 163 | 7,551 |
InvokeAI | tests/backend/model_manager/configs/test_qwen_image_main_config.py | .py | from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import MagicMock
import gguf
import pytest
import torch
from invokeai.backend.model_manager.configs.main import Main_GGUF_QwenImage_Config
from invokeai.backend.quantization.gguf.ggml_tensor import GGMLTensor
def _build_ggml_tensor(... | 53 | 1,718 |
InvokeAI | tests/backend/model_manager/configs/test_qwen_image_checkpoint_variant_detection.py | .py | """Tests for Qwen Image single-file checkpoint variant detection.
Mirrors `test_qwen_image_gguf_variant_detection.py`. The Checkpoint and GGUF
configs share the same variant inference (`_infer_qwen_image_variant`):
1. Explicit `variant` in override_fields wins.
2. Presence of the `__index_timestep_zero__` tensor → Ed... | 188 | 9,762 |
InvokeAI | tests/backend/model_manager/configs/test_model_path_validation.py | .py | import json
from pathlib import Path
import pytest
from invokeai.backend.model_manager.configs.factory import _MAX_FILES_IN_MODEL_DIR, ModelConfigFactory
def _fill_directory(path: Path) -> None:
for index in range(_MAX_FILES_IN_MODEL_DIR + 1):
(path / f"asset-{index}.txt").touch()
def test_large_direc... | 97 | 3,637 |
InvokeAI | tests/backend/model_manager/configs/test_qwen_vl_encoder_config.py | .py | """Tests for Qwen VL encoder config identification.
The single-file checkpoint identifier reads only the safetensors key index
instead of loading the full tensor data — a 7GB fp8 encoder otherwise pins
~7GB of RAM during model scan.
"""
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mo... | 102 | 3,807 |
InvokeAI | tests/backend/model_manager/configs/test_sdxl_slider_lora_identification.py | .py | """Tests for identifying UNet-only SDXL LoRAs (e.g. self-attention "slider" LoRAs).
Some SDXL LoRAs only patch the UNet and contain no cross-attention (`attn2`) or
text-encoder (`lora_te*`) keys. `lora_token_vector_length()` reads the base's
context dimension from exactly those keys, so for such LoRAs it returns `None... | 295 | 15,300 |
InvokeAI | tests/backend/model_manager/configs/test_krea2_lora_config.py | .py | from unittest.mock import MagicMock, patch
import pytest
from invokeai.backend.model_manager.configs.identification_utils import NotAMatchError
from invokeai.backend.model_manager.configs.lora import LoRA_LyCORIS_Krea2_Config
from invokeai.backend.model_manager.taxonomy import BaseModelType
_REQUIRED_FIELDS = {
... | 240 | 11,185 |
InvokeAI | tests/backend/model_manager/configs/test_wan_main_config.py | .py | """Tests for Wan 2.2 model identification (Main_Diffusers_Wan_Config)."""
import json
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import MagicMock
import pytest
from invokeai.backend.model_manager.configs.main import Main_Diffusers_Wan_Config
from invokeai.backend.model_manage... | 153 | 6,747 |
InvokeAI | tests/backend/model_manager/configs/test_wan_lora_config.py | .py | """Tests for the Wan LoRA probe (LoRA_LyCORIS_Wan_Config).
These tests cover detection across the three formats Wan LoRAs ship in:
- **Diffusers PEFT**, with or without a ``transformer.`` prefix
- **Native upstream PEFT** with ``diffusion_model.`` prefix (ComfyUI-trained)
- **Kohya** ``lora_unet_blocks_N_<submodule>`... | 373 | 16,058 |
InvokeAI | tests/backend/model_manager/configs/test_double_variant_regression.py | .py | """Regression tests for the double-variant kwarg bug.
When override_fields contains a field (variant, repo_variant, prediction_type, etc.)
that is also computed and passed as an explicit kwarg to cls(), using .get() instead
of .pop() causes TypeError("got multiple values for keyword argument ...").
These tests verify... | 116 | 5,056 |
InvokeAI | tests/backend/model_manager/configs/test_wan_vae_config.py | .py | """Tests for Wan 2.2 VAE config probes (checkpoint + diffusers)."""
import json
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import MagicMock
import pytest
import torch
from invokeai.backend.model_manager.configs.identification_utils import NotAMatchError
from invokeai.backend.... | 174 | 6,267 |
InvokeAI | tests/backend/model_manager/configs/test_qwen3_encoder_sdnq_folder_identification.py | .py | """Tests that Qwen3Encoder_SDNQ_Folder_Config only accepts real Qwen3 encoder folders.
An SDNQ transformer / VAE / other component folder also has a quantization_config.json with
quant_method="sdnq". Without verifying the folder is actually a Qwen3 encoder, such a folder would
be classified as type=qwen3_encoder and o... | 249 | 12,773 |
InvokeAI | tests/backend/model_manager/configs/test_sdnq_flux1_submodel_discovery.py | .py | """Tests for FLUX.1 SDNQ pipeline submodel discovery.
`model_index.json` advertises which components a pipeline *should* have and what class each one is.
Neither is a fact about the folder: a partial download keeps a complete index over missing or empty
component directories, and the advertised class is a claim the fo... | 216 | 8,702 |
InvokeAI | tests/backend/model_manager/configs/test_text_llm_gemma2_config.py | .py | """Regression tests for TextLLM classification of Gemma 2 causal LMs.
PiD added a dedicated Gemma2 encoder config that only accepts Gemma-2-2b (2304-dim hidden state).
Automatic classification must:
- defer a 2304-dim Gemma2 to the encoder config (so it becomes Gemma2Encoder, not a generic TextLLM),
- but keep lar... | 104 | 4,458 |
InvokeAI | tests/backend/model_manager/configs/test_wan_lora_probe_independence.py | .py | """Regression tests for Wan vs Anima LoRA probe mutual exclusivity.
InvokeAI's ``Config_Base.CONFIG_CLASSES`` is a ``set``, so iteration order is
non-deterministic across Python process restarts. The probe MUST therefore be
mutually exclusive at the per-config level — first-match-wins is not safe to
rely on.
The hist... | 276 | 11,434 |
InvokeAI | tests/backend/model_manager/configs/test_qwen3_vl_encoder_config.py | .py | """Tests for Qwen3-VL text-encoder identification (used by Krea-2).
A single-file Qwen3-VL encoder is distinguished from the text-only ``Qwen3Encoder`` (Z-Image /
FLUX.2 Klein) by the presence of the Qwen3-VL **visual tower** (``visual.*`` / ``model.visual.*``).
Both have a Qwen3 text decoder (``model.layers.*``), so ... | 284 | 13,049 |
InvokeAI | tests/backend/model_manager/configs/test_anima_controlnet_config.py | .py | """Tests for Anima ControlNet-LLLite config probing.
Anima LLLite adapters (v2 named-key format) are identified by the presence of both the shared
conditioning trunk (`lllite_conditioning1.*`) and per-module weights (`lllite_dit_blocks_*`).
SDXL ControlNet-LLLite models (`lllite_unet_*`) and Z-Image Control adapters
(... | 194 | 7,927 |
InvokeAI | tests/backend/model_manager/configs/test_sdnq_t5_encoder_identification.py | .py | """Tests for SDNQ T5 encoder identification and tokenizer/encoder directory resolution.
T5Encoder_SDNQ_Config accepts two layouts:
1. **Standalone bundle** — ``path`` is the pipeline root; T5 lives under ``text_encoder_2/`` and the
tokenizer under a sibling ``tokenizer_2/``.
2. **Inline submodel** — ``path`` *is* ... | 146 | 6,801 |
InvokeAI | tests/backend/model_manager/configs/test_gemma2_encoder_config.py | .py | """Regression tests for Gemma2 encoder (PiD caption encoder) config probing.
PiD's caption projection is hard-wired to Gemma-2-2b's 2304-dim hidden state. The classifier used
to accept every ``Gemma2ForCausalLM`` directory, so larger variants (9B → 3584, 27B → 4608) were
offered as compatible PiD encoders and then fai... | 109 | 4,979 |
InvokeAI | tests/backend/model_manager/configs/test_z_image_sdnq_identification.py | .py | """Tests that an SDNQ-quantized ZImagePipeline folder identifies as the SDNQ config.
A full ZImagePipeline folder whose ``transformer/quantization_config.json`` has
``quant_method: "sdnq"`` must classify as ``Main_SDNQ_Diffusers_ZImage_Config``, not as the plain
``Main_Diffusers_ZImage_Config``. Both configs accept th... | 115 | 4,900 |
InvokeAI | tests/backend/model_manager/configs/test_pid_decoder_config.py | .py | """Regression tests for PiD decoder checkpoint identification.
Covers what identification has to get right before a checkpoint reaches the decode:
- The contract: identification holds a file to exactly the key set and shapes `load_pid_decoder`
enforces. Checking a subset is not a milder version of the same guarante... | 543 | 30,695 |
InvokeAI | tests/backend/model_manager/configs/test_wan_gguf_config.py | .py | """Tests for the GGUF Wan probe (Main_GGUF_Wan_Config)."""
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import MagicMock
import gguf
import pytest
import torch
from invokeai.backend.model_manager.configs.identification_utils import NotAMatchError
from invokeai.backend.model_man... | 327 | 12,407 |
InvokeAI | tests/backend/text_llm/test_text_llm_thinking.py | .py | """Regression tests for reasoning ("thinking") models in TextLLMPipeline.
Reasoning models such as Qwen3 emit a chain of thought before their answer unless the chat
template is rendered with ``enable_thinking=False``. Prompt expansion returns the raw generated
text, so without the flag the user gets the model's reason... | 136 | 5,175 |
InvokeAI | tests/backend/text_llm/test_text_llm_api_models.py | .py | """Tests for TextLLM API request/response models and validation."""
from unittest.mock import MagicMock, patch
import pytest
import torch
from pydantic import ValidationError
from invokeai.app.api.dependencies import ApiDependencies
from invokeai.app.api.routers.utilities import (
ExpandPromptRequest,
Expand... | 98 | 4,145 |
InvokeAI | tests/backend/text_llm/test_text_llm_pipeline.py | .py | """Tests for the TextLLMPipeline class."""
import importlib
import queue
import threading
from unittest.mock import MagicMock, patch
import pytest
import torch
from transformers import LlamaConfig, LlamaForCausalLM
from invokeai.backend import text_llm_pipeline
from invokeai.backend.text_llm_pipeline import DEFAULT_... | 487 | 18,561 |
InvokeAI | tests/backend/rectified_flow/test_er_sde_scheduler.py | .py | """Smoke / structural tests for ``ERSDEScheduler`` (PoC).
Parity against the existing ``er_sde_rf_step`` (Anima ground truth) is
deliberately deferred to Task D and lives in a separate test file.
"""
from __future__ import annotations
import pytest
import torch
from invokeai.backend.rectified_flow.er_sde_scheduler ... | 305 | 12,717 |
InvokeAI | tests/backend/patches/test_layer_patcher_shared_weights.py | .py | """Regression tests: LoRA direct patching must not mutate the model's canonical CPU weights.
In multi-GPU mode the per-device caches share one canonical CPU state_dict (SharedCpuWeightsStore),
and that same dict is the keep_ram_copy used to restore a model after unpatching. Direct patching
must therefore never mutate ... | 107 | 4,761 |
InvokeAI | tests/backend/patches/test_layer_patcher.py | .py | import gc
import weakref
import pytest
import torch
from invokeai.backend.model_manager.load.model_cache.cached_model.cached_model_with_partial_load import (
CachedModelWithPartialLoad,
)
from invokeai.backend.model_manager.load.model_cache.torch_module_autocast.torch_module_autocast import (
apply_custom_lay... | 672 | 28,621 |
InvokeAI | tests/backend/patches/layers/test_set_parameter_layer.py | .py | import pytest
import torch
from invokeai.backend.patches.layers.set_parameter_layer import SetParameterLayer
def test_set_parameter_layer_get_parameters():
orig_module = torch.nn.Linear(4, 8)
target_weight = torch.randn(8, 4)
layer = SetParameterLayer(param_name="weight", weight=target_weight)
para... | 50 | 1,705 |
InvokeAI | tests/backend/patches/layers/test_lora_layer.py | .py | import logging
import pytest
import torch
from invokeai.backend.patches.layers.lora_layer import LoRALayer
def test_lora_layer_init_from_state_dict():
"""Test initializing a LoRALayer from state dict values."""
# Create mock state dict values
in_features = 8
out_features = 16
rank = 4
alpha ... | 115 | 3,681 |
InvokeAI | tests/backend/patches/layers/test_flux_control_lora_layer.py | .py | import torch
from invokeai.backend.patches.layers.flux_control_lora_layer import FluxControlLoRALayer
def test_flux_control_lora_layer_get_parameters():
"""Test getting weight and bias parameters from FluxControlLoRALayer."""
small_in_features = 4
big_in_features = 8
out_features = 16
rank = 4
... | 26 | 1,037 |
InvokeAI | tests/backend/patches/lora_conversions/test_flux_aitoolkit_lora_conversion_utils.py | .py | import accelerate
import pytest
from invokeai.backend.flux.model import Flux
from invokeai.backend.flux.util import get_flux_transformers_params
from invokeai.backend.model_manager.taxonomy import FluxVariantType
from invokeai.backend.patches.lora_conversions.flux_aitoolkit_lora_conversion_utils import (
_group_st... | 67 | 2,871 |
InvokeAI | tests/backend/patches/lora_conversions/test_peft_adapter_utils.py | .py | import torch
from invokeai.backend.patches.lora_conversions.peft_adapter_utils import (
has_peft_named_adapter_keys,
normalize_peft_adapter_names,
)
def _t() -> torch.Tensor:
return torch.zeros(1)
def test_no_op_when_no_named_adapter_keys():
"""State dicts without named-adapter keys are returned un... | 91 | 3,404 |
InvokeAI | tests/backend/patches/lora_conversions/test_anima_lora_conversion_utils.py | .py | import pytest
import torch
from invokeai.backend.patches.lora_conversions.anima_lora_constants import (
ANIMA_LORA_QWEN3_PREFIX,
ANIMA_LORA_TRANSFORMER_PREFIX,
)
from invokeai.backend.patches.lora_conversions.anima_lora_conversion_utils import (
_convert_kohya_te_key,
_convert_kohya_unet_key,
is_st... | 231 | 10,773 |
InvokeAI | tests/backend/patches/lora_conversions/test_flux_diffusers_lora_conversion_utils.py | .py | import pytest
import torch
from invokeai.backend.patches.lora_conversions.flux_diffusers_lora_conversion_utils import (
is_state_dict_likely_in_flux_diffusers_format,
lora_model_from_flux_diffusers_state_dict,
)
from invokeai.backend.patches.lora_conversions.flux_lora_constants import FLUX_LORA_TRANSFORMER_PRE... | 95 | 4,472 |
InvokeAI | tests/backend/patches/lora_conversions/test_qwen_image_lora_conversion_utils.py | .py | """Tests for Qwen Image LoRA conversion utilities."""
import torch
from invokeai.backend.patches.lora_conversions.qwen_image_lora_constants import (
QWEN_IMAGE_EDIT_LORA_TRANSFORMER_PREFIX,
)
from invokeai.backend.patches.lora_conversions.qwen_image_lora_conversion_utils import (
_convert_kohya_key,
is_st... | 150 | 6,310 |
InvokeAI | tests/backend/patches/lora_conversions/test_wan_lora_conversion_utils.py | .py | """Tests for Wan LoRA state-dict conversion to ModelPatchRaw."""
import torch
from invokeai.backend.patches.lora_conversions.wan_lora_constants import WAN_LORA_TRANSFORMER_PREFIX
from invokeai.backend.patches.lora_conversions.wan_lora_conversion_utils import (
_kohya_layer_to_diffusers_path,
_native_layer_pat... | 176 | 8,833 |
InvokeAI | tests/backend/patches/lora_conversions/test_flux_onetrainer_lora_conversion_utils.py | .py | import pytest
from invokeai.backend.patches.lora_conversions.flux_lora_constants import (
FLUX_LORA_CLIP_PREFIX,
FLUX_LORA_T5_PREFIX,
FLUX_LORA_TRANSFORMER_PREFIX,
)
from invokeai.backend.patches.lora_conversions.flux_onetrainer_lora_conversion_utils import (
is_state_dict_likely_in_flux_onetrainer_for... | 78 | 3,277 |
InvokeAI | tests/backend/patches/lora_conversions/test_krea2_lora_conversion_utils.py | .py | import pytest
import torch
from invokeai.backend.patches.layers.dora_layer import DoRALayer
from invokeai.backend.patches.layers.lora_layer import LoRALayer
from invokeai.backend.patches.lora_conversions.krea2_lora_constants import (
KREA2_LORA_QWEN3VL_PREFIX,
KREA2_LORA_TRANSFORMER_PREFIX,
)
from invokeai.bac... | 253 | 11,738 |
InvokeAI | tests/backend/patches/lora_conversions/test_kohya_key_utils.py | .py | import pytest
from invokeai.backend.patches.lora_conversions.kohya_key_utils import (
INDEX_PLACEHOLDER,
ParsingTree,
generate_kohya_parsing_tree_from_keys,
insert_periods_into_kohya_key,
)
def test_insert_periods_into_kohya_key():
"""Test that insert_periods_into_kohya_key() correctly inserts pe... | 97 | 2,824 |
InvokeAI | tests/backend/patches/lora_conversions/test_flux_control_lora_conversion_utils.py | .py | import pytest
import torch
from invokeai.backend.patches.lora_conversions.flux_control_lora_utils import (
is_state_dict_likely_flux_control,
lora_model_from_flux_control_state_dict,
)
from invokeai.backend.patches.lora_conversions.flux_lora_constants import FLUX_LORA_TRANSFORMER_PREFIX
from tests.backend.patc... | 72 | 3,457 |
InvokeAI | tests/backend/patches/lora_conversions/test_flux_kohya_lora_conversion_utils.py | .py | import accelerate
import pytest
import torch
from invokeai.backend.flux.model import Flux
from invokeai.backend.flux.util import get_flux_transformers_params
from invokeai.backend.model_manager.taxonomy import FluxVariantType
from invokeai.backend.patches.lora_conversions.flux_kohya_lora_conversion_utils import (
... | 117 | 5,217 |
InvokeAI | tests/backend/patches/lora_conversions/test_flux_xlabs_lora_conversion_utils.py | .py | import accelerate
import pytest
import torch
from invokeai.backend.flux.model import Flux
from invokeai.backend.flux.util import get_flux_transformers_params
from invokeai.backend.model_manager.taxonomy import FluxVariantType
from invokeai.backend.patches.lora_conversions.flux_lora_constants import FLUX_LORA_TRANSFORM... | 100 | 4,665 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/flux_lora_diffusers_no_proj_mlp_format.py | .py | # A sample state dict in the Diffusers FLUX LoRA format without .proj_mlp layers.
# This format was added in response to https://github.com/invoke-ai/InvokeAI/issues/7129
state_dict_keys = {
"transformer.single_transformer_blocks.0.attn.to_k.lora_A.weight": [16, 3072],
"transformer.single_transformer_blocks.0.a... | 689 | 56,133 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/anima_lora_kohya_format.py | .py | # A sample state dict in the Kohya Anima LoRA format.
# These keys are based on Anima LoRAs targeting the Cosmos Predict2 DiT transformer.
# Keys follow the pattern: lora_unet_blocks_{N}_{component}.{suffix}
state_dict_keys: dict[str, list[int]] = {
# Block 0 - cross attention
"lora_unet_blocks_0_cross_attn_k_p... | 43 | 2,536 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/flux_lora_xlabs_format.py | .py | # A sample state dict in the xlabs FLUX LoRA format.
# The xlabs format uses:
# - lora1 for image attention stream (img_attn)
# - lora2 for text attention stream (txt_attn)
# - qkv for query/key/value projection
# - proj for output projection
state_dict_keys = {
"double_blocks.0.processor.proj_lora1.down.weight": [... | 33 | 1,869 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/flux_lora_kohya_with_te1_format.py | .py | # A sample state dict in the Kohya FLUX LoRA format that patches both the transformer and CLIP text encoder.
# These keys are based on the LoRA model here:
# https://huggingface.co/cocktailpeanut/optimus
state_dict_keys = {
"lora_te1_text_model_encoder_layers_0_mlp_fc1.alpha": [],
"lora_te1_text_model_encoder_l... | 1,134 | 77,874 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/utils.py | .py | import torch
def keys_to_mock_state_dict(keys: dict[str, list[int]]) -> dict[str, torch.Tensor]:
state_dict: dict[str, torch.Tensor] = {}
for k, shape in keys.items():
state_dict[k] = torch.empty(shape)
return state_dict
| 9 | 243 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/qwen_image_lora_kohya_format.py | .py | # Kohya-format Qwen Image LoRA state dict keys.
# Keys use the pattern: lora_unet_transformer_blocks_{N}_{sub_module}.{param}
# where sub_module uses underscores instead of dots.
state_dict_keys: dict[str, list[int]] = {
# Block 0 - attention projections (LoKR format)
"lora_unet_transformer_blocks_0_attn_to_k.... | 35 | 2,007 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/anima_lora_lokr_format.py | .py | # A sample state dict in the LoKR Anima LoRA format (with DoRA).
# Some Anima LoRAs use LoKR weights (lokr_w1/lokr_w2) combined with DoRA (dora_scale).
# The dora_scale should be stripped from LoKR layers during conversion.
state_dict_keys: dict[str, list[int]] = {
# Block 0 - cross attention with LoKR + DoRA
"... | 19 | 1,097 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/flux_dora_onetrainer_format.py | .py | # A sample state dict in the OneTrainer FLUX DoRA format.
# This state dict is based on the ball_flux.safetensors file from here:
# https://github.com/invoke-ai/InvokeAI/issues/6912
state_dict_keys = {
"lora_te1_text_model_encoder_layers_0_mlp_fc1.alpha": [],
"lora_te1_text_model_encoder_layers_0_mlp_fc1.dora_s... | 2,030 | 163,932 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/flux_lora_kohya_format.py | .py | # A sample state dict in the Kohya FLUX LoRA format.
# These keys are based on the LoRA model here:
# https://civitai.com/models/159333/pokemon-trainer-sprite-pixelart?modelVersionId=779247
state_dict_keys = {
"lora_unet_double_blocks_0_img_attn_proj.alpha": [],
"lora_unet_double_blocks_0_img_attn_proj.lora_dow... | 918 | 61,344 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/anima_lora_peft_format.py | .py | # A sample state dict in the diffusers PEFT Anima LoRA format.
# Keys follow the pattern: diffusion_model.blocks.{N}.{component}.lora_{A|B}.weight
state_dict_keys: dict[str, list[int]] = {
# Block 0 - cross attention
"diffusion_model.blocks.0.cross_attn.k_proj.lora_A.weight": [8, 2048],
"diffusion_model.blo... | 20 | 1,156 |
InvokeAI | tests/backend/patches/lora_conversions/lora_state_dicts/flux_lora_diffusers_base_model_format.py | .py | # A sample state dict in the Diffusers FLUX LoRA format with base_model.model prefix.
# These keys are based on the LoRA model in peft_adapter_model.safetensors
state_dict_keys = {
"base_model.model.proj_out.lora_A.weight": [4, 3072],
"base_model.model.proj_out.lora_B.weight": [64, 4],
"base_model.model.sin... | 767 | 65,851 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.