Skip to content

Commit e2532c7

Browse files
authored
Merge pull request pytorch#146 from pjh5/always_upload
Allowing individual uploads of builds
2 parents 666e50b + dada862 commit e2532c7

File tree

10 files changed

+157
-163
lines changed

10 files changed

+157
-163
lines changed

conda/build_pytorch.sh

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,17 @@ set -ex
1010
# There's also duplicate versioning logic amongst *all* the building scripts
1111

1212
# Env variables that should be set
13-
# LINUX env variables that should be set
14-
# HOST_PACKAGE_DIR
15-
# Absolute path (in docker space) to folder where final packages will be
16-
# stored.
13+
# PYTORCH_FINAL_PACKAGE_DIR
14+
# Absolute path (in docker space) to folder where final packages will be
15+
# stored.
1716
#
1817
# MACOS env variables that should be set
19-
# MAC_CONDA_FINAL_FOLDER
20-
# **Absolute** path to folder where final packages will be stored.
21-
#
2218
# MAC_PACKAGE_WORK_DIR
2319
# Absolute path to a workdir in which to clone an isolated conda
2420
# installation and pytorch checkout. If the pytorch checkout already exists
2521
# then it will not be overwritten.
2622
#
2723
# WINDOWS env variables that should be set
28-
# WIN_CONDA_FINAL_FOLDER
29-
# **Absolute** path to folder where final packages will be stored.
30-
#
3124
# WIN_PACKAGE_WORK_DIR
3225
# Absolute path to a workdir in which to clone an isolated conda
3326
# installation and pytorch checkout. If the pytorch checkout already exists
@@ -267,17 +260,8 @@ for py_ver in "${DESIRED_PYTHON[@]}"; do
267260
built_package="$(find $output_folder/ -name '*pytorch*.tar.bz2')"
268261

269262
# Copy the built package to the host machine for persistence before testing
270-
if [[ -n "$HOST_PACKAGE_DIR" ]]; then
271-
mkdir -p "$HOST_PACKAGE_DIR/conda_pkgs" || true
272-
cp "$built_package" "$HOST_PACKAGE_DIR/conda_pkgs/"
273-
fi
274-
if [[ -n "$MAC_CONDA_FINAL_FOLDER" ]]; then
275-
mkdir -p "$MAC_CONDA_FINAL_FOLDER" || true
276-
cp "$built_package" "$MAC_CONDA_FINAL_FOLDER/"
277-
fi
278-
if [[ -n "$WIN_CONDA_FINAL_FOLDER" ]]; then
279-
mkdir -p "$WIN_CONDA_FINAL_FOLDER" || true
280-
cp "$built_package" "$WIN_CONDA_FINAL_FOLDER/"
263+
if [[ -n "$PYTORCH_FINAL_PACKAGE_DIR" && -d "$PYTORCH_FINAL_PACKAGE_DIR" ]]; then
264+
cp "$built_package" "$PYTORCH_FINAL_PACKAGE_DIR/"
281265
fi
282266

283267
conda install -y "$built_package"

cron/build_docker.sh

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,9 @@ SOURCE_DIR=$(cd $(dirname $0) && pwd)
77
source "${SOURCE_DIR}/nightly_defaults.sh"
88

99
# Handles building for manywheels and linux conda packages.
10-
# Env variables that should be set:
11-
# PYTORCH_BUILD_VERSION
12-
# This is the version string, e.g. 0.4.1 , that will be used as the
13-
# pip/conda version, OR the word 'nightly', which signals all the
14-
# downstream scripts to use the current date as the version number (plus
15-
# other changes). This is NOT the conda build string.
16-
#
17-
# PYTORCH_BUILD_NUMBER
18-
# This is usually the number 1. If more than one build is uploaded for the
19-
# same version/date, then this can be incremented to 2,3 etc in which case
20-
# '.post2' will be appended to the version string of the package. This can
21-
# be set to '0' only if OVERRIDE_PACKAGE_VERSION is being used to bypass
22-
# all the version string logic in downstream scripts.
23-
#
24-
# NIGHTLIES_FOLDER
25-
# An arbitrary root folder to store all nightlies folders, each of which is
26-
# a parent level date folder with separate subdirs for logs, wheels, conda
27-
# packages, etc. This should be kept the same across all scripts called in
28-
# a cron job, so it only has a default value in the top-most script
29-
# build_cron.sh to avoid the default values from diverging.
30-
#
31-
# NIGHTLIES_DATE
32-
# The date in YYYY_mm_dd format that we are building for. This defaults to
33-
# the current date. Sometimes cron uses a different time than that returned
34-
# by `date`, so ideally this is set once by the top-most script
35-
# build_cron.sh so that all scripts use the same date.
3610

