Skip to content

Commit d4c3c10

Browse files
authored
lora : raise error if lm_head is ignored (#9103)
* lora : raise error if lm_head is ignored * fix style * clarify comment
1 parent 2a82511 commit d4c3c10

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

convert_lora_to_gguf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,13 @@ def get_tensors(self) -> Iterator[tuple[str, Tensor]]:
363363
yield (name, cast(torch.Tensor, LoraTorchTensor(tensor.A, tensor.B)))
364364

365365
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
366-
dest = super().modify_tensors(data_torch, name, bid)
366+
dest = list(super().modify_tensors(data_torch, name, bid))
367+
# some archs may have the same tensor for lm_head and output (tie word embeddings)
368+
# in this case, adapters targeting lm_head will fail when using llama-export-lora
369+
# therefore, we ignore them for now
370+
# see: https://github.com/ggerganov/llama.cpp/issues/9065
371+
if name == "lm_head.weight" and len(dest) == 0:
372+
raise ValueError("lm_head is present in adapter, but is ignored in base model")
367373
for dest_name, dest_data in dest:
368374
assert isinstance(dest_data, LoraTorchTensor)
369375
lora_a, lora_b = dest_data.get_lora_A_B()

0 commit comments

Comments
 (0)