Hi, I was inspired by your solution, but I found JSON deserializing to be slow with large tensors.
So I used the similar logic but implemented a simple binary read write mechanism,
torch tensors can convert to  numpy and numpy can convert to bytestring that’s how the python can write the underlying allocations data in binary file,
While in C++ the ifstream’s read method in binary mode allows us to pass a char* to char array of size length and reads length bytes in that array.
Since the tensor created in libtorch has same shape and size that of python tensor, its .numel() * .elemenetsize() yeilds the exact number of bytes that needs to be read from the file, and the tensor.sizes() can be passed to stride the inner data accordingly.
If you want I can post the snippet of my loading and saving code.
I think the load times and save times were faster