3711
# Parameters
3812
##############################################################################
39-
4013
if [[ "$#" != 3 ]]; then
4114
if [[ -z "$DESIRED_PYTHON" || -z "$DESIRED_CUDA" || -z "$PACKAGE_TYPE" ]]; then
4215
echo "The env variabled PACKAGE_TYPE must be set to 'conda' or 'manywheel' or 'libtorch'"
@@ -60,10 +33,15 @@ fi
6033
echo "Building a $package_type package for python$desired_python and $desired_cuda"
6134
echo "Starting to run the build at $(date)"
6235

36+
# Organize folders by os, package_type, and cuda version
37+
host_package_dir="$(nightlies_package_folder $package_type $desired_cuda)"
38+
mkdir -p "$host_package_dir" || true
39+
40+
# This is the name of the package dir dockerside
41+
docker_package_dir="/host_machine_pkgs"
42+
6343
# Move to today's workspace folder
6444
mkdir -p "$today" || true
65-
host_package_dir="$today"
66-
docker_package_dir="/host_machine_pkgs"
6745

6846
# Map cuda/python/storage dirs for conda or manywheel
6947
python_nodot="${desired_python:0:1}${desired_python:2:1}"
@@ -164,7 +142,7 @@ nvidia-docker cp "$NIGHTLIES_PYTORCH_ROOT" "$id:/pytorch"
164142
echo "export DESIRED_PYTHON=${desired_python}"
165143
echo "export DESIRED_CUDA=${desired_cuda}"
166144
# the following line is true from the docker's perspective
167-
echo "export HOST_PACKAGE_DIR=${docker_package_dir}"
145+
echo "export PYTORCH_FINAL_PACKAGE_DIR=${docker_package_dir}"
168146
echo "export CMAKE_ARGS=${CMAKE_ARGS[@]}"
169147
echo "export EXTRA_CAFFE2_CMAKE_FLAGS=${EXTRA_CAFFE2_CMAKE_FLAGS[@]}"
170148
echo "export RUN_TEST_PARAMS=${RUN_TEST_PARAMS}"

cron/build_mac.sh

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,9 @@ source "${SOURCE_DIR}/nightly_defaults.sh"
77

88
# Handles building for mac wheels and mac conda packages and mac libtorch packages.
99
# Env variables that should be set:
10-
# PYTORCH_BUILD_VERSION
11-
# This is the version string, e.g. 0.4.1 , that will be used as the
12-
# pip/conda version, OR the word 'nightly', which signals all the
13-
# downstream scripts to use the current date as the version number (plus
14-
# other changes). This is NOT the conda build string.
15-
#
16-
# PYTORCH_BUILD_NUMBER
17-
# This is usually the number 1. If more than one build is uploaded for the
18-
# same version/date, then this can be incremented to 2,3 etc in which case
19-
# '.post2' will be appended to the version string of the package. This can
20-
# be set to '0' only if OVERRIDE_PACKAGE_VERSION is being used to bypass
21-
# all the version string logic in downstream scripts.
22-
#
23-
# NIGHTLIES_FOLDER
24-
# An arbitrary root folder to store all nightlies folders, each of which is
25-
# a parent level date folder with separate subdirs for logs, wheels, conda
26-
# packages, etc. This should be kept the same across all scripts called in
27-
# a cron job, so it only has a default value in the top-most script
28-
# build_cron.sh to avoid the default values from diverging.
29-
#
30-
# NIGHTLIES_DATE
31-
# The date in YYYY_mm_dd format that we are building for. This defaults to
32-
# the current date. Sometimes cron uses a different time than that returned
33-
# by `date`, so ideally this is set once by the top-most script
34-
# build_cron.sh so that all scripts use the same date.
3510

