评价此页

类型信息#

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

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

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 返回最小的正规数,但存在更小的非正规数(subnormal numbers)。有关更多信息,请参见 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

可表示的最小数值。