This code uses APIs with nondeterministic operations by default which could affect reproducibility. Use torch.use_deterministic_algorithms(True) to ensure deterministic algorithms are used.
1def pytorch_use_nondeterministic_algorithm_noncompliant():
2 import torch
3 # Noncompliant: `torch.bmm` doesn't use deterministic algorithms
4 # by default.
5 torch.bmm(torch.randn(2, 2, 2).to_sparse().cuda(),
6 torch.randn(2, 2, 2).cuda())
1def pytorch_use_nondeterministic_algorithm_compliant():
2 import torch
3 # Compliant: configure `torch.bmm` to use deterministic algorithms.
4 torch.use_deterministic_algorithms(True)
5 torch.bmm(torch.randn(2, 2, 2).to_sparse().cuda(),
6 torch.randn(2, 2, 2).cuda())