Skip to content

Commit

Permalink
Merge branch 'main' into tb-profiler-tutorial-docs-update
Browse files Browse the repository at this point in the history
  • Loading branch information
svekars authored Nov 10, 2023
2 parents 5126cb8 + 16e4f2a commit 71d9f09
Show file tree
Hide file tree
Showing 75 changed files with 7,291 additions and 253 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ipython
# to run examples
pandas
scikit-image
pillow==9.3.0
pillow==10.0.1
wget

# for codespaces env
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/docathon-label-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def main():
issue_number = int(re.findall(r'#(\d{1,5})', pull_request_body)[0])
issue = repo.get_issue(issue_number)
issue_labels = issue.labels
docathon_label_present = any(label.name == 'docathon-h1-2023' for label in issue_labels)
docathon_label_present = any(label.name == 'docathon-h2-2023' for label in issue_labels)

# if the issue has a docathon label, add all labels from the issue to the PR.
if not docathon_label_present:
print("The 'docathon-h1-2023' label is not present in the issue.")
print("The 'docathon-h2-2023' label is not present in the issue.")
return
pull_request_labels = pull_request.get_labels()
issue_label_names = [label.name for label in issue_labels]
Expand Down
39 changes: 16 additions & 23 deletions .github/workflows/docathon-assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ jobs:
assign:
runs-on: ubuntu-latest
steps:
- name: Install Dependencies
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install @octokit/core
run: |
npm i @octokit/core @octokit/rest
- name: Check for "/assigntome" in comment
uses: actions/github-script@v4
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand All @@ -27,39 +20,39 @@ jobs:
if (assignRegex.test(issueComment)) {
const assignee = context.payload.comment.user.login;
const issueNumber = context.payload.issue.number;
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
const { data: issue } = await octokit.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
const hasLabel = issue.labels.some(label => label.name === 'docathon-h1-2023');
try {
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
const hasLabel = issue.labels.some(label => label.name === 'docathon-h2-2023');
if (hasLabel) {
if (issue.assignee !== null) {
await octokit.issues.createComment({
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: "The issue is already assigned. Please pick an opened and unnasigned issue with the [docathon-h1-2023 label](https://github.com/pytorch/tutorials/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h1-2023)."
body: "The issue is already assigned. Please pick an opened and unnasigned issue with the [docathon-h2-2023 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h2-2023)."
});
} else {
octokit.issues.addAssignees({
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
assignees: [assignee]
});
}
} else {
const commmentMessage = "This issue does not have the correct label. Please pick an opened and unnasigned issue with the [docathon-h1-2023 label](https://github.com/pytorch/tutorials/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h1-2023)."
await octokit.issues.createComment({
const commmentMessage = "This issue does not have the correct label. Please pick an opened and unnasigned issue with the [docathon-h2-2023 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h2-2023)."
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: commmentMessage
});
}
} catch (error) {
console.error(error);
}
}
9 changes: 4 additions & 5 deletions .jenkins/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ pip install --progress-bar off -r $DIR/../requirements.txt

#Install PyTorch Nightly for test.
# Nightly - pip install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html
# RC Link
# pip uninstall -y torch torchvision torchaudio torchtext
# pip install --pre --upgrade -f https://download.pytorch.org/whl/test/cu102/torch_test.html torch torchvision torchaudio torchtext
# pip uninstall -y torch torchvision torchaudio torchtext
# pip install --pre --upgrade -f https://download.pytorch.org/whl/test/cu116/torch_test.html torch torchdata torchvision torchaudio torchtext
# Install 2.1 for testing
# pip uninstall -y torch torchvision torchaudio torchtext torchdata
# pip3 install torch torchvision torchaudio --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu121
# pip3 install torchdata torchtext --index-url https://download.pytorch.org/whl/test/cpu

# Install two language tokenizers for Translation with TorchText tutorial
python -m spacy download en_core_web_sm
Expand Down
128 changes: 128 additions & 0 deletions .jenkins/download_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env python3
import hashlib
import os

from typing import Optional
from urllib.request import urlopen, Request
from pathlib import Path
from zipfile import ZipFile

REPO_BASE_DIR = Path(__file__).absolute().parent.parent
DATA_DIR = REPO_BASE_DIR / "_data"
BEGINNER_DATA_DIR = REPO_BASE_DIR / "beginner_source" / "data"
INTERMEDIATE_DATA_DIR = REPO_BASE_DIR / "intermediate_source" / "data"
ADVANCED_DATA_DIR = REPO_BASE_DIR / "advanced_source" / "data"
PROTOTYPE_DATA_DIR = REPO_BASE_DIR / "prototype_source" / "data"
FILES_TO_RUN = os.getenv("FILES_TO_RUN")


