{"record":{"id":"adc84d21cf1c25ff","repo":"invoke-ai/InvokeAI","slug":"invalid-embeddings-file-file-path-name","errorCode":null,"errorMessage":"Invalid embeddings file: {file_path.name}","messagePattern":"Invalid embeddings file: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/textual_inversion.py","lineNumber":65,"sourceCode":"\n        # v3 (easynegative)\n        elif \"emb_params\" in state_dict:\n            result.embedding = state_dict[\"emb_params\"]\n\n        # v5(sdxl safetensors file)\n        elif \"clip_g\" in state_dict and \"clip_l\" in state_dict:\n            result.embedding = state_dict[\"clip_g\"]\n            result.embedding_2 = state_dict[\"clip_l\"]\n\n        # v4(diffusers bin files)\n        else:\n            result.embedding = next(iter(state_dict.values()))\n\n            if len(result.embedding.shape) == 1:\n                result.embedding = result.embedding.unsqueeze(0)\n\n            if not isinstance(result.embedding, torch.Tensor):\n                raise ValueError(f\"Invalid embeddings file: {file_path.name}\")\n\n        return result\n\n    def to(self, device: Optional[torch.device] = None, dtype: Optional[torch.dtype] = None) -> None:\n        if not torch.cuda.is_available() and not (hasattr(torch, \"xpu\") and torch.xpu.is_available()):\n            return\n        for emb in [self.embedding, self.embedding_2]:\n            if emb is not None:\n                emb.to(device=device, dtype=dtype)\n\n    def calc_size(self) -> int:\n        \"\"\"Get the size of this model in bytes.\"\"\"\n        return calc_tensors_size([self.embedding, self.embedding_2])\n\n\nclass TextualInversionManager(BaseTextualInversionManager):\n    \"\"\"TextualInversionManager implements the BaseTextualInversionManager ABC from the compel library.\"\"\"\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/textual_inversion.py#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the file is a genuine textual-inversion embedding (state_dict containing a tensor value)","Re-download or re-export the embedding from its source","Inspect with torch.load()/safetensors to confirm the value type is torch.Tensor","Regenerate the embedding with a supported tool/version if it was custom-saved"],"exampleFix":"# before\nresult = TextualInversionModel.from_checkpoint(file_path=Path(\"notes.pt\"))\n# after\nsd = torch.load(\"notes.pt\"); assert any(isinstance(v, torch.Tensor) for v in sd.values())\nresult = TextualInversionModel.from_checkpoint(file_path=Path(\"notes.pt\"))","handlingStrategy":"validation","validationCode":"import torch\nfrom pathlib import Path\n\ndef is_valid_embedding_file(path: Path) -> bool:\n    try:\n        if path.suffix == \".safetensors\":\n            from safetensors.torch import load_file\n            sd = load_file(str(path))\n        else:\n            sd = torch.load(path, map_location=\"cpu\")\n        return any(isinstance(v, torch.Tensor) for v in (sd.values() if isinstance(sd, dict) else [sd]))\n    except Exception:\n        return False","typeGuard":"def is_tensor_embedding(value) -> bool:\n    return isinstance(value, torch.Tensor)","tryCatchPattern":"try:\n    emb = TextualInversionModel.from_checkpoint(file_path=path)\nexcept ValueError as e:\n    if \"Invalid embeddings file\" in str(e):\n        log.error(f\"{path} is not a valid embeddings checkpoint\")\n    raise","preventionTips":["Only point embeddings config at files produced by supported TI trainers","Validate checkpoint contents with torch.load before registering models","Re-download corrupted files and verify checksums/hashes","Keep embeddings in .pt/.safetensors formats from known-good sources"],"tags":["validation","embeddings","torch","model-loading"],"backgroundTag":"invalid-model-checkpoint","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}