Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/openaccel-lab/blob/main/workloads/layernorm/reference.py # openaccel-lab aien-dev/openaccel-lab Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `openaccel-lab / workloads / layernorm / reference.py` 31 lines ยท 984 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 2 import numpy as np 3 4 U = 2.0 ** -24 5 EPS = float(np.float32(1e-5)) # every entrant writes eps as the f32 constant 1e-5 6 7 8 def _g(n): 9 return n * U / (1.0 - n * U) 10 11 12 def reference(p, x): 13 D = p["D"] 14 v = x["x"].astype(np.float64) 15 g = x["gamma"].astype(np.float64)[None, :] 16 b = x["beta"].astype(np.float64)[None, :] 17 mu = v.mean(axis=1, keepdims=True) 18 c = v - mu 19 var = (c * c).mean(axis=1, keepdims=True) 20 vv = var + EPS 21 s = 1.0 / np.sqrt(vv) 22 y = c * s * g + b 23 # error bound; derivation in workload.json tolerance.why 24 em = _g(D + 1) * np.abs(v).sum(axis=1, keepdims=True) / D 25 dc = em + U * (np.abs(c) + em) 26 rho = (1.0 + em * em / vv) * (1.0 + _g(D + 5)) - 1.0 27 phi = (1.0 + rho) * (1.0 + 4.0 * U) - 1.0 28 ag = np.abs(g) 29 bound = ag * s * (dc * (1.0 + phi) + np.abs(c) * phi) 30 bound = bound + _g(3) * (ag * s * (np.abs(c) + dc) * (1.0 + phi) + np.abs(b)) 31 return {"y": (y, bound)}