* Use mmap in torch load, prefer .bin files when loading
* Revert .bin > .safetensors preference
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():