Skip to content

Commit 5256a4f

Browse files
author
Svetlana Karslioglu
authored
Merge branch 'master' into translation_transformer_fix
2 parents fbe11fe + ddcff31 commit 5256a4f

File tree

93 files changed

+6075
-1875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+6075
-1875
lines changed

.circleci/config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ setup_linux_system_environment: &setup_linux_system_environment
2626
command: |
2727
set -ex
2828
29-
# Set up CircleCI GPG keys for apt, if needed
30-
curl -L https://packagecloud.io/circleci/trusty/gpgkey | sudo apt-key add -
31-
3229
# Stop background apt updates. Hypothetically, the kill should not
3330
# be necessary, because stop is supposed to send a kill signal to
3431
# the process, but we've added it for good luck. Also

.circleci/config.yml.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ setup_linux_system_environment: &setup_linux_system_environment
2626
command: |
2727
set -ex
2828

29-
# Set up CircleCI GPG keys for apt, if needed
30-
curl -L https://packagecloud.io/circleci/trusty/gpgkey | sudo apt-key add -
31-
3229
# Stop background apt updates. Hypothetically, the kill should not
3330
# be necessary, because stop is supposed to send a kill signal to
3431
# the process, but we've added it for good luck. Also

.circleci/scripts/build_for_windows.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ PROJECT_DIR="${SOURCE_DIR}/../.."
1010
pushd $SOURCE_DIR
1111

1212
#install wget and make
13-
curl -k https://ymu.dl.osdn.jp/mingw/68260/mingw-get-0.6.3-mingw32-pre-20170905-1-bin.zip -o mingw32.zip
13+
curl --retry 3 -k https://ymu.dl.osdn.jp/mingw/68260/mingw-get-0.6.3-mingw32-pre-20170905-1-bin.zip -o mingw32.zip
1414
unzip mingw32.zip -d mingw32
1515
mingw32/bin/mingw-get.exe install mingw32-make
1616
mingw32/bin/mingw-get.exe install msys-findutils
1717
mv mingw32/bin/mingw32-make.exe mingw32/bin/make.exe
18-
curl -k https://eternallybored.org/misc/wget/1.20.3/64/wget.exe -o mingw32/bin/wget.exe
18+
curl --retry 3 -k https://eternallybored.org/misc/wget/1.20.3/64/wget.exe -o mingw32/bin/wget.exe
1919
export PATH="${SOURCE_DIR}/mingw32/bin:${SOURCE_DIR}/mingw32/msys/1.0/bin:$PATH"
2020

2121
#install anaconda3
2222
export CONDA_HOME="${SOURCE_DIR}/conda"
2323
export tmp_conda="${SOURCE_DIR}/conda"
2424
export miniconda_exe="${SOURCE_DIR}/miniconda.exe"
2525
rm -rf conda miniconda.exe
26-
curl -k https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o miniconda.exe
26+
curl --retry 3 -k https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o miniconda.exe
2727
./install_conda.bat
2828
export PATH="${tmp_conda}:${tmp_conda}/Library/usr/bin:${tmp_conda}/Library/bin:${tmp_conda}/Scripts:${tmp_conda}/bin:$PATH"
2929

@@ -38,8 +38,8 @@ pip install pySoundFile
3838
# Force uninstall torch & related packages, we'll install them using conda later.
3939
pip uninstall -y torch torchvision torchtext
4040
conda install -yq -c pytorch "cudatoolkit=10.2" pytorch torchvision torchtext torchaudio
41-
python -m spacy download de
42-
python -m spacy download en
41+
python -m spacy download de_core_news_sm
42+
python -m spacy download en_core_web_sm
4343
pushd ${PROJECT_DIR}
4444
DIR=.jenkins
4545
export NUM_WORKERS=4

.jenkins/build.sh

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export PATH=/opt/conda/bin:$PATH
2121
rm -rf src
2222
pip install -r $DIR/../requirements.txt
2323

