PyTorch torch.cuda.manual_seed_all 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.cuda.manual_seed_allPyTorch において、すべての CUDA デバイスのランダムシードを設定するための関数です。すべての CUDA デバイスにランダムシードを設定します。

関数定義

torch.cuda.manual_seed_all(seed)

使用例

実例

import torch

# すべての CUDA デバイスにランダムシードを設定する
if torch.cuda.is_available():
    torch.cuda.manual_seed_all(42)
    x = torch.randn(3, 3).cuda()
    print(f"Random tensor: {x}")
    print(f"CUDA device count: {torch.cuda.device_count()}")
else:
    print("CUDA not available")

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張