fix: support bf16 lora weights (#82)
This commit is contained in:
parent
ae1d5dcebb
commit
c874063408
@ -192,7 +192,7 @@ def preprocess(state_dict):
|
|||||||
if skip:
|
if skip:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# # convert BF16 to FP16
|
# convert BF16 to FP16
|
||||||
if w.dtype == torch.bfloat16:
|
if w.dtype == torch.bfloat16:
|
||||||
w = w.to(torch.float16)
|
w = w.to(torch.float16)
|
||||||
|
|
||||||
@ -342,6 +342,11 @@ def preprocess_lora(state_dict):
|
|||||||
for name, w in state_dict.items():
|
for name, w in state_dict.items():
|
||||||
if not isinstance(w, torch.Tensor):
|
if not isinstance(w, torch.Tensor):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# convert BF16 to FP16
|
||||||
|
if w.dtype == torch.bfloat16:
|
||||||
|
w = w.to(torch.float16)
|
||||||
|
|
||||||
name_without_network_parts, network_part = name.split(".", 1)
|
name_without_network_parts, network_part = name.split(".", 1)
|
||||||
new_name_without_network_parts = convert_diffusers_name_to_compvis(name_without_network_parts)
|
new_name_without_network_parts = convert_diffusers_name_to_compvis(name_without_network_parts)
|
||||||
if new_name_without_network_parts == None:
|
if new_name_without_network_parts == None:
|
||||||
@ -421,6 +426,7 @@ def convert(model_path, out_type = None, out_file=None, lora=False):
|
|||||||
continue
|
continue
|
||||||
if name in unused_tensors:
|
if name in unused_tensors:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
data = state_dict[name].numpy()
|
data = state_dict[name].numpy()
|
||||||
|
|
||||||
n_dims = len(data.shape)
|
n_dims = len(data.shape)
|
||||||
|
Loading…
Reference in New Issue
Block a user