hiascend commited on
Commit
e89c6d2
·
verified ·
1 Parent(s): 99447d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -2,27 +2,27 @@ import gradio as gr
2
  import spaces
3
  import torch
4
 
 
5
 
6
- @spaces.GPU()
7
- def fn():
8
- print('fn')
9
 
 
10
 
11
- def greet(n):
12
- print('cuda avaliable: ' + str(torch.cuda.is_available()))
13
-
14
- torch.set_default_device('cuda')
15
-
16
- zero = torch.Tensor([0]).cuda()
17
-
18
- one = torch.ones(2, 2, device='cuda')
19
-
20
- two = torch.matmul(one, one).cuda()
21
 
 
 
22
  print('zero device: ' + str(zero.device))
23
  print('one device: ' + str(one.device))
24
  print('two device: ' + str(two.device))
25
 
 
 
 
 
 
 
 
 
26
  return f"Hello {zero + n} Tensor"
27
 
28
 
 
2
  import spaces
3
  import torch
4
 
5
+ zero = torch.Tensor([0]).cuda()
6
 
7
+ one = torch.ones(2, 2, device='cuda')
 
 
8
 
9
+ two = torch.matmul(one, one).cuda()
10
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ def print_device():
13
+ print('cuda avaliable: ' + str(torch.cuda.is_available()))
14
  print('zero device: ' + str(zero.device))
15
  print('one device: ' + str(one.device))
16
  print('two device: ' + str(two.device))
17
 
18
+
19
+ print_device() # cpu
20
+
21
+
22
+ @spaces.GPU
23
+ def greet(n):
24
+ print('on zero gpu')
25
+ print_device() # cuda
26
  return f"Hello {zero + n} Tensor"
27
 
28