capcut8128 commited on
Commit
e683d4e
·
verified ·
1 Parent(s): bf731c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -2,13 +2,12 @@ import gradio as gr
2
  import spaces
3
  import torch
4
 
5
- zero = torch.Tensor([0]).cuda()
6
- print(zero.device) # <-- 'cpu' 🤔
7
-
8
  @spaces.GPU
9
  def greet(n):
10
- print(zero.device) # <-- 'cuda:0' 🤗
 
 
11
  return f"Hello {zero + n} Tensor"
12
 
13
  demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
14
- demo.launch()
 
2
  import spaces
3
  import torch
4
 
 
 
 
5
  @spaces.GPU
6
  def greet(n):
7
+ # Create the tensor inside the GPU worker where a real GPU exists
8
+ zero = torch.Tensor([0]).to("cuda")
9
+ print(zero.device) # This will print 'cuda:0'
10
  return f"Hello {zero + n} Tensor"
11
 
12
  demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
13
+ demo.launch()