3611
# Parameters
3712
##############################################################################
38-
3913
if [[ "$#" != 2 ]]; then
4014
if [[ -z "$DESIRED_PYTHON" || -z "$PACKAGE_TYPE" ]]; then
4115
echo "The env variabled PACKAGE_TYPE must be set to 'conda' or 'manywheel' or 'libtorch'"
@@ -47,20 +21,17 @@ if [[ "$#" != 2 ]]; then
4721
else
4822
package_type="$1"
4923
desired_python="$2"
50-
desired_cuda="$3"
5124
fi
5225
if [[ "$package_type" != 'conda' && "$package_type" != 'wheel' && "$package_type" != 'libtorch' ]]; then
5326
echo "The package type must be 'conda' or 'wheel' or 'libtorch'"
5427
exit 1
5528
fi
29+
echo "$(date) Building a $package_type MacOS package for python$desired_python"
30+
export PYTORCH_FINAL_PACKAGE_DIR="$(nightlies_package_folder $package_type cpu)"
31+
mkdir -p "$PYTORCH_FINAL_PACKAGE_DIR"
5632

57-
echo "Building a $package_type package for python$desired_python"
58-
echo "Starting to run the build at $(date)"
59-
60-
# Move to today's workspace folder
61-
mkdir -p "$today" || true
62-
63-
# Make the workdir for the mac builds
33+
# Setup a workdir
34+
##############################################################################
6435
workdir="${today}/wheel_build_dirs/${package_type}_${desired_python}"
6536
export MAC_PACKAGE_WORK_DIR="$workdir"
6637
rm -rf "$workdir"
@@ -70,21 +41,16 @@ mkdir -p "$workdir"
7041
cp -R "$NIGHTLIES_PYTORCH_ROOT" "$workdir"
7142

7243
# Build the package
44+
##############################################################################
7345
if [[ "$package_type" == 'conda' ]]; then
74-
# Conda package settings
7546
export TORCH_PACKAGE_NAME="$(echo $TORCH_PACKAGE_NAME | tr '_' '-')"
76-
export MAC_PACKAGE_FINAL_FOLDER="$MAC_CONDA_FINAL_FOLDER"
7747
"${NIGHTLIES_BUILDER_ROOT}/conda/build_pytorch.sh"
7848
ret="$?"
7949
else
8050
if [[ "$package_type" == 'libtorch' ]]; then
8151
export BUILD_PYTHONLESS=1
8252
fi
83-
84-
# Wheel settings
8553
export TORCH_PACKAGE_NAME="$(echo $TORCH_PACKAGE_NAME | tr '-' '_')"
86-
export MAC_PACKAGE_FINAL_FOLDER="$MAC_WHEEL_FINAL_FOLDER"
87-
building_wheels=1
8854
"${NIGHTLIES_BUILDER_ROOT}/wheel/build_wheel.sh"
8955
ret="$?"
9056
fi

