You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

RunConfigTest.cs 4.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using Tensorflow;
  4. using Tensorflow.Eager;
  5. using Tensorflow.Estimators;
  6. namespace TensorFlowNET.UnitTest.Estimators
  7. {
  8. /// <summary>
  9. /// estimator/tensorflow_estimator/python/estimator/run_config_test.py
  10. /// </summary>
  11. [TestClass]
  12. public class RunConfigTest
  13. {
  14. private static readonly string _TEST_DIR = "test_dir";
  15. private static readonly string _MASTER = "master_";
  16. private static readonly string _NOT_SUPPORTED_REPLACE_PROPERTY_MSG = "Replacing .*is not supported";
  17. private static readonly string _SAVE_CKPT_ERR = "`save_checkpoints_steps` and `save_checkpoints_secs` cannot be both set.";
  18. private static readonly string _MODEL_DIR_ERR = "model_dir should be non-empty";
  19. private static readonly string _MODEL_DIR_TF_CONFIG_ERR = "model_dir in TF_CONFIG should be non-empty";
  20. private static readonly string _MODEL_DIR_MISMATCH_ERR = "`model_dir` provided in RunConfig construct, if set, must have the same value as the model_dir in TF_CONFIG. ";
  21. private static readonly string _SAVE_SUMMARY_STEPS_ERR = "save_summary_steps should be >= 0";
  22. private static readonly string _SAVE_CKPT_STEPS_ERR = "save_checkpoints_steps should be >= 0";
  23. private static readonly string _SAVE_CKPT_SECS_ERR = "save_checkpoints_secs should be >= 0";
  24. private static readonly string _SESSION_CONFIG_ERR = "session_config must be instance of ConfigProto";
  25. private static readonly string _KEEP_CKPT_MAX_ERR = "keep_checkpoint_max should be >= 0";
  26. private static readonly string _KEEP_CKPT_HOURS_ERR = "keep_checkpoint_every_n_hours should be > 0";
  27. private static readonly string _TF_RANDOM_SEED_ERR = "tf_random_seed must be integer";
  28. private static readonly string _DEVICE_FN_ERR = "device_fn must be callable with exactly one argument \"op\".";
  29. private static readonly string _ONE_CHIEF_ERR = "The \"cluster\" in TF_CONFIG must have only one \"chief\" node.";
  30. private static readonly string _ONE_MASTER_ERR = "The \"cluster\" in TF_CONFIG must have only one \"master\" node.";
  31. private static readonly string _MISSING_CHIEF_ERR = "If \"cluster\" is set .* it must have one \"chief\" node";
  32. private static readonly string _MISSING_TASK_TYPE_ERR = "If \"cluster\" is set .* task type must be set";
  33. private static readonly string _MISSING_TASK_ID_ERR = "If \"cluster\" is set .* task index must be set";
  34. private static readonly string _INVALID_TASK_INDEX_ERR = "is not a valid task_id";
  35. private static readonly string _NEGATIVE_TASK_INDEX_ERR = "Task index must be non-negative number.";
  36. private static readonly string _INVALID_TASK_TYPE_ERR = "is not a valid task_type";
  37. private static readonly string _INVALID_TASK_TYPE_FOR_LOCAL_ERR = "If \"cluster\" is not set in TF_CONFIG, task type must be WORKER.";
  38. private static readonly string _INVALID_TASK_INDEX_FOR_LOCAL_ERR = "If \"cluster\" is not set in TF_CONFIG, task index must be 0.";
  39. private static readonly string _INVALID_EVALUATOR_IN_CLUSTER_WITH_MASTER_ERR = "If `master` node exists in `cluster`, task_type `evaluator` is not supported.";
  40. private static readonly string _INVALID_CHIEF_IN_CLUSTER_WITH_MASTER_ERR = "If `master` node exists in `cluster`, job `chief` is not supported.";
  41. private static readonly string _INVALID_SERVICE_TYPE_ERR = "If \"service\" is set in TF_CONFIG, it must be a dict. Given";
  42. private static readonly string _EXPERIMENTAL_MAX_WORKER_DELAY_SECS_ERR = "experimental_max_worker_delay_secs must be an integer if set.";
  43. private static readonly string _SESSION_CREATION_TIMEOUT_SECS_ERR = "session_creation_timeout_secs should be > 0";
  44. [TestMethod]
  45. public void test_default_property_values()
  46. {
  47. var config = new RunConfig();
  48. Assert.IsNull(config.model_dir);
  49. Assert.IsNull(config.session_config);
  50. Assert.IsNull(config.tf_random_seed);
  51. Assert.AreEqual(100, config.save_summary_steps);
  52. Assert.AreEqual(600, config.save_checkpoints_secs);
  53. Assert.AreEqual(5, config.keep_checkpoint_max);
  54. Assert.AreEqual(10000, config.keep_checkpoint_every_n_hours);
  55. Assert.IsNull(config.service);
  56. Assert.IsNull(config.device_fn);
  57. Assert.IsNull(config.experimental_max_worker_delay_secs);
  58. Assert.AreEqual(7200, config.session_creation_timeout_secs);
  59. }
  60. }
  61. }