24-
# export PATH=/opt/conda/bin:$PATH
25-
# pip install sphinx==1.8.2 pandas
26-
2724
#Install PyTorch Nightly for test.
2825
# Nightly - pip install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html
2926
# RC Link
@@ -32,17 +29,9 @@ pip install -r $DIR/../requirements.txt
3229
# pip uninstall -y torch torchvision torchaudio torchtext
3330
# pip install -f https://download.pytorch.org/whl/test/cu111/torch_test.html torch torchvision torchaudio torchtext
3431

35-
# For Tensorboard. Until 1.14 moves to the release channel.
36-
pip install tb-nightly
37-
3832
# Install two language tokenizers for Translation with TorchText tutorial
39-
python -m spacy download en
40-
python -m spacy download de
41-
42-
# PyTorch Theme
43-
rm -rf src
44-
pip install -e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
45-
pip install sphinx-gallery==0.3.1 tqdm matplotlib ipython pillow==9.0.1
33+
python -m spacy download en_core_web_sm
34+
python -m spacy download de_core_news_sm
4635

4736
awsv2 -i
4837
awsv2 configure set default.s3.multipart_threshold 5120MB
@@ -63,7 +52,7 @@ if [[ "${JOB_BASE_NAME}" == *worker_* ]]; then
6352
# python $DIR/remove_runnable_code.py beginner_source/audio_classifier_tutorial.py beginner_source/audio_classifier_tutorial.py || true
6453

6554
# Remove runnable code from tensorboard_profiler_tutorial.py as it frequently crashes, see https://github.com/pytorch/pytorch/issues/74139
66-
python $DIR/remove_runnable_code.py intermediate_source/tensorboard_profiler_tutorial.py intermediate_source/tensorboard_profiler_tutorial.py || true
55+
# python $DIR/remove_runnable_code.py intermediate_source/tensorboard_profiler_tutorial.py intermediate_source/tensorboard_profiler_tutorial.py || true
6756

6857

6958
# Step 2: Keep certain tutorials based on file count, and remove runnable code in all other tutorials
@@ -77,45 +66,54 @@ if [[ "${JOB_BASE_NAME}" == *worker_* ]]; then
7766

7867
# Step 4: If any of the generated files are not related the tutorial files we want to run,
7968
# then we remove them
69+
set +x
8070
for filename in $(find docs/beginner docs/intermediate docs/advanced docs/recipes docs/prototype -name '*.html'); do
8171
file_basename=$(basename $filename .html)
8272
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
73+
echo "removing $filename"
8374
rm $filename
8475
fi
8576
done
8677
for filename in $(find docs/beginner docs/intermediate docs/advanced docs/recipes docs/prototype -name '*.rst'); do
8778
file_basename=$(basename $filename .rst)
8879
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
80+
echo "removing $filename"
8981
rm $filename
9082
fi
9183
done
9284
for filename in $(find docs/_downloads -name '*.py'); do
9385
file_basename=$(basename $filename .py)
9486
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
87+
echo "removing $filename"
9588
rm $filename
9689
fi
9790
done
9891
for filename in $(find docs/_downloads -name '*.ipynb'); do
9992
file_basename=$(basename $filename .ipynb)
10093
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
94+
echo "removing $filename"
10195
rm $filename
10296
fi
10397
done
10498
for filename in $(find docs/_sources/beginner docs/_sources/intermediate docs/_sources/advanced docs/_sources/recipes -name '*.rst.txt'); do
10599
file_basename=$(basename $filename .rst.txt)
106100
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
101+
echo "removing $filename"
107102
rm $filename
108103
fi
109104
done
110105
for filename in $(find docs/.doctrees/beginner docs/.doctrees/intermediate docs/.doctrees/advanced docs/.doctrees/recipes docs/.doctrees/prototype -name '*.doctree'); do
111106
file_basename=$(basename $filename .doctree)
112107
if [[ ! " ${FILES_TO_RUN} " =~ " ${file_basename} " ]]; then
108+
echo "removing $filename"
113109
rm $filename
114110
fi
115111
done
112+
set -x
116113