cron/build_multiple.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ source "${SOURCE_DIR}/nightly_defaults.sh"
2424
if [ "$#" -lt 3 ]; then
2525
echo 'Illegal number of parameters'
2626
echo ' build_multiple.sh [conda|manywheel|wheel] DESIRED_PYTHON,s DESIRED_CUDA,s'
27-
echo 'e.g. build_multiple.sh manywheel 2.7mu,3.5,3.6 cpu,cu80'
27+
echo 'e.g. build_multiple.sh manywheel 2.7mu,3.5m,3.6m cpu,cu80'
2828
echo 'e.g. build_multiple.sh conda,manywheel 2.7 all'
2929
echo ' DESIRED_PYTHONs must match: \d.\d(mu?)?'
3030
echo ' DESIRED_CUDAs must match : (cpu|cu\d\d)'
@@ -73,12 +73,9 @@ while [[ $# -gt 0 ]]; do
7373
done
7474

7575

76-
# Allow 'all' to translate to all python/cuda versions
77-
7876
set +x
7977
echo
80-
echo "Starting PyTorch binary build for $NIGHTLIES_DATE"
81-
echo "$(date) :: Starting PyTorch binaries build"
78+
echo "$(date) :: Starting PyTorch binary build for $NIGHTLIES_DATE"
8279
echo "Building all of [${all_configs[@]}]"
8380
set -x
8481

cron/nightly_defaults.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fi
6060
# Used in lots of places as the root dir to store all conda/wheel/manywheel
6161
# packages as well as logs for the day
6262
export today="$NIGHTLIES_FOLDER/$NIGHTLIES_DATE"
63+
mkdir -p "$today" || true
6364

6465
# N.B. BUILDER_REPO and BUILDER_BRANCH are both set in cron_start.sh, as that
6566
# is the script that actually clones the builder repo that /this/ script is
@@ -154,12 +155,15 @@ if [[ -z "$PIP_UPLOAD_FOLDER" ]]; then
154155
export PIP_UPLOAD_FOLDER='nightly/'
155156
fi
156157

157-
# MAC_(CONDA|WHEEL|LIBTORCH)_FINAL_FOLDER
158-
# Absolute path to the folders where final conda/wheel packages should be
159-
# stored
160-
export MAC_CONDA_FINAL_FOLDER="${today}/mac_conda_pkgs"
161-
export MAC_WHEEL_FINAL_FOLDER="${today}/mac_wheels"
162-
export MAC_LIBTORCH_FINAL_FOLDER="${today}/mac_libtorch_packages"
158+
# nightlies_package_folder()
159+
# Function from (package_type, CUDA/cpu ver) -> where packages should be
160+
# stored. OS does not factor since the folders will be on different machines
161+
# and won't overlap
162+
# N.B. PYTORCH_FINAL_PACKAGE_DIR is not a constant, and is not set here. This
163+
# should be set by build_docker or build_mac according to this function.
164+
nightlies_package_folder () {
165+
echo "${today}/$1/$2/"
166+
}
163167

164168
# (FAILED|SUCCEEDED)_LOG_DIR
165169
# Absolute path to folders that store final logs. Initially these folders

cron/upload.sh

Lines changed: 89 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,36 @@ echo "upload.sh at $(pwd) starting at $(date) on $(uname -a) with pid $$"
55
SOURCE_DIR=$(cd $(dirname $0) && pwd)
66
source "${SOURCE_DIR}/nightly_defaults.sh"
77

8-
# Upload all the wheels and conda packages.
8+
# Upload all nightly packages.
9+
# This has two use cases:
10+
# In the regular nightlies use-case this script is passed all the succesfull
11+
# logs
12+
# ./cron/upload.sh conda_2.7_cpu.log manywheel_2.7mu_cu80.log ...
13+
# and only those corresponding packages are uploaded.
14+
# Otherwise, if given no parameters this will upload all packages.
915

10-
# If given package types, then only upload those package types
11-
if [[ "$#" -eq 0 ]]; then
12-
upload_wheels=1
13-
upload_condas=1
14-
else
15-
upload_wheels=0
16-
upload_condas=0
17-
while [[ $# -gt 0 ]]; do
18-
if [[ "$1" == *wheel* ]]; then
19-
upload_wheels=1
20-
fi
21-
if [[ "$1" == *conda* ]]; then
22-
upload_condas=1
23-
fi
24-
shift
25-
done
26-
fi
16+
upload_it () {
17+
pkg_type="$1"
18+
cuda_ver="$2"
19+
pkg="$3"
2720

21+
if [[ "$pkg_type" == 'conda' ]]; then
22+
echo "Uploading $pkg_dir/$pkg to anaconda"
23+
anaconda upload "$pkg_dir/$pkg" -u pytorch --label main
24+
elif [[ "$pkg_type" == 'libtorch' ]]; then
25+
s3_dir="s3://pytorch/libtorch/${PIP_UPLOAD_FOLDER}${cuda_ver}/"
26+
echo "Uploading $pkg_dir/$pkg to $s3_dir"
27+
aws s3 cp "$pkg_dir/$pkg" "$s3_dir" --acl public-read
28+
else
29+
uploaded_a_wheel=1
30+
s3_dir="s3://pytorch/whl/${PIP_UPLOAD_FOLDER}${cuda_ver}/"
31+
echo "Uploading $pkg_dir/$pkg to $s3_dir"
32+
aws s3 cp "$pkg_dir/$pkg" "$s3_dir" --acl public-read
33+
fi
34+
}
2835

36+
# Set-up tools we need to upload
37+
##############################################################################
2938
# Source the credentials if given
3039
if [[ -x "$PYTORCH_CREDENTIALS_FILE" ]]; then
3140
source "$PYTORCH_CREDENTIALS_FILE"
@@ -61,20 +70,69 @@ if [[ "$ret" -ne 0 || "$ret1" -ne 0 || "$ret2" -ne 0 ]]; then
6170
yes | anaconda login --username "$PYTORCH_ANACONDA_USERNAME" --password "$PYTORCH_ANACONDA_PASSWORD"
6271
fi
6372

73+
# Loop through all packages to upload
74+
##############################################################################
75+
# If given package types, then only upload those package types
76+
packages_to_upload=()
77+
if [[ "$#" -eq 0 ]]; then
78+
# If not given any specific packages to upload, then upload everything that
79+
# we can find
80+
# Packages are organized by type and CUDA/cpu version so we have to loop
81+
# over these to find all the packages
82+
_ALL_PKG_TYPES=("manywheel" "wheel" "conda" "libtorch")
83+
_ALL_CUDA_VERSIONS=("cpu" "cu80" "cu90" "cu92")
84+
for pkg_type in "${_ALL_PKG_TYPES[@]}"; do
85+
for cuda_ver in "${_ALL_CUDA_VERSIONS[@]}"; do
86+
pkg_dir="$(nightlies_package_folder $pkg_type $cuda_ver)"
87+
if [[ ! -d "$pkg_dir" ]]; then
88+
continue
89+
fi
90+
all_pkgs=($(ls $pkg_dir))
91+
for pkg in "${all_pkgs[@]}"; do
92+
upload_it "$pkg_type" "$cuda_ver" "$pkg"
93+
done
94+
done
95+
done
96+
else
97+
# Else we're given a bunch of log names, turn these into exact packages
98+
# Remove all '.log's from the names
99+
all_configs=()
100+
while [[ $# -gt 0 ]]; do
101+
IFS=, confs=($(basename $1 .log | tr '_' ','))
102+
pkg_type="${confs[0]}"
103+
py_ver="${confs[1]}"
104+
cuda_ver="${confs[2]}"
105+
pkg_dir="$(nightlies_package_folder $pkg_type $cuda_ver)"
64106

65-
# Upload wheels
66-
if [[ "$upload_wheels" == 1 ]]; then
67-
if [[ "$(uname)" == 'Darwin' ]]; then
68-
"${NIGHTLIES_BUILDER_ROOT}/wheel/upload.sh"
69-
else
70-
PACKAGE_ROOT_DIR="$today" "${NIGHTLIES_BUILDER_ROOT}/manywheel/upload.sh"
71-
fi
107+
# Map e.g. 2.7mu -> cp27mu
108+
if [[ "${#py_ver}" -gt 3 ]]; then
109+
if [[ "$py_ver" == '2.7mu' ]]; then
110+
py_ver="cp27mu"
111+
else
112+
py_ver="cp${py_ver:0:1}${py_ver:2:1}m"
113+
fi
114+
fi
72115

73-
# Update wheel htmls
74-
"${NIGHTLIES_BUILDER_ROOT}/update_s3_htmls.sh"
116+
# Find the exact package to upload
117+
# We need to match - or _ after the python version to avoid matching
118+
# cp27mu when we're trying to mach cp27m. TODO this will only work when
119+
# the name in both conda and wheel packages does follow the python
120+
# version with a - or _
121+
set +e
122+
unset pkg
123+
pkg="$(ls $pkg_dir | grep $py_ver[-_])"
124+
set -e
125+
if [[ -n "$pkg" ]]; then
126+
# Add pkg_type/cuda_ver/package_name to the list
127+
upload_it "$pkg_type" "$cuda_ver" "$pkg"
128+
else
129+
echo "!!WARNING!! Could not find the package for $1. I looked for"
130+
echo "!!WARNING!! python version $py_ver in $pkg_dir but couldn't"
131+
echo "!!WARNING!! find anything"
132+
fi
133+
shift
134+
done
75135
fi
76136

77-
# Upload conda packages
78-
if [[ "$upload_condas" == 1 ]]; then
79-
"${NIGHTLIES_BUILDER_ROOT}/conda/upload.sh"
80-
fi
137+
# Update wheel htmls
138+
"${NIGHTLIES_BUILDER_ROOT}/update_s3_htmls.sh"

0 commit comments

Comments
 (0)