Spaces:
Runtime error
Runtime error
ljy266987
commited on
Commit
•
4d99f77
1
Parent(s):
bb15bb6
try
Browse files
app.py
CHANGED
@@ -9,44 +9,12 @@ for key, value in env_vars.items():
|
|
9 |
print(f"{key}: {value}")
|
10 |
##
|
11 |
import subprocess
|
12 |
-
|
13 |
-
|
14 |
-
# 运行nvidia-smi命令并以JSON格式获取输出
|
15 |
result = subprocess.run(
|
16 |
-
['nvidia-smi',
|
17 |
-
'--format=csv,noheader,nounits', '--json'],
|
18 |
-
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
|
19 |
)
|
20 |
|
21 |
-
# 解析输出
|
22 |
-
if result.stdout:
|
23 |
-
gpu_info_json = result.stdout
|
24 |
-
print(gpu_info_json)
|
25 |
-
try:
|
26 |
-
# 将JSON字符串转换成Python字典
|
27 |
-
gpu_info = json.loads(gpu_info_json)
|
28 |
-
|
29 |
-
# 打印全部GPU信息
|
30 |
-
print(json.dumps(gpu_info, indent=4))
|
31 |
-
except json.JSONDecodeError as e:
|
32 |
-
pass
|
33 |
-
else:
|
34 |
-
print("Error:", result.stderr)
|
35 |
-
|
36 |
##
|
37 |
-
import GPUtil
|
38 |
-
|
39 |
-
# 获取所有可用的GPU列表
|
40 |
-
gpus = GPUtil.getGPUs()
|
41 |
-
|
42 |
-
# 遍历列表,打印每个GPU的详细信息
|
43 |
-
for gpu in gpus:
|
44 |
-
print(f"GPU ID: {gpu.id}, Name: {gpu.name}")
|
45 |
-
print(f" Total Memory: {gpu.memoryTotal}MB")
|
46 |
-
print(f" Used Memory: {gpu.memoryUsed}MB")
|
47 |
-
print(f" Free Memory: {gpu.memoryFree}MB")
|
48 |
-
print(f" GPU Utilization: {gpu.load*100}%")
|
49 |
-
print(f" GPU Temperature: {gpu.temperature}C\n")
|
50 |
|
51 |
import spaces
|
52 |
from threading import Thread
|
|
|
9 |
print(f"{key}: {value}")
|
10 |
##
|
11 |
import subprocess
|
12 |
+
# 运行nvidia-smi
|
|
|
|
|
13 |
result = subprocess.run(
|
14 |
+
['nvidia-smi'], text=True
|
|
|
|
|
15 |
)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
import spaces
|
20 |
from threading import Thread
|