Initial GPTQ model commit
Browse files- split_pytorch.py +24 -0
split_pytorch.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# load your large model
|
| 6 |
+
model = SomeLargeModel('/mnt/e/ai_cache/output/wizardcoder_mmlu_2/merged')
|
| 7 |
+
model.load_state_dict(torch.load('pytorch_model.bin'))
|
| 8 |
+
|
| 9 |
+
# save each tensor to a separate file and record the mapping in the index
|
| 10 |
+
state_dict = model.state_dict()
|
| 11 |
+
index = {"metadata": {"total_size": 0}, "weight_map": {}}
|
| 12 |
+
i = 1
|
| 13 |
+
total_files = len(state_dict.keys())
|
| 14 |
+
|
| 15 |
+
for 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_file
|
| 19 |
+
index["metadata"]["total_size"] += tensor.nelement() * tensor.element_size()
|
| 20 |
+
i += 1
|
| 21 |
+
|
| 22 |
+
# save the index
|
| 23 |
+
with open('pytorch_model.bin.index', 'w') as f:
|
| 24 |
+
json.dump(index, f)
|