pytorch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. set -e
  3. root=$(cd $(dirname ${0})/..; pwd)
  4. build=${root}/build
  5. node_modules=${root}/node_modules
  6. src=${root}/src
  7. tools=${root}/tools
  8. third_party=${root}/third_party
  9. identifier=pytorch
  10. virtualenv=${build}/virtualenv/${identifier}
  11. python="python"
  12. pip="pip"
  13. git_sync() {
  14. mkdir -p "${third_party}"
  15. if [ -d "${third_party}/${1}" ]; then
  16. git -C "${third_party}/${1}" fetch -p --quiet
  17. git -C "${third_party}/${1}" reset --quiet --hard origin/master
  18. else
  19. echo "Clone ${2}..."
  20. git -C "${third_party}" clone --recursive ${2}
  21. fi
  22. git submodule update --init
  23. }
  24. sync() {
  25. git_sync pytorch https://github.com/pytorch/pytorch.git
  26. }
  27. install() {
  28. echo "Install Caffe2"
  29. if [ "$(uname -s)" == "Darwin" ] && [ "$(which brew)" != "" ]; then
  30. brew bundle --file=- <<-EOS
  31. brew "automake"
  32. brew "cmake"
  33. brew "gflags"
  34. brew "glog"
  35. EOS
  36. fi
  37. virtualenv --quiet -p ${python} ${virtualenv}
  38. source ${virtualenv}/bin/activate
  39. ${pip} install --quiet future leveldb numpy protobuf pydot python-gflags pyyaml scikit-image setuptools six hypothesis typing
  40. pushd "${third_party}/pytorch" > /dev/null
  41. ${python} setup.py install
  42. popd > /dev/null
  43. deactivate
  44. }
  45. schema() {
  46. echo "Generate 'caffe2.js'"
  47. ${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
  48. node ${tools}/update_pbjs.js enumeration ${src}/caffe2-proto.js floats float 1
  49. }
  50. metadata() {
  51. source ${virtualenv}/bin/activate
  52. pushd ${tools} > /dev/null
  53. echo "Generate 'caffe2-metadata.json'"
  54. ${python} caffe2-script.py metadata
  55. echo "Generate 'pytorch-metadata.json'"
  56. ${python} pytorch-script.py metadata
  57. popd > /dev/null
  58. deactivate
  59. }
  60. while [ "$#" != 0 ]; do
  61. command="$1" && shift
  62. case "${command}" in
  63. "sync") sync;;
  64. "install") install;;
  65. "schema") schema;;
  66. "metadata") metadata;;
  67. esac
  68. done