def size_fmt(nbytes: int) -> str:
"""Returns a formatted file size string"""
KB = 1024
MB = 1024 * KB
GB = 1024 * MB
if abs(nbytes) >= GB:
return f"{nbytes * 1.0 / GB:.2f} Gb"
elif abs(nbytes) >= MB:
return f"{nbytes * 1.0 / MB:.2f} Mb"
elif abs(nbytes) >= KB:
return f"{nbytes * 1.0 / KB:.2f} Kb"
return str(nbytes) + " bytes"


def download_url_to_file(url: str,
dst: Optional[str] = None,
prefix: Optional[Path] = None,
sha256: Optional[str] = None) -> Path:
dst = dst if dst is not None else Path(url).name
dst = dst if prefix is None else str(prefix / dst)
if Path(dst).exists():
print(f"Skip downloading {url} as {dst} already exists")
return Path(dst)
file_size = None
u = urlopen(Request(url, headers={"User-Agent": "tutorials.downloader"}))
meta = u.info()
if hasattr(meta, 'getheaders'):
content_length = meta.getheaders("Content-Length")
else:
content_length = meta.get_all("Content-Length")
if content_length is not None and len(content_length) > 0:
file_size = int(content_length[0])
sha256_sum = hashlib.sha256()
with open(dst, "wb") as f:
while True:
buffer = u.read(32768)
if len(buffer) == 0:
break
sha256_sum.update(buffer)
f.write(buffer)
digest = sha256_sum.hexdigest()
if sha256 is not None and sha256 != digest:
Path(dst).unlink()
raise RuntimeError(f"Downloaded {url} has unexpected sha256sum {digest} should be {sha256}")
print(f"Downloaded {url} sha256sum={digest} size={size_fmt(file_size)}")
return Path(dst)


def unzip(archive: Path, tgt_dir: Path) -> None:
with ZipFile(str(archive), "r") as zip_ref:
zip_ref.extractall(str(tgt_dir))


def download_hymenoptera_data():
# transfer learning tutorial data
z = download_url_to_file("https://download.pytorch.org/tutorial/hymenoptera_data.zip",
prefix=DATA_DIR,
sha256="fbc41b31d544714d18dd1230b1e2b455e1557766e13e67f9f5a7a23af7c02209",
)
unzip(z, BEGINNER_DATA_DIR)


def download_nlp_data() -> None:
# nlp tutorial data
z = download_url_to_file("https://download.pytorch.org/tutorial/data.zip",
prefix=DATA_DIR,
sha256="fb317e80248faeb62dc25ef3390ae24ca34b94e276bbc5141fd8862c2200bff5",
)
# This will unzip all files in data.zip to intermediate_source/data/ folder
unzip(z, INTERMEDIATE_DATA_DIR.parent)


def download_dcgan_data() -> None:
# Download dataset for beginner_source/dcgan_faces_tutorial.py
z = download_url_to_file("https://s3.amazonaws.com/pytorch-tutorial-assets/img_align_celeba.zip",
prefix=DATA_DIR,
sha256="46fb89443c578308acf364d7d379fe1b9efb793042c0af734b6112e4fd3a8c74",
)
unzip(z, BEGINNER_DATA_DIR / "celeba")


def download_lenet_mnist() -> None:
# Download model for beginner_source/fgsm_tutorial.py
download_url_to_file("https://docs.google.com/uc?export=download&id=1HJV2nUHJqclXQ8flKvcWmjZ-OU5DGatl",
prefix=BEGINNER_DATA_DIR,
dst="lenet_mnist_model.pth",
sha256="cb5f8e578aef96d5c1a2cc5695e1aa9bbf4d0fe00d25760eeebaaac6ebc2edcb",
)


def main() -> None:
DATA_DIR.mkdir(exist_ok=True)
BEGINNER_DATA_DIR.mkdir(exist_ok=True)
ADVANCED_DATA_DIR.mkdir(exist_ok=True)
INTERMEDIATE_DATA_DIR.mkdir(exist_ok=True)
PROTOTYPE_DATA_DIR.mkdir(exist_ok=True)

