Fix dtype mismatch for SparseCtrl and SVD-ControlNet models

load_sparsectrl and load_svdcontrolnet never set controlnet_config["dtype"],
so the control model was built with dtype=None (float32) while the UNet runs
in fp16. This caused "mat1 and mat2 must have the same dtype, but got Half and
Float" at sampling time (notably for .pth/.ckpt SparseCtrl models).

Set controlnet_config["dtype"] = unet_dtype before building the model, matching
the existing ControlNet++ and CtrLoRA loaders and ComfyUI's own controlnet loader.

Fixes #574

Amp-Thread-ID: https://ampcode.com/threads/T-019e947a-9fd3-76df-a847-5eb68d7f18de
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Jedrzej Kosinski
2026-06-04 14:26:17 -07:00
co-authored by Amp
parent b03791e456
commit 71b536c47f
+2
View File
@@ -811,6 +811,7 @@ def load_sparsectrl(ckpt_path: str, controlnet_data: dict[str, Tensor]=None, tim
controlnet_config["operations"] = manual_cast_clean_groupnorm
else:
controlnet_config["operations"] = disable_weight_init_clean_groupnorm
controlnet_config["dtype"] = unet_dtype
controlnet_config.pop("out_channels")
# get proper hint channels
if use_simplified_conditioning_embedding:
@@ -944,6 +945,7 @@ def load_svdcontrolnet(ckpt_path: str, controlnet_data: dict[str, Tensor]=None,
manual_cast_dtype = comfy.model_management.unet_manual_cast(unet_dtype, load_device)
if manual_cast_dtype is not None:
controlnet_config["operations"] = comfy.ops.manual_cast
controlnet_config["dtype"] = unet_dtype
controlnet_config.pop("out_channels")
controlnet_config["hint_channels"] = controlnet_data["{}input_hint_block.0.weight".format(prefix)].shape[1]
control_model = SVDControlNet(**controlnet_config)