"""Deterministic checks for the article's synthetic arithmetic. Standard library only.
No cluster, model benchmark, GPU, network or stochastic experiment.
"""
import math
p0=0.5
loss0=-math.log(p0)
loss1=math.log(math.exp(-0.05)+math.exp(0.05))-0.05
assert abs(loss0-0.69314718056)<1e-10
assert abs(loss1-0.64439666007)<1e-10 and loss1<loss0
# First AdamW moment correction with a scalar gradient.
g=0.5;beta1=0.9;beta2=0.999
m=(1-beta1)*g;v=(1-beta2)*g*g
assert math.isclose(m/(1-beta1),g)
assert math.isclose(v/(1-beta2),g*g)
assert 4*128*512*4==1024**2
assert 2*(4-1)*8/4/25==0.48
slots=16*sum(math.ceil(t/16) for t in [17,31])
assert slots==64 and slots-17-31==16
assert 2*32*8*128*2*8192==1024**3
assert sum([20,10,80,150,10])==270
assert 1/(10-8)==0.5 and 1/(10-9.5)==2
print('PASS: gradient step, AdamW bias correction, logits bytes, ring budget, KV blocks, TTFT and queue arithmetic')
