From 02440f670df71d26b39e924ade41e85e860deb38 Mon Sep 17 00:00:00 2001 From: Bhaskar <39916271+bhaskar0210s@users.noreply.github.com> Date: Tue, 14 Oct 2025 17:21:11 +0530 Subject: [PATCH] fix: return inf instead of crashing when evaluate_bpb has zero total_bytes Edge case: all tokens are special tokens or ignored Return infinity to indicate no meaningful bytes were processed --- nanochat/loss_eval.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nanochat/loss_eval.py b/nanochat/loss_eval.py index d103ef6..b59b4a3 100644 --- a/nanochat/loss_eval.py +++ b/nanochat/loss_eval.py @@ -59,5 +59,7 @@ def evaluate_bpb(model, batches, steps, token_bytes): # move both to cpu, calculate bpb and return total_nats = total_nats.item() total_bytes = total_bytes.item() + if total_bytes == 0: + return float('inf') bpb = total_nats / (math.log(2) * total_bytes) return bpb