I need to transfer a pytorch_model.bin of a pretrained deeppavlov ruBERT model but I have a file size limit. So I split it into chunks using python, transferred and reassembled in the correct order. However, the size of the file increased, and when I tried to load the resulting file using BertModel.from_pretrained(pytorch_model.bin) I received an error:
During handling of the above exception, another exception occurred:
OSError: Unable to load weights from pytorch checkpoint <...>
So my question is: is it actually possible to split the file like that? I could possibly have a mistake in the way I split and reassemble the file. However, this could also be some version mismatch.
My python code to get chunks:
chunk_size = 40000000
file_num = 1
with open("pytorch_model.bin", "rb") as f:
chunk = f.read(chunk_size)
while chunk:
with open("chunk_" + str(file_num), "wb") as chunk_file:
chunk_file.write(chunk)
file_num += 1
chunk = f.read(chunk_size)
Code to reassemble one file:
chunks = !ls | grep chunk_
chunks = sorted(chunks, key=lambda x: int(x.split("_")[-1]))
for chunk in chunks:
with open(chunk, "rb") as f:
contents = f.read()
if chunk == chunks[0]:
write_mode = "wb"
else:
write_mode = "ab"
with open("pytorch_model.bin", write_mode) as f:
f.write(contents)
python 3.7.0, torch 1.5.1, transformers 4.2.2. I have no way to move files bigger than 40 MB.
TIA for your help!