pytorch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. clean() {
  9. echo "pytorch clean"
  10. rm -rf "./third_party/source/pytorch"
  11. rm -rf "./third_party/source/executorch/schema"
  12. }
  13. sync() {
  14. echo "pytorch sync"
  15. [ -d "./third_party/source/pytorch" ] || git clone --quiet https://github.com/pytorch/pytorch.git "./third_party/source/pytorch"
  16. git -C "./third_party/source/pytorch" pull --quiet --prune
  17. mkdir -p "./third_party/source/executorch/schema"
  18. curl --silent --location --output "./third_party/source/executorch/schema/scalar_type.fbs" "https://github.com/pytorch/executorch/raw/main/schema/scalar_type.fbs"
  19. curl --silent --location --output "./third_party/source/executorch/schema/program.fbs" "https://github.com/pytorch/executorch/raw/main/schema/program.fbs"
  20. }
  21. schema() {
  22. [[ $(grep -U $'\x0D' ./source/pytorch-schema.js) ]] && crlf=1
  23. echo "pytorch schema"
  24. node ./tools/flatc.js --root torch --out ./source/pytorch-schema.js ./third_party/source/pytorch/torch/csrc/jit/serialization/mobile_bytecode.fbs ./third_party/source/executorch/schema/program.fbs
  25. if [[ -n ${crlf} ]]; then
  26. unix2dos --quiet --newfile ./source/pytorch-schema.js ./source/pytorch-schema.js
  27. fi
  28. }
  29. metadata() {
  30. echo "pytorch metadata"
  31. [[ $(grep -U $'\x0D' ./source/pytorch-metadata.json) ]] && crlf=1
  32. ${python} ./tools/pytorch_script.py
  33. if [[ -n ${crlf} ]]; then
  34. unix2dos --quiet --newfile ./source/pytorch-metadata.json ./source/pytorch-metadata.json
  35. fi
  36. }
  37. while [ "$#" != 0 ]; do
  38. command="$1" && shift
  39. case "${command}" in
  40. "clean") clean;;
  41. "sync") sync;;
  42. "schema") schema;;
  43. "metadata") metadata;;
  44. esac
  45. done