| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/bin/bash
- set -e
- pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
- case "${OSTYPE}" in
- msys*) python="winpty python";;
- *) python="python";;
- esac
- 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() {
- echo "pytorch clean"
- rm -rf "./third_party/env/pytorch"
- rm -rf "./third_party/source/pytorch"
- }
- sync() {
- echo "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() {
- echo "pytorch install"
- venv
- ${python} -m pip install --quiet --upgrade future protobuf
- if [[ "${OSTYPE}" == darwin* ]] && [[ "$(uname -sm)" = "Darwin arm64" ]] && [[ $(${python} -c "import platform; print(platform.uname().machine);") = "arm64" ]]; then
- [ -x "$(brew --prefix openblas)" ] || brew install openblas > /dev/null
- export OPENBLAS=$(brew --prefix openblas)
- ${python} -m pip install --upgrade --quiet pybind11 cython pyyaml
- ${python} -m pip install --upgrade --quiet numpy --no-use-pep517
- else
- ${python} -m pip install --quiet --upgrade scipy
- fi
- ${python} -m pip install --quiet --upgrade --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
- deactivate
- }
- schema() {
- echo "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() {
- echo "pytorch metadata"
- 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
- echo "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
- }
- while [ "$#" != 0 ]; do
- command="$1" && shift
- case "${command}" in
- "clean") clean;;
- "sync") sync;;
- "install") install;;
- "schema") schema;;
- "metadata") metadata;;
- esac
- done
|