Skip to content

Commit

Permalink
py : cast lora_alpha to int in convert-lora-to-ggml (#1170)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavol Rusnak <[email protected]>
  • Loading branch information
ostix360 and prusnak authored Apr 25, 2023
1 parent bb98e77 commit 667c501
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions convert-lora-to-ggml.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ def translate_tensor_name(t: str) -> str:
def write_file_header(fout: TextIO, params: Dict[str, Any]) -> None:
fout.write(b"ggla"[::-1]) # magic (ggml lora)
fout.write(struct.pack("i", 1)) # file version
fout.write(struct.pack("ii", params["r"], params["lora_alpha"]))
fout.write(struct.pack("i", params["r"]))
# https://opendelta.readthedocs.io/en/latest/modules/deltas.html says that `lora_alpha` is an int
# but some models ship a float value instead
# let's convert to int, but fail if lossless conversion is not possible
assert int(params["lora_alpha"]) == params["lora_alpha"], "cannot convert float to int losslessly"
fout.write(struct.pack("i", int(params["lora_alpha"])))


def write_tensor_header(
Expand Down Expand Up @@ -89,7 +94,7 @@ def write_tensor_header(
print(f"Error: unsupported adapter type {params['peft_type']}, expected LORA")
sys.exit(1)

if params["fan_in_fan_out"] == True:
if params["fan_in_fan_out"] is True:
print("Error: param fan_in_fan_out is not supported")
sys.exit(1)

Expand Down

0 comments on commit 667c501

Please sign in to comment.