import torch
from collections import OrderedDict
a= torch.tensor([[1,2,3,4], [5,6,7,8]])
o = OrderedDict()
o["test"] = a
torch.save(o, "test.pt")
torch.save({"model_state_dict": o}, "test_with_key.pt")
import numpy as np
array_fortran = np.asfortranarray(np.arange(1, 2*3*4 + 1).reshape(2, 3, 4))
print("Is Fortran contiguous (F order):", array_fortran.flags['F_CONTIGUOUS']) print("Is C contiguous (C order):", array_fortran.flags['C_CONTIGUOUS'])
tensor_fortran = torch.from_numpy(array_fortran)
print("Tensor stride:", tensor_fortran.stride())
torch.save({"tensor_fortran": tensor_fortran}, 'fortran_tensor_3d.pth')
print("3D Tensor saved with Fortran layout.")