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 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 os
  19. import numpy as np
  20. import mindspore.dataset as ds
  21. FILES = ["../data/dataset/testTFTestAllTypes/test.data"]
  22. DATASET_ROOT = "../data/dataset/testTFTestAllTypes/"
  23. SCHEMA_FILE = "../data/dataset/testTFTestAllTypes/datasetSchema.json"
  24. PIPELINE_FILE = "./pipeline_profiling_1.json"
  25. DATASET_ITERATOR_FILE = "./dataset_iterator_profiling_1.txt"
  26. def test_profiling_simple_pipeline():
  27. """
  28. Generator -> Shuffle -> Batch
  29. """
  30. os.environ['PROFILING_MODE'] = 'true'
  31. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  32. os.environ['DEVICE_ID'] = '1'
  33. source = [(np.array([x]),) for x in range(1024)]
  34. data1 = ds.GeneratorDataset(source, ["data"])
  35. data1 = data1.shuffle(64)
  36. data1 = data1.batch(32)
  37. for _ in data1:
  38. pass
  39. assert os.path.exists(PIPELINE_FILE) is True
  40. os.remove(PIPELINE_FILE)
  41. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  42. os.remove(DATASET_ITERATOR_FILE)
  43. del os.environ['PROFILING_MODE']
  44. del os.environ['MINDDATA_PROFILING_DIR']
  45. def test_profiling_complex_pipeline():
  46. """
  47. Generator -> Map ->
  48. -> Zip -> Batch
  49. TFReader -> Shuffle ->
  50. """
  51. os.environ['PROFILING_MODE'] = 'true'
  52. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  53. os.environ['DEVICE_ID'] = '1'
  54. source = [(np.array([x]),) for x in range(1024)]
  55. data1 = ds.GeneratorDataset(source, ["gen"])
  56. data1 = data1.map("gen", operations=[(lambda x: x + 1)])
  57. pattern = DATASET_ROOT + "/test.data"
  58. data2 = ds.TFRecordDataset(pattern, SCHEMA_FILE, shuffle=ds.Shuffle.FILES)
  59. data2 = data2.shuffle(4)
  60. data3 = ds.zip((data1, data2))
  61. for _ in data3:
  62. pass
  63. assert os.path.exists(PIPELINE_FILE) is True
  64. os.remove(PIPELINE_FILE)
  65. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  66. os.remove(DATASET_ITERATOR_FILE)
  67. del os.environ['PROFILING_MODE']
  68. del os.environ['MINDDATA_PROFILING_DIR']
  69. def test_profiling_sampling_iterval():
  70. """
  71. Test non-default monitor sampling interval
  72. """
  73. os.environ['PROFILING_MODE'] = 'true'
  74. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  75. os.environ['DEVICE_ID'] = '1'
  76. interval_origin = ds.config.get_monitor_sampling_interval()
  77. ds.config.set_monitor_sampling_interval(30)
  78. interval = ds.config.get_monitor_sampling_interval()
  79. assert interval == 30
  80. source = [(np.array([x]),) for x in range(1024)]
  81. data1 = ds.GeneratorDataset(source, ["data"])
  82. data1 = data1.shuffle(64)
  83. data1 = data1.batch(32)
  84. for _ in data1:
  85. pass
  86. assert os.path.exists(PIPELINE_FILE) is True
  87. os.remove(PIPELINE_FILE)
  88. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  89. os.remove(DATASET_ITERATOR_FILE)
  90. ds.config.set_monitor_sampling_interval(interval_origin)
  91. del os.environ['PROFILING_MODE']
  92. del os.environ['MINDDATA_PROFILING_DIR']
  93. if __name__ == "__main__":
  94. test_profiling_simple_pipeline()
  95. test_profiling_complex_pipeline()
  96. test_profiling_sampling_iterval()