use empty_like to reduce model loading time

This commit is contained in:
Won-Kyu Park 2024-09-14 00:08:44 +09:00
parent 5865da28d1
commit 62da1aaf28
No known key found for this signature in database
GPG Key ID: 53AA79C8C9535D15

View File

@ -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