Skip to content

Commit 534e0b5

Browse files
committed
Fix: Prevent (potential) error in parameter dtype check
Adds a check to ensure the `_keep_in_fp32_modules` attribute exists on a parameter before it is accessed. This prevents a potential `AttributeError`, making the utility function more robust when used with models that do not define this attribute.
1 parent 6f8d800 commit 534e0b5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/diffusers/models/modeling_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ def get_parameter_dtype(parameter: torch.nn.Module) -> torch.dtype:
168168

169169
for name, param in parameter.named_parameters():
170170
last_dtype = param.dtype
171-
if parameter._keep_in_fp32_modules and any(m in name for m in parameter._keep_in_fp32_modules):
171+
if (
172+
hasattr(parameter, "_keep_in_fp32_modules")
173+
and parameter._keep_in_fp32_modules
174+
and any(m in name for m in parameter._keep_in_fp32_modules)
175+
):
172176
continue
173177

174178
if param.is_floating_point():

0 commit comments

Comments
 (0)