Skip to content

Commit 05490fa

Browse files
add safetensors support to convert-lora-to-ggml.py (ggml-org#5062)
* add safetensors support to convert-lora-to-ggml.py * Update convert-lora-to-ggml.py Remove white space in line 69.
1 parent 6c5629d commit 05490fa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: convert-lora-to-ggml.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ def write_tensor_header(fout: BinaryIO, name: str, shape: Sequence[int], data_ty
5959
input_model = os.path.join(sys.argv[1], "adapter_model.bin")
6060
output_path = os.path.join(sys.argv[1], "ggml-adapter-model.bin")
6161

62-
model = torch.load(input_model, map_location="cpu")
62+
if os.path.exists(input_model):
63+
model = torch.load(input_model, map_location="cpu")
64+
else:
65+
input_model = os.path.join(sys.argv[1], "adapter_model.safetensors")
66+
# lazy import load_file only if lora is in safetensors format.
67+
from safetensors.torch import load_file
68+
model = load_file(input_model, device="cpu")
69+
6370
arch_name = sys.argv[2] if len(sys.argv) == 3 else "llama"
6471

6572
if arch_name not in gguf.MODEL_ARCH_NAMES.values():

0 commit comments

Comments
 (0)