invoke-ai/InvokeAI · error · NotAMatchError
directory does not contain Gemma2 tokenizer files (tokenizer
Error message
directory does not contain Gemma2 tokenizer files (tokenizer.json/tokenizer.model)
What it means
NotAMatchError raised by Gemma2Encoder_Gemma2Encoder_Config.from_model_on_disk when the model directory contains a valid Gemma2ForCausalLM config.json but no tokenizer.json or tokenizer.model file. PiD later calls AutoTokenizer.from_pretrained on this same directory, so the tokenizer files must live alongside the weights; the config refuses to match a directory that would fail at load time.
Source
Thrown at invokeai/backend/model_manager/configs/gemma2_encoder.py:85
raise NotAMatchError("directory looks like a full diffusers pipeline, not a standalone Gemma2 encoder")
# Architecture marker is the canonical signal.
raise_for_class_name(config_path, {"Gemma2ForCausalLM"})
# Only Gemma-2-2b (2304-dim hidden state) is compatible with PiD's fixed caption projection.
# Reject 9B/27B variants here so they are not offered as compatible encoders and then fail with
# a matrix-shape error deep inside PiD inference.
hidden_size = get_config_dict_or_raise(config_path).get("hidden_size")
if hidden_size != _PID_GEMMA_HIDDEN_SIZE:
raise NotAMatchError(
f"Gemma2 hidden_size {hidden_size} is incompatible with PiD, which requires "
f"{_PID_GEMMA_HIDDEN_SIZE} (Gemma-2-2b); 9B/27B variants are not supported."
)
# Sanity check that tokenizer files live alongside the model (PiD calls
# AutoTokenizer.from_pretrained on the same directory).
if not any((mod.path / f).exists() for f in ("tokenizer.json", "tokenizer.model")):
raise NotAMatchError("directory does not contain Gemma2 tokenizer files (tokenizer.json/tokenizer.model)")
return cls(**override_fields)
def _read_gguf_arch_and_hidden_size(path: Path) -> tuple[str, int | None]:
"""Read (general.architecture, <arch>.embedding_length) from a GGUF file's metadata.
Raises NotAMatchError if the file is not a readable GGUF or is missing the architecture marker.
"""
import gguf
try:
reader = gguf.GGUFReader(path)
except Exception as e:
raise NotAMatchError(f"not a readable GGUF file: {e}") from e
arch_field = reader.fields.get("general.architecture")
if arch_field is None:View on GitHub (pinned to 0b6a024f2f)
Solutions
- Copy tokenizer.json (or tokenizer.model) and tokenizer_config.json from the original HuggingFace repo into the model directory root
- Re-download the full gemma-2-2b-it repo rather than cherry-picking files
- Verify with ls: the directory must contain config.json, model*.safetensors, and tokenizer.json/tokenizer.model at the same level
Example fix
// before
models/gemma-2-2b-it/{config.json, model.safetensors}
// after
models/gemma-2-2b-it/{config.json, model.safetensors, tokenizer.json, tokenizer_config.json} Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def tokenizer_files_present(model_dir: str | Path) -> bool:
d = Path(model_dir)
return any((d / f).exists() for f in ("tokenizer.json", "tokenizer.model")) Type guard
def is_complete_gemma2_dir(p: Path) -> bool:
return p.is_dir() and (p / "config.json").is_file() and tokenizer_files_present(p) Try / catch
try:
add_model_and_import(model_dir)
except NotAMatchError as e:
if "tokenizer" in str(e):
print("Copy tokenizer.json/tokenizer.model from the HuggingFace repo into the model dir") Prevention
- Download the whole HuggingFace repo (huggingface-cli download) instead of cherry-picking files
- After copying models, verify config.json + weights + tokenizer.json/tokenizer.model sit at the same directory level
- Keep tokenizer_config.json too — PiD calls AutoTokenizer.from_pretrained on the directory
When it happens
Trigger: Importing a directory that has config.json + weights but the tokenizer files were deleted, not downloaded, or were saved into a sibling subdirectory instead of the model root.
Common situations: Manually copying only the safetensors and config.json from a HuggingFace repo; a download tool that skips tokenizer assets; hand-assembled model folders; using save_pretrained on a subdirectory while pointing InvokeAI at the parent.
Related errors
- unable to load config file: {config_path_nested} does not ex
- standalone Qwen3-VL encoder directory does not contain token
- Expected PreTrainedTokenizerBase for tokenizer, got {type(to
- Tokenizer returned unexpected types.
- Blend is not supported here - you need to get tokens for eac
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/7c3d5b8a0b611a5d.
Report an issue: GitHub.