model_trainer_test.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # Copyright 2017 Google Inc. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ==============================================================================
  16. # This test runs the model trainer on a snapshotted model directory. This is a
  17. # "don't crash" test, so it does not evaluate the trained model.
  18. set -eu
  19. readonly DRAGNN_DIR="${TEST_SRCDIR}/${TEST_WORKSPACE}/dragnn"
  20. readonly MODEL_TRAINER="${DRAGNN_DIR}/tools/model_trainer"
  21. readonly MODEL_DIR="${DRAGNN_DIR}/tools/testdata/biaffine.model"
  22. readonly CORPUS="${DRAGNN_DIR}/tools/testdata/small.conll"
  23. readonly TMP_DIR="/tmp/model_trainer_test.$$"
  24. readonly TMP_MODEL_DIR="${TMP_DIR}/biaffine.model"
  25. rm -rf "${TMP_DIR}"
  26. mkdir -p "${TMP_DIR}"
  27. # Copy all testdata files to a temp dir, so they can be modified (see below).
  28. cp "${CORPUS}" "${TMP_DIR}"
  29. mkdir -p "${TMP_MODEL_DIR}"
  30. for name in hyperparameters.pbtxt targets.pbtxt resources; do
  31. cp -r "${MODEL_DIR}/${name}" "${TMP_MODEL_DIR}/${name}"
  32. done
  33. # Replace "TESTDATA" with the temp dir path in config files that contain paths.
  34. for name in config.txt master.pbtxt; do
  35. sed "s=TESTDATA=${TMP_DIR}=" "${MODEL_DIR}/${name}" \
  36. > "${TMP_MODEL_DIR}/${name}"
  37. done
  38. "${MODEL_TRAINER}" \
  39. --model_dir="${TMP_MODEL_DIR}" \
  40. --pretrain_steps='1' \
  41. --train_epochs='10' \
  42. --alsologtostderr
  43. echo "PASS"