{"record":{"id":"d46b4df1004b613d","repo":"invoke-ai/InvokeAI","slug":"provided-model-was-not-a-diffusers-model-pipeline","errorCode":null,"errorMessage":"Provided model was not a diffusers model/pipeline, as expected.","messagePattern":"Provided model was not a diffusers model/pipeline, as expected\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/hidiffusion/hidiffusion.py","lineNumber":2063,"sourceCode":"    generator: torch.Generator | None = None,\n    has_controlnet: bool = False,\n    is_controlnet_text_to_image: bool = False,\n):\n    \"\"\"\n    model: diffusers model. We support SD 1.5, 2.1, XL, XL Turbo.\n\n    apply_raunet: whether to apply RAU-Net\n\n    apply_window_attn: whether to apply MSW-MSA.\n    \"\"\"\n\n    # Make sure the module is not currently patched\n    remove_hidiffusion(model)\n\n    is_diffusers = isinstance_str(model, \"DiffusionPipeline\") or isinstance_str(model, \"ModelMixin\")\n\n    if not is_diffusers:\n        raise RuntimeError(\"Provided model was not a diffusers model/pipeline, as expected.\")\n    else:\n        # Check if the pipeline is a ControlNet pipeline. InvokeAI's modular\n        # denoise passes a bare UNet, so it reports ControlNet separately.\n        has_controlnet = has_controlnet or hasattr(model, \"controlnet\")\n        is_sdxl_controlnet = hasattr(model, \"controlnet\") and isinstance_str(\n            model, \"StableDiffusionXLControlNet\", prefix=True\n        )\n        is_sd_controlnet = hasattr(model, \"controlnet\") and isinstance_str(\n            model, \"StableDiffusionControlNet\", prefix=True\n        )\n\n        # Check for ControlNet Inpaint pipelines\n        is_sdxl_controlnet_inpaint = is_sdxl_controlnet and isinstance_str(model, \"Inpaint\", contains=True)\n        is_sd_controlnet_inpaint = is_sd_controlnet and isinstance_str(model, \"Inpaint\", contains=True)\n\n        if is_sdxl_controlnet_inpaint or is_sd_controlnet_inpaint:\n            # For ControlNet Inpaint pipelines, we don't patch the pipeline class\n            # because they already have all the necessary inpainting logic","sourceCodeStart":2045,"sourceCodeEnd":2081,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/hidiffusion/hidiffusion.py#L2045-L2081","documentation":"apply_hidiffusion (hidiffusion.py:2063) requires the target to be a diffusers DiffusionPipeline or ModelMixin (checked via isinstance_str) because it relies on pipeline attributes like `.unet` and `name_or_path`. Passing anything else — a bare torch module that is not a diffusers ModelMixin, a dict, a wrapper, or None — raises this RuntimeError before any patching.","triggerScenarios":"Calling hidiffusion_patch/apply_hidiffusion with a raw torch.nn.Module UNet that is not a diffusers ModelMixin subclass, a compiled (torch.compile) or DDP-wrapped model whose type no longer reports as DiffusionPipeline/ModelMixin, a None value from a failed pipeline load, or the InvokeAI modular denoise passing an unexpected object.","commonSituations":"Applying HiDiffusion inside custom inference code where the model was already unwrapped/compiled; wrapping the pipeline in a accelerator/distributed wrapper first; typos passing scheduler or text_encoder instead of the pipeline.","solutions":["Pass the diffusers pipeline object itself (e.g. StableDiffusionXLPipeline instance), not an inner component or wrapper.","Apply HiDiffusion before torch.compile/DDP/accelerate wrapping so isinstance checks still match.","Verify the argument is not None — check the from_pretrained call succeeded.","If you only have a bare UNet, wrap/load it via a diffusers pipeline, or use a diffusers ModelMixin subclass."],"exampleFix":"// before\napply_hidiffusion(pipe.unet, apply_raunet=True)\n// after\napply_hidiffusion(pipe, apply_raunet=True, apply_window_attn=True)","handlingStrategy":"type-guard","validationCode":"def is_diffusers_model(model) -> bool:\n    from invokeai.backend.util import isinstance_str\n    return isinstance_str(model, \"DiffusionPipeline\") or isinstance_str(model, \"ModelMixin\")\n\nif not is_diffusers_model(model):\n    raise TypeError(\"Pass the diffusers pipeline, not a wrapped/inner module\")\napply_hidiffusion(model, apply_raunet=True)","typeGuard":"def is_hidiffusion_target(model) -> bool:\n    from invokeai.backend.util import isinstance_str\n    return model is not None and (\n        isinstance_str(model, \"DiffusionPipeline\") or isinstance_str(model, \"ModelMixin\")\n    )","tryCatchPattern":"try:\n    apply_hidiffusion(model, apply_raunet=True, apply_window_attn=True)\nexcept RuntimeError as e:\n    if \"not a diffusers model\" in str(e):\n        logger.error(\"apply_hidiffusion requires the raw diffusers pipeline (pre-compile, pre-wrap)\")\n    else:\n        raise","preventionTips":["Apply HiDiffusion before torch.compile / DDP / accelerate wrapping.","Pass the pipeline object itself, never pipe.unet or a scheduler.","Null-check the model after from_pretrained to avoid passing None.","Avoid custom pipeline wrappers that don't subclass DiffusionPipeline."],"tags":["hidiffusion","type-check","diffusers","api-misuse"],"backgroundTag":"invalid-argument-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}