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
This commit is contained in:
Bhaskar 2025-10-14 17:21:11 +05:30
parent dd6ff9a1cc
commit 02440f670d

View File

@ -59,5 +59,7 @@ def evaluate_bpb(model, batches, steps, token_bytes):
# move both to cpu, calculate bpb and return # move both to cpu, calculate bpb and return
total_nats = total_nats.item() total_nats = total_nats.item()
total_bytes = total_bytes.item() total_bytes = total_bytes.item()
if total_bytes == 0:
return float('inf')
bpb = total_nats / (math.log(2) * total_bytes) bpb = total_nats / (math.log(2) * total_bytes)
return bpb return bpb