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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. for _ in data1:
  39. pass
  40. assert os.path.exists(PIPELINE_FILE) is True
  41. os.remove(PIPELINE_FILE)
  42. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  43. os.remove(DATASET_ITERATOR_FILE)
  44. del os.environ['PROFILING_MODE']
  45. del os.environ['MINDDATA_PROFILING_DIR']
  46. def test_profiling_complex_pipeline():
  47. """
  48. Generator -> Map ->
  49. -> Zip
  50. TFReader -> Shuffle ->
  51. """
  52. os.environ['PROFILING_MODE'] = 'true'
  53. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  54. os.environ['DEVICE_ID'] = '1'
  55. source = [(np.array([x]),) for x in range(1024)]
  56. data1 = ds.GeneratorDataset(source, ["gen"])
  57. data1 = data1.map(operations=[(lambda x: x + 1)], input_columns=["gen"])
  58. pattern = DATASET_ROOT + "/test.data"
  59. data2 = ds.TFRecordDataset(pattern, SCHEMA_FILE, shuffle=ds.Shuffle.FILES)
  60. data2 = data2.shuffle(4)
  61. data3 = ds.zip((data1, data2))
  62. for _ in data3:
  63. pass
  64. with open(PIPELINE_FILE) as f:
  65. data = json.load(f)
  66. op_info = data["op_info"]
  67. assert len(op_info) == 5
  68. for i in range(5):
  69. assert "size" in op_info[i]["metrics"]["output_queue"]
  70. assert "length" in op_info[i]["metrics"]["output_queue"]
  71. assert "throughput" in op_info[i]["metrics"]["output_queue"]
  72. assert os.path.exists(PIPELINE_FILE) is True
  73. os.remove(PIPELINE_FILE)
  74. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  75. os.remove(DATASET_ITERATOR_FILE)
  76. del os.environ['PROFILING_MODE']
  77. del os.environ['MINDDATA_PROFILING_DIR']
  78. def test_profiling_sampling_iterval():
  79. """
  80. Test non-default monitor sampling interval
  81. """
  82. os.environ['PROFILING_MODE'] = 'true'
  83. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  84. os.environ['DEVICE_ID'] = '1'
  85. interval_origin = ds.config.get_monitor_sampling_interval()
  86. ds.config.set_monitor_sampling_interval(30)
  87. interval = ds.config.get_monitor_sampling_interval()
  88. assert interval == 30
  89. source = [(np.array([x]),) for x in range(1024)]
  90. data1 = ds.GeneratorDataset(source, ["data"])
  91. data1 = data1.shuffle(64)
  92. data1 = data1.batch(32)
  93. for _ in data1:
  94. pass
  95. assert os.path.exists(PIPELINE_FILE) is True
  96. os.remove(PIPELINE_FILE)
  97. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  98. os.remove(DATASET_ITERATOR_FILE)
  99. ds.config.set_monitor_sampling_interval(interval_origin)
  100. del os.environ['PROFILING_MODE']
  101. del os.environ['MINDDATA_PROFILING_DIR']
  102. if __name__ == "__main__":
  103. test_profiling_simple_pipeline()
  104. test_profiling_complex_pipeline()
  105. test_profiling_sampling_iterval()