-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_gpu_types.py
executable file
·62 lines (49 loc) · 2.18 KB
/
get_gpu_types.py
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
#!/usr/bin/env python3
import json
import runpod
def get_gpu_types():
api = runpod.API()
response = api.get_gpu_types()
resp_json = response.json()
if response.status_code == 200 and 'errors' not in resp_json:
gpu_types = resp_json['data']['gpuTypes']
sorted_gpu_types = sorted(gpu_types, key=lambda x: x["memoryInGb"])
return sorted_gpu_types
else:
return []
if __name__ == '__main__':
runpod = runpod.API()
response = runpod.get_gpu_types()
resp_json = response.json()
if response.status_code == 200:
if 'errors' in resp_json:
print('ERROR:')
for error in resp_json['errors']:
print(error['message'])
else:
gpu_types = resp_json['data']['gpuTypes']
sorted_gpu_types = sorted(gpu_types, key=lambda x: x["memoryInGb"])
#print(json.dumps(sorted_gpu_types, indent=4, default=str))
# Define the column widths
widths = [33, 22, 8, 9, 9, 11, 9]
print('ID Name GPU GPU Max Secure Community Spot')
print('------------------------------- -------------------- ------ ------- ------- --------- ------')
for pod in sorted_gpu_types:
memory = f"{pod['memoryInGb']} GB"
row = f"{pod['id']:<{widths[0]}}"
row += f"{pod['displayName']:<{widths[1]}}"
row += f"{memory:<{widths[2]}}"
row += f"{pod['maxGpuCount']:<{widths[3]}}"
if not pod['secureCloud']:
pod['securePrice'] = '-'
if not pod['communityCloud']:
pod['communityPrice'] = '-'
row += f"{pod['securePrice']:<{widths[4]}}"
row += f"{pod['communityPrice']:<{widths[5]}}"
if pod['lowestPrice']['minimumBidPrice'] is None:
pod['lowestPrice']['minimumBidPrice'] = '-'
row += f"{pod['lowestPrice']['minimumBidPrice']:<{widths[6]}}"
print(row)
else:
print(response.status_code)
print(json.dumps(resp_json, indent=4, default=str))