import { Y as y, e as I, Z as P } from "../index-DSGwv2Yx.js";
import { z as c } from "../zeros-Bw0puq_w.js";
async function w(s) {
  const t = c([1, s.config.blockSize], "int32"), n = s.forward({ training: !1 }, t);
  await n.data(), n.dispose(), t.dispose();
}
async function G(s) {
  const t = y(), n = t.numBytesInGPUAllocated ?? t.numBytesAllocatedInGPU ?? t.numBytes;
  await w(s);
  const a = c([1, s.config.blockSize], "int32"), e = {
    perBatch: 0,
    tapeSize: 0,
    gradients: s.getNumParams() * 4
  };
  try {
    const i = () => {
      const o = s.forward({ training: !0 }, a), u = I().state.activeTape;
      let p = 0;
      if (u)
        for (const g of u)
          p += g.saved?.reduce((B, z) => B + z.size * 4, 0) || 0;
      e.tapeSize = p;
      const l = o.mean();
      return o.dispose(), l;
    }, { value: d, grads: m } = P(i), r = y(), f = r.numBytesInGPUAllocated ?? r.numBytesAllocatedInGPU ?? r.numBytes;
    e.perBatch = f - n - e.gradients, await d.data(), d.dispose();
    for (const o in m)
      m[o].dispose();
    a.dispose();
  } catch (i) {
    console.error("Error during dummy training pass:", i), a.dispose();
  }
  return e;
}
function b(s) {
  const t = c([1, s.config.blockSize], "int32");
  s.forward({ training: !1 }, t).dispose(), t.dispose();
}
export {
  b as dummyPass,
  w as dummyPassAsync,
  G as dummyPassTrainAsync
};