if FILES_TO_RUN is None or "transfer_learning_tutorial" in FILES_TO_RUN:
download_hymenoptera_data()
nlp_tutorials = ["seq2seq_translation_tutorial", "char_rnn_classification_tutorial", "char_rnn_generation_tutorial"]
if FILES_TO_RUN is None or any(x in FILES_TO_RUN for x in nlp_tutorials):
download_nlp_data()
if FILES_TO_RUN is None or "dcgan_faces_tutorial" in FILES_TO_RUN:
download_dcgan_data()
if FILES_TO_RUN is None or "fgsm_tutorial" in FILES_TO_RUN:
download_lenet_mnist()


if __name__ == "__main__":
main()
19 changes: 9 additions & 10 deletions .jenkins/get_files_to_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,26 @@ def add_to_shard(i, filename):
)

all_other_files = all_files.copy()
needs_gpu_nvidia_small_multi = list(
filter(lambda x: get_needs_machine(x) == "gpu.nvidia.small.multi", all_files,)
needs_multigpu = list(
filter(lambda x: get_needs_machine(x) == "linux.16xlarge.nvidia.gpu", all_files,)
)
needs_gpu_nvidia_medium = list(
filter(lambda x: get_needs_machine(x) == "gpu.nvidia.large", all_files,)
needs_a10g = list(
filter(lambda x: get_needs_machine(x) == "linux.g5.4xlarge.nvidia.gpu", all_files,)
)
for filename in needs_gpu_nvidia_small_multi:
# currently, the only job that uses gpu.nvidia.small.multi is the 0th worker,
for filename in needs_multigpu:
# currently, the only job that has multigpu is the 0th worker,
# so we'll add all the jobs that need this machine to the 0th worker
add_to_shard(0, filename)
all_other_files.remove(filename)
for filename in needs_gpu_nvidia_medium:
# currently, the only job that uses gpu.nvidia.large is the 1st worker,
for filename in needs_a10g:
# currently, workers 1-5 use linux.g5.4xlarge.nvidia.gpu (sm86, A10G),
# so we'll add all the jobs that need this machine to the 1st worker
add_to_shard(1, filename)
all_other_files.remove(filename)

sorted_files = sorted(all_other_files, key=get_duration, reverse=True,)

for filename in sorted_files:
min_shard_index = sorted(range(num_shards), key=lambda i: sharded_files[i][0])[
min_shard_index = sorted(range(1, num_shards), key=lambda i: sharded_files[i][0])[
0
]
add_to_shard(min_shard_index, filename)
Expand Down
11 changes: 7 additions & 4 deletions .jenkins/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
},
"intermediate_source/pipeline_tutorial.py": {
"duration": 320,
"needs": "gpu.nvidia.small.multi"
"needs": "linux.16xlarge.nvidia.gpu"
},
"beginner_source/blitz/data_parallel_tutorial.py": {
"needs": "gpu.nvidia.small.multi"
"needs": "linux.16xlarge.nvidia.gpu"
},
"intermediate_source/model_parallel_tutorial.py": {
"needs": "gpu.nvidia.small.multi"
"needs": "linux.16xlarge.nvidia.gpu"
},
"intermediate_source/torch_compile_tutorial.py": {
"needs": "gpu.nvidia.large"
"needs": "linux.g5.4xlarge.nvidia.gpu"
},
"intermediate_source/scaled_dot_product_attention_tutorial.py": {
"needs": "linux.g5.4xlarge.nvidia.gpu"
}
}
4 changes: 3 additions & 1 deletion .jenkins/validate_tutorials_built.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

NOT_RUN = [
"beginner_source/basics/intro", # no code
"beginner_source/onnx/intro_onnx",
"beginner_source/translation_transformer",
"beginner_source/profiler",
"beginner_source/saving_loading_models",
Expand All @@ -21,10 +22,11 @@
"beginner_source/former_torchies/tensor_tutorial_old",
"beginner_source/examples_autograd/polynomial_autograd",
"beginner_source/examples_autograd/polynomial_custom_function",
"beginner_source/t5_tutorial", # re-enable after this is fixed: https://github.com/pytorch/text/issues/1756
"beginner_source/t5_tutorial", # re-enable after this is fixed: https://github.com/pytorch/text/issues/1756
"intermediate_source/parametrizations",
"intermediate_source/mnist_train_nas", # used by ax_multiobjective_nas_tutorial.py
"intermediate_source/fx_conv_bn_fuser",
"intermediate_source/_torch_export_nightly_tutorial", # does not work on release
"advanced_source/super_resolution_with_onnxruntime",
"advanced_source/ddp_pipeline", # requires 4 gpus
"prototype_source/fx_graph_mode_ptq_dynamic",
Expand Down
4 changes: 2 additions & 2 deletions .pyspelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ matrix:
- open: '\.\.\s+(figure|literalinclude|math|image|grid)::'
close: '\n'
# Exclude roles:
- open: ':(?:(class|py:mod|mod|func)):`'
- open: ':(?:(class|py:mod|mod|func|meth|obj)):`'
content: '[^`]*'
close: '`'
# Exclude reStructuredText hyperlinks
Expand Down Expand Up @@ -70,7 +70,7 @@ matrix:
- open: ':figure:.*'
close: '\n'
# Ignore reStructuredText roles
- open: ':(?:(class|file|func|math|ref|octicon)):`'
- open: ':(?:(class|file|func|math|ref|octicon|meth|obj)):`'
content: '[^`]*'
close: '`'
- open: ':width:'
Expand Down
28 changes: 2 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,8 @@ download:
# Step2-2. UNTAR: tar -xzf $(DATADIR)/[SOURCE_FILE] -C [*_source/data/]
# Step2-3. AS-IS: cp $(DATADIR)/[SOURCE_FILE] [*_source/data/]

# make data directories
mkdir -p $(DATADIR)
mkdir -p advanced_source/data
mkdir -p beginner_source/data
mkdir -p intermediate_source/data
mkdir -p prototype_source/data

# transfer learning tutorial data
wget -nv -N https://download.pytorch.org/tutorial/hymenoptera_data.zip -P $(DATADIR)
unzip $(ZIPOPTS) $(DATADIR)/hymenoptera_data.zip -d beginner_source/data/

# nlp tutorial data
wget -nv -N https://download.pytorch.org/tutorial/data.zip -P $(DATADIR)
unzip $(ZIPOPTS) $(DATADIR)/data.zip -d intermediate_source/ # This will unzip all files in data.zip to intermediate_source/data/ folder
# Run structured downloads first (will also make directories
python3 .jenkins/download_data.py

# data loader tutorial
wget -nv -N https://download.pytorch.org/tutorial/faces.zip -P $(DATADIR)
Expand All @@ -65,10 +53,6 @@ download:
mkdir -p advanced_source/data/images/
cp -r _static/img/neural-style/ advanced_source/data/images/

# Download dataset for beginner_source/dcgan_faces_tutorial.py
wget -nv -N https://s3.amazonaws.com/pytorch-tutorial-assets/img_align_celeba.zip -P $(DATADIR)
unzip $(ZIPOPTS) $(DATADIR)/img_align_celeba.zip -d beginner_source/data/celeba

# Download dataset for beginner_source/hybrid_frontend/introduction_to_hybrid_frontend_tutorial.py
wget -nv -N https://s3.amazonaws.com/pytorch-tutorial-assets/iris.data -P $(DATADIR)
cp $(DATADIR)/iris.data beginner_source/data/
Expand All @@ -77,14 +61,6 @@ download:
wget -nv -N https://s3.amazonaws.com/pytorch-tutorial-assets/cornell_movie_dialogs_corpus_v2.zip -P $(DATADIR)
unzip $(ZIPOPTS) $(DATADIR)/cornell_movie_dialogs_corpus_v2.zip -d beginner_source/data/

# Download dataset for beginner_source/audio_classifier_tutorial.py
wget -nv -N https://s3.amazonaws.com/pytorch-tutorial-assets/UrbanSound8K.tar.gz -P $(DATADIR)
tar $(TAROPTS) -xzf $(DATADIR)/UrbanSound8K.tar.gz -C ./beginner_source/data/

# Download model for beginner_source/fgsm_tutorial.py
wget -nv -N 'https://docs.google.com/uc?export=download&id=1HJV2nUHJqclXQ8flKvcWmjZ-OU5DGatl' -O $(DATADIR)/lenet_mnist_model.pth
cp $(DATADIR)/lenet_mnist_model.pth ./beginner_source/data/lenet_mnist_model.pth

# Download model for advanced_source/dynamic_quantization_tutorial.py
wget -nv -N https://s3.amazonaws.com/pytorch-tutorial-assets/word_language_model_quantize.pth -P $(DATADIR)
cp $(DATADIR)/word_language_model_quantize.pth advanced_source/data/word_language_model_quantize.pth
Expand Down
Loading

0 comments on commit 71d9f09

Please sign in to comment.