PyTorch 1.0 中文文档:Tensor(张量)的属性

译者:阿远

每个 torch.Tensor 对象都有以下几个属性: torch.dtype, torch.device, 和 torch.layout

torch.dtype

class torch.dtype

torch.dtype 属性标识了 torch.Tensor的数据类型。PyTorch 有八种不同的数据类型:

Data typedtypeTensor types
32-bit floating pointtorch.float32 or torch.floattorch.*.FloatTensor
64-bit floating pointtorch.float64 or torch.doubletorch.*.DoubleTensor
16-bit floating pointtorch.float16 or torch.halftorch.*.HalfTensor
8-bit integer (unsigned)torch.uint8torch.*.ByteTensor
8-bit integer (signed)torch.int8torch.*.CharTensor
16-bit integer (signed)torch.int16 or torch.shorttorch.*.ShortTensor
32-bit integer (signed)torch.int32 or torch.inttorch.*.IntTensor
64-bit integer (signed)torch.int64 or torch.longtorch.*.LongTensor

torch.device

class torch.device

torch.device 属性标识了torch.Tensor对象在创建之后所存储在的设备名称,而在对象创建之前此属性标识了即将为此对象申请存储空间的设备名称。

torch.device 包含了两种设备类型 ('cpu' 或者 'cuda') ,分别标识将Tensor对象储存于cpu内存或者gpu内存中,同时支持指定设备编号,比如多张gpu,可以通过gpu编号指定某一块gpu。 如果没有指定设备编号,则默认将对象存储于current_device()当前设备中; 举个例子, 一个torch.Tensor 对象构造函数中的设备字段如果填写'cuda',那等价于填写了'cuda:X',其中X是函数 torch.cuda.current_device()的返回值。

阅读全文/改进本文

posted @ 2023-02-17 09:18  绝不原创的飞龙  阅读(92)  评论(0)    收藏  举报  来源