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.

test_path_parser.py 3.7 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Test the path_parser module."""
  16. from datetime import datetime
  17. from unittest import TestCase, mock
  18. from mindinsight.datavisual.data_transform.summary_watcher import SummaryWatcher
  19. from mindinsight.lineagemgr.common.path_parser import SummaryPathParser
  20. MOCK_SUMMARY_DIRS = [
  21. {
  22. 'relative_path': './relative_path0'
  23. },
  24. {
  25. 'relative_path': './'
  26. },
  27. {
  28. 'relative_path': './relative_path1'
  29. }
  30. ]
  31. MOCK_SUMMARIES = [
  32. {
  33. 'file_name': 'file0.summary.1',
  34. 'create_time': datetime.fromtimestamp(1582031970)
  35. },
  36. {
  37. 'file_name': 'file0.summary.1_lineage',
  38. 'create_time': datetime.fromtimestamp(1582031970)
  39. },
  40. {
  41. 'file_name': 'file1.summary.2',
  42. 'create_time': datetime.fromtimestamp(1582031971)
  43. },
  44. {
  45. 'file_name': 'file1.summary.2_lineage',
  46. 'create_time': datetime.fromtimestamp(1582031971)
  47. }
  48. ]
  49. class TestSummaryPathParser(TestCase):
  50. """Test the class of SummaryPathParser."""
  51. @mock.patch.object(SummaryWatcher, 'list_summaries')
  52. def test_get_lineage_summaries(self, *args):
  53. """Test the function of get_lineage_summaries."""
  54. args[0].return_value = MOCK_SUMMARIES
  55. exp_result = ['file0.summary.1_lineage', 'file1.summary.2_lineage']
  56. summary_dir = '/path/to/summary_dir'
  57. result = SummaryPathParser.get_lineage_summaries(summary_dir)
  58. self.assertEqual(exp_result, result)
  59. args[0].return_value = [
  60. {
  61. 'file_name': 'file0.summary.1',
  62. 'create_time': datetime.fromtimestamp(1582031970)
  63. }
  64. ]
  65. result = SummaryPathParser.get_lineage_summaries(summary_dir)
  66. self.assertEqual([], result)
  67. args[0].return_value = [
  68. {
  69. 'file_name': 'file0.summary.1_lineage',
  70. 'create_time': datetime.fromtimestamp(1582031970)
  71. }
  72. ]
  73. result = SummaryPathParser.get_lineage_summaries(summary_dir)
  74. self.assertEqual(['file0.summary.1_lineage'], result)
  75. args[0].return_value = [
  76. {
  77. 'file_name': 'file0.summary.3_lineage',
  78. 'create_time': datetime.fromtimestamp(1582031970)
  79. },
  80. {
  81. 'file_name': 'file0.summary.2_lineage_lineage',
  82. 'create_time': datetime.fromtimestamp(1582031970)
  83. },
  84. {
  85. 'file_name': 'file1.summary.1_lineage',
  86. 'create_time': datetime.fromtimestamp(1582031971)
  87. },
  88. {
  89. 'file_name': 'file1.summary.7_lineage_lineage',
  90. 'create_time': datetime.fromtimestamp(1582031971)
  91. }
  92. ]
  93. exp_result = ['file1.summary.1_lineage',
  94. 'file0.summary.2_lineage_lineage',
  95. 'file0.summary.3_lineage',
  96. 'file1.summary.7_lineage_lineage']
  97. result = SummaryPathParser.get_lineage_summaries(summary_dir, is_sorted=True)
  98. self.assertEqual(exp_result, result)

MindInsight为MindSpore提供了简单易用的调优调试能力。在训练过程中,可以将标量、张量、图像、计算图、模型超参、训练耗时等数据记录到文件中,通过MindInsight可视化页面进行查看及分析。