Skip to content

Commit dc2661a

Browse files
committed
Adding workflow for calling the release matrix
run on pull Testing Testing test test Test testing test test test test test Test testing testing test Update preview section Use new scriptcalling it from the workflow Refactor code Refactor workflow naming Adding version modifications adding published_versions.json modifications Fix file writing Fix typo Use write_published_versions fix
1 parent d7332ff commit dc2661a

File tree

3 files changed

+242
-7
lines changed

3 files changed

+242
-7
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Update quick start module
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
channel:
6+
description: "Channel to use (nightly, test, release)"
7+
required: true
8+
type: choice
9+
options:
10+
- release
11+
- nightly
12+
- test
13+
version:
14+
description: "Version to update"
15+
required: false
16+
type: string
17+
18+
jobs:
19+
validate-binaries:
20+
uses: pytorch/builder/.github/workflows/validate-binaries.yml@main
21+
with:
22+
os: all
23+
channel: ${{ inputs.channel }}
24+
linux-matrix:
25+
needs: [validate-binaries]
26+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
27+
with:
28+
package-type: all
29+
os: linux
30+
channel: ${{ inputs.channel }}
31+
windows-matrix:
32+
needs: [validate-binaries]
33+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
34+
with:
35+
package-type: all
36+
os: windows
37+
channel: ${{ inputs.channel }}
38+
macos-matrix:
39+
needs: [validate-binaries]
40+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
41+
with:
42+
package-type: all
43+
os: macos
44+
channel: ${{ inputs.channel }}
45+
46+
generate-json-file:
47+
needs: [linux-matrix, windows-matrix, macos-matrix]
48+
runs-on: "ubuntu-18.04"
49+
steps:
50+
- name: Checkout builder
51+
uses: actions/checkout@v2
52+
- name: Setup Python
53+
uses: actions/setup-python@v2
54+
with:
55+
python-version: 3.8
56+
architecture: x64
57+
- name: Create json file
58+
shell: bash
59+
env:
60+
LINUX_MATRIX: ${{ needs.linux-matrix.outputs.matrix }}
61+
WINDOWS_MATRIX: ${{ needs.windows-matrix.outputs.matrix }}
62+
MACOS_MATRIX: ${{ needs.macos-matrix.outputs.matrix }}
63+
VERSION: ${{ inputs.version }}
64+
run: |
65+
set -ex
66+
printf '%s\n' "$LINUX_MATRIX" > linux_matrix.json
67+
printf '%s\n' "$WINDOWS_MATRIX" > windows_matrix.json
68+
printf '%s\n' "$MACOS_MATRIX" > macos_matrix.json
69+
if [ -z "${VERSION}" ]; then
70+
python3 ./scripts/gen_quick_start_module.py --autogenerate enable
71+
else
72+
python3 ./scripts/gen_quick_start_module.py --autogenerate enable --version "${VERSION}"
73+
fi
74+
75+
rm *_matrix.json
76+
- name: Create Pull Request
77+
uses: peter-evans/create-pull-request@v3
78+
with:
79+
token: ${{ secrets.GITHUB_TOKEN }}
80+
commit-message: Modify published_versions.json file
81+
title: '[Getting Started Page] Modify published_versions.json file'
82+
body: >
83+
This PR is auto-generated Gettins Started page update
84+
labels: automated pr

