File size: 602 Bytes
d4f211f
 
 
 
e65f9d5
1ee0472
2f50e34
d4f211f
06acf20
 
d4f211f
4cf9cd7
cdab2e6
 
 
 
 
 
 
 
 
404559e
5438a6b
d4f211f
 
cdab2e6
 
d4f211f
 
1ee0472
d4f211f
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
import gradio as gr
import spaces
import torch

print('cuda avaliable: ' + str(torch.cuda.is_available()))
torch.set_default_device('cuda')

zero = torch.Tensor([0]).cuda()

one = torch.ones(2, 2, device='cuda')

two = torch.matmul(one, one).cuda()


def print_device():
    print('zero device: ' + str(zero.device))
    print('one device: ' + str(one.device))
    print('two device: ' + str(two.device))


print_device()


@spaces.GPU
def greet(n):
    print('greeting')
    print_device()
    return f"Hello {zero + n} Tensor"


gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text()).launch()