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.

conftest.py 2.4 kB

6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright 2019 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. """The st config."""
  16. import os
  17. import shutil
  18. import sys
  19. import tempfile
  20. import pytest
  21. from ....utils import mindspore
  22. from ....utils.mindspore.dataset.engine.serializer_deserializer import SERIALIZED_PIPELINE
  23. sys.modules['mindspore'] = mindspore
  24. BASE_SUMMARY_DIR = tempfile.mkdtemp(prefix='test_lineage_summary_dir_base_')
  25. SUMMARY_DIR = os.path.join(BASE_SUMMARY_DIR, 'run1')
  26. SUMMARY_DIR_2 = os.path.join(BASE_SUMMARY_DIR, 'run2')
  27. SUMMARY_DIR_3 = os.path.join(BASE_SUMMARY_DIR, 'except_run')
  28. COLLECTION_MODULE = 'TestModelLineage'
  29. API_MODULE = 'TestModelApi'
  30. DATASET_GRAPH = SERIALIZED_PIPELINE
  31. def get_module_name(nodeid):
  32. """Get the module name from nodeid."""
  33. _, module_name, _ = nodeid.split("::")
  34. return module_name
  35. def pytest_collection_modifyitems(items):
  36. """Modify the execution order."""
  37. split_items = {
  38. COLLECTION_MODULE: [],
  39. API_MODULE: []
  40. }
  41. for item in items:
  42. module_name = get_module_name(item.nodeid)
  43. module_item = split_items.get(module_name)
  44. if module_item is not None:
  45. module_item.append(item)
  46. ordered_items = split_items.get(COLLECTION_MODULE)
  47. ordered_items.extend(split_items.get(API_MODULE))
  48. items[:] = ordered_items
  49. @pytest.fixture(scope="session")
  50. def create_summary_dir():
  51. """Create summary directory."""
  52. try:
  53. if os.path.exists(BASE_SUMMARY_DIR):
  54. shutil.rmtree(BASE_SUMMARY_DIR)
  55. permissions = os.R_OK | os.W_OK | os.X_OK
  56. mode = permissions << 6
  57. if not os.path.exists(BASE_SUMMARY_DIR):
  58. os.mkdir(BASE_SUMMARY_DIR, mode=mode)
  59. yield
  60. finally:
  61. if os.path.exists(BASE_SUMMARY_DIR):
  62. shutil.rmtree(BASE_SUMMARY_DIR)

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