pytorch:variable.long() 是否保证 64 位?

pytorch: Does variable.long() guarantee 64-bits?

在pytorch中,我有一个变量可能是IntTensorcuda.IntTensor。需要改为64位保留cpu/gpu。 variable.long() 是否保证 pytorch 的所有实现都是 64 位的?如果不是,如何将变量转换为 64 位并为所有实现保留 cpu/gpu?

根据 PyTorch 文档 heretorch.LongTensortorch.cuda.LongTensor 可用于确保 64 位有符号整数。

同样,对于64位浮点数,可以使用torch.DoubleTensortorch.cuda.DoubleTensor

您可以使用 Variable(tensor) 方法将它们转换为变量,其中 tensor 表示上面创建的张量。