Update app.py
Browse files
app.py
CHANGED
@@ -3,25 +3,24 @@ import spaces
|
|
3 |
import torch
|
4 |
|
5 |
print('cuda avaliable: ' + str(torch.cuda.is_available()))
|
|
|
6 |
|
7 |
zero = torch.Tensor([0]).cuda()
|
8 |
-
print('zero device: ' + str(zero.device))
|
9 |
|
10 |
one = torch.ones(2, 2, device='cuda')
|
11 |
-
print('one device: ' + str(one.device))
|
12 |
|
13 |
two = torch.matmul(one, one).cuda()
|
14 |
-
print('two device: ' + str(two.device))
|
15 |
|
16 |
-
xpu_res = torch.ones(2, 2, device='xpu')
|
17 |
-
print('xpu_res device: ' + str(xpu_res.device))
|
18 |
|
19 |
@spaces.GPU
|
20 |
def greet(n):
|
21 |
-
print('zero device: ' + str(zero.device))
|
22 |
-
print('one device: ' + str(one.device))
|
23 |
-
print('two device: ' + str(two.device))
|
24 |
-
print('xpu_res device: ' + str(xpu_res.device))
|
25 |
return f"Hello {zero + n} Tensor"
|
26 |
|
|
|
27 |
gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text()).launch()
|
|
|
3 |
import torch
|
4 |
|
5 |
print('cuda avaliable: ' + str(torch.cuda.is_available()))
|
6 |
+
torch.set_default_device('cuda')
|
7 |
|
8 |
zero = torch.Tensor([0]).cuda()
|
9 |
+
print('zero device: ' + str(zero.device)) # cpu
|
10 |
|
11 |
one = torch.ones(2, 2, device='cuda')
|
12 |
+
print('one device: ' + str(one.device)) # cpu
|
13 |
|
14 |
two = torch.matmul(one, one).cuda()
|
15 |
+
print('two device: ' + str(two.device)) # cpu
|
16 |
|
|
|
|
|
17 |
|
18 |
@spaces.GPU
|
19 |
def greet(n):
|
20 |
+
print('zero device: ' + str(zero.device)) # cuda
|
21 |
+
print('one device: ' + str(one.device)) # cuda
|
22 |
+
print('two device: ' + str(two.device)) # cuda
|
|
|
23 |
return f"Hello {zero + n} Tensor"
|
24 |
|
25 |
+
|
26 |
gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text()).launch()
|