Reputation: 653
What is the idiomatic way of saving a bfloat
torch.tensor
to disk as raw binary? Below code will throw error since numpy doesn't support bfloat16
.
import torch
import numpy as np
tensor = torch.tensor([1, 2, 3, 4, 5]).bfloat16()
# TypeError: Got unsupported ScalarType BFloat16
arr = tensor.numpy()
arr.tofile("output.bin")
Upvotes: 1
Views: 1676
Reputation: 365
If we assume that in Python any object can be serialized, you can simply register your arr object with Python's pickile.
import pickle
with open(""output.bin", "wb") as me:
pickle.dump(arr, me)
Upvotes: 1