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

#578 Feature/sg 516 support head replacement for local pretrained weights unknown dataset

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-516_support_head_replacement_for_local_pretrained_weights_unknown_dataset
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
  1. import sys
  2. import boto3
  3. import logging
  4. from botocore.exceptions import ClientError, ProfileNotFound
  5. class AWSConnector:
  6. """
  7. AWSConnector - Connects to AWS using Credentials File or IAM Role
  8. """
  9. @staticmethod
  10. def __create_boto_3_session(profile_name: str):
  11. """
  12. __create_boto_3_session
  13. :param profile_name:
  14. :return:
  15. """
  16. current_class_name = __class__.__name__
  17. logger = logging.getLogger(current_class_name)
  18. try:
  19. try:
  20. if profile_name and boto3.session.Session(profile_name=profile_name).get_credentials():
  21. # TRY USING A SPECIFIC PROFILE_NAME (USING A CREDENTIALS FILE)
  22. logger.info('Trying to connect to AWS using Credentials File with profile_name: ' + profile_name)
  23. session = boto3.Session(profile_name=profile_name)
  24. return session
  25. except ProfileNotFound as profileNotFoundException:
  26. logger.debug(
  27. '[' + current_class_name + '] - Could not find profile name - Trying using Default Profile/IAM Role' + str(
  28. profileNotFoundException))
  29. # TRY USING AN IAM ROLE (OR *DEFAULT* CREDENTIALS - USING A CREDENTIALS FILE)
  30. logger.info('Trying to connect to AWS using IAM role or Default Credentials')
  31. session = boto3.Session()
  32. return session
  33. except Exception as ex:
  34. logger.critical(
  35. '[' + current_class_name + '] - Caught Exception while trying to connect to AWS Credentials Manager ' + str(
  36. ex))
  37. return None
  38. @staticmethod
  39. def get_aws_session(profile_name: str) -> boto3.Session:
  40. """
  41. get_aws_session - Connects to AWS to retrieve an AWS Session
  42. :param profile_name: The Config Profile (Environment Name in Credentials file)
  43. :return: boto3 Session
  44. """
  45. current_class_name = __class__.__name__
  46. logger = logging.getLogger(current_class_name)
  47. aws_session = AWSConnector.__create_boto_3_session(profile_name=profile_name)
  48. if aws_session is None:
  49. logger.error('Failed to initiate an AWS Session')
  50. return aws_session
  51. @staticmethod
  52. def get_aws_client_for_service_name(profile_name: str, service_name: str) -> boto3.Session.client:
  53. """
  54. get_aws_client_for_service_name - Connects to AWS to retrieve the relevant Client
  55. :param profile_name: The Config Profile (Environment Name in Credentials file)
  56. :param service_name: The AWS Service name to get the Client for
  57. :return: Service client instance
  58. """
  59. current_class_name = __class__.__name__
  60. logger = logging.getLogger(current_class_name)
  61. aws_session = AWSConnector.__create_boto_3_session(profile_name=profile_name)
  62. if aws_session is None:
  63. logger.error('Failed to connect to AWS client: ' + str(service_name))
  64. return aws_session.client(service_name=service_name)
  65. @staticmethod
  66. def get_aws_resource_for_service_name(profile_name: str, service_name: str) -> boto3.Session.resource:
  67. """
  68. Connects to AWS to retrieve the relevant Resource (More functionality then Client)
  69. :param profile_name: The Config Profile (Environment Name in Credentials file)
  70. :param service_name: The AWS Service name to get the Client for
  71. :return: Service client instance
  72. """
  73. current_class_name = __class__.__name__
  74. logger = logging.getLogger(current_class_name)
  75. aws_session = AWSConnector.__create_boto_3_session(profile_name=profile_name)
  76. if aws_session is None:
  77. logger.error('Failed to connect to AWS client: ' + str(service_name))
  78. return aws_session.resource(service_name=service_name)
  79. @staticmethod
  80. def is_client_error(code):
  81. e = sys.exc_info()[1]
  82. if isinstance(e, ClientError) and e.response["Error"]["Code"] == code:
  83. return ClientError
  84. return type("NeverEverRaisedException", (Exception,), {})
Discard
Tip!

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