pytorch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. set -e
  3. pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
  4. [[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
  5. bold() {
  6. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  7. }
  8. venv() {
  9. venv_dir=./third_party/venv/pytorch
  10. [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
  11. case "${OSTYPE}" in
  12. msys*) source ${venv_dir}/Scripts/activate;;
  13. *) source ${venv_dir}/bin/activate;;
  14. esac
  15. ${python} -m pip install --quiet --upgrade pip
  16. }
  17. git_sync() {
  18. mkdir -p "./third_party"
  19. if [ -d "./third_party/${1}" ]; then
  20. git -C "./third_party/${1}" pull --quiet --prune
  21. else
  22. git -C "./third_party" clone --quiet --recursive ${2} ${1}
  23. fi
  24. git -C "./third_party/${1}" submodule sync --quiet
  25. git -C "./third_party/${1}" submodule update --quiet --init --recursive
  26. }
  27. clean() {
  28. bold "pytorch clean"
  29. rm -rf ./third_party/venv/pytorch
  30. rm -rf ./third_party/pytorch
  31. rm -rf ./third_party/torchvision
  32. }
  33. sync() {
  34. bold "pytorch sync"
  35. git_sync pytorch https://github.com/pytorch/pytorch.git
  36. git_sync torchvision https://github.com/pytorch/vision.git
  37. }
  38. install() {
  39. bold "pytorch install"
  40. venv
  41. ${python} -m pip install --quiet --upgrade future protobuf
  42. ${python} -m pip install --quiet --pre --upgrade torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
  43. ${python} -m pip install --quiet --pre --upgrade 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/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. bold "pytorch metadata"
  59. ${python} ./tools/pytorch-script.py metadata
  60. bold "caffe2 metadata"
  61. ${python} ./tools/caffe2-script.py metadata
  62. deactivate
  63. if [[ -n ${crlf} ]]; then
  64. unix2dos --quiet --newfile ./src/pytorch-metadata.json ./src/pytorch-metadata.json
  65. unix2dos --quiet --newfile ./src/caffe2-metadata.json ./src/caffe2-metadata.json
  66. fi
  67. }
  68. zoo() {
  69. bold "pytorch zoo"
  70. venv
  71. ${python} ./tools/pytorch-script.py zoo
  72. deactivate
  73. }
  74. while [ "$#" != 0 ]; do
  75. command="$1" && shift
  76. case "${command}" in
  77. "clean") clean;;
  78. "sync") sync;;
  79. "install") install;;
  80. "schema") schema;;
  81. "metadata") metadata;;
  82. "zoo") zoo;;
  83. esac
  84. done