现在位置: 首页 > PyTorch 教程 > 正文

PyTorch torch.are_deterministic_algorithms_enabled 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.are_deterministic_algorithms_enabled 是 PyTorch 中用于检查确定性算法是否启用的函数。返回 True 表示启用了确定性算法,这意味着每次运行都会产生相同的结果。

函数定义

torch.are_deterministic_algorithms_enabled()

使用示例

实例

import torch

# 检查确定性算法是否启用
is_deterministic = torch.are_deterministic_algorithms_enabled()
print(f"Deterministic algorithms enabled: {is_deterministic}")

# 设置启用确定性算法
torch.use_deterministic_algorithms(True)
is_deterministic = torch.are_deterministic_algorithms_enabled()
print(f"After setting: {is_deterministic}")

Pytorch torch 参考手册 Pytorch torch 参考手册