Skip to content

Commit 80b03f6

Browse files
committed
extract functions to ease maintenance
1 parent 9353dd9 commit 80b03f6

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

update-pytorch.sh

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
#!/bin/bash
22

3-
# old non-updated compute platforms:
4-
# cu75 cu80 cu90 cu91 cu92 cu100 cu101 cu102 cu110 cu111 cu113 cu115 cu116 cu117 cu117_pypi_cudnn
5-
# rocm3.10 rocm3.7 rocm3.8 rocm4.0.1 rocm4.1 rocm4.2 rocm4.3.1 rocm4.5.2 rocm5.0 rocm5.1.1 rocm5.2 rocm5.3 rocm5.4.2 rocm5.5 rocm5.6 rocm5.7
6-
for d in . cpu cpu-cxx11-abi cpu_pypi_pkg cu118 cu121 cu124 rocm6.0 rocm6.1
7-
do
8-
d="whl/$d"
9-
[ "$d" == "whl/." ] && d="whl"
3+
# update a PyPI index from PyTorch = https://download.pytorch.org/$d with d=whl or whl/<compute platform>
4+
# this copies the content (main url + follows links to projects) and does 2 updates:
5+
# 1. copies the content in a "simple/" sub-directory to match the convention from PEP 503 simple (that allows other APIs in parallel)
6+
# 2. updates the links to binary packages by adding "https://download.pytorch.org" prefix to PyTorch-provided "/whl/*" path to link back to PyTorch binaries in their home location
7+
function updateIndex() {
8+
local d=$1
9+
10+
# will copy source $d to $d/simple
1011
mkdir -p $d/simple
11-
dir="$(pwd)"
12+
local dir="$(pwd)"
1213
cd $d/simple
14+
15+
# projects list
1316
curl -s https://download.pytorch.org/$d/ | grep -v 'TIMESTAMP 1' > index.html
14-
count="$(cat index.html | cut -d '>' -f 2 | cut -d '<' -f 1 | grep -cve '^\s*$')"
17+
local count="$(cat index.html | cut -d '>' -f 2 | cut -d '<' -f 1 | grep -cve '^\s*$')"
1518

16-
echo "https://download.pytorch.org/$d/ $count => $d/simple/"
17-
if [ $count -lt 40 ]
18-
then
19-
echo "failing because low packages count for $d: $count (intermittent download failure?)"
20-
exit 1
21-
fi
19+
echo "https://download.pytorch.org/$d/ => $d/simple/"
20+
checkCount $d $count 40
2221

23-
i=0
22+
# copy also content of each project
23+
local i=0
2424
for p in `cat index.html | cut -d '>' -f 2 | cut -d '<' -f 1`
2525
do
2626
mkdir -p $p
@@ -31,20 +31,40 @@ do
3131
| grep -v 'TIMESTAMP 1' \
3232
> index.html
3333

34-
count="$(cat index.html | grep -c 'https://download.pytorch.org/whl/')"
35-
echo "$i $d/$p/ => $d/simple/$p/ $count"
36-
if [ $count -lt 1 ]
37-
then
38-
echo "failing because low packages count for $d/$p: $count (intermittent download failure?)"
39-
exit 1
40-
fi
34+
local pcount="$(cat index.html | grep -c 'https://download.pytorch.org/whl/')"
35+
printf "%5d / $count $d/$p/ => $d/simple/$p/ $pcount\n" $i
36+
checkCount $d/$p $count 1
4137
cd ..
4238
done
4339
echo
4440
cd "$dir"
41+
}
42+
43+
function checkCount() {
44+
local content="$1"
45+
local count="$2"
46+
local minimum="$3"
47+
48+
if [ $count -lt $minimum ]
49+
then
50+
echo "!!! failing because low packages count for $content: $count (probably intermittent download failure)"
51+
exit 1
52+
fi
53+
}
54+
55+
# update main PyTorch index, that contains everything, whatever the compute platform
56+
updateIndex "whl"
57+
58+
# update compute-platform specific indexes
59+
# ignore old non-updated ones:
60+
# - cu75 cu80 cu90 cu91 cu92 cu100 cu101 cu102 cu110 cu111 cu113 cu115 cu116 cu117 cu117_pypi_cudnn
61+
# - rocm3.10 rocm3.7 rocm3.8 rocm4.0.1 rocm4.1 rocm4.2 rocm4.3.1 rocm4.5.2 rocm5.0 rocm5.1.1 rocm5.2 rocm5.3 rocm5.4.2 rocm5.5 rocm5.6 rocm5.7
62+
for d in cpu cpu-cxx11-abi cpu_pypi_pkg cu118 cu121 cu124 rocm6.0 rocm6.1
63+
do
64+
updateIndex "whl/$d"
4565
done
4666

4767
du -sh whl/*
4868

49-
for d in whl/simple whl/*/simple ; do echo "$(ls $d | wc -l) $d" ; done > summary.txt
69+
for d in whl/simple whl/*/simple ; do echo "$(ls $d | wc -l | xargs) $d" ; done > summary.txt
5070
cat summary.txt

0 commit comments

Comments
 (0)