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

#367 fix: Request correct hydra-core

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:hotfix/ALG-000_hydra-req
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
  1. <!DOCTYPE html>
  2. <html class="writer-html5" lang="en" >
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>super_gradients.common.aws_connection.aws_connector &mdash; SuperGradients 1.0 documentation</title>
  7. <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
  8. <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  9. <link rel="stylesheet" href="../../../../_static/graphviz.css" type="text/css" />
  10. <!--[if lt IE 9]>
  11. <script src="../../../../_static/js/html5shiv.min.js"></script>
  12. <![endif]-->
  13. <script data-url_root="../../../../" id="documentation_options" src="../../../../_static/documentation_options.js"></script>
  14. <script src="../../../../_static/jquery.js"></script>
  15. <script src="../../../../_static/underscore.js"></script>
  16. <script src="../../../../_static/doctools.js"></script>
  17. <script src="../../../../_static/js/theme.js"></script>
  18. <link rel="index" title="Index" href="../../../../genindex.html" />
  19. <link rel="search" title="Search" href="../../../../search.html" />
  20. </head>
  21. <body class="wy-body-for-nav">
  22. <div class="wy-grid-for-nav">
  23. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  24. <div class="wy-side-scroll">
  25. <div class="wy-side-nav-search" >
  26. <a href="../../../../index.html" class="icon icon-home"> SuperGradients
  27. </a>
  28. <div role="search">
  29. <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
  30. <input type="text" name="q" placeholder="Search docs" />
  31. <input type="hidden" name="check_keywords" value="yes" />
  32. <input type="hidden" name="area" value="default" />
  33. </form>
  34. </div>
  35. </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
  36. <p class="caption"><span class="caption-text">Welcome To SuperGradients</span></p>
  37. <ul>
  38. <li class="toctree-l1"><a class="reference internal" href="../../../../welcome.html">Fill our 4-question quick survey! We will raffle free SuperGradients swag between those who will participate -&gt; Fill Survey</a></li>
  39. <li class="toctree-l1"><a class="reference internal" href="../../../../welcome.html#supergradients">SuperGradients</a></li>
  40. </ul>
  41. <p class="caption"><span class="caption-text">Technical Documentation</span></p>
  42. <ul>
  43. <li class="toctree-l1"><a class="reference internal" href="../../../../super_gradients.common.html">Common package</a></li>
  44. <li class="toctree-l1"><a class="reference internal" href="../../../../super_gradients.training.html">Training package</a></li>
  45. </ul>
  46. <p class="caption"><span class="caption-text">User Guide</span></p>
  47. <ul>
  48. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html">What is SuperGradients?</a></li>
  49. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#introducing-the-supergradients-library">Introducing the SuperGradients library</a></li>
  50. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#installation">Installation</a></li>
  51. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#integrating-your-training-code-complete-walkthrough">Integrating Your Training Code - Complete Walkthrough</a></li>
  52. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#training-parameters">Training Parameters</a></li>
  53. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#logs-and-checkpoints">Logs and Checkpoints</a></li>
  54. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#dataset-parameters">Dataset Parameters</a></li>
  55. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#network-architectures">Network Architectures</a></li>
  56. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#pretrained-models">Pretrained Models</a></li>
  57. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#how-to-reproduce-our-training-recipes">How To Reproduce Our Training Recipes</a></li>
  58. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#professional-tools-integration">Professional Tools Integration</a></li>
  59. <li class="toctree-l1"><a class="reference internal" href="../../../../user_guide.html#supergradients-faq">SuperGradients FAQ</a></li>
  60. </ul>
  61. </div>
  62. </div>
  63. </nav>
  64. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
  65. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  66. <a href="../../../../index.html">SuperGradients</a>
  67. </nav>
  68. <div class="wy-nav-content">
  69. <div class="rst-content">
  70. <div role="navigation" aria-label="Page navigation">
  71. <ul class="wy-breadcrumbs">
  72. <li><a href="../../../../index.html" class="icon icon-home"></a> &raquo;</li>
  73. <li><a href="../../../index.html">Module code</a> &raquo;</li>
  74. <li>super_gradients.common.aws_connection.aws_connector</li>
  75. <li class="wy-breadcrumbs-aside">
  76. </li>
  77. </ul>
  78. <hr/>
  79. </div>
  80. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  81. <div itemprop="articleBody">
  82. <h1>Source code for super_gradients.common.aws_connection.aws_connector</h1><div class="highlight"><pre>
  83. <span></span><span class="kn">import</span> <span class="nn">sys</span>
  84. <span class="kn">import</span> <span class="nn">boto3</span>
  85. <span class="kn">import</span> <span class="nn">logging</span>
  86. <span class="kn">from</span> <span class="nn">botocore.exceptions</span> <span class="kn">import</span> <span class="n">ClientError</span><span class="p">,</span> <span class="n">ProfileNotFound</span>
  87. <div class="viewcode-block" id="AWSConnector"><a class="viewcode-back" href="../../../../super_gradients.common.aws_connection.html#super_gradients.common.AWSConnector">[docs]</a><span class="k">class</span> <span class="nc">AWSConnector</span><span class="p">:</span>
  88. <span class="sd">&quot;&quot;&quot;</span>
  89. <span class="sd"> AWSConnector - Connects to AWS using Credentials File or IAM Role</span>
  90. <span class="sd"> &quot;&quot;&quot;</span>
  91. <span class="nd">@staticmethod</span>
  92. <span class="k">def</span> <span class="nf">__create_boto_3_session</span><span class="p">(</span><span class="n">profile_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
  93. <span class="sd">&quot;&quot;&quot;</span>
  94. <span class="sd"> __create_boto_3_session</span>
  95. <span class="sd"> :param profile_name:</span>
  96. <span class="sd"> :return:</span>
  97. <span class="sd"> &quot;&quot;&quot;</span>
  98. <span class="n">current_class_name</span> <span class="o">=</span> <span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
  99. <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">current_class_name</span><span class="p">)</span>
  100. <span class="k">try</span><span class="p">:</span>
  101. <span class="k">try</span><span class="p">:</span>
  102. <span class="k">if</span> <span class="n">profile_name</span> <span class="ow">and</span> <span class="n">boto3</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">Session</span><span class="p">(</span><span class="n">profile_name</span><span class="o">=</span><span class="n">profile_name</span><span class="p">)</span><span class="o">.</span><span class="n">get_credentials</span><span class="p">():</span>
  103. <span class="c1"># TRY USING A SPECIFIC PROFILE_NAME (USING A CREDENTIALS FILE)</span>
  104. <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Trying to connect to AWS using Credentials File with profile_name: &#39;</span> <span class="o">+</span> <span class="n">profile_name</span><span class="p">)</span>
  105. <span class="n">session</span> <span class="o">=</span> <span class="n">boto3</span><span class="o">.</span><span class="n">Session</span><span class="p">(</span><span class="n">profile_name</span><span class="o">=</span><span class="n">profile_name</span><span class="p">)</span>
  106. <span class="k">return</span> <span class="n">session</span>
  107. <span class="k">except</span> <span class="n">ProfileNotFound</span> <span class="k">as</span> <span class="n">profileNotFoundException</span><span class="p">:</span>
  108. <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span>
  109. <span class="s1">&#39;[&#39;</span> <span class="o">+</span> <span class="n">current_class_name</span> <span class="o">+</span> <span class="s1">&#39;] - Could not find profile name - Trying using Default Profile/IAM Role&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
  110. <span class="n">profileNotFoundException</span><span class="p">))</span>
  111. <span class="c1"># TRY USING AN IAM ROLE (OR *DEFAULT* CREDENTIALS - USING A CREDENTIALS FILE)</span>
  112. <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Trying to connect to AWS using IAM role or Default Credentials&#39;</span><span class="p">)</span>
  113. <span class="n">session</span> <span class="o">=</span> <span class="n">boto3</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
  114. <span class="k">return</span> <span class="n">session</span>
  115. <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
  116. <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span>
  117. <span class="s1">&#39;[&#39;</span> <span class="o">+</span> <span class="n">current_class_name</span> <span class="o">+</span> <span class="s1">&#39;] - Caught Exception while trying to connect to AWS Credentials Manager &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
  118. <span class="n">ex</span><span class="p">))</span>
  119. <span class="k">return</span> <span class="kc">None</span>
  120. <div class="viewcode-block" id="AWSConnector.get_aws_session"><a class="viewcode-back" href="../../../../super_gradients.common.aws_connection.html#super_gradients.common.AWSConnector.get_aws_session">[docs]</a> <span class="nd">@staticmethod</span>
  121. <span class="k">def</span> <span class="nf">get_aws_session</span><span class="p">(</span><span class="n">profile_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">boto3</span><span class="o">.</span><span class="n">Session</span><span class="p">:</span>
  122. <span class="sd">&quot;&quot;&quot;</span>
  123. <span class="sd"> get_aws_session - Connects to AWS to retrieve an AWS Session</span>
  124. <span class="sd"> :param profile_name: The Config Profile (Environment Name in Credentials file)</span>
  125. <span class="sd"> :return: boto3 Session</span>
  126. <span class="sd"> &quot;&quot;&quot;</span>
  127. <span class="n">current_class_name</span> <span class="o">=</span> <span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
  128. <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">current_class_name</span><span class="p">)</span>
  129. <span class="n">aws_session</span> <span class="o">=</span> <span class="n">AWSConnector</span><span class="o">.</span><span class="n">__create_boto_3_session</span><span class="p">(</span><span class="n">profile_name</span><span class="o">=</span><span class="n">profile_name</span><span class="p">)</span>
  130. <span class="k">if</span> <span class="n">aws_session</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  131. <span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Failed to initiate an AWS Session&#39;</span><span class="p">)</span>
  132. <span class="k">return</span> <span class="n">aws_session</span></div>
  133. <div class="viewcode-block" id="AWSConnector.get_aws_client_for_service_name"><a class="viewcode-back" href="../../../../super_gradients.common.aws_connection.html#super_gradients.common.AWSConnector.get_aws_client_for_service_name">[docs]</a> <span class="nd">@staticmethod</span>
  134. <span class="k">def</span> <span class="nf">get_aws_client_for_service_name</span><span class="p">(</span><span class="n">profile_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">service_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">boto3</span><span class="o">.</span><span class="n">Session</span><span class="o">.</span><span class="n">client</span><span class="p">:</span>
  135. <span class="sd">&quot;&quot;&quot;</span>
  136. <span class="sd"> get_aws_client_for_service_name - Connects to AWS to retrieve the relevant Client</span>
  137. <span class="sd"> :param profile_name: The Config Profile (Environment Name in Credentials file)</span>
  138. <span class="sd"> :param service_name: The AWS Service name to get the Client for</span>
  139. <span class="sd"> :return: Service client instance</span>
  140. <span class="sd"> &quot;&quot;&quot;</span>
  141. <span class="n">current_class_name</span> <span class="o">=</span> <span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
  142. <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">current_class_name</span><span class="p">)</span>
  143. <span class="n">aws_session</span> <span class="o">=</span> <span class="n">AWSConnector</span><span class="o">.</span><span class="n">__create_boto_3_session</span><span class="p">(</span><span class="n">profile_name</span><span class="o">=</span><span class="n">profile_name</span><span class="p">)</span>
  144. <span class="k">if</span> <span class="n">aws_session</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  145. <span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Failed to connect to AWS client: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">service_name</span><span class="p">))</span>
  146. <span class="k">return</span> <span class="n">aws_session</span><span class="o">.</span><span class="n">client</span><span class="p">(</span><span class="n">service_name</span><span class="o">=</span><span class="n">service_name</span><span class="p">)</span></div>
  147. <div class="viewcode-block" id="AWSConnector.get_aws_resource_for_service_name"><a class="viewcode-back" href="../../../../super_gradients.common.aws_connection.html#super_gradients.common.AWSConnector.get_aws_resource_for_service_name">[docs]</a> <span class="nd">@staticmethod</span>
  148. <span class="k">def</span> <span class="nf">get_aws_resource_for_service_name</span><span class="p">(</span><span class="n">profile_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">service_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">boto3</span><span class="o">.</span><span class="n">Session</span><span class="o">.</span><span class="n">resource</span><span class="p">:</span>
  149. <span class="sd">&quot;&quot;&quot;</span>
  150. <span class="sd"> Connects to AWS to retrieve the relevant Resource (More functionality then Client)</span>
  151. <span class="sd"> :param profile_name: The Config Profile (Environment Name in Credentials file)</span>
  152. <span class="sd"> :param service_name: The AWS Service name to get the Client for</span>
  153. <span class="sd"> :return: Service client instance</span>
  154. <span class="sd"> &quot;&quot;&quot;</span>
  155. <span class="n">current_class_name</span> <span class="o">=</span> <span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
  156. <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">current_class_name</span><span class="p">)</span>
  157. <span class="n">aws_session</span> <span class="o">=</span> <span class="n">AWSConnector</span><span class="o">.</span><span class="n">__create_boto_3_session</span><span class="p">(</span><span class="n">profile_name</span><span class="o">=</span><span class="n">profile_name</span><span class="p">)</span>
  158. <span class="k">if</span> <span class="n">aws_session</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  159. <span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Failed to connect to AWS client: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">service_name</span><span class="p">))</span>
  160. <span class="k">return</span> <span class="n">aws_session</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="n">service_name</span><span class="o">=</span><span class="n">service_name</span><span class="p">)</span></div>
  161. <div class="viewcode-block" id="AWSConnector.is_client_error"><a class="viewcode-back" href="../../../../super_gradients.common.aws_connection.html#super_gradients.common.AWSConnector.is_client_error">[docs]</a> <span class="nd">@staticmethod</span>
  162. <span class="k">def</span> <span class="nf">is_client_error</span><span class="p">(</span><span class="n">code</span><span class="p">):</span>
  163. <span class="n">e</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
  164. <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">ClientError</span><span class="p">)</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">response</span><span class="p">[</span><span class="s2">&quot;Error&quot;</span><span class="p">][</span><span class="s2">&quot;Code&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">code</span><span class="p">:</span>
  165. <span class="k">return</span> <span class="n">ClientError</span>
  166. <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;NeverEverRaisedException&quot;</span><span class="p">,</span> <span class="p">(</span><span class="ne">Exception</span><span class="p">,),</span> <span class="p">{})</span></div></div>
  167. </pre></div>
  168. </div>
  169. </div>
  170. <footer>
  171. <hr/>
  172. <div role="contentinfo">
  173. <p>&#169; Copyright 2021, SuperGradients team.</p>
  174. </div>
  175. Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
  176. <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
  177. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  178. </footer>
  179. </div>
  180. </div>
  181. </section>
  182. </div>
  183. <script>
  184. jQuery(function () {
  185. SphinxRtdTheme.Navigation.enable(true);
  186. });
  187. </script>
  188. </body>
  189. </html>
Discard
Tip!

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