Skip to content

Commit

Permalink
scripts : Use mmap in torch load (#4202)
Browse files Browse the repository at this point in the history
* Use mmap in torch load, prefer .bin files when loading

* Revert .bin > .safetensors preference
  • Loading branch information
Galunid authored Nov 25, 2023
1 parent f837c3a commit 1ddb52e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion convert-hf-to-gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_tensors(self) -> Iterator[tuple[str, Tensor]]:
from safetensors import safe_open
ctx = cast(ContextManager[Any], safe_open(self.dir_model / part_name, framework="pt", device="cpu"))
else:
ctx = contextlib.nullcontext(torch.load(self.dir_model / part_name, map_location="cpu"))
ctx = contextlib.nullcontext(torch.load(str(self.dir_model / part_name), map_location="cpu", mmap=True, weights_only=True))

with ctx as model_part:
for name in model_part.keys():
Expand Down

0 comments on commit 1ddb52e

Please sign in to comment.