Different values after loading tensor with torch.load


I’m trying to save a tensor and then load it using torch.save and torch.load. But I’m losing information doing so.

How I’ve done it:
torch.save(data, path)
ld_data = torch.load(path)

When comparing data with ld_data one can see, that the outputs are different:

data = tensor([[ 1.7173e-01, -2.5369e-02, 4.3857e-02, ..., -1.7239e-02, -3.3998e-11, -2.7491e-02], [-2.5369e-02, 7.7908e-02, 3.1315e-02, ..., -3.0796e-02, 1.4849e-11, -6.0712e-02], [ 4.3857e-02, 3.1315e-02, 8.2180e-02, ..., -3.8967e-02, -1.1373e-11, -8.8518e-02], ..., [-1.7239e-02, -3.0796e-02, -3.8967e-02, ..., 5.5503e-02, -2.0781e-11, 7.9386e-02], [-3.3998e-11, 1.4849e-11, -1.1373e-11, ..., -2.0781e-11, 1.0000e-04, -1.7010e-11], [-2.7491e-02, -6.0712e-02, -8.8518e-02, ..., 7.9386e-02, -1.7010e-11, 2.0927e-01]])

ld_data = tensor([[ 1.2479e+00, -1.9974e-02, 7.4556e-02, ..., -4.1448e-02, 3.9807e-13, -7.2844e-02], [-1.9974e-02, 1.0799e+00, 3.2171e-02, ..., -2.7830e-02, 9.3514e-15, -7.1534e-02], [ 7.4556e-02, 3.2171e-02, 1.1049e+00, ..., -4.7784e-02, 3.3500e-14, -1.2831e-01], ..., [-4.1448e-02, -2.7830e-02, -4.7784e-02, ..., 1.0771e+00, 3.3965e-14, 1.2947e-01], [ 3.9807e-13, 9.3514e-15, 3.3500e-14, ..., 3.3965e-14, 1.0000e+00, -1.6675e-12], [-7.2844e-02, -7.1534e-02, -1.2831e-01, ..., 1.2947e-01, -1.6675e-12, 1.3670e+00]])

How can I save and load such data without losing information?

Thank you!

I haven’t seen this issue before, so could you post an executable code snippet, which would reproduce this behavior, please?

SOLVED: there was an error in the datapath. This led to a different tensor to be loaded…