{"record":{"id":"3d3171a7d2cb45b4","repo":"lllyasviel/Fooocus","slug":"invalid-style-model","errorCode":null,"errorMessage":"invalid style model {}","messagePattern":"invalid style model (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ldm_patched/modules/sd.py","lineNumber":296,"sourceCode":"\n    def get_sd(self):\n        return self.first_stage_model.state_dict()\n\nclass StyleModel:\n    def __init__(self, model, device=\"cpu\"):\n        self.model = model\n\n    def get_cond(self, input):\n        return self.model(input.last_hidden_state)\n\n\ndef load_style_model(ckpt_path):\n    model_data = ldm_patched.modules.utils.load_torch_file(ckpt_path, safe_load=True)\n    keys = model_data.keys()\n    if \"style_embedding\" in keys:\n        model = ldm_patched.t2ia.adapter.StyleAdapter(width=1024, context_dim=768, num_head=8, n_layes=3, num_token=8)\n    else:\n        raise Exception(\"invalid style model {}\".format(ckpt_path))\n    model.load_state_dict(model_data)\n    return StyleModel(model)\n\n\ndef load_clip(ckpt_paths, embedding_directory=None):\n    clip_data = []\n    for p in ckpt_paths:\n        clip_data.append(ldm_patched.modules.utils.load_torch_file(p, safe_load=True))\n\n    class EmptyClass:\n        pass\n\n    for i in range(len(clip_data)):\n        if \"transformer.resblocks.0.ln_1.weight\" in clip_data[i]:\n            clip_data[i] = ldm_patched.modules.utils.transformers_convert(clip_data[i], \"\", \"text_model.\", 32)\n\n    clip_target = EmptyClass()\n    clip_target.params = {}","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/modules/sd.py#L278-L314","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"from ldm_patched.modules.utils import load_torch_file\n\nsd = load_torch_file(path, safe_load=True)\n# before: any file without 'style_embedding' -> Exception: invalid style model\n# after: gate the call\nif 'style_embedding' not in sd:\n    raise SystemExit(f'{path} is not a T2I style model')\nstyle_model = ldm_patched.modules.sd.load_style_model(path)","handlingStrategy":"validation","validationCode":"from ldm_patched.modules.utils import load_torch_file\n\ndef is_style_model(path):\n    try:\n        sd = load_torch_file(path, safe_load=True)\n    except Exception:\n        return False\n    return 'style_embedding' in sd\n\nif not is_style_model(user_path):\n    skip_style_model(user_path)","typeGuard":"def is_style_model_state(sd: dict) -> bool:\n    return isinstance(sd, dict) and 'style_embedding' in sd","tryCatchPattern":"try:\n    style = ldm_patched.modules.sd.load_style_model(path)\nexcept Exception as e:\n    if 'invalid style model' in str(e):\n        show_hint(f'{path} is not a T2I style model (missing style_embedding key)')\n    else:\n        raise","preventionTips":["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"],"tags":["style-model","t2i-adapter","invalid-file","model-loading","validation"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}