| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #!/bin/bash
- set -e
- pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
- case "${OSTYPE}" in
- msys*) python="winpty python";;
- *) python="python";;
- esac
- bold() {
- echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
- }
- venv() {
- env_dir=./third_party/env/pytorch
- [ -d "${env_dir}" ] || ${python} -m venv ${env_dir}
- case "${OSTYPE}" in
- msys*) source ${env_dir}/Scripts/activate;;
- *) source ${env_dir}/bin/activate;;
- esac
- ${python} -m pip install --quiet --upgrade pip
- }
- clean() {
- bold "pytorch clean"
- rm -rf "./third_party/env/pytorch"
- rm -rf "./third_party/source/pytorch"
- }
- sync() {
- bold "pytorch sync"
- [ -d "./third_party/source/pytorch" ] || git clone --quiet --recursive https://github.com/pytorch/pytorch.git "./third_party/source/pytorch"
- pushd "./third_party/source/pytorch" > /dev/null
- git pull --quiet --prune
- git submodule sync --quiet
- git submodule update --quiet --init --recursive
- popd > /dev/null
- }
- install() {
- bold "pytorch install"
- if [ "$(uname -ms)" = "Darwin arm64" ]; then
- echo "- arm64 [skip]"
- return
- fi
- venv
- ${python} -m pip install --quiet --upgrade future protobuf scipy
- ${python} -m pip install --quiet --upgrade --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
- deactivate
- }
- schema() {
- bold "caffe2 schema"
- [[ $(grep -U $'\x0D' ./source/caffe2-proto.js) ]] && crlf=1
- node ./tools/protoc.js --text --root caffe2 --out ./source/caffe2-proto.js ./third_party/source/pytorch/caffe2/proto/caffe2.proto
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./source/caffe2-proto.js ./source/caffe2-proto.js
- fi
- }
- metadata() {
- bold "pytorch metadata"
- if [ "$(uname -ms)" = "Darwin arm64" ]; then
- echo "- arm64 [skip]"
- return
- fi
- venv
- export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- if [[ $(grep -U $'\x0D' ./source/pytorch-metadata.json) ]]; then crlf=1; else crlf=; fi
- ${python} ./tools/pytorch-script.py metadata
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./source/pytorch-metadata.json ./source/pytorch-metadata.json
- fi
- deactivate
- bold "caffe2 metadata"
- venv
- if [[ $(grep -U $'\x0D' ./source/caffe2-metadata.json) ]]; then crlf=1; else crlf=; fi
- ${python} ./tools/caffe2-script.py metadata
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./source/caffe2-metadata.json ./source/caffe2-metadata.json
- fi
- deactivate
- }
- zoo() {
- bold "pytorch zoo"
- rm -rf "./third_party/env/pytorch"
- venv
- ${python} -m pip install --quiet --upgrade future protobuf scipy
- ${python} -m pip install --quiet --upgrade --pre torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
- export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- ${python} ./tools/pytorch-script.py zoo
- deactivate
- rm -rf "./third_party/env/pytorch"
- }
- while [ "$#" != 0 ]; do
- command="$1" && shift
- case "${command}" in
- "clean") clean;;
- "sync") sync;;
- "install") install;;
- "schema") schema;;
- "metadata") metadata;;
- "zoo") zoo;;
- esac
- done
|