From ba0913da0356c8c28f053094fc8669996fae85b6 Mon Sep 17 00:00:00 2001 From: Catherine Lee Date: Tue, 6 Jun 2023 15:50:22 -0700 Subject: [PATCH 1/6] add seed --- conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/conf.py b/conf.py index eaa25a956c6..35dd95a4f97 100644 --- a/conf.py +++ b/conf.py @@ -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 @@ -85,6 +86,10 @@ # -- Sphinx-gallery configuration -------------------------------------------- +def reset_seeds(gallery_conf, fname): + torch.manual_seed(42) + random.seed(10) + sphinx_gallery_conf = { 'examples_dirs': ['beginner_source', 'intermediate_source', 'advanced_source', 'recipes_source', 'prototype_source'], @@ -94,7 +99,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'): From ed86392fb2de9893924e661e72410f65fe2909cf Mon Sep 17 00:00:00 2001 From: clee2000 <44682903+clee2000@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:07:10 -0700 Subject: [PATCH 2/6] Update conf.py Co-authored-by: Nikita Shulga --- conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conf.py b/conf.py index 35dd95a4f97..e4673bc5b85 100644 --- a/conf.py +++ b/conf.py @@ -88,6 +88,7 @@ def reset_seeds(gallery_conf, fname): torch.manual_seed(42) + torch.set_default_device('cpu') random.seed(10) sphinx_gallery_conf = { From fd1be7b1ba6525d81bb9076ea65dca17abedc4ba Mon Sep 17 00:00:00 2001 From: Catherine Lee Date: Tue, 6 Jun 2023 17:16:52 -0700 Subject: [PATCH 3/6] update --- advanced_source/neural_style_tutorial.py | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced_source/neural_style_tutorial.py b/advanced_source/neural_style_tutorial.py index 4c42c228448..0dbc6ac818c 100644 --- a/advanced_source/neural_style_tutorial.py +++ b/advanced_source/neural_style_tutorial.py @@ -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 From 8a8cc94f46e740f0266d0d6f4148e2822db79621 Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Wed, 7 Jun 2023 09:07:10 -0700 Subject: [PATCH 4/6] Update changing_default_device.py --- recipes_source/recipes/changing_default_device.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/recipes_source/recipes/changing_default_device.py b/recipes_source/recipes/changing_default_device.py index f5e50b3f0be..103560fd743 100644 --- a/recipes_source/recipes/changing_default_device.py +++ b/recipes_source/recipes/changing_default_device.py @@ -43,9 +43,6 @@ print(mod.weight.device) print(mod(torch.randn(128, 20)).device) -# And then globally return it back to CPU -torch.set_default_device('cpu') - ################################################################ # This function imposes a slight performance cost on every Python # call to the torch API (not just factory functions). If this From 5f2160cf0f5f3f3cb73f069ef6d48412ebfe82bf Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Wed, 7 Jun 2023 09:08:48 -0700 Subject: [PATCH 5/6] Update conf.py --- conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.py b/conf.py index e4673bc5b85..5f88045adb3 100644 --- a/conf.py +++ b/conf.py @@ -88,7 +88,7 @@ def reset_seeds(gallery_conf, fname): torch.manual_seed(42) - torch.set_default_device('cpu') + torch.set_default_device(None) random.seed(10) sphinx_gallery_conf = { From 4179a4f91d429014ae8a36564bfd45fffc6f3d0e Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Wed, 7 Jun 2023 09:09:35 -0700 Subject: [PATCH 6/6] Update neural_style_tutorial.py --- advanced_source/neural_style_tutorial.py | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced_source/neural_style_tutorial.py b/advanced_source/neural_style_tutorial.py index 0dbc6ac818c..4c42c228448 100644 --- a/advanced_source/neural_style_tutorial.py +++ b/advanced_source/neural_style_tutorial.py @@ -70,7 +70,6 @@ # 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