torch.backends¶
torch.backends 控制 PyTorch 支持的各种后端的行为。
这些后端包括:
torch.backends.cudatorch.backends.cudnntorch.backends.mkltorch.backends.mkldnntorch.backends.openmp
torch.backends.cuda¶
-
torch.backends.cuda.is_built()[source]¶ 返回 PyTorch 是否以 CUDA 支持构建。请注意,这并不一定意味着 CUDA 是可用的;这只是表示如果在具有正常工作的 CUDA 驱动程序和设备的机器上运行此 PyTorch 二进制文件,我们将能够使用它。
-
torch.backends.cuda.matmul.allow_tf32¶ A
boolthat controls whether TensorFloat-32 tensor cores may be used in matrix multiplications on Ampere or newer GPUs. See TensorFloat-32(TF32) on Ampere devices.
-
torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction¶ 一个
bool,用于控制是否允许使用fp16精度的归约(例如,具有fp16累加类型的归约)与fp16 GEMM结合。
-
torch.backends.cuda.preferred_linalg_library(backend=None)[source]¶ 警告
此标志为实验性质,可能会发生变化。
当 PyTorch 运行一个 CUDA 线性代数操作时,它通常会使用 cuSOLVER 或 MAGMA 库,并且如果两者都可用,它会根据启发式方法决定使用哪个库。此标志(值为
str)允许覆盖这些启发式方法。如果设置为“cusolver”,则在可能的情况下使用cuSOLVER。
如果设置为“magma”,则在可能的情况下会使用MAGMA。
如果设置为“default”(默认值),则在 cuSOLVER 和 MAGMA 都可用时,将使用启发式方法进行选择。
在没有输入的情况下,此函数返回当前首选的库。
注意:当优先选择某个库时,如果该优先库未实现所需的操作,仍可使用其他库。 此标志在 PyTorch 的启发式库选择对应用程序输入不正确的情况下,可能会获得更好的性能。
当前支持的线性代数运算符:
torch.backends.cudnn¶
-
torch.backends.cudnn.allow_tf32¶ A
boolthat controls where TensorFloat-32 tensor cores may be used in cuDNN convolutions on Ampere or newer GPUs. See TensorFloat-32(TF32) on Ampere devices.
-
torch.backends.cudnn.deterministic¶ 如果为 True,则会导致 cuDNN 只使用确定性的卷积算法的
bool。 另请参见torch.are_deterministic_algorithms_enabled()和torch.use_deterministic_algorithms()。