Bendtorch.adamh_l: def of bendtorch@1.3.0.0 Import: import bendtorch@1.3.0.0/main.bend as Bendtorch Lines 352-366 of bendtorch@1.3.0.0/main.bend: https://jend.leeeet.dev/read.txt?path=bendtorch@1.3.0.0/main.bend&start_line=352&end_line=366 import Base # m and v packed. rm and rv hold the word of element t (index t >> 1), read after the previous element's write. def adamh_l(nleft: Nat, +t: U32, +lr: F32, +c1: F32, +b2: F32, +c2: F32, +eps: F32, +wd: F32, +dec: Bool, +step: F32, +bc2: F32, rw: Array & F32, rg: Array & F32, rm: Array & U32, rv: Array & U32) -> PQ: match nleft rw rg rm rv: case 0n Tuple{w, x} Tuple{g, y} Tuple{m, a} Tuple{v, b}: PQ{w, g, m, v} case 1n+p Tuple{w, +x} Tuple{g, +y} Tuple{m, +a} Tuple{v, +b}: +odd = U32.is_eq((t .&. 1 : U32), 1) +gg = adam_grad(dec, wd, x, y) +hm = ph_of(adam_m(c1, ph_to(ph_half(odd, a)), gg)) +hv = ph_of(adam_v(b2, c2, ph_to(ph_half(odd, b)), gg)) +nw = adam_w(step, bc2, eps, adam_decay(dec, lr, wd, x), ph_to(hm), ph_to(hv)) +u = (t + 1 : U32) +k = U32.shrn(t, 1n) +ku = U32.shrn(u, 1n) adamh_l(p, u, lr, c1, b2, c2, eps, wd, dec, step, bc2, Array.get(F32, Array.set(F32, w, t, nw), u), Array.get(F32, Array.set(F32, g, t, 0.0), u), Array.get(U32, Array.set(U32, m, k, ph_put(odd, a, hm)), ku), Array.get(U32, Array.set(U32, v, k, ph_put(odd, b, hv)), ku)) Uses (23): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array.get https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array.set https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_eq https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.shrn https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=PQ https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=adam_decay https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=adam_grad https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=adam_m https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=adam_v https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=adam_w https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=ph_half https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=ph_of https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=ph_put https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/main.bend&name=ph_to