jburtoft's picture
nki-kernel-bench v0.1
0fef070
Raw History Blame Contribute Delete
845 Bytes
import numpy as np
import ml_dtypes
BF16 = ml_dtypes.bfloat16
def bf(x):
return np.ascontiguousarray(np.asarray(x, np.float32).astype(BF16))
import math
SHAPES = {"m8192": 8192, "m32768": 32768}
def make_inputs(seed, shape_id):
M = SHAPES[shape_id]
rng = np.random.default_rng(seed)
f = lambda a: np.ascontiguousarray(np.asarray(a, np.float32))
lr, b1, b2, eps, wd, step = 1e-3, 0.9, 0.999, 1e-8, 0.05, 10
bc1, bc2 = 1 - b1 ** step, 1 - b2 ** step
wdf = 1 - lr * wd
hp = f([[b1, 1 - b1, b2, math.sqrt(1 - b2), 1 / bc2, eps, -lr / bc1 / wdf, wdf]])
p = f(rng.standard_normal((128, M)) * 0.02)
m = f(rng.standard_normal((128, M)) * 1e-3)
v = f(np.abs(rng.standard_normal((128, M))) * 1e-6)
g = bf(rng.standard_normal((128, M)) * 1e-3)
return (p, m, v, g, np.zeros((128, M), BF16), hp), {}