Skip to content

Set random seed #2438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions advanced_source/neural_style_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
# method is used to move tensors or modules to a desired device.

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
torch.set_default_device(device)

######################################################################
# Loading the Images
Expand Down
9 changes: 8 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import pytorch_sphinx_theme
import torch
import glob
import random
import shutil
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
import distutils.file_util
Expand Down Expand Up @@ -85,6 +86,11 @@

# -- Sphinx-gallery configuration --------------------------------------------

def reset_seeds(gallery_conf, fname):
torch.manual_seed(42)
torch.set_default_device('cpu')
random.seed(10)

sphinx_gallery_conf = {
'examples_dirs': ['beginner_source', 'intermediate_source',
'advanced_source', 'recipes_source', 'prototype_source'],
Expand All @@ -94,7 +100,8 @@
'backreferences_dir': None,
'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n"
"# https://pytorch.org/tutorials/beginner/colab\n"
"%matplotlib inline")
"%matplotlib inline"),
'reset_modules': (reset_seeds)
}

if os.getenv('GALLERY_PATTERN'):
Expand Down