The best ChatGPT that $100 can buy.
Python
fix(model): apply float32 cast before logits softcapping
spjosyula16788eed3cc3
diff --git a/nanochat/gpt.py b/nanochat/gpt.pyindex 216343c..52f7075 100644--- a/nanochat/gpt.py+++ b/nanochat/gpt.py@@ -265,13 +265,14 @@ class GPT(nn.Module):# training mode: compute and return the loss# TODO: experiment with Liger Kernels / chunked cross-entropy etc.logits = self.lm_head(x)- logits = softcap * torch.tanh(logits / softcap) # logits softcaplogits = logits.float() # use tf32/fp32 for logits+ logits = softcap * torch.tanh(logits / softcap) # logits softcaploss = F.cross_entropy(logits.view(-1, logits.size(-1)), targets.view(-1), ignore_index=-1, reduction=loss_reduction)return losselse:# inference mode: compute and return the logitslogits = self.lm_head(x)+ logits = logits.float() # use tf32/fp32 for logitslogits = softcap * torch.tanh(logits / softcap) # logits softcapreturn logits