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.

task_manager_api.py 3.1 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. """
  16. Task manager api.
  17. This module provides the interfaces to task manage functions.
  18. """
  19. import os
  20. from flask import Blueprint
  21. from flask import request
  22. from flask import jsonify
  23. from mindinsight.conf import settings
  24. from mindinsight.datavisual.utils.tools import str_to_bool
  25. from mindinsight.datavisual.utils.tools import get_train_id
  26. from mindinsight.datavisual.processors.train_task_manager import TrainTaskManager
  27. from mindinsight.datavisual.data_transform.summary_watcher import SummaryWatcher
  28. from mindinsight.datavisual.data_transform.data_manager import DATA_MANAGER
  29. BLUEPRINT = Blueprint("task_manager", __name__, url_prefix=settings.URL_PREFIX)
  30. @BLUEPRINT.route("/datavisual/single-job", methods=["GET"])
  31. def query_single_train_task():
  32. """Query single train task"""
  33. plugin_name = request.args.get('plugin_name')
  34. train_id = get_train_id(request)
  35. processor = TrainTaskManager(DATA_MANAGER)
  36. tasks = processor.get_single_train_task(train_id=train_id, plugin_name=plugin_name)
  37. return jsonify(tasks)
  38. @BLUEPRINT.route("/datavisual/plugins", methods=["GET"])
  39. def query_plugins():
  40. """Query plugins."""
  41. train_id = get_train_id(request)
  42. manual_update = request.args.get('manual_update', default='false')
  43. manual_update = str_to_bool(manual_update, "manual_update")
  44. processor = TrainTaskManager(DATA_MANAGER)
  45. plugins = processor.get_plugins(train_id, manual_update)
  46. return jsonify(plugins)
  47. @BLUEPRINT.route("/datavisual/train-jobs", methods=["GET"])
  48. def query_train_jobs():
  49. """Query train jobs."""
  50. offset = request.args.get("offset", default=0)
  51. limit = request.args.get("limit", default=10)
  52. summary_watcher = SummaryWatcher()
  53. total, directories = summary_watcher.list_summary_directories_by_pagination(
  54. settings.SUMMARY_BASE_DIR, offset, limit)
  55. train_jobs = [{
  56. 'train_id': directory['relative_path'],
  57. 'relative_path': directory['relative_path'],
  58. 'create_time': directory['create_time'].strftime('%Y-%m-%d %H:%M:%S'),
  59. 'update_time': directory['update_time'].strftime('%Y-%m-%d %H:%M:%S'),
  60. } for directory in directories]
  61. return jsonify({
  62. 'name': os.path.basename(os.path.realpath(settings.SUMMARY_BASE_DIR)),
  63. 'total': total,
  64. 'train_jobs': train_jobs,
  65. })
  66. def init_module(app):
  67. """
  68. Init module entry.
  69. Args:
  70. app: the application obj.
  71. """
  72. app.register_blueprint(BLUEPRINT)

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

Contributors (1)