Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
import spaces
|
3 |
import torch
|
4 |
|
|
|
|
|
|
|
|
|
5 |
torch.set_default_device('cuda')
|
6 |
|
7 |
-
zero = torch.Tensor([0]).cuda()
|
8 |
|
9 |
one = torch.ones(2, 2, device='cuda')
|
10 |
|
@@ -13,7 +17,6 @@ two = torch.matmul(one, one).cuda()
|
|
13 |
|
14 |
def print_device():
|
15 |
print('cuda avaliable: ' + str(torch.cuda.is_available()))
|
16 |
-
# print('default device: ' + str(torch.get_default_device())) # 报错:AttributeError: module 'torch' has no attribute 'get_default_device'
|
17 |
print('zero device: ' + str(zero.device))
|
18 |
print('one device: ' + str(one.device))
|
19 |
print('two device: ' + str(two.device))
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces # 导入spaces时会应用torch补丁
|
3 |
import torch
|
4 |
|
5 |
+
spaces.zero.torch.unpatch() # 手动调用解除torch补丁方法
|
6 |
+
|
7 |
+
print('cuda avaliable: ' + str(torch.cuda.is_available())) # false
|
8 |
+
|
9 |
torch.set_default_device('cuda')
|
10 |
|
11 |
+
zero = torch.Tensor([0]).cuda() # 报错:无GPU资源
|
12 |
|
13 |
one = torch.ones(2, 2, device='cuda')
|
14 |
|
|
|
17 |
|
18 |
def print_device():
|
19 |
print('cuda avaliable: ' + str(torch.cuda.is_available()))
|
|
|
20 |
print('zero device: ' + str(zero.device))
|
21 |
print('one device: ' + str(one.device))
|
22 |
print('two device: ' + str(two.device))
|