From 62da1aaf280f9094ad20361299d34293c36aa66a Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Sat, 14 Sep 2024 00:08:44 +0900 Subject: [PATCH] use empty_like to reduce model loading time --- modules/sd_disable_initialization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sd_disable_initialization.py b/modules/sd_disable_initialization.py index 273a7edd8..e521780e2 100644 --- a/modules/sd_disable_initialization.py +++ b/modules/sd_disable_initialization.py @@ -188,7 +188,7 @@ class LoadStateDictOnMeta(ReplaceHelper): if param.is_meta: dtype = sd_param.dtype if sd_param is not None else param.dtype - module._parameters[name] = torch.nn.parameter.Parameter(torch.zeros_like(param, device=device, dtype=dtype), requires_grad=param.requires_grad) + module._parameters[name] = torch.nn.parameter.Parameter(torch.empty_like(param, device=device, dtype=dtype), requires_grad=param.requires_grad) for name in module._buffers: key = prefix + name