Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

#670 add clearml & wandb

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-612-add_experiment_monitoring_tutp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  1. import sys
  2. import pkg_resources
  3. from pkg_resources import parse_version
  4. from packaging.specifiers import SpecifierSet
  5. from typing import List, Optional
  6. from pathlib import Path
  7. from super_gradients.common.abstractions.abstract_logger import get_logger
  8. from super_gradients.common.environment.ddp_utils import is_main_process
  9. logger = get_logger(__name__, "DEBUG")
  10. def format_error_msg(test_name: str, error_msg: str) -> str:
  11. """Format an error message in the appropriate format.
  12. :param test_name: Name of the test being tested.
  13. :param error_msg: Message to format in appropriate format.
  14. :return: Formatted message
  15. """
  16. return f"\33[31mFailed to verify {test_name}: {error_msg}\33[0m"
  17. def check_os():
  18. """Check the operating system name and platform."""
  19. if "linux" not in sys.platform.lower():
  20. error = "Deci officially supports only Linux kernels. Some features may not work as expected."
  21. logger.error(msg=format_error_msg(test_name="operating system", error_msg=error))
  22. def get_requirements_path(requirements_file_name: str) -> Optional[Path]:
  23. """Get the path of requirement.txt from the root if exist.
  24. There is a difference when installed from artifact or locally.
  25. - In the first case, requirements.txt is copied to the package during the CI.
  26. - In the second case, requirements.txt in the root of the project.
  27. Note: This is because when installed from artifact only the source code is accessible, so requirements.txt has to be
  28. copied to the package root (./src/super_gradients). This is automatically done with the CI to make sure that
  29. in the github we only have 1 source of truth for requirements.txt. The consequence being that when the code
  30. is copied/cloned from github, the requirements.txt was not copied to the super_gradients package root, so we
  31. need to go to the project root (.) to find it.
  32. """
  33. file_path = Path(__file__) # Refers to: .../super-gradients/src/super_gradients/sanity_check/env_sanity_check.py
  34. package_root = file_path.parent.parent # Refers to: .../super-gradients/src/super_gradients
  35. project_root = package_root.parent.parent # Refers to .../super-gradients
  36. # If installed from artifact, requirements.txt is in package_root, if installed locally it is in project_root
  37. if (package_root / requirements_file_name).exists():
  38. return package_root / requirements_file_name
  39. elif (project_root / requirements_file_name).exists():
  40. return project_root / requirements_file_name
  41. else:
  42. return None # Could happen when installed through github directly ("pip install git+https://github.com/...")
  43. def get_requirements(use_pro_requirements: bool) -> Optional[List[str]]:
  44. requirements_path = get_requirements_path("requirements.txt")
  45. pro_requirements_path = get_requirements_path("requirements.pro.txt")
  46. if (requirements_path is None) or (pro_requirements_path is None):
  47. return None
  48. with open(requirements_path, "r") as f:
  49. requirements = f.read().splitlines()
  50. with open(pro_requirements_path, "r") as f:
  51. pro_requirements = f.read().splitlines()
  52. return requirements + pro_requirements if use_pro_requirements else requirements
  53. def check_packages():
  54. """Check that all installed libs respect the requirement.txt, and requirements.pro.txt if relevant.
  55. Note: We only log an error
  56. """
  57. test_name = "installed packages"
  58. installed_packages = {package.key.lower(): package.version for package in pkg_resources.working_set}
  59. requirements = get_requirements(use_pro_requirements="deci-lab-client" in installed_packages)
  60. if requirements is None:
  61. logger.info(msg='Library check is not supported when super_gradients installed through "git+https://github.com/..." command')
  62. return
  63. for requirement in pkg_resources.parse_requirements(requirements):
  64. package_name = requirement.name.lower()
  65. if package_name not in installed_packages.keys():
  66. error = f"{package_name} required but not found"
  67. logger.error(msg=format_error_msg(test_name=test_name, error_msg=error))
  68. continue
  69. installed_version_str = installed_packages[package_name]
  70. for operator_str, req_version_str in requirement.specs:
  71. installed_version = parse_version(installed_version_str)
  72. req_version = parse_version(req_version_str)
  73. req_spec = SpecifierSet(operator_str + req_version_str)
  74. if installed_version_str not in req_spec:
  75. error = f"{package_name}=={installed_version} does not satisfy requirement {requirement}"
  76. requires_at_least = operator_str in ("==", "~=", ">=", ">")
  77. if requires_at_least and installed_version < req_version:
  78. logger.error(msg=format_error_msg(test_name=test_name, error_msg=error))
  79. else:
  80. logger.debug(msg=error)
  81. def env_sanity_check():
  82. """Run the sanity check tests and log everything that does not meet requirements."""
  83. if is_main_process():
  84. check_os()
  85. check_packages()
  86. if __name__ == "__main__":
  87. env_sanity_check()
Discard
Tip!

Press p or to see the previous file or, n or to see the next file