Skip to content

The best ChatGPT that $100 can buy.

Python

Merge pull request #540 from svlandeg/fix/kernel

Andrej2fc63c962889
diff --cc nanochat/gpt.py
index f266a43,3775bc6..44acfcb
--- a/nanochat/gpt.py
+++ b/nanochat/gpt.py
@@@ -100,10 -98,10 +100,10 @@@ class CausalSelfAttention(nn.Module)
cos, sin = cos_sin
q, k = apply_rotary_emb(q, cos, sin), apply_rotary_emb(k, cos, sin)
q, k = norm(q), norm(k) # QK norm
- q = q * 1.15 # sharper attention (split scale between Q and K), TODO think through better
- k = k * 1.15
+ q = q * 1.2 # sharper attention (split scale between Q and K), TODO think through better
+ k = k * 1.2
- # Flash Attention (FA3 on Hopper+, PyTorch SDPA fallback elsewhere)
+ # Flash Attention (FA3 or SDPA fallback)
# window_size is (left, right) tuple: (N, 0) for causal, (-1, 0) for full context
if kv_cache is None:
# Training: causal attention with optional sliding window