AUTOMATIC1111/stable-diffusion-webui · error · Exception
Couldn't identify {filename} as neither textual inversion em
Error message
Couldn't identify {filename} as neither textual inversion embedding nor diffuser concept. What it means
textual_inversion.py's embedding loader inspects the torch-loaded object to decide what it is: SD1.x embeddings (string->tensor dict), SD2/klg, clip_g/clip_l pairs, or single-tensor diffuser concepts. If the data matches none of these shapes (not a dict of tensors, not the expected keys), it raises this 'couldn't identify' error before constructing the Embedding.
Source
Thrown at modules/textual_inversion/textual_inversion.py:310
emb = next(iter(param_dict.items()))[1]
vec = emb.detach().to(devices.device, dtype=torch.float32)
shape = vec.shape[-1]
vectors = vec.shape[0]
elif type(data) == dict and 'clip_g' in data and 'clip_l' in data: # SDXL embedding
vec = {k: v.detach().to(devices.device, dtype=torch.float32) for k, v in data.items()}
shape = data['clip_g'].shape[-1] + data['clip_l'].shape[-1]
vectors = data['clip_g'].shape[0]
elif type(data) == dict and type(next(iter(data.values()))) == torch.Tensor: # diffuser concepts
assert len(data.keys()) == 1, 'embedding file has multiple terms in it'
emb = next(iter(data.values()))
if len(emb.shape) == 1:
emb = emb.unsqueeze(0)
vec = emb.detach().to(devices.device, dtype=torch.float32)
shape = vec.shape[-1]
vectors = vec.shape[0]
else:
raise Exception(f"Couldn't identify {filename} as neither textual inversion embedding nor diffuser concept.")
embedding = Embedding(vec, name)
embedding.step = data.get('step', None)
embedding.sd_checkpoint = data.get('sd_checkpoint', None)
embedding.sd_checkpoint_name = data.get('sd_checkpoint_name', None)
embedding.vectors = vectors
embedding.shape = shape
if filepath:
embedding.filename = filepath
embedding.set_hash(hashes.sha256(filepath, "textual_inversion/" + name) or '')
return embedding
def write_loss(log_directory, filename, step, epoch_len, values):
if shared.opts.training_write_csv_every == 0:
return
View on GitHub (pinned to 82a973c043)
Solutions
- Verify the file is genuinely a textual-inversion embedding (small, usually < 1 MB, contains '<concept>' string keys mapping to tensors)
- Re-download the embedding from its original source; compare file size/hash against the publisher
- If it is a Kohya-style file, convert it first or use a trainer/tool that emits the dict-of-tensors format
- Inspect locally: d = torch.load(f, map_location='cpu'); print(type(d), list(d)[:5]) — the loader needs dict values of torch.Tensor
Example fix
# before: passing a LoRA/unknown .pt into the embedding loader
# after: check the shape before loading
import torch
d = torch.load(path, map_location='cpu')
if not (isinstance(d, dict) and any(isinstance(v, torch.Tensor) for v in d.values())):
raise SystemExit(f'{path} is not a textual-inversion embedding') Defensive patterns
Strategy: type-guard
Validate before calling
import torch
def looks_like_embedding(path):
d = torch.load(path, map_location='cpu')
if not isinstance(d, dict):
return False
vals = list(d.values())
return len(vals) > 0 and all(isinstance(v, torch.Tensor) for v in vals[:3]) or 'clip_g' in d Type guard
def is_ti_embedding(data) -> bool:
if not isinstance(data, dict):
return False
if 'clip_g' in data and 'clip_l' in data:
return True
vals = list(data.values())
return bool(vals) and isinstance(vals[0], torch.Tensor) Try / catch
try:
ti_manager.load_from_file(path)
except Exception as e:
if 'Could not identify' in str(e) or "Couldn't identify" in str(e):
log.warning('skipping non-embedding file %s', path)
else:
raise Prevention
- Sanity-check file size (< a few MB) before treating a .pt as an embedding
- Bulk loaders should catch and skip unrecognized files instead of aborting the scan
- Keep embeddings, LoRAs, and checkpoints in their designated directories
When it happens
Trigger: Loading a .pt/.bin file through the train/embedding tab whose pickled content is e.g. a raw state dict with unexpected keys, a whole model object, an empty dict, or a numpy array instead of torch.Tensor; also truncated downloads that unpickle to garbage.
Common situations: Downloading a LoRA or full checkpoint and renaming it .pt as if it were an embedding; embeddings saved by incompatible forks (Kohya, old A1111); partial/interrupted downloads.
Related errors
- Invalid learning rate schedule. It should be a number or, fo
- Unknown checkpoint: {x}
- Lora layer {self.network_key} matched a layer with unsupport
- Could not find a module type (out of {', '.join([x.__class__
- Sampler not found
AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14).
Data as JSON: /api/errors/20cc3df00b113b95.
Report an issue: GitHub.