| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #!/bin/bash
- set -e
- pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
- [[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
- bold() {
- echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
- }
- venv() {
- venv_dir=./third_party/venv/pytorch
- [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
- case "${OSTYPE}" in
- msys*) source ${venv_dir}/Scripts/activate;;
- *) source ${venv_dir}/bin/activate;;
- esac
- ${python} -m pip install --quiet --upgrade pip
- }
- git_sync() {
- mkdir -p "./third_party"
- if [ -d "./third_party/${1}" ]; then
- git -C "./third_party/${1}" pull --quiet --prune
- else
- git -C "./third_party" clone --quiet --recursive ${2} ${1}
- fi
- git -C "./third_party/${1}" submodule sync --quiet
- git -C "./third_party/${1}" submodule update --quiet --init --recursive
- }
- clean() {
- bold "pytorch clean"
- rm -rf ./third_party/venv/pytorch
- rm -rf ./third_party/pytorch
- rm -rf ./third_party/torchvision
- }
- sync() {
- bold "pytorch sync"
- git_sync pytorch https://github.com/pytorch/pytorch.git
- git_sync torchvision https://github.com/pytorch/vision.git
- }
- install() {
- bold "pytorch install"
- venv
- ${python} -m pip install --quiet --upgrade future protobuf
- ${python} -m pip install --quiet --pre --upgrade torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
- ${python} -m pip install --quiet --pre --upgrade torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
- deactivate
- }
- schema() {
- bold "caffe2 schema"
- [[ $(grep -U $'\x0D' ./src/caffe2-proto.js) ]] && crlf=1
- npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r caffe2 -o ./src/caffe2-proto.js ./third_party/pytorch/caffe2/proto/caffe2.proto
- node ./tools/update_pbjs.js enumeration ./src/caffe2-proto.js floats float 1
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./src/caffe2-proto.js ./src/caffe2-proto.js
- fi
- }
- metadata() {
- [[ $(grep -U $'\x0D' ./src/pytorch-metadata.json) ]] && crlf=1
- venv
- bold "pytorch metadata"
- ${python} ./tools/pytorch-script.py metadata
- bold "caffe2 metadata"
- ${python} ./tools/caffe2-script.py metadata
- deactivate
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./src/pytorch-metadata.json ./src/pytorch-metadata.json
- unix2dos --quiet --newfile ./src/caffe2-metadata.json ./src/caffe2-metadata.json
- fi
- }
- zoo() {
- bold "pytorch zoo"
- venv
- ${python} ./tools/pytorch-script.py zoo
- deactivate
- }
- while [ "$#" != 0 ]; do
- command="$1" && shift
- case "${command}" in
- "clean") clean;;
- "sync") sync;;
- "install") install;;
- "schema") schema;;
- "metadata") metadata;;
- "zoo") zoo;;
- esac
- done
|