invoke-ai/InvokeAI · error · ValueError

Invalid embeddings file: {file_path.name}

Error message

Invalid embeddings file: {file_path.name}

What it means

TextualInversionModel.from_checkpoint validates that the loaded embedding is a torch.Tensor before returning. If the state_dict's first value is not a tensor, the checkpoint is not a recognized textual-inversion/embeddings format and this ValueError is thrown.

Source

Thrown at invokeai/backend/textual_inversion.py:65

        # v3 (easynegative)
        elif "emb_params" in state_dict:
            result.embedding = state_dict["emb_params"]

        # v5(sdxl safetensors file)
        elif "clip_g" in state_dict and "clip_l" in state_dict:
            result.embedding = state_dict["clip_g"]
            result.embedding_2 = state_dict["clip_l"]

        # v4(diffusers bin files)
        else:
            result.embedding = next(iter(state_dict.values()))

            if len(result.embedding.shape) == 1:
                result.embedding = result.embedding.unsqueeze(0)

            if not isinstance(result.embedding, torch.Tensor):
                raise ValueError(f"Invalid embeddings file: {file_path.name}")

        return result

    def to(self, device: Optional[torch.device] = None, dtype: Optional[torch.dtype] = None) -> None:
        if not torch.cuda.is_available() and not (hasattr(torch, "xpu") and torch.xpu.is_available()):
            return
        for emb in [self.embedding, self.embedding_2]:
            if emb is not None:
                emb.to(device=device, dtype=dtype)

    def calc_size(self) -> int:
        """Get the size of this model in bytes."""
        return calc_tensors_size([self.embedding, self.embedding_2])


class TextualInversionManager(BaseTextualInversionManager):
    """TextualInversionManager implements the BaseTextualInversionManager ABC from the compel library."""

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Verify the file is a genuine textual-inversion embedding (state_dict containing a tensor value)
  2. Re-download or re-export the embedding from its source
  3. Inspect with torch.load()/safetensors to confirm the value type is torch.Tensor
  4. Regenerate the embedding with a supported tool/version if it was custom-saved

Example fix

# before
result = TextualInversionModel.from_checkpoint(file_path=Path("notes.pt"))
# after
sd = torch.load("notes.pt"); assert any(isinstance(v, torch.Tensor) for v in sd.values())
result = TextualInversionModel.from_checkpoint(file_path=Path("notes.pt"))
Defensive patterns

Strategy: validation

Validate before calling

import torch
from pathlib import Path

def is_valid_embedding_file(path: Path) -> bool:
    try:
        if path.suffix == ".safetensors":
            from safetensors.torch import load_file
            sd = load_file(str(path))
        else:
            sd = torch.load(path, map_location="cpu")
        return any(isinstance(v, torch.Tensor) for v in (sd.values() if isinstance(sd, dict) else [sd]))
    except Exception:
        return False

Type guard

def is_tensor_embedding(value) -> bool:
    return isinstance(value, torch.Tensor)

Try / catch

try:
    emb = TextualInversionModel.from_checkpoint(file_path=path)
except ValueError as e:
    if "Invalid embeddings file" in str(e):
        log.error(f"{path} is not a valid embeddings checkpoint")
    raise

Prevention

When it happens

Trigger: Calling TextualInversionModel.from_checkpoint() on a file whose state_dict's first value is not a torch.Tensor — e.g. a pickled dict of arbitrary objects, a wrong file passed as --embedding, or a corrupted checkpoint.

Common situations: Pointing InvokeAI at a non-embedding file (.safetensors/.pt of unrelated weights), downloading a corrupt or placeholder file, or using an embeddings file saved with an unsupported serialization layout.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/adc84d21cf1c25ff. Report an issue: GitHub.