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_profiling.py 4.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. """
  16. Testing profiling support in DE
  17. """
  18. import json
  19. import os
  20. import numpy as np
  21. import mindspore.dataset as ds
  22. FILES = ["../data/dataset/testTFTestAllTypes/test.data"]
  23. DATASET_ROOT = "../data/dataset/testTFTestAllTypes/"
  24. SCHEMA_FILE = "../data/dataset/testTFTestAllTypes/datasetSchema.json"
  25. PIPELINE_FILE = "./pipeline_profiling_1.json"
  26. DATASET_ITERATOR_FILE = "./dataset_iterator_profiling_1.txt"
  27. def test_profiling_simple_pipeline():
  28. """
  29. Generator -> Shuffle -> Batch
  30. """
  31. os.environ['PROFILING_MODE'] = 'true'
  32. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  33. os.environ['DEVICE_ID'] = '1'
  34. source = [(np.array([x]),) for x in range(1024)]
  35. data1 = ds.GeneratorDataset(source, ["data"])
  36. data1 = data1.shuffle(64)
  37. data1 = data1.batch(32)
  38. # try output shape type and dataset size and make sure no profiling file is generated
  39. assert data1.output_shapes() == [[32, 1]]
  40. assert [str(tp) for tp in data1.output_types()] == ["int64"]
  41. assert data1.get_dataset_size() == 32
  42. assert os.path.exists(PIPELINE_FILE) is False
  43. assert os.path.exists(DATASET_ITERATOR_FILE) is False
  44. for _ in data1:
  45. pass
  46. assert os.path.exists(PIPELINE_FILE) is True
  47. os.remove(PIPELINE_FILE)
  48. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  49. os.remove(DATASET_ITERATOR_FILE)
  50. del os.environ['PROFILING_MODE']
  51. del os.environ['MINDDATA_PROFILING_DIR']
  52. def test_profiling_complex_pipeline():
  53. """
  54. Generator -> Map ->
  55. -> Zip
  56. TFReader -> Shuffle ->
  57. """
  58. os.environ['PROFILING_MODE'] = 'true'
  59. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  60. os.environ['DEVICE_ID'] = '1'
  61. source = [(np.array([x]),) for x in range(1024)]
  62. data1 = ds.GeneratorDataset(source, ["gen"])
  63. data1 = data1.map(operations=[(lambda x: x + 1)], input_columns=["gen"])
  64. pattern = DATASET_ROOT + "/test.data"
  65. data2 = ds.TFRecordDataset(pattern, SCHEMA_FILE, shuffle=ds.Shuffle.FILES)
  66. data2 = data2.shuffle(4)
  67. data3 = ds.zip((data1, data2))
  68. for _ in data3:
  69. pass
  70. with open(PIPELINE_FILE) as f:
  71. data = json.load(f)
  72. op_info = data["op_info"]
  73. assert len(op_info) == 5
  74. for i in range(4):
  75. assert "size" in op_info[i]["metrics"]["output_queue"]
  76. assert "length" in op_info[i]["metrics"]["output_queue"]
  77. assert "throughput" in op_info[i]["metrics"]["output_queue"]
  78. assert os.path.exists(PIPELINE_FILE) is True
  79. os.remove(PIPELINE_FILE)
  80. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  81. os.remove(DATASET_ITERATOR_FILE)
  82. del os.environ['PROFILING_MODE']
  83. del os.environ['MINDDATA_PROFILING_DIR']
  84. def test_profiling_sampling_interval():
  85. """
  86. Test non-default monitor sampling interval
  87. """
  88. os.environ['PROFILING_MODE'] = 'true'
  89. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  90. os.environ['DEVICE_ID'] = '1'
  91. interval_origin = ds.config.get_monitor_sampling_interval()
  92. ds.config.set_monitor_sampling_interval(30)
  93. interval = ds.config.get_monitor_sampling_interval()
  94. assert interval == 30
  95. source = [(np.array([x]),) for x in range(1024)]
  96. data1 = ds.GeneratorDataset(source, ["data"])
  97. data1 = data1.shuffle(64)
  98. data1 = data1.batch(32)
  99. for _ in data1:
  100. pass
  101. assert os.path.exists(PIPELINE_FILE) is True
  102. os.remove(PIPELINE_FILE)
  103. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  104. os.remove(DATASET_ITERATOR_FILE)
  105. ds.config.set_monitor_sampling_interval(interval_origin)
  106. del os.environ['PROFILING_MODE']
  107. del os.environ['MINDDATA_PROFILING_DIR']
  108. if __name__ == "__main__":
  109. test_profiling_simple_pipeline()
  110. test_profiling_complex_pipeline()
  111. test_profiling_sampling_interval()