-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdebug_gauge.py
More file actions
64 lines (48 loc) · 1.61 KB
/
Copy pathdebug_gauge.py
File metadata and controls
64 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import time
import jax
import jax.numpy as jnp
from matrix_exponential_gauge_learning import GaugeAttentionBlock, GaugeTransformerConfig
# Force CPU for debugging
os.environ["JAX_PLATFORM_NAME"] = "cpu"
def debug_run():
print("--- Starting Debug Run ---")
# 1. Setup Config (Minimal)
D = 64
H = 4
dh = 16
N = 32
cfg = GaugeTransformerConfig(
d_model=D,
n_heads=H,
d_head=dh,
mlp_hidden=4 * D,
offsets=[-1, 1], # Minimal offsets
use_structured_blocks=True,
)
print(f"Config: N={N}, D={D}, H={H}")
# 2. Initialize Block
block = GaugeAttentionBlock(cfg, name="debug_block")
key = jax.random.PRNGKey(0)
x = jax.random.normal(key, (1, N, D))
print("Initializing block...")
variables = block.init(key, x, train=False, return_debug=True)
print("Block initialized.")
# 3. Inspect Parameters to guess K
# The time parameter determines loop length
t_param = variables["params"]["time_scale"]
t_val = float(jax.nn.softplus(t_param)[0])
print(f"Time scale t ≈ {t_val:.4f}")
# 4. Run Forward (JIT disabled to see progress)
print("Running forward pass (JIT DISABLED)...")
with jax.disable_jit():
start = time.time()
y, dbg = block.apply(variables, x, train=False, return_debug=True)
end = time.time()
print(f"Forward pass finished in {end - start:.4f}s")
# 5. Check Diagnostics
k_max = int(jnp.max(dbg["uniformization_K"]))
print(f"Uniformization K_max used: {k_max}")
print("Output shape:", y.shape)
if __name__ == "__main__":
debug_run()