import p from "../tokeniser/CharTokeniser.js";
import _ from "../tokeniser/bpe.js";
import { load_safetensors as b } from "../utilities/safetensors.js";
import { aa as c } from "../index-DSGwv2Yx.js";
import { dummyPassAsync as u } from "../utilities/dummy.js";
import y from "../models/factory.js";
function h(e) {
  let a;
  return e.model_type === "GenAI_NanoGPT_v1" ? a = {
    modelType: "GenAI_NanoGPT_v1",
    vocabSize: e.vocab_size,
    blockSize: e.block_size,
    nLayer: e.num_hidden_layers,
    nHead: e.num_attention_heads,
    nEmbed: e.hidden_size,
    mlpFactor: e.mlpFactor,
    useRope: e.useRope
  } : a = {
    modelType: "GenAI_NanoGPT_v2",
    vocabSize: e.vocab_size,
    blockSize: e.block_size,
    nLayer: e.num_hidden_layers,
    nHead: e.num_attention_heads,
    nEmbed: e.hidden_size,
    mlpFactor: e.mlpFactor,
    loraConfig: e.loraConfig ? new Map(Object.entries(e.loraConfig)) : void 0,
    loraName: e.loraName,
    windowSize: e.windowSize
  }, a;
}
async function G(e, a, r, n) {
  const m = h(e), o = (a.type ?? "char") === "char" ? new p(a.vocab) : new _(a.vocab, a.merges);
  a.datasetID && (o.datasetID = a.datasetID), a.id ? o.id = a.id : o.generateID();
  const d = await b(n), s = /* @__PURE__ */ new Map();
  for (const [i, l] of Object.entries(d))
    s.set(i, [l]);
  c();
  const t = y(m);
  return t.metaData = r, await u(t), t.weightStore.loadWeights(s, !!r.url), { model: t, tokeniser: o, metaData: r };
}
export {
  G as default,
  h as mapTransformersConfigToGPTConfig
};
