Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Fix bias dtype issue in mixed ops. (#11293)

comfyanonymousc5a47a16924e
diff --git a/comfy/ops.py b/comfy/ops.py
index 6ae6e791a..0384c8717 100644
--- a/comfy/ops.py
+++ b/comfy/ops.py
@@ -504,10 +504,7 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec
self.in_features = in_features
self.out_features = out_features
- if bias:
- self.bias = torch.nn.Parameter(torch.empty(out_features, **self.factory_kwargs))
- else:
- self.register_parameter("bias", None)
+ self._has_bias = bias
self.tensor_class = None
self._full_precision_mm = MixedPrecisionOps._full_precision_mm
@@ -536,6 +533,10 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec
self.weight = torch.nn.Parameter(weight.to(device=device, dtype=dtype), requires_grad=False)
if dtype != MixedPrecisionOps._compute_dtype:
self.comfy_cast_weights = True
+ if self._has_bias:
+ self.bias = torch.nn.Parameter(torch.empty(self.out_features, device=device, dtype=dtype))
+ else:
+ self.register_parameter("bias", None)
else:
self.quant_format = layer_conf.get("format", None)
if not self._full_precision_mm:
@@ -565,6 +566,11 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec
requires_grad=False
)
+ if self._has_bias:
+ self.bias = torch.nn.Parameter(torch.empty(self.out_features, device=device, dtype=MixedPrecisionOps._compute_dtype))
+ else:
+ self.register_parameter("bias", None)
+
for param_name in qconfig["parameters"]:
param_key = f"{prefix}{param_name}"
_v = state_dict.pop(param_key, None)