|
import gradio as gr |
|
import spaces |
|
import torch |
|
import os |
|
|
|
spaces.zero.torch.unpatch() |
|
|
|
os.environ['CUDA_VISIBLE_DEVICES'] = 'MIG-2f70e35e-577e-52c1-9054-bc9f9d04054e' |
|
|
|
print('cuda visible devices: ' + str(os.getenv('CUDA_VISIBLE_DEVICES'))) |
|
print('cuda avaliable: ' + str(torch.cuda.is_available())) |
|
print('cuda device count: ' + str(torch.cuda.device_count())) |
|
print('cuda device name: ' + str(torch.cuda.get_device_name())) |
|
print('cuda device capability: ' + str(torch.cuda.get_device_capability())) |
|
|
|
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('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() |
|
|
|
|
|
@spaces.GPU |
|
def greet(n): |
|
print('on zero gpu') |
|
print_device() |
|
return f"Hello {zero + n} Tensor" |
|
|
|
|
|
gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text()).launch() |
|
|