2
0

pytorch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. set -e
  3. pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
  4. case "${OSTYPE}" in
  5. msys*) python="winpty python";;
  6. *) python="python";;
  7. esac
  8. venv() {
  9. env_dir=./third_party/env/pytorch
  10. [ -d "${env_dir}" ] || ${python} -m venv ${env_dir}
  11. case "${OSTYPE}" in
  12. msys*) source ${env_dir}/Scripts/activate;;
  13. *) source ${env_dir}/bin/activate;;
  14. esac
  15. ${python} -m pip install --quiet --upgrade pip
  16. }
  17. clean() {
  18. echo "pytorch clean"
  19. rm -rf "./third_party/env/pytorch"
  20. rm -rf "./third_party/source/pytorch"
  21. }
  22. sync() {
  23. echo "pytorch sync"
  24. [ -d "./third_party/source/pytorch" ] || git clone --quiet https://github.com/pytorch/pytorch.git "./third_party/source/pytorch"
  25. git -C "./third_party/source/pytorch" pull --quiet --prune
  26. }
  27. install() {
  28. echo "pytorch install"
  29. venv
  30. ${python} -m pip install --quiet --upgrade future protobuf
  31. ${python} -m pip install --quiet --upgrade six pybind11 cython pyyaml numpy
  32. ${python} -m pip install --quiet --upgrade --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
  33. deactivate
  34. }
  35. schema() {
  36. echo "caffe2 schema"
  37. [[ $(grep -U $'\x0D' ./source/caffe2-proto.js) ]] && crlf=1
  38. node ./tools/protoc.js --text --root caffe2 --out ./source/caffe2-proto.js ./third_party/source/pytorch/caffe2/proto/caffe2.proto
  39. if [[ -n ${crlf} ]]; then
  40. unix2dos --quiet --newfile ./source/caffe2-proto.js ./source/caffe2-proto.js
  41. fi
  42. }
  43. metadata() {
  44. echo "pytorch metadata"
  45. venv
  46. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  47. if [[ $(grep -U $'\x0D' ./source/pytorch-metadata.json) ]]; then crlf=1; else crlf=; fi
  48. ${python} ./tools/pytorch_script.py metadata
  49. if [[ -n ${crlf} ]]; then
  50. unix2dos --quiet --newfile ./source/pytorch-metadata.json ./source/pytorch-metadata.json
  51. fi
  52. deactivate
  53. }
  54. while [ "$#" != 0 ]; do
  55. command="$1" && shift
  56. case "${command}" in
  57. "clean") clean;;
  58. "sync") sync;;
  59. "install") install;;
  60. "schema") schema;;
  61. "metadata") metadata;;
  62. esac
  63. done