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

#378 Feature/sg 281 add kd notebook

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-281-add_kd_notebook
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
  1. import os
  2. from super_gradients.common.abstractions.abstract_logger import get_logger
  3. from super_gradients.common.sg_loggers.base_sg_logger import BaseSGLogger
  4. from super_gradients.common.environment.env_helpers import multi_process_safe
  5. logger = get_logger(__name__)
  6. try:
  7. from deci_lab_client.client import DeciPlatformClient
  8. _imported_deci_lab_failure = None
  9. except (ImportError, NameError, ModuleNotFoundError) as import_err:
  10. logger.warn("Failed to import deci_lab_client")
  11. _imported_deci_lab_failure = import_err
  12. TENSORBOARD_EVENTS_PREFIX = 'events.out.tfevents'
  13. LOGS_PREFIX = 'log_'
  14. class DeciPlatformSGLogger(BaseSGLogger):
  15. """Logger responsible to push logs and tensorboard artifacts to Deci platform."""
  16. def __init__(self, **kwargs):
  17. if _imported_deci_lab_failure is not None:
  18. raise _imported_deci_lab_failure
  19. auth_token = os.getenv("DECI_PLATFORM_TOKEN")
  20. if auth_token is None:
  21. raise ValueError('The environment variable "DECI_PLATFORM_TOKEN" is required in order to use '
  22. 'DeciPlatformSGLogger. Please set it with your own credentials '
  23. '(available in https://console.deci.ai/settings)')
  24. super().__init__(**kwargs)
  25. self.platform_client = DeciPlatformClient()
  26. self.platform_client.login(token=auth_token)
  27. self.platform_client.register_experiment(name=kwargs["experiment_name"])
  28. self.checkpoints_dir_path = kwargs["checkpoints_dir_path"]
  29. @multi_process_safe
  30. def upload(self):
  31. """
  32. Upload both to the destination specified by the user (base behavior), and to Deci platform.
  33. """
  34. # Upload to the destination specified by the user
  35. super(DeciPlatformSGLogger, self).upload()
  36. # Upload to Deci platform
  37. if not os.path.isdir(self.checkpoints_dir_path):
  38. raise ValueError('Provided directory does not exist')
  39. self._upload_latest_file_starting_with(start_with=TENSORBOARD_EVENTS_PREFIX)
  40. self._upload_latest_file_starting_with(start_with=LOGS_PREFIX)
  41. @multi_process_safe
  42. def _upload_latest_file_starting_with(self, start_with: str):
  43. """
  44. Upload the most recent file starting with a specific prefix to the Deci platform.
  45. :param start_with: prefix of the file to upload
  46. """
  47. files_path = [
  48. os.path.join(self.checkpoints_dir_path, file_name)
  49. for file_name in os.listdir(self.checkpoints_dir_path)
  50. if file_name.startswith(start_with)
  51. ]
  52. most_recent_file_path = max(files_path, key=os.path.getctime)
  53. self.platform_client.save_experiment_file(file_path=most_recent_file_path)
  54. logger.info(f"File saved to Deci platform: {most_recent_file_path}")
Discard
Tip!

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