File size: 590 Bytes
d4f211f 9d8ce1d d4f211f e89c6d2 f384f81 e89c6d2 99447d8 e89c6d2 99447d8 cdab2e6 e89c6d2 cdab2e6 e89c6d2 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 |
import gradio as gr
import spaces
import torch
zero = torch.Tensor([0]).cuda()
one = torch.ones(2, 2, device='cuda')
two = torch.matmul(one, one).cuda()
def print_device():
print('cuda avaliable: ' + str(torch.cuda.is_available()))
print('zero device: ' + str(zero.device))
print('one device: ' + str(one.device))
print('two device: ' + str(two.device))
print_device() # cpu
@spaces.GPU
def greet(n):
print('on zero gpu')
print_device() # cuda
return f"Hello {zero + n} Tensor"
gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text()).launch()
|