import { a as o, t as d } from "../../index-DSGwv2Yx.js";
function i(t) {
  const { inputs: e } = t, { x: n, gamma: s } = e, r = n, a = s;
  return d(() => {
    const u = r.square().mean(-1, !0).add(1e-8).rsqrt();
    return r.mul(u).mul(a);
  });
}
const f = {
  kernelName: "RMSNorm",
  backendName: "cpu",
  kernelFunc: i
};
o(f);
const g = {
  kernelName: "RMSNorm",
  backendName: "tensorflow",
  kernelFunc: i
};
o(g);
function N(t) {
  const { dy: e, x: n, gamma: s } = t.inputs;
  return d(() => {
    const r = n.shape[n.shape.length - 1], a = n.square().mean(-1, !0), m = a.add(1e-8).rsqrt(), u = n.mul(m), l = e.mul(u).sum([0, 1]), c = e.mul(s), k = c.mul(n).sum(-1, !0).div(r);
    return [c.mul(m).sub(n.mul(k).mul(m).div(a.add(1e-8))), l];
  });
}
const S = {
  kernelName: "RMSNormGrad",
  backendName: "cpu",
  kernelFunc: N
};
o(S);
const R = {
  kernelName: "RMSNormGrad",
  backendName: "tensorflow",
  kernelFunc: N
};
o(R);
