{"record":{"id":"5461dd271fcf36bd","repo":"lllyasviel/Fooocus","slug":"error-could-not-detect-model-type-of","errorCode":null,"errorMessage":"ERROR: Could not detect model type of: {}","messagePattern":"ERROR: Could not detect model type of: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"ldm_patched/modules/sd.py","lineNumber":453,"sourceCode":"    vae = None\n    vae_filename = None\n    model = None\n    model_patcher = None\n    clip_target = None\n\n    parameters = ldm_patched.modules.utils.calculate_parameters(sd, \"model.diffusion_model.\")\n    unet_dtype = model_management.unet_dtype(model_params=parameters)\n    load_device = model_management.get_torch_device()\n    manual_cast_dtype = model_management.unet_manual_cast(unet_dtype, load_device)\n\n    class WeightsLoader(torch.nn.Module):\n        pass\n\n    model_config = model_detection.model_config_from_unet(sd, \"model.diffusion_model.\", unet_dtype)\n    model_config.set_manual_cast(manual_cast_dtype)\n\n    if model_config is None:\n        raise RuntimeError(\"ERROR: Could not detect model type of: {}\".format(ckpt_path))\n\n    if model_config.clip_vision_prefix is not None:\n        if output_clipvision:\n            clipvision = clip_vision.load_clipvision_from_sd(sd, model_config.clip_vision_prefix, True)\n\n    if output_model:\n        inital_load_device = model_management.unet_inital_load_device(parameters, unet_dtype)\n        offload_device = model_management.unet_offload_device()\n        model = model_config.get_model(sd, \"model.diffusion_model.\", device=inital_load_device)\n        model.load_model_weights(sd, \"model.diffusion_model.\")\n\n    if output_vae:\n        if vae_filename_param is None:\n            vae_sd = ldm_patched.modules.utils.state_dict_prefix_replace(sd, {\"first_stage_model.\": \"\"}, filter_keys=True)\n            vae_sd = model_config.process_vae_state_dict(vae_sd)\n        else:\n            vae_sd = ldm_patched.modules.utils.load_torch_file(vae_filename_param)\n            vae_filename = vae_filename_param","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/modules/sd.py#L435-L471","documentation":"In load_checkpoint_guess_config, model_detection.model_config_from_unet inspects the 'model.diffusion_model.' keys to fingerprint the architecture (SD1.x/SD2.x/SDXL etc.). If no known UNet signature matches, the returned config is None and this RuntimeError is raised: the checkpoint's UNet layout is not recognized by this version of ldm_patched. (Note the code calls model_config.set_manual_cast before the None check, so in practice a None config usually surfaces as an AttributeError first in this vendored copy — the RuntimeError is the intended signal.)","triggerScenarios":"Pointing load_checkpoint_guess_config at a non-checkpoint file (a bare VAE, LoRA, or CLIP), or at a checkpoint whose UNet uses an architecture this ldm_patched snapshot does not know (e.g. SD3/Flux-style UNet in an older Fooocus). Also fires for heavily renamed/merged checkpoints whose diffusion_model keys were altered.","commonSituations":"User selects a VAE file in the checkpoint slot; user tries a brand-new community model with an old Fooocus build; key renaming during a merge breaks the fingerprint regexes.","solutions":["Confirm the file is a full diffusion checkpoint containing 'model.diffusion_model.*' keys, and put VAEs/LoRAs in their own slots","Update Fooocus / ldm_patched to a version that supports the model architecture","Re-download the checkpoint in case of corruption, and re-merge with standard key names if you produced it yourself"],"exampleFix":"from safetensors import safe_open\n\nwith safe_open(path, framework='pt') as f:\n    has_unet = any(k.startswith('model.diffusion_model.') for k in f.keys())\n# before: loading a bare VAE -> RuntimeError: Could not detect model type\n# after:\nif not has_unet:\n    raise SystemExit(f'{path} has no model.diffusion_model.* keys; not a diffusion checkpoint')\nmodel = ldm_patched.modules.sd.load_checkpoint_guess_config(path)","handlingStrategy":"validation","validationCode":"from safetensors import safe_open\nimport os\n\ndef looks_like_diffusion_checkpoint(path):\n    if os.path.splitext(path)[1] not in ('.safetensors', '.ckpt', '.pt'):\n        return False\n    try:\n        with safe_open(path, framework='pt') as f:\n            return any(k.startswith('model.diffusion_model.') for k in f.keys())\n    except Exception:\n        return False\n\nif not looks_like_diffusion_checkpoint(path):\n    reject_file(path, 'not a diffusion checkpoint')","typeGuard":null,"tryCatchPattern":"try:\n    out = ldm_patched.modules.sd.load_checkpoint_guess_config(path, output_vae=True, output_clip=True)\nexcept Exception as e:\n    msg = str(e)\n    if 'Could not detect model type' in msg or ('NoneType' in msg and 'set_manual_cast' in msg):\n        raise ModelFormatError(f'{path}: unsupported/unknown UNet architecture - update Fooocus or use a standard checkpoint') from e\n    raise","preventionTips":["Validate that model.diffusion_model.* keys exist before loading user files","Keep Fooocus/ldm_patched updated when adopting newly released architectures","Use the correct input slot per file type (checkpoint vs VAE vs LoRA)"],"tags":["checkpoint","model-detection","unet","unsupported-model","model-loading"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}