published_versions.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,18 @@
7575
"pip": {
7676
"cuda.x": {
7777
"note": "# CUDA is not available on MacOS, please use default package",
78-
"command": "pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu"
78+
"command": "pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu",
79+
"default": true
7980
},
8081
"cuda.y": {
8182
"note": "# CUDA is not available on MacOS, please use default package",
82-
"command": "pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu"
83+
"command": "pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu",
84+
"default": true
8385
},
8486
"rocm5.x": {
8587
"note": "# ROCm is not available on MacOS, please use default package",
86-
"command": "pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu"
88+
"command": "pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu",
89+
"default": true
8790
},
8891
"accnone": {
8992
"note": "# MPS acceleration is available on MacOS 12.3+",
@@ -93,15 +96,18 @@
9396
"conda": {
9497
"cuda.x": {
9598
"note": "# CUDA is not available on MacOS, please use default package",
96-
"command": "conda install pytorch torchvision torchaudio -c pytorch-nightly"
99+
"command": "conda install pytorch torchvision torchaudio -c pytorch-nightly",
100+
"default": true
97101
},
98102
"cuda.y": {
99103
"note": "# CUDA is not available on MacOS, please use default package",
100-
"command": "conda install pytorch torchvision torchaudio -c pytorch-nightly"
104+
"command": "conda install pytorch torchvision torchaudio -c pytorch-nightly",
105+
"default": true
101106
},
102107
"rocm5.x": {
103108
"note": "# ROCm is not available on MacOS, please use default package",
104-
"command": "conda install pytorch torchvision torchaudio -c pytorch-nightly"
109+
"command": "conda install pytorch torchvision torchaudio -c pytorch-nightly",
110+
"default": true
105111
},
106112
"accnone": {
107113
"note": "# MPS acceleration is available on MacOS 12.3+",

scripts/gen_quick_start_module.py

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,139 @@
11
#!/usr/bin/env python3
22
import json
33
import os
4-
from typing import Dict
4+
import argparse
5+
import io
6+
import sys
7+
from pathlib import Path
8+
from typing import Dict, Set, List, Iterable
9+
from enum import Enum
10+
511
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
612

13+
class OperatingSystem(Enum):
14+
LINUX: str = "linux"
15+
WINDOWS: str = "windows"
16+
MACOS: str = "macos"
17+
18+
PRE_CXX11_ABI = "pre-cxx11"
19+
CXX11_ABI = "cxx11-abi"
20+
DEBUG = "debug"
21+
RELEASE = "release"
22+
DEFAULT = "default"
23+
ENABLE = "enable"
24+
DISABLE = "disable"
725

26+
# Mapping json to release matrix is here for now
27+
# TBD drive the mapping via:
28+
# 1. Scanning release matrix and picking 2 latest cuda versions and 1 latest rocm
29+
# 2. Possibility to override the scanning algorithm with arguments passed from workflow
30+
acc_arch_map = {
31+
"accnone": ("cpu", ""),
32+
"cuda.x": ("cuda", "11.6"),
33+
"cuda.y": ("cuda", "11.7"),
34+
"rocm5.x": ("rocm", "5.2")
35+
}
36+
37+
LIBTORCH_DWNL_INSTR = {
38+
PRE_CXX11_ABI: "Download here (Pre-cxx11 ABI):",
39+
CXX11_ABI: "Download here (cxx11 ABI):",
40+
RELEASE: "Download here (Release version):",
41+
DEBUG: "Download here (Debug version):",
42+
}
843

944
def read_published_versions():
1045
with open(os.path.join(BASE_DIR, "published_versions.json")) as fp:
1146
return json.load(fp)
1247

48+
def write_published_versions(versions):
49+
with open(os.path.join(BASE_DIR, "published_versions.json"), "w") as outfile:
50+
json.dump(versions, outfile, indent=2)
51+
52+
def read_matrix_for_os(osys: OperatingSystem):
53+
try:
54+
with open(os.path.join(BASE_DIR, f"{osys.value}_matrix.json")) as fp:
55+
return json.load(fp)["include"]
56+
except FileNotFoundError as e:
57+
raise ImportError(f"Release matrix not found for: {osys.value} error: {e.strerror}") from e
58+
1359

1460
def read_quick_start_module_template():
1561
with open(os.path.join(BASE_DIR, "_includes", "quick-start-module.js")) as fp:
1662
return fp.read()
1763

64+
def update_versions(versions, release_matrix, version):
65+
version_map = {
66+
"preview": "preview",
67+
}
68+
69+
# Generating for a specific version
70+
if(version != "preview"):
71+
version_map = {
72+
version: version,
73+
}
74+
if version in versions["versions"]:
75+
if version != versions["latest_stable"]:
76+
raise RuntimeError(f"Can only update prview, latest stable: {versions['latest_stable']} or new version")
77+
else:
78+
import copy
79+
new_version = copy.deepcopy(versions["versions"]["preview"])
80+
versions["versions"][version] = new_version
81+
versions["latest_stable"] = version
82+
83+
# Perform update of the json file from release matrix
84+
for ver, ver_key in version_map.items():
85+
for os_key, os_vers in versions["versions"][ver_key].items():
86+
for pkg_key, pkg_vers in os_vers.items():
87+
for acc_key, instr in pkg_vers.items():
88+
89+
package_type = pkg_key
90+
if pkg_key == 'pip':
91+
package_type = 'manywheel' if os_key == OperatingSystem.LINUX.value else 'wheel'
92+
93+
gpu_arch_type, gpu_arch_version = acc_arch_map[acc_key]
94+
if(DEFAULT in instr):
95+
gpu_arch_type, gpu_arch_version = acc_arch_map["accnone"]
96+
97+
pkg_arch_matrix = list(filter(
98+
lambda x:
99+
(x["package_type"], x["gpu_arch_type"], x["gpu_arch_version"]) ==
100+
(package_type, gpu_arch_type, gpu_arch_version),
101+
release_matrix[os_key]
102+
))
103+
104+
if pkg_arch_matrix:
105+
if package_type != 'libtorch':
106+
instr["command"] = pkg_arch_matrix[0]["installation"]
107+
else:
108+
if os_key == OperatingSystem.LINUX.value:
109+
rel_entry_pre_cxx1 = next(filter(
110+
lambda x:
111+
x["devtoolset"] == PRE_CXX11_ABI,
112+
pkg_arch_matrix
113+
), None)
114+
rel_entry_cxx1_abi = next(filter(
115+
lambda x:
116+
x["devtoolset"] == CXX11_ABI,
117+
pkg_arch_matrix
118+
), None)
119+
if(instr['versions'] is not None):
120+
instr['versions'][LIBTORCH_DWNL_INSTR[PRE_CXX11_ABI]] = rel_entry_pre_cxx1["installation"]
121+
instr['versions'][LIBTORCH_DWNL_INSTR[CXX11_ABI]] = rel_entry_cxx1_abi["installation"]
122+
elif os_key == OperatingSystem.WINDOWS.value:
123+
rel_entry_release = next(filter(
124+
lambda x:
125+
x["libtorch_config"] == RELEASE,
126+
pkg_arch_matrix
127+
), None)
128+
rel_entry_debug = next(filter(
129+
lambda x:
130+
x["libtorch_config"] == DEBUG,
131+
pkg_arch_matrix
132+
), None)
133+
if(instr['versions'] is not None):
134+
instr['versions'][LIBTORCH_DWNL_INSTR[RELEASE]] = rel_entry_release["installation"]
135+
instr['versions'][LIBTORCH_DWNL_INSTR[DEBUG]] = rel_entry_debug["installation"]
136+
18137

19138
def gen_install_matrix(versions) -> Dict[str, str]:
20139
rc = {}
@@ -41,8 +160,34 @@ def gen_install_matrix(versions) -> Dict[str, str]:
41160
rc[key] = "<br />".join(lines)
42161
return rc
43162

163+
44164
def main():
165+
parser = argparse.ArgumentParser()
166+
parser.add_argument(
167+
"--version",
168+
help="Version to generate the instructions for",
169+
type=str,
170+
default="preview",
171+
)
172+
parser.add_argument(
173+
"--autogenerate",
174+
help="Is this call being initiated from workflow? update published_versions",
175+
type=str,
176+
choices=[ENABLE, DISABLE],
177+
default=DISABLE,
178+
)
179+
180+
options = parser.parse_args()
45181
versions = read_published_versions()
182+
183+
if options.autogenerate == ENABLE:
184+
release_matrix = {}
185+
for osys in OperatingSystem:
186+
release_matrix[osys.value] = read_matrix_for_os(osys)
187+
188+
update_versions(versions, release_matrix, options.version)
189+
write_published_versions()
190+
46191
template = read_quick_start_module_template()
47192
versions_str = json.dumps(gen_install_matrix(versions))
48193
print(template.replace("{{ installMatrix }}", versions_str))

0 commit comments

Comments
 (0)