Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -9,27 +9,32 @@ def log_tensor(name, x):
|
|
9 |
|
10 |
# Simple function
|
11 |
def g(x, y):
|
12 |
-
log_tensor("g input x", x)
|
13 |
-
log_tensor("g input y", y)
|
14 |
z = x + y
|
15 |
-
log_tensor("g output z", z)
|
16 |
return z
|
17 |
|
18 |
# Compiled function
|
19 |
@torch.compile(backend="eager")
|
20 |
def f(x):
|
21 |
-
log_tensor("f input x", x)
|
22 |
x = torch.sin(x)
|
23 |
-
log_tensor("f after torch.sin(x)", x)
|
24 |
x = g(x, x)
|
25 |
-
log_tensor("f after g(x, x)", x)
|
26 |
return x
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
# Run compiled function
|
33 |
-
out = f(x)
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Simple function
|
11 |
def g(x, y):
|
|
|
|
|
12 |
z = x + y
|
|
|
13 |
return z
|
14 |
|
15 |
# Compiled function
|
16 |
@torch.compile(backend="eager")
|
17 |
def f(x):
|
|
|
18 |
x = torch.sin(x)
|
|
|
19 |
x = g(x, x)
|
|
|
20 |
return x
|
21 |
|
22 |
+
# --- Initialization / run once ---
|
23 |
+
def init_and_run_once():
|
24 |
+
# Example input
|
25 |
+
x = torch.ones(3, 3, dtype=torch.float32)
|
26 |
+
print("=== INITIAL INPUT ===")
|
27 |
+
log_tensor("original input x", x)
|
28 |
|
29 |
+
# Run compiled function once
|
30 |
+
out = f(x)
|
31 |
|
32 |
+
print("=== OUTPUT AFTER FIRST RUN ===")
|
33 |
+
log_tensor("final output", out)
|
34 |
+
|
35 |
+
# Return output if needed
|
36 |
+
return out
|
37 |
+
|
38 |
+
# Run once at import / init
|
39 |
+
if __name__ == "__main__":
|
40 |
+
init_and_run_once()
|