jyh-zero / app.py
hiascend's picture
Update app.py
1ee0472 verified
raw
history blame
689 Bytes
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()
print('zero device: ' + str(zero.device)) # cpu
one = torch.ones(2, 2, device='cuda')
print('one device: ' + str(one.device)) # cpu
two = torch.matmul(one, one).cuda()
print('two device: ' + str(two.device)) # cpu
@spaces.GPU
def greet(n):
print('zero device: ' + str(zero.device)) # cuda
print('one device: ' + str(one.device)) # cuda
print('two device: ' + str(two.device)) # cuda
return f"Hello {zero + n} Tensor"
gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text()).launch()