pytorch-update 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. set -e
  3. if [ "$#" == 0 ]; then
  4. __sync=true
  5. __build=true
  6. __update=true
  7. else
  8. while test $# -gt 0
  9. do
  10. case "$1" in
  11. sync) __sync=true;;
  12. build) __build=true;;
  13. update) __update=true;;
  14. esac
  15. shift
  16. done
  17. fi
  18. root=$(cd $(dirname ${0})/../..; pwd)
  19. build=${root}/build
  20. node_modules=${root}/node_modules
  21. src=${root}/src
  22. tools=${root}/tools
  23. third_party=${root}/third_party
  24. python="python"
  25. pip="pip"
  26. identifier=pytorch
  27. if [ ${__sync} ]; then
  28. repository=https://github.com/pytorch/pytorch.git
  29. mkdir -p ${third_party}
  30. if [ -d "${third_party}/${identifier}" ]; then
  31. git -C "${third_party}/${identifier}" fetch -p
  32. git -C "${third_party}/${identifier}" reset --hard origin/master
  33. else
  34. echo "Clone ${repository}..."
  35. git -C "${third_party}" clone --recursive ${repository}
  36. fi
  37. git submodule update --init
  38. fi
  39. if [ ${__update} ]; then
  40. echo "Generate 'caffe2.js'"
  41. ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --keep-case --decode-text -r caffe2 -o ${src}/caffe2-proto.js ${third_party}/pytorch/caffe2/proto/caffe2.proto
  42. node ${tools}/metadata/update_pbjs.js enumeration ${src}/caffe2-proto.js floats float 1
  43. fi
  44. if [ ${__build} ]; then
  45. echo "Install Caffe2"
  46. if [ "$(uname -s)" == "Darwin" ] && [ "$(which brew)" != "" ]; then
  47. brew bundle --file=- <<-EOS
  48. brew "automake"
  49. brew "cmake"
  50. brew "gflags"
  51. brew "glog"
  52. EOS
  53. fi
  54. fi
  55. virtualenv=${build}/virtualenv/${identifier}
  56. if [ ${__build} ]; then
  57. virtualenv -p ${python} ${virtualenv}
  58. fi
  59. if [ -f ${virtualenv}/bin/activate ]; then
  60. source ${virtualenv}/bin/activate
  61. fi
  62. if [ ${__build} ]; then
  63. ${pip} install --quiet future leveldb numpy protobuf pydot python-gflags pyyaml scikit-image setuptools six hypothesis typing
  64. pushd "${third_party}/pytorch" > /dev/null
  65. ${python} setup.py install
  66. # MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ ${python} setup.py install
  67. popd > /dev/null
  68. fi
  69. if [ ${__update} ]; then
  70. echo "Generate 'caffe2-metadata.json'"
  71. pushd ${tools}/metadata > /dev/null
  72. ${python} caffe2-metadata.py
  73. popd > /dev/null
  74. fi
  75. if [ -f ${virtualenv}/bin/activate ]; then
  76. deactivate
  77. fi