pytorch 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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=python3;;
  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/src/pytorch"
  24. rm -rf "./third_party/src/torchvision"
  25. }
  26. sync() {
  27. bold "pytorch sync"
  28. [ -d "./third_party/src/pytorch" ] || git clone --quiet --recursive https://github.com/pytorch/pytorch.git "./third_party/src/pytorch"
  29. pushd "./third_party/src/pytorch" > /dev/null
  30. git pull --quiet --prune
  31. git submodule sync --quiet
  32. git submodule update --quiet --init --recursive
  33. popd > /dev/null
  34. [ -d "./third_party/src/torchvision" ] || git clone --quiet --recursive https://github.com/pytorch/vision.git "./third_party/src/torchvision"
  35. pushd "./third_party/src/torchvision" > /dev/null
  36. git pull --quiet --prune
  37. popd > /dev/null
  38. }
  39. install() {
  40. bold "pytorch install"
  41. venv
  42. ${python} -m pip install --quiet --upgrade future protobuf scipy
  43. ${python} -m pip install --quiet --upgrade --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
  44. deactivate
  45. }
  46. schema() {
  47. bold "caffe2 schema"
  48. [[ $(grep -U $'\x0D' ./src/caffe2-proto.js) ]] && crlf=1
  49. 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/src/pytorch/caffe2/proto/caffe2.proto
  50. node ./tools/update_pbjs.js enumeration ./src/caffe2-proto.js floats float 1
  51. if [[ -n ${crlf} ]]; then
  52. unix2dos --quiet --newfile ./src/caffe2-proto.js ./src/caffe2-proto.js
  53. fi
  54. }
  55. metadata() {
  56. [[ $(grep -U $'\x0D' ./src/pytorch-metadata.json) ]] && crlf=1
  57. venv
  58. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  59. bold "pytorch metadata"
  60. ${python} ./tools/pytorch-script.py metadata
  61. bold "caffe2 metadata"
  62. ${python} ./tools/caffe2-script.py metadata
  63. deactivate
  64. if [[ -n ${crlf} ]]; then
  65. unix2dos --quiet --newfile ./src/pytorch-metadata.json ./src/pytorch-metadata.json
  66. unix2dos --quiet --newfile ./src/caffe2-metadata.json ./src/caffe2-metadata.json
  67. fi
  68. }
  69. zoo() {
  70. bold "pytorch zoo"
  71. venv
  72. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  73. ${python} ./tools/pytorch-script.py zoo
  74. deactivate
  75. }
  76. while [ "$#" != 0 ]; do
  77. command="$1" && shift
  78. case "${command}" in
  79. "clean") clean;;
  80. "sync") sync;;
  81. "install") install;;
  82. "schema") schema;;
  83. "metadata") metadata;;
  84. "zoo") zoo;;
  85. esac
  86. done