Skip to content

Commit aa3a1f9

Browse files
committed
added pandas 2.0 support, minor issues
1 parent b7ceb5b commit aa3a1f9

30 files changed

+848
-527
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test.ipnb
2+
venv/*
3+
my_emission_file.csv
4+
.DS_Store

eco2ai/.DS_Store

6 KB
Binary file not shown.
544 Bytes
Binary file not shown.
570 Bytes
Binary file not shown.
542 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
22.7 KB
Binary file not shown.
15.4 KB
Binary file not shown.
20.6 KB
Binary file not shown.
15.5 KB
Binary file not shown.

eco2ai/data/config.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"project_name": "YourProjectName", "experiment_description": "training the <your model> model", "file_name": "my_emission_file.csv", "measure_period": 10, "pue": 1}

eco2ai/emission_track.py

Lines changed: 445 additions & 405 deletions
Large diffs are not rendered by default.
163 Bytes
Binary file not shown.
167 Bytes
Binary file not shown.
161 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

eco2ai/tools/tools_gpu.py

Lines changed: 125 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,62 @@
22
import time
33
import warnings
44

5-
FROM_mWATTS_TO_kWATTH = 1000*1000*3600
5+
FROM_mWATTS_TO_kWATTH = 1000 * 1000 * 3600
6+
67

78
class NoGPUWarning(Warning):
89
pass
910

10-
class GPU():
11+
12+
class GPU:
1113
"""
12-
This class is interface for tracking gpu consumption.
13-
All methods are done here on the assumption that all gpu devices are of equal model.
14-
The GPU class is not intended for separate usage, outside the Tracker class
14+
This class is interface for tracking gpu consumption.
15+
All methods are done here on the assumption that all gpu devices are of equal model.
16+
The GPU class is not intended for separate usage, outside the Tracker class
1517
1618
"""
19+
1720
def __init__(self, ignore_warnings=False):
1821
"""
19-
This class method initializes GPU object.
20-
Creates fields of class object. All the fields are private variables
22+
This class method initializes GPU object.
23+
Creates fields of class object. All the fields are private variables
2124
22-
Parameters
23-
----------
24-
ignore_warnings: bool
25-
If true, then user will be notified of all the warnings. If False, there won't be any warnings.
26-
The default is False.
25+
Parameters
26+
----------
27+
ignore_warnings: bool
28+
If true, then user will be notified of all the warnings. If False, there won't be any warnings.
29+
The default is False.
2730
28-
Returns
29-
-------
30-
GPU: GPU
31-
Object of class GPU
31+
Returns
32+
-------
33+
GPU: GPU
34+
Object of class GPU
3235
3336
"""
3437
self._consumption = 0
3538
self._ignore_warnings = ignore_warnings
3639
self.is_gpu_available = is_gpu_available()
3740

3841
if not self.is_gpu_available and not self._ignore_warnings:
39-
warnings.warn(message="\n\nThere is no any available GPU devices or your GPU is not supported by Nvidia library!\nThe tracker will consider CPU usage only\n",
40-
category=NoGPUWarning)
42+
warnings.warn(
43+
message="""There is no any available GPU devices or your GPU is not supported by Nvidia library!\nThe tracker will consider CPU usage only""",
44+
category=NoGPUWarning,
45+
)
4146
if self.is_gpu_available:
4247
self._start = time.time()
43-
48+
4449
def calculate_consumption(self):
4550
"""
46-
This class method calculates GPU power consumption.
47-
48-
Parameters
49-
----------
50-
No parameters
51-
52-
Returns
53-
-------
54-
consumption: float
55-
CPU power consumption
51+
This class method calculates GPU power consumption.
52+
53+
Parameters
54+
----------
55+
No parameters
56+
57+
Returns
58+
-------
59+
consumption: float
60+
CPU power consumption
5661
"""
5762
if not self.is_gpu_available:
5863
return 0
@@ -65,37 +70,37 @@ def calculate_consumption(self):
6570
consumption = 0
6671
self._consumption += consumption
6772
return consumption
68-
73+
6974
def get_consumption(self):
7075
"""
71-
This class method returns GPU power consupmtion amount.
76+
This class method returns GPU power consupmtion amount.
7277
73-
Parameters
74-
----------
75-
No parameters
78+
Parameters
79+
----------
80+
No parameters
7681
77-
Returns
78-
-------
79-
self._consumption: float
80-
CPU power consumption
82+
Returns
83+
-------
84+
self._consumption: float
85+
CPU power consumption
8186
8287
"""
8388
if not self.is_gpu_available:
8489
return 0
8590
return self._consumption
86-
91+
8792
def gpu_memory(self):
8893
"""
89-
This class method returns GPU Memory used. Pynvml library is used.
94+
This class method returns GPU Memory used. Pynvml library is used.
9095
91-
Parameters
92-
----------
93-
No parameters
96+
Parameters
97+
----------
98+
No parameters
9499
95-
Returns
96-
-------
97-
gpus_memory: list
98-
list of GPU Memory used per every GPU
100+
Returns
101+
-------
102+
gpus_memory: list
103+
list of GPU Memory used per every GPU
99104
100105
"""
101106
if not self.is_gpu_available:
@@ -111,16 +116,16 @@ def gpu_memory(self):
111116

112117
def gpu_temperature(self):
113118
"""
114-
This class method returns GPU temperature. Pynvml library is used.
119+
This class method returns GPU temperature. Pynvml library is used.
115120
116-
Parameters
117-
----------
118-
No parameters
121+
Parameters
122+
----------
123+
No parameters
119124
120-
Returns
121-
-------
122-
gpus_temps: list
123-
list of GPU temperature per every GPU
125+
Returns
126+
-------
127+
gpus_temps: list
128+
list of GPU temperature per every GPU
124129
125130
"""
126131
if not self.is_gpu_available:
@@ -136,16 +141,16 @@ def gpu_temperature(self):
136141

137142
def gpu_power(self):
138143
"""
139-
This class method returns GPU power consumption. Pynvml library is used.
144+
This class method returns GPU power consumption. Pynvml library is used.
140145
141-
Parameters
142-
----------
143-
No parameters
146+
Parameters
147+
----------
148+
No parameters
144149
145-
Returns
146-
-------
147-
gpus_powers: list
148-
list of GPU power consumption per every GPU
150+
Returns
151+
-------
152+
gpus_powers: list
153+
list of GPU power consumption per every GPU
149154
150155
"""
151156
if not self.is_gpu_available:
@@ -161,16 +166,16 @@ def gpu_power(self):
161166

162167
def gpu_power_limit(self):
163168
"""
164-
This class method returns GPU power limits. Pynvml library is used.
169+
This class method returns GPU power limits. Pynvml library is used.
165170
166-
Parameters
167-
----------
168-
No parameters
171+
Parameters
172+
----------
173+
No parameters
169174
170-
Returns
171-
-------
172-
gpus_limits: list
173-
list of GPU power limits per every GPU
175+
Returns
176+
-------
177+
gpus_limits: list
178+
list of GPU power limits per every GPU
174179
175180
"""
176181
if not self.is_gpu_available:
@@ -183,21 +188,23 @@ def gpu_power_limit(self):
183188
gpus_limits.append(pynvml.nvmlDeviceGetEnforcedPowerLimit(handle))
184189
pynvml.nvmlShutdown()
185190
return gpus_limits
186-
187-
def name(self,):
191+
192+
def name(
193+
self,
194+
):
188195
"""
189-
This class method returns GPU name if there are any GPU visible
190-
or it returns empty string. All the GPU devices are intended to be of the same model
191-
Pynvml library is used.
196+
This class method returns GPU name if there are any GPU visible
197+
or it returns empty string. All the GPU devices are intended to be of the same model
198+
Pynvml library is used.
192199
193-
Parameters
194-
----------
195-
No parameters
200+
Parameters
201+
----------
202+
No parameters
196203
197-
Returns
198-
-------
199-
gpus_name: string
200-
string with GPU name.
204+
Returns
205+
-------
206+
gpus_name: string
207+
string with GPU name.
201208
202209
"""
203210
try:
@@ -212,20 +219,20 @@ def name(self,):
212219
return gpus_name[0].encode().decode("UTF-8")
213220
except:
214221
return ""
215-
222+
216223
def gpu_num(self):
217224
"""
218-
This class method returns number of visible GPU devices.
219-
Pynvml library is used.
225+
This class method returns number of visible GPU devices.
226+
Pynvml library is used.
220227
221-
Parameters
222-
----------
223-
No parameters
228+
Parameters
229+
----------
230+
No parameters
224231
225-
Returns
226-
-------
227-
deviceCount: int
228-
Number of visible GPU devices.
232+
Returns
233+
-------
234+
deviceCount: int
235+
Number of visible GPU devices.
229236
230237
"""
231238
try:
@@ -236,24 +243,24 @@ def gpu_num(self):
236243
pynvml.nvmlDeviceGetPowerUsage(handle)
237244
pynvml.nvmlShutdown()
238245
return deviceCount
239-
except:
246+
except:
240247
return 0
241248

242249

243250
def is_gpu_available():
244251
"""
245-
This function checks if there are any available GPU devices
246-
All the GPU devices are intended to be of the same model
247-
248-
Parameters
249-
----------
250-
No parameters
251-
252-
Returns
253-
-------
254-
gpu_availability: bool
255-
If there are any visible GPU devices,
256-
then gpu_availability = True, else gpu_availability = False
252+
This function checks if there are any available GPU devices
253+
All the GPU devices are intended to be of the same model
254+
255+
Parameters
256+
----------
257+
No parameters
258+
259+
Returns
260+
-------
261+
gpu_availability: bool
262+
If there are any visible GPU devices,
263+
then gpu_availability = True, else gpu_availability = False
257264
258265
"""
259266
try:
@@ -268,18 +275,19 @@ def is_gpu_available():
268275
except pynvml.NVMLError:
269276
return False
270277

278+
271279
def all_available_gpu():
272280
"""
273-
This function prints all seeable GPU devices
274-
All the GPU devices are intended to be of the same model
275-
276-
Parameters
277-
----------
278-
No parameters
279-
280-
Returns
281-
-------
282-
No returns
281+
This function prints all seeable GPU devices
282+
All the GPU devices are intended to be of the same model
283+
284+
Parameters
285+
----------
286+
No parameters
287+
288+
Returns
289+
-------
290+
No returns
283291
284292
"""
285293
try:
@@ -295,4 +303,4 @@ def all_available_gpu():
295303
print(string)
296304
pynvml.nvmlShutdown()
297305
except:
298-
print("There is no any available gpu device(s)")
306+
print("There is no any available gpu device(s)")

0 commit comments

Comments
 (0)