评价此页

类型信息#

创建日期:2025年6月6日 | 最后更新:2025年8月14日

torch.dtype 的数值属性可以通过 torch.finfotorch.iinfo 来访问。

torch.finfo#

class torch.finfo#

torch.finfo 是一个表示浮点型 torch.dtype(例如 torch.float32torch.float64torch.float16torch.bfloat16)数值属性的对象。这类似于 numpy.finfo

torch.finfo 提供以下属性:

名称

类型

描述

bits

int

该类型占用的位数。

eps

浮点数

1.0 与大于 1.0 的下一个最小可表示浮点数之间的差值。

max

浮点数

最大可表示数值。

min

浮点数

最小可表示数值(通常为 -max)。

tiny

浮点数

最小的正规格化数。等同于 smallest_normal

smallest_normal

浮点数

最小的正规格化数。参见注释。

resolution

浮点数

该类型的近似十进制分辨率,即 10**-precision

注意

torch.finfo 的构造函数可以在不带参数的情况下调用,此时将为 pytorch 默认的 dtype(由 torch.get_default_dtype() 返回)创建该类对象。

注意

smallest_normal 返回最小的规格化数,但还存在更小的非规格化数。更多信息请参阅 https://en.wikipedia.org/wiki/Denormal_number 。

torch.iinfo#

class torch.iinfo#

torch.iinfo 是一个表示整型 torch.dtype(例如 torch.uint8torch.int8torch.int16torch.int32torch.int64)数值属性的对象。这类似于 numpy.iinfo

torch.iinfo 提供以下属性:

名称

类型

描述

bits

int

该类型占用的位数。

max

int

最大可表示数值。

min

int

最小可表示数值。