Skip to content

Commit b202420

Browse files
authored
[ci] Run all python files in the *_source folders (#2034)
* run more * captum * captum * gitignore * comment * update * build all python files * update * change runtime * comment
1 parent e87a735 commit b202420

File tree

4 files changed

+63
-55
lines changed

4 files changed

+63
-55
lines changed

.jenkins/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,50 @@ if [[ "${JOB_BASE_NAME}" == *worker_* ]]; then
6666

6767
# Step 4: If any of the generated files are not related the tutorial files we want to run,
6868
# then we remove them
69+
set +x
6970
for filename in $(find docs/beginner docs/intermediate docs/advanced docs/recipes docs/prototype -name '*.html'); do
7071
file_basename=$(basename $filename .html)
7172
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
73+
echo "removing $filename"
7274
rm $filename
7375
fi
7476
done
7577
for filename in $(find docs/beginner docs/intermediate docs/advanced docs/recipes docs/prototype -name '*.rst'); do
7678
file_basename=$(basename $filename .rst)
7779
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
80+
echo "removing $filename"
7881
rm $filename
7982
fi
8083
done
8184
for filename in $(find docs/_downloads -name '*.py'); do
8285
file_basename=$(basename $filename .py)
8386
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
87+
echo "removing $filename"
8488
rm $filename
8589
fi
8690
done
8791
for filename in $(find docs/_downloads -name '*.ipynb'); do
8892
file_basename=$(basename $filename .ipynb)
8993
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
94+
echo "removing $filename"
9095
rm $filename
9196
fi
9297
done
9398
for filename in $(find docs/_sources/beginner docs/_sources/intermediate docs/_sources/advanced docs/_sources/recipes -name '*.rst.txt'); do
9499
file_basename=$(basename $filename .rst.txt)
95100
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
101+
echo "removing $filename"
96102
rm $filename
97103
fi
98104
done
99105
for filename in $(find docs/.doctrees/beginner docs/.doctrees/intermediate docs/.doctrees/advanced docs/.doctrees/recipes docs/.doctrees/prototype -name '*.doctree'); do
100106
file_basename=$(basename $filename .doctree)
101107
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
108+
echo "removing $filename"
102109
rm $filename
103110
fi
104111
done
112+
set -x
105113

106114
# Step 5: Remove INVISIBLE_CODE_BLOCK from .html/.rst.txt/.ipynb/.py files
107115
bash $DIR/remove_invisible_code_block_batch.sh docs

.jenkins/metadata.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"intermediate_source/ax_multiobjective_nas_tutorial.py": {
3-
"extra_files": ["intermediate_source/mnist_train_nas.py"]
3+
"extra_files": ["intermediate_source/mnist_train_nas.py"],
4+
"duration": 2000
45
},
56
"beginner_source/dcgan_faces_tutorial.py": {
67
"duration": 2000
@@ -9,7 +10,7 @@
910
"duration": 1200
1011
},
1112
"beginner_source/hyperparameter_tuning_tutorial.py": {
12-
"duration": 910
13+
"duration": 0
1314
},
1415
"advanced_source/dynamic_quantization_tutorial.py": {
1516
"duration": 380

.jenkins/validate_tutorials_built.py

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,54 @@
55

66
REPO_ROOT = Path(__file__).parent.parent
77

8-
# files that are ok to have 0 min 0 sec time, probably because they don't have any python code
9-
OK_TO_NOT_RUN = [
10-
"beginner/basics/intro.html", # no code
11-
]
8+
# For every tutorial on this list, we should determine if it is ok to not run the tutorial (add a comment after
9+
# the file name to explain why, like intro.html), or fix the tutorial and remove it from this list).
1210

13-
# when the tutorial is fixed, remove it from this list
14-
KNOWN_BAD = [
15-
"beginner/translation_transformer.html",
16-
"beginner/profiler.html",
17-
"beginner/saving_loading_models.html",
18-
"beginner/introyt/captumyt.html",
19-
"beginner/introyt/trainingyt.html",
20-
"beginner/examples_nn/polynomial_module.html",
21-
"beginner/examples_nn/dynamic_net.html",
22-
"beginner/examples_nn/polynomial_optim.html",
23-
"beginner/examples_nn/polynomial_nn.html",
24-
"beginner/examples_tensor/polynomial_numpy.html",
25-
"beginner/examples_tensor/polynomial_tensor.html",
26-
"beginner/former_torchies/autograd_tutorial_old.html",
27-
"beginner/former_torchies/tensor_tutorial_old.html",
28-
"beginner/examples_autograd/polynomial_autograd.html",
29-
"beginner/examples_autograd/polynomial_custom_function.html",
30-
"intermediate/forward_ad_usage.html",
31-
"intermediate/parametrizations.html",
32-
"intermediate/reinforcement_q_learning.html",
33-
"intermediate/text_to_speech_with_torchaudio.html",
34-
"intermediate/mnist_train_nas.html",
35-
"intermediate/fx_conv_bn_fuser.html",
36-
"advanced/super_resolution_with_onnxruntime.html",
37-
"advanced/ddp_pipeline.html",
38-
"prototype/fx_graph_mode_ptq_dynamic.html",
39-
"prototype/vmap_recipe.html",
40-
"prototype/torchscript_freezing.html",
41-
"prototype/nestedtensor.html",
42-
"recipes/recipes/saving_and_loading_models_for_inference.html",
43-
"recipes/recipes/saving_multiple_models_in_one_file.html",
44-
"recipes/recipes/loading_data_recipe.html",
45-
"recipes/recipes/tensorboard_with_pytorch.html",
46-
"recipes/recipes/what_is_state_dict.html",
47-
"recipes/recipes/profiler_recipe.html",
48-
"recipes/recipes/save_load_across_devices.html",
49-
"recipes/recipes/warmstarting_model_using_parameters_from_a_different_model.html",
50-
"recipes/recipes/dynamic_quantization.html",
51-
"recipes/recipes/saving_and_loading_a_general_checkpoint.html",
52-
"recipes/recipes/benchmark.html",
53-
"recipes/recipes/tuning_guide.html",
54-
"recipes/recipes/zeroing_out_gradients.html",
55-
"recipes/recipes/defining_a_neural_network.html",
56-
"recipes/recipes/timer_quick_start.html",
57-
"recipes/recipes/amp_recipe.html",
58-
"recipes/recipes/Captum_Recipe.html",
11+
NOT_RUN = [
12+
"basics/intro", # no code
13+
"translation_transformer",
14+
"profiler",
15+
"saving_loading_models",
16+
"introyt/captumyt",
17+
"introyt/trainingyt",
18+
"examples_nn/polynomial_module",
19+
"examples_nn/dynamic_net",
20+
"examples_nn/polynomial_optim",
21+
"former_torchies/autograd_tutorial_old",
22+
"former_torchies/tensor_tutorial_old",
23+
"examples_autograd/polynomial_autograd",
24+
"examples_autograd/polynomial_custom_function",
25+
"forward_ad_usage",
26+
"parametrizations",
27+
"reinforcement_q_learning",
28+
"text_to_speech_with_torchaudio",
29+
"mnist_train_nas", # used by ax_multiobjective_nas_tutorial.py
30+
"fx_conv_bn_fuser",
31+
"super_resolution_with_onnxruntime",
32+
"ddp_pipeline", # requires 4 gpus
33+
"fx_graph_mode_ptq_dynamic",
34+
"vmap_recipe",
35+
"torchscript_freezing",
36+
"nestedtensor",
37+
"recipes/saving_and_loading_models_for_inference",
38+
"recipes/saving_multiple_models_in_one_file",
39+
"recipes/loading_data_recipe",
40+
"recipes/tensorboard_with_pytorch",
41+
"recipes/what_is_state_dict",
42+
"recipes/profiler_recipe",
43+
"recipes/save_load_across_devices",
44+
"recipes/warmstarting_model_using_parameters_from_a_different_model",
45+
"recipes/dynamic_quantization",
46+
"recipes/saving_and_loading_a_general_checkpoint",
47+
"recipes/benchmark",
48+
"recipes/tuning_guide",
49+
"recipes/zeroing_out_gradients",
50+
"recipes/defining_a_neural_network",
51+
"recipes/timer_quick_start",
52+
"recipes/amp_recipe",
53+
"recipes/Captum_Recipe",
54+
"hyperparameter_tuning_tutorial",
55+
"flask_rest_api_tutorial",
5956
]
6057

6158

@@ -84,7 +81,7 @@ def main() -> None:
8481
"Total running time of the script: ( 0 minutes 0.000 seconds)"
8582
in elem.text
8683
and not any(
87-
html_file_path.match(file) for file in KNOWN_BAD + OK_TO_NOT_RUN
84+
html_file_path.match(file) for file in NOT_RUN
8885
)
8986
):
9087
did_not_run.append(html_file_path.as_posix())

conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
import os
3131
import sys
3232
sys.path.insert(0, os.path.abspath('.'))
33+
sys.path.insert(0, os.path.abspath('./.jenkins'))
3334
import pytorch_sphinx_theme
3435
import torch
3536
import glob
3637
import shutil
3738
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
3839
import distutils.file_util
3940
import re
41+
from validate_tutorials_built import NOT_RUN
4042

4143
import plotly.io as pio
4244
pio.renderers.default = 'sphinx_gallery'
@@ -84,8 +86,8 @@
8486
'examples_dirs': ['beginner_source', 'intermediate_source',
8587
'advanced_source', 'recipes_source', 'prototype_source'],
8688
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'],
87-
'filename_pattern': 'tutorial.py',
88-
'ignore_pattern': r'(hyperparameter_tuning_tutorial|flask_rest_api_tutorial).py$',
89+
'filename_pattern': '.py',
90+
'ignore_pattern': re.compile(f"({'|'.join(NOT_RUN)}).py$"),
8991
'backreferences_dir': None
9092
}
9193

0 commit comments

Comments
 (0)