目录
1. NVIDIA TF32
1.1 数据格式比较
1.2 使用方法及条件
NVIDIA TF32开关
2. Pytorch
2.1 Pytorch对NVIDIA TF32的支持
2.2 Pytorch自动混合精度AMP
参考
TensorFloat-32,是NVIDIA在Ampere架构的GPU上推出的专门运用于TensorCore的一种计算格式。
TF32仅仅是在使用TensorCore时的一种中间计算格式,它并不是一个完全的数据类型
如何查询版本号?
在Ampere架构的GPU上,默认启用了TF32来进行计算加速,但是并不是每一个矩阵及卷积计算都一定会使用FP32。如果想强制关闭TF32,可以通过设置环境变量:
export NVIDIA_TF32_OVERRIDE=0
Pytorch 1.7中添加了对TensorFloat32运算的支持,allow_tf32 标志在PyTroch1.7到PyTroch1.11中默认为True,在PyTorch1.12及更高版本中默认为False。
此标志控制PyTorch是否允许使用TensorFloat32 TensorCore。
# The flag below controls whether to allow TF32 on matmul. This flag defaults to False# in PyTorch 1.12 and later.
torch.backends.cuda.matmul.allow_tf32=True
# The flag below controls whether to allow TF32 on cuDNN. This flag defaults to True.
torch.backends.cudnn.allow_tf32=True
查询开关的默认值
PyTorch自1.6版本开始增加内置 torch.cuda.amp, 采用Float32和Float16的自动混合运算,注意与TF32计算模式是不同的。
NVIDIA TF32 — DeepRec latest 文档
CUDA semantics — PyTorch 1.13 documentation
https://arxiv.org/pdf/1710.03740.pdf
TF32和AMP训练为何可以保证训练精度收敛_来自底层的仰望的博客-CSDN博客