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

PyTorch torch.use_deterministic_algorithms 函数


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

torch.use_deterministic_algorithms 是 PyTorch 中用于使用确定性算法的函数。设置是否在可能的情况下使用确定性算法。

函数定义

torch.use_deterministic_algorithms(enabled, warn_only=False)

使用示例

实例

import torch

# 启用确定性算法
torch.use_deterministic_algorithms(True)

# 检查是否启用
print(f"Using deterministic algorithms: {torch.are_deterministic_algorithms_enabled()}")

# 禁用确定性算法
torch.use_deterministic_algorithms(False)
print(f"Using deterministic algorithms: {torch.are_deterministic_algorithms_enabled()}")

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