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.

logfile_utils.py 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: UTF-8 -*-
  2. """
  3. Copyright 2021 Tianshu AI Platform. All Rights Reserved.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =============================================================
  14. """
  15. from pathlib import Path
  16. from .config_utils import ConfigInstance
  17. from .redis_utils import RedisInstance
  18. support = ["events", ".json"]
  19. def id2logdir(uid, trainJobName):
  20. _base = Path(ConfigInstance.conf_logdir_base()).absolute()
  21. log_dir = _base / uid / trainJobName / "visualizedlog"
  22. try:
  23. int(uid)
  24. except ValueError:
  25. _base = Path("../demo_logs").absolute()
  26. log_dir = _base / uid / trainJobName
  27. cache_dir = Path("../__cache__").absolute() / uid / trainJobName
  28. return log_dir, cache_dir
  29. def get_runinfo(logdir):
  30. """
  31. 给定日志目录,返回有哪些run(文件夹)
  32. """
  33. def check(p):
  34. files = list(p.glob('*events*')) + list(p.glob('*.json'))
  35. return True if files else False
  36. p = Path(logdir)
  37. dirs = sorted(f for f in p.rglob('*') if f.is_dir())
  38. res = {}
  39. if check(p):
  40. res['.'] = p.absolute()
  41. for _dir in dirs:
  42. if check(_dir):
  43. res[_dir.name] = _dir.absolute()
  44. return res
  45. def is_available_flie(filename):
  46. filename = Path(filename)
  47. if filename.is_file():
  48. for _s in support:
  49. if _s in filename.name:
  50. return True
  51. return False
  52. def get_file_path(uid, run, type, tag):
  53. _key = uid + '_' + run + '_' + type + '_' + tag
  54. try:
  55. _res = RedisInstance.get(_key)
  56. return Path(_res)
  57. except TypeError:
  58. raise OSError('Redis key {} not found according to request '
  59. 'parameters, please check the parameters\n _path={}'
  60. .format(_key, _res))
  61. def path_parser(cache_path, run, category, tag):
  62. run = run if not (run == '.') else 'root'
  63. tag = tag.replace('/', '#').replace(':', '$')
  64. if isinstance(cache_path, str):
  65. cache_path = Path(cache_path)
  66. else:
  67. assert isinstance(cache_path, Path), \
  68. f"Parameter cache_path must be a instance of {Path.__name__}"
  69. file_path = cache_path / run / category / tag
  70. return file_path

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能