import { a as t, t as d } from "../../index-DSGwv2Yx.js";
const o = 0.7978845608028654, c = 0.044715;
function m(r) {
  const { inputs: u } = r, { x: n } = u, e = n;
  return d(() => {
    const l = e.pow(3), a = e.add(l.mul(c)).mul(o).tanh().add(1).mul(0.5);
    return e.mul(a);
  });
}
const p = {
  kernelName: "Gelu",
  backendName: "cpu",
  kernelFunc: m
};
t(p);
const K = {
  kernelName: "Gelu",
  backendName: "tensorflow",
  kernelFunc: m
};
t(K);
function i(r) {
  const { dy: u, x: n } = r.inputs;
  return d(() => {
    const e = n.square(), l = e.mul(n), s = n.add(l.mul(c)).mul(o).tanh(), f = s.square().neg().add(1), k = e.mul(3 * c).add(1), g = s.add(1).mul(0.5), G = n.mul(f).mul(o).mul(k).mul(0.5), N = g.add(G);
    return u.mul(N);
  });
}
const x = {
  kernelName: "GeluGrad",
  backendName: "cpu",
  kernelFunc: i
};
t(x);
const h = {
  kernelName: "GeluGrad",
  backendName: "tensorflow",
  kernelFunc: i
};
t(h);
