Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions orttraining/orttraining/python/training/ortmodule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,25 @@
from ._custom_autograd_function import enable_custom_autograd_support
enable_custom_autograd_support()

# Initalized ORT's random seed with pytorch's initial seed
# Initalized ORT's random seed with pytorch's current seed,
# in case user has set pytorch seed before importing ORTModule
import sys
from onnxruntime import set_seed
set_seed((torch.initial_seed() % sys.maxsize))

# Override torch.manual_seed and torch.cuda.manual_seed
def override_torch_manual_seed(seed):
set_seed(seed % sys.maxsize)
return torch_manual_seed(seed)
torch_manual_seed = torch.manual_seed
torch.manual_seed = override_torch_manual_seed
Comment thread
SherlockNoMad marked this conversation as resolved.

def override_torch_cuda_manual_seed(seed):
set_seed(seed % sys.maxsize)
return torch_cuda_manual_seed(seed)
torch_cuda_manual_seed = torch.cuda.manual_seed
torch.cuda.manual_seed = override_torch_cuda_manual_seed

# ORTModule must be loaded only after all validation passes
from .ortmodule import ORTModule