pytorch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. bold() {
  9. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  10. }
  11. venv() {
  12. env_dir=./third_party/env/pytorch
  13. [ -d "${env_dir}" ] || ${python} -m venv ${env_dir}
  14. case "${OSTYPE}" in
  15. msys*) source ${env_dir}/Scripts/activate;;
  16. *) source ${env_dir}/bin/activate;;
  17. esac
  18. ${python} -m pip install --quiet --upgrade pip
  19. }
  20. clean() {
  21. bold "pytorch clean"
  22. rm -rf "./third_party/env/pytorch"
  23. rm -rf "./third_party/source/pytorch"
  24. }
  25. sync() {
  26. bold "pytorch sync"
  27. [ -d "./third_party/source/pytorch" ] || git clone --quiet --recursive https://github.com/pytorch/pytorch.git "./third_party/source/pytorch"
  28. pushd "./third_party/source/pytorch" > /dev/null
  29. git pull --quiet --prune
  30. git submodule sync --quiet
  31. git submodule update --quiet --init --recursive
  32. popd > /dev/null
  33. }
  34. install() {
  35. bold "pytorch install"
  36. if [ "$(uname -ms)" = "Darwin arm64" ]; then
  37. echo "- arm64 [skip]"
  38. return
  39. fi
  40. venv
  41. ${python} -m pip install --quiet --upgrade future protobuf scipy
  42. ${python} -m pip install --quiet --upgrade --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
  43. deactivate
  44. }
  45. schema() {
  46. bold "caffe2 schema"
  47. [[ $(grep -U $'\x0D' ./source/caffe2-proto.js) ]] && crlf=1
  48. node ./tools/protoc.js --text --root caffe2 --out ./source/caffe2-proto.js ./third_party/source/pytorch/caffe2/proto/caffe2.proto
  49. if [[ -n ${crlf} ]]; then
  50. unix2dos --quiet --newfile ./source/caffe2-proto.js ./source/caffe2-proto.js
  51. fi
  52. }
  53. metadata() {
  54. bold "pytorch metadata"
  55. if [ "$(uname -ms)" = "Darwin arm64" ]; then
  56. echo "- arm64 [skip]"
  57. return
  58. fi
  59. venv
  60. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  61. if [[ $(grep -U $'\x0D' ./source/pytorch-metadata.json) ]]; then crlf=1; else crlf=; fi
  62. ${python} ./tools/pytorch-script.py metadata
  63. if [[ -n ${crlf} ]]; then
  64. unix2dos --quiet --newfile ./source/pytorch-metadata.json ./source/pytorch-metadata.json
  65. fi
  66. deactivate
  67. bold "caffe2 metadata"
  68. venv
  69. if [[ $(grep -U $'\x0D' ./source/caffe2-metadata.json) ]]; then crlf=1; else crlf=; fi
  70. ${python} ./tools/caffe2-script.py metadata
  71. if [[ -n ${crlf} ]]; then
  72. unix2dos --quiet --newfile ./source/caffe2-metadata.json ./source/caffe2-metadata.json
  73. fi
  74. deactivate
  75. }
  76. zoo() {
  77. bold "pytorch zoo"
  78. rm -rf "./third_party/env/pytorch"
  79. venv
  80. ${python} -m pip install --quiet --upgrade future protobuf scipy
  81. ${python} -m pip install --quiet --upgrade --pre torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
  82. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  83. ${python} ./tools/pytorch-script.py zoo
  84. deactivate
  85. rm -rf "./third_party/env/pytorch"
  86. }
  87. while [ "$#" != 0 ]; do
  88. command="$1" && shift
  89. case "${command}" in
  90. "clean") clean;;
  91. "sync") sync;;
  92. "install") install;;
  93. "schema") schema;;
  94. "metadata") metadata;;
  95. "zoo") zoo;;
  96. esac
  97. done