PyTorch torch.set_deterministic_debug_mode 函数
torch.set_deterministic_debug_mode 是 PyTorch 中用于设置确定性调试模式的函数。当设置为非零值时,PyTorch 会在使用非确定性算法时抛出错误或警告。
函数定义
torch.set_deterministic_debug_mode(debug_mode)
参数说明
debug_mode: 调试模式,可选值:0: 关闭(默认)1: 启用严格模式2: 启用警告模式
使用示例
实例
import torch
# 设置确定性调试模式为严格模式
# 这会在使用非确定性操作时抛出错误
torch.set_deterministic_debug_mode(1)
# 设置为警告模式
torch.set_deterministic_debug_mode(2)
# 关闭调试模式
torch.set_deterministic_debug_mode(0)
print("确定性调试模式已设置")
# 设置确定性调试模式为严格模式
# 这会在使用非确定性操作时抛出错误
torch.set_deterministic_debug_mode(1)
# 设置为警告模式
torch.set_deterministic_debug_mode(2)
# 关闭调试模式
torch.set_deterministic_debug_mode(0)
print("确定性调试模式已设置")
输出结果为:
确定性调试模式已设置

Pytorch torch 参考手册