lllyasviel/Fooocus · error · Exception
invalid style model {}
Error message
invalid style model {} What it means
load_style_model loads a file with safe_load=True and decides it is a style model ONLY if the key 'style_embedding' is present; any other content raises 'invalid style model'. Style models here are T2I-Adapter StyleAdapter checkpoints (the Fooocus/ComfyUI style-model format), and the key check is the entire format validation.
Source
Thrown at ldm_patched/modules/sd.py:296
def get_sd(self):
return self.first_stage_model.state_dict()
class StyleModel:
def __init__(self, model, device="cpu"):
self.model = model
def get_cond(self, input):
return self.model(input.last_hidden_state)
def load_style_model(ckpt_path):
model_data = ldm_patched.modules.utils.load_torch_file(ckpt_path, safe_load=True)
keys = model_data.keys()
if "style_embedding" in keys:
model = ldm_patched.t2ia.adapter.StyleAdapter(width=1024, context_dim=768, num_head=8, n_layes=3, num_token=8)
else:
raise Exception("invalid style model {}".format(ckpt_path))
model.load_state_dict(model_data)
return StyleModel(model)
def load_clip(ckpt_paths, embedding_directory=None):
clip_data = []
for p in ckpt_paths:
clip_data.append(ldm_patched.modules.utils.load_torch_file(p, safe_load=True))
class EmptyClass:
pass
for i in range(len(clip_data)):
if "transformer.resblocks.0.ln_1.weight" in clip_data[i]:
clip_data[i] = ldm_patched.modules.utils.transformers_convert(clip_data[i], "", "text_model.", 32)
clip_target = EmptyClass()
clip_target.params = {}View on GitHub (pinned to ae05379cc9)
Solutions
- Verify the file is an actual T2I-Adapter style model (e.g. the official 'style' T2I adapters used by Fooocus) and not a LoRA/CLIP/controlnet
- Load the file and check for the 'style_embedding' key: if absent, it is not this format
- Re-download the style model from a trusted source; a truncated download can also lose keys
Example fix
from ldm_patched.modules.utils import load_torch_file
sd = load_torch_file(path, safe_load=True)
# before: any file without 'style_embedding' -> Exception: invalid style model
# after: gate the call
if 'style_embedding' not in sd:
raise SystemExit(f'{path} is not a T2I style model')
style_model = ldm_patched.modules.sd.load_style_model(path) Defensive patterns
Strategy: validation
Validate before calling
from ldm_patched.modules.utils import load_torch_file
def is_style_model(path):
try:
sd = load_torch_file(path, safe_load=True)
except Exception:
return False
return 'style_embedding' in sd
if not is_style_model(user_path):
skip_style_model(user_path) Type guard
def is_style_model_state(sd: dict) -> bool:
return isinstance(sd, dict) and 'style_embedding' in sd Try / catch
try:
style = ldm_patched.modules.sd.load_style_model(path)
except Exception as e:
if 'invalid style model' in str(e):
show_hint(f'{path} is not a T2I style model (missing style_embedding key)')
else:
raise Prevention
- Only place T2I-Adapter style files in the styles/models folder
- Check for the 'style_embedding' key before passing any user-supplied file
- Keep LoRA/ip-adapter/controlnet files out of the style model slot
When it happens
Trigger: Calling load_style_model(ckpt_path) with a path that is not a T2I style adapter: a LoRA, a CLIP vision model, a full checkpoint, or a random safetensors file. Also fires if the file is a style adapter saved under a different key layout by a newer/older exporter.
Common situations: User drops the wrong file into the style models folder (e.g. mistakes an ip-adapter or controlnet for a style model); file extension is .safetensors but content is a LoRA; drag-and-drop confusion in the Fooocus style model input.
Related errors
- provide num_res_blocks either as an int (globally constant)
- sigma_min and sigma_max must not be 0
- ERROR: Could not detect model type of: {}
- sam model {sam_model} does not exist.
- Folder path is not a valid directory.
AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15).
Data as JSON: /api/errors/3d3171a7d2cb45b4.
Report an issue: GitHub.