117114
# Step 5: Remove INVISIBLE_CODE_BLOCK from .html/.rst.txt/.ipynb/.py files
118115
bash $DIR/remove_invisible_code_block_batch.sh docs
116+
python .jenkins/validate_tutorials_built.py
119117

120118
# Step 6: Copy generated files to S3, tag with commit ID
121119
7z a worker_${WORKER_ID}.7z docs
@@ -149,6 +147,7 @@ elif [[ "${JOB_BASE_NAME}" == *manager ]]; then
149147

150148
# Step 5: Remove INVISIBLE_CODE_BLOCK from .html/.rst.txt/.ipynb/.py files
151149
bash $DIR/remove_invisible_code_block_batch.sh docs
150+
python .jenkins/validate_tutorials_built.py
152151

153152
# Step 6: Copy generated HTML files and static files to S3
154153
7z a manager.7z docs

.jenkins/get_files_to_run.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import Any, Dict, List, Optional, Tuple
22
import json
33
import os
44
from pathlib import Path
@@ -14,17 +14,21 @@ def get_all_files() -> List[str]:
1414
return [str(x) for x in sources]
1515

1616

17-
def calculate_shards(all_files, num_shards=20):
17+
def read_metadata() -> Dict[str, Any]:
1818
with (REPO_BASE_DIR / ".jenkins" / "metadata.json").open() as fp:
19-
metadata = json.load(fp)
20-
sharded_files = [(0.0, []) for _ in range(num_shards)]
19+
return json.load(fp)
2120

22-
def get_duration(file):
21+
22+
def calculate_shards(all_files: List[str], num_shards: int = 20) -> List[List[str]]:
23+
sharded_files: List[Tuple[float, List[str]]] = [(0.0, []) for _ in range(num_shards)]
24+
metadata = read_metadata()
25+
26+
def get_duration(file: str) -> int:
2327
# tutorials not listed in the metadata.json file usually take
2428
# <3min to run, so we'll default to 1min if it's not listed
2529
return metadata.get(file, {}).get("duration", 60)
2630

27-
def get_needs_machine(file):
31+
def get_needs_machine(file: str) -> Optional[str]:
2832
return metadata.get(file, {}).get("needs", None)
2933

3034
def add_to_shard(i, filename):
@@ -55,19 +59,38 @@ def add_to_shard(i, filename):
5559
return [x[1] for x in sharded_files]
5660

5761

58-
def remove_other_files(all_files, files_to_run) -> None:
62+
def compute_files_to_keep(files_to_run: List[str]) -> List[str]:
63+
metadata = read_metadata()
64+
files_to_keep = list(files_to_run)
65+
for file in files_to_run:
66+
extra_files = metadata.get(file, {}).get("extra_files", [])
67+
files_to_keep.extend(extra_files)
68+
return files_to_keep
69+
70+
71+
def remove_other_files(all_files, files_to_keep) -> None:
72+
5973
for file in all_files:
60-
if file not in files_to_run:
74+
if file not in files_to_keep:
6175
remove_runnable_code(file, file)
6276

6377

78+
def parse_args() -> Any:
79+
from argparse import ArgumentParser
80+
parser = ArgumentParser("Select files to run")
81+
parser.add_argument("--dry-run", action="store_true")
82+
parser.add_argument("--num-shards", type=int, default=int(os.environ.get("NUM_WORKERS", 20)))
83+
parser.add_argument("--shard-num", type=int, default=int(os.environ.get("WORKER_ID", 0)))
84+
return parser.parse_args()
85+
86+
6487
def main() -> None:
65-
num_shards = int(os.environ.get("NUM_WORKERS", 20))
66-
shard_num = int(os.environ.get("WORKER_ID", 0))
88+
args = parse_args()
6789

6890
all_files = get_all_files()
69-
files_to_run = calculate_shards(all_files, num_shards=num_shards)[shard_num]
70-
remove_other_files(all_files, files_to_run)
91+
files_to_run = calculate_shards(all_files, num_shards=args.num_shards)[args.shard_num]
92+
if not args.dry_run:
93+
remove_other_files(all_files, compute_files_to_keep(files_to_run))
7194
stripped_file_names = [Path(x).stem for x in files_to_run]
7295
print(" ".join(stripped_file_names))
7396

