CoolFace
Modelpublic

LoupGarou/WizardCoder-Guanaco-15B-V1.1

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
12likes185downloads
split_pytorch.py25 linesDownload Raw Back to root
1import os2import torch3import json4 5# load your large model6model = SomeLargeModel('/mnt/e/ai_cache/output/wizardcoder_mmlu_2/merged')7model.load_state_dict(torch.load('pytorch_model.bin'))8 9# save each tensor to a separate file and record the mapping in the index10state_dict = model.state_dict()11index = {"metadata": {"total_size": 0}, "weight_map": {}}12i = 113total_files = len(state_dict.keys())14 15for key, tensor in state_dict.items():16    chunk_file = f'pytorch_model-{str(i).zfill(5)}-of-{str(total_files).zfill(5)}.bin'17    torch.save({key: tensor}, chunk_file)18    index["weight_map"][key] = chunk_file19    index["metadata"]["total_size"] += tensor.nelement() * tensor.element_size()20    i += 121 22# save the index23with open('pytorch_model.bin.index', 'w') as f:24    json.dump(index, f)25