Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,46 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
import torch
|
|
|
4 |
|
5 |
-
|
6 |
-
print(zero.device) # <-- 'cpu' 🤔
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def greet(n):
|
10 |
print(zero.device) # <-- 'cuda:0' 🤗
|
11 |
return f"Hello {zero + n} Tensor"
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
import torch
|
4 |
+
import time
|
5 |
|
6 |
+
import numpy as np
|
|
|
7 |
|
8 |
+
|
9 |
+
print(f"torch_version: {torch.__version__}")
|
10 |
+
|
11 |
+
# Define two matrices using NumPy arrays
|
12 |
+
A = np.array([[1, 2], [3, 4]])
|
13 |
+
B = np.array([[5, 6], [7, 8]])
|
14 |
+
|
15 |
+
# Start the timer
|
16 |
+
start_time = time.time()
|
17 |
+
|
18 |
+
# Perform matrix multiplication
|
19 |
+
result = np.dot(A, B)
|
20 |
+
|
21 |
+
# End the timer
|
22 |
+
end_time = time.time()
|
23 |
+
|
24 |
+
# Calculate and print the time taken
|
25 |
+
print(f"Time taken for matrix multiplication with NumPy: {end_time - start_time:.6f} seconds")
|
26 |
+
|
27 |
+
# Define two matrices
|
28 |
+
A = torch.tensor([[1, 2], [3, 4]])
|
29 |
+
B = torch.tensor([[5, 6], [7, 8]])
|
30 |
+
|
31 |
+
# Start the timer
|
32 |
+
start_time = time.time()
|
33 |
+
|
34 |
+
# Perform matrix multiplication
|
35 |
+
result = torch.matmul(A, B)
|
36 |
+
|
37 |
+
# End the timer
|
38 |
+
end_time = time.time()
|
39 |
+
|
40 |
+
# Calculate and print the time taken
|
41 |
+
print(f"Time taken for matrix multiplication with PyTorch: {end_time - start_time:.6f} seconds")
|
42 |
+
|
43 |
+
@spaces.GPU
|
44 |
def greet(n):
|
45 |
print(zero.device) # <-- 'cuda:0' 🤗
|
46 |
return f"Hello {zero + n} Tensor"
|