Skip to content

Commit bab2780

Browse files
authored
Update hyperparameter_tuning_tutorial.py
1 parent 8e6ae12 commit bab2780

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

beginner_source/hyperparameter_tuning_tutorial.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
from torch.utils.data import random_split
4949
import torchvision
5050
import torchvision.transforms as transforms
51+
# sphinx_gallery_start_ignore
52+
# Fixes ``AttributeError: '_LoggingTee' object has no attribute 'fileno'``.
53+
# This is only needed to run with sphinx-build.
54+
import sys
55+
if not hasattr(sys.stdout, "encoding"):
56+
sys.stdout.encoding = "latin1"
57+
sys.stdout.fileno = lambda: 0
58+
# sphinx_gallery_end_ignore
5159
from ray import tune
5260
from ray.air import Checkpoint, session
5361
from ray.tune.schedulers import ASHAScheduler
@@ -451,13 +459,6 @@ def main(num_samples=10, max_num_epochs=10, gpus_per_trial=2):
451459

452460

453461
if __name__ == "__main__":
454-
# sphinx_gallery_start_ignore
455-
# Fixes ``AttributeError: '_LoggingTee' object has no attribute 'fileno'``.
456-
# This is only needed to run with sphinx-build.
457-
import sys
458-
if not hasattr(sys.stdout, "encoding"):
459-
sys.stdout.encoding = "latin1"
460-
# sphinx_gallery_end_ignore
461462
# You can change the number of GPUs per trial here:
462463
main(num_samples=10, max_num_epochs=10, gpus_per_trial=0)
463464

0 commit comments

Comments
 (0)