.jenkins/metadata.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
2+
"intermediate_source/ax_multiobjective_nas_tutorial.py": {
3+
"extra_files": ["intermediate_source/mnist_train_nas.py"],
4+
"duration": 2000
5+
},
26
"beginner_source/dcgan_faces_tutorial.py": {
37
"duration": 2000
48
},
59
"intermediate_source/seq2seq_translation_tutorial.py": {
610
"duration": 1200
711
},
812
"beginner_source/hyperparameter_tuning_tutorial.py": {
9-
"duration": 910
13+
"duration": 0
1014
},
1115
"advanced_source/dynamic_quantization_tutorial.py": {
1216
"duration": 380

.jenkins/validate_tutorials_built.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from pathlib import Path
2+
from typing import List
3+
4+
from bs4 import BeautifulSoup
5+
6+
REPO_ROOT = Path(__file__).parent.parent
7+
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).
10+
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+
"parametrizations",
26+
"mnist_train_nas", # used by ax_multiobjective_nas_tutorial.py
27+
"fx_conv_bn_fuser",
28+
"super_resolution_with_onnxruntime",
29+
"ddp_pipeline", # requires 4 gpus
30+
"fx_graph_mode_ptq_dynamic",
31+
"vmap_recipe",
32+
"torchscript_freezing",
33+
"nestedtensor",
34+
"recipes/saving_and_loading_models_for_inference",
35+
"recipes/saving_multiple_models_in_one_file",
36+
"recipes/loading_data_recipe",
37+
"recipes/tensorboard_with_pytorch",
38+
"recipes/what_is_state_dict",
39+
"recipes/profiler_recipe",
40+
"recipes/save_load_across_devices",
41+
"recipes/warmstarting_model_using_parameters_from_a_different_model",
42+
"recipes/dynamic_quantization",
43+
"recipes/saving_and_loading_a_general_checkpoint",
44+
"recipes/benchmark",
45+
"recipes/tuning_guide",
46+
"recipes/zeroing_out_gradients",
47+
"recipes/defining_a_neural_network",
48+
"recipes/timer_quick_start",
49+
"recipes/amp_recipe",
50+
"recipes/Captum_Recipe",
51+
"hyperparameter_tuning_tutorial",
52+
"flask_rest_api_tutorial",
53+
]
54+
55+
56+
def tutorial_source_dirs() -> List[Path]:
57+
return [
58+
p.relative_to(REPO_ROOT).with_name(p.stem[:-7])
59+
for p in REPO_ROOT.glob("*_source")
60+
]
61+
62+
63+
def main() -> None:
64+
docs_dir = REPO_ROOT / "docs"
65+
html_file_paths = []
66+
for tutorial_source_dir in tutorial_source_dirs():
67+
glob_path = f"{tutorial_source_dir}/**/*.html"
68+
html_file_paths += docs_dir.glob(glob_path)
69+
70+
did_not_run = []
71+
for html_file_path in html_file_paths:
72+
with open(html_file_path, "r", encoding="utf-8") as html_file:
73+
html = html_file.read()
74+
html_soup = BeautifulSoup(html, "html.parser")
75+
elems = html_soup.find_all("p", {"class": "sphx-glr-timing"})
76+
for elem in elems:
77+
if (
78+
"Total running time of the script: ( 0 minutes 0.000 seconds)"
79+
in elem.text
80+
and not any(
81+
html_file_path.match(file) for file in NOT_RUN
82+
)
83+
):
84+
did_not_run.append(html_file_path.as_posix())
85+
86+
if len(did_not_run) != 0:
87+
raise RuntimeError(
88+
"The following file(s) are not known bad but ran in 0.000 sec, meaning that any "
89+
+ "python code in this tutorial probably didn't run:\n{}".format(
90+
"\n".join(did_not_run)
91+
)
92+
)
93+
94+
95+
if __name__ == "__main__":
96+
main()

0 commit comments

Comments
 (0)