@seanhogg/builderforce-memory-engine 2026.6.31 → 2026.6.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/bench/harness.d.ts +37 -0
- package/dist/bench/harness.d.ts.map +1 -0
- package/dist/bench/harness.js +171 -0
- package/dist/bench/harness.js.map +1 -0
- package/dist/bench/index.d.ts +11 -0
- package/dist/bench/index.d.ts.map +1 -0
- package/dist/bench/index.js +10 -0
- package/dist/bench/index.js.map +1 -0
- package/dist/bench/metrics.d.ts +36 -0
- package/dist/bench/metrics.d.ts.map +1 -0
- package/dist/bench/metrics.js +83 -0
- package/dist/bench/metrics.js.map +1 -0
- package/dist/bench/types.d.ts +119 -0
- package/dist/bench/types.d.ts.map +1 -0
- package/dist/bench/types.js +16 -0
- package/dist/bench/types.js.map +1 -0
- package/dist/export/gguf.d.ts +23 -0
- package/dist/export/gguf.d.ts.map +1 -0
- package/dist/export/gguf.js +158 -0
- package/dist/export/gguf.js.map +1 -0
- package/dist/export/hf.d.ts +32 -0
- package/dist/export/hf.d.ts.map +1 -0
- package/dist/export/hf.js +138 -0
- package/dist/export/hf.js.map +1 -0
- package/dist/export/index.d.ts +57 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +85 -0
- package/dist/export/index.js.map +1 -0
- package/dist/export/onnx.d.ts +32 -0
- package/dist/export/onnx.d.ts.map +1 -0
- package/dist/export/onnx.js +265 -0
- package/dist/export/onnx.js.map +1 -0
- package/dist/export/protobuf.d.ts +34 -0
- package/dist/export/protobuf.d.ts.map +1 -0
- package/dist/export/protobuf.js +77 -0
- package/dist/export/protobuf.js.map +1 -0
- package/dist/export/safetensors.d.ts +22 -0
- package/dist/export/safetensors.d.ts.map +1 -0
- package/dist/export/safetensors.js +66 -0
- package/dist/export/safetensors.js.map +1 -0
- package/dist/export/tensors.d.ts +51 -0
- package/dist/export/tensors.d.ts.map +1 -0
- package/dist/export/tensors.js +76 -0
- package/dist/export/tensors.js.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/kernels/selective_scan.d.ts.map +1 -1
- package/dist/kernels/selective_scan.js +7 -3
- package/dist/kernels/selective_scan.js.map +1 -1
- package/dist/lm/evermind_lm.d.ts +17 -1
- package/dist/lm/evermind_lm.d.ts.map +1 -1
- package/dist/lm/evermind_lm.js +49 -5
- package/dist/lm/evermind_lm.js.map +1 -1
- package/dist/model/mamba_model.d.ts.map +1 -1
- package/dist/model/mamba_model.js +9 -1
- package/dist/model/mamba_model.js.map +1 -1
- package/dist/utils/crc32.d.ts +37 -0
- package/dist/utils/crc32.d.ts.map +1 -0
- package/dist/utils/crc32.js +70 -0
- package/dist/utils/crc32.js.map +1 -0
- package/dist/utils/delta.d.ts +55 -0
- package/dist/utils/delta.d.ts.map +1 -0
- package/dist/utils/delta.js +148 -0
- package/dist/utils/delta.js.map +1 -0
- package/dist/utils/gpu_utils.d.ts +21 -0
- package/dist/utils/gpu_utils.d.ts.map +1 -1
- package/dist/utils/gpu_utils.js +64 -5
- package/dist/utils/gpu_utils.js.map +1 -1
- package/package.json +1 -1
- package/src/bench/harness.ts +219 -0
- package/src/bench/index.ts +37 -0
- package/src/bench/metrics.ts +98 -0
- package/src/bench/types.ts +121 -0
- package/src/export/gguf.ts +168 -0
- package/src/export/hf.ts +155 -0
- package/src/export/index.ts +128 -0
- package/src/export/onnx.ts +331 -0
- package/src/export/protobuf.ts +86 -0
- package/src/export/safetensors.ts +77 -0
- package/src/export/tensors.ts +107 -0
- package/src/index.ts +70 -0
- package/src/kernels/selective_scan.ts +7 -3
- package/src/lm/evermind_lm.ts +53 -8
- package/src/model/mamba_model.ts +9 -1
- package/src/utils/crc32.ts +82 -0
- package/src/utils/delta.ts +156 -0
- package/src/utils/gpu_utils.ts +60 -5
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
`@seanhogg/builderforce-memory-engine` is a **TypeScript-first** library that brings the Mamba family of State Space Models to the browser via WebGPU. It ships **Mamba-2** (SSD), **Mamba-3** (complex-valued MIMO + ET discretisation), and **hybrid attention** layers, while remaining fully backward-compatible with Mamba-1 checkpoints. It is the zero-runtime-dep engine consumed by [`@seanhogg/builderforce-memory`](../memory) (the runtime layer).
|
|
9
9
|
|
|
10
|
+
> **Technical report & peer review.** The kernels and discretisations here are specified mathematically in the Evermind technical report ([`../../publication/evermind/`](../../publication/evermind)). Its adversarial [`PEER-REVIEW.md`](../../publication/evermind/PEER-REVIEW.md) flags engine-level items worth knowing before depending on them at scale: the "parallel" selective scan walks tiles sequentially, `softplus` is the unstable `log(1+exp(v))` form, int8 quantisation uses a single per-tensor scale (weights only), and GPU buffers are allocated per call (no pool). Tracked as `EVM-1/EVM-8`.
|
|
11
|
+
|
|
10
12
|
---
|
|
11
13
|
|
|
12
14
|
## What's New in v2.0.0
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bench/harness.ts — run a benchmark and A/B two models.
|
|
3
|
+
*
|
|
4
|
+
* The harness drives a model over held-out token sequences, scores next-token
|
|
5
|
+
* prediction with {@link metrics}, and produces a {@link BenchmarkReport}. It
|
|
6
|
+
* also offers a one-call {@link trainAndBenchmark} that builds a fresh
|
|
7
|
+
* `EvermindLM` from a corpus, holds out a slice, trains on the rest, and scores
|
|
8
|
+
* — the path the Studio uses to benchmark a model in the browser.
|
|
9
|
+
*/
|
|
10
|
+
import type { AsyncLogitsModel, BenchmarkOptions, BenchmarkReport, ComparisonReport, LogitsModel, TrainAndBenchmarkOptions, TrainAndBenchmarkResult } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Benchmark a model (synchronous forward) over held-out token sequences.
|
|
13
|
+
* Sequences shorter than 2 tokens have no prediction target and are skipped.
|
|
14
|
+
*/
|
|
15
|
+
export declare function benchmarkModel(model: LogitsModel, sequences: number[][], opts?: BenchmarkOptions): BenchmarkReport;
|
|
16
|
+
/** Benchmark a model whose forward pass is asynchronous (e.g. a WebGPU backend). */
|
|
17
|
+
export declare function benchmarkModelAsync(model: AsyncLogitsModel, sequences: number[][], opts?: BenchmarkOptions): Promise<BenchmarkReport>;
|
|
18
|
+
/** A/B two models on the same eval set. Lower perplexity wins (the primary metric). */
|
|
19
|
+
export declare function compareModels(candidate: LogitsModel, baseline: LogitsModel, sequences: number[][], opts?: BenchmarkOptions): ComparisonReport;
|
|
20
|
+
/** Build a {@link ComparisonReport} from two already-computed scorecards. */
|
|
21
|
+
export declare function compareReports(candidate: BenchmarkReport, baseline: BenchmarkReport): ComparisonReport;
|
|
22
|
+
/** Split a corpus into next-token training sequences (one per sentence). */
|
|
23
|
+
export declare function corpusToSequences(corpus: string, codec: {
|
|
24
|
+
encode(text: string): number[];
|
|
25
|
+
}): number[][];
|
|
26
|
+
/** Benchmark an existing model against a raw-text corpus (tokenized per sentence). */
|
|
27
|
+
export declare function benchmarkText(model: LogitsModel, codec: {
|
|
28
|
+
encode(text: string): number[];
|
|
29
|
+
}, corpus: string, opts?: BenchmarkOptions): BenchmarkReport;
|
|
30
|
+
/**
|
|
31
|
+
* Train a fresh `EvermindLM` on a corpus and benchmark it on a held-out slice —
|
|
32
|
+
* the canonical "build + score a model from text" path. A real benchmark must
|
|
33
|
+
* score data the model never trained on, so `heldOutRatio` is clamped to leave
|
|
34
|
+
* at least one eval sequence and one train sequence.
|
|
35
|
+
*/
|
|
36
|
+
export declare function trainAndBenchmark(corpus: string, opts?: TrainAndBenchmarkOptions): TrainAndBenchmarkResult;
|
|
37
|
+
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/bench/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,gBAAgB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B two models.
|
|
3
|
+
*
|
|
4
|
+
* The harness drives a model over held-out token sequences, scores next-token
|
|
5
|
+
* prediction with {@link metrics}, and produces a {@link BenchmarkReport}. It
|
|
6
|
+
* also offers a one-call {@link trainAndBenchmark} that builds a fresh
|
|
7
|
+
* `EvermindLM` from a corpus, holds out a slice, trains on the rest, and scores
|
|
8
|
+
* — the path the Studio uses to benchmark a model in the browser.
|
|
9
|
+
*/
|
|
10
|
+
import { EvermindLM, EvermindLMTrainer } from "../lm/evermind_lm.js";
|
|
11
|
+
import { BPETokenizer } from "../tokenizer/bpe.js";
|
|
12
|
+
import { SeededRng } from "../utils/rng.js";
|
|
13
|
+
import { newAccumulator, scoreInto, perplexity, bitsPerToken } from "./metrics.js";
|
|
14
|
+
/** A monotonic clock, preferring `performance.now()` when present. */
|
|
15
|
+
function defaultNow() {
|
|
16
|
+
const g = globalThis;
|
|
17
|
+
return typeof g.performance?.now === "function" ? g.performance.now() : Date.now();
|
|
18
|
+
}
|
|
19
|
+
/** Next-token targets for a sequence: tokens[1..T-1] predicted from positions 0..T-2. */
|
|
20
|
+
function nextTokenTargets(seq) {
|
|
21
|
+
return seq.slice(1);
|
|
22
|
+
}
|
|
23
|
+
function finalize(acc, sequences, topK, elapsedMs) {
|
|
24
|
+
const meanCe = acc.tokens > 0 ? acc.ceSum / acc.tokens : 0;
|
|
25
|
+
const report = {
|
|
26
|
+
sequences,
|
|
27
|
+
tokens: acc.tokens,
|
|
28
|
+
crossEntropy: meanCe,
|
|
29
|
+
perplexity: perplexity(meanCe),
|
|
30
|
+
bitsPerToken: bitsPerToken(meanCe),
|
|
31
|
+
top1Accuracy: acc.tokens > 0 ? acc.top1Hits / acc.tokens : 0,
|
|
32
|
+
topKAccuracy: acc.tokens > 0 ? acc.topKHits / acc.tokens : 0,
|
|
33
|
+
topK,
|
|
34
|
+
};
|
|
35
|
+
if (elapsedMs !== undefined) {
|
|
36
|
+
report.elapsedMs = elapsedMs;
|
|
37
|
+
report.tokensPerSecond = elapsedMs > 0 ? (acc.tokens / elapsedMs) * 1000 : 0;
|
|
38
|
+
}
|
|
39
|
+
return report;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Benchmark a model (synchronous forward) over held-out token sequences.
|
|
43
|
+
* Sequences shorter than 2 tokens have no prediction target and are skipped.
|
|
44
|
+
*/
|
|
45
|
+
export function benchmarkModel(model, sequences, opts = {}) {
|
|
46
|
+
const topK = opts.topK ?? 5;
|
|
47
|
+
const measure = opts.measureLatency ?? true;
|
|
48
|
+
const now = opts.now ?? defaultNow;
|
|
49
|
+
const acc = newAccumulator();
|
|
50
|
+
let scored = 0;
|
|
51
|
+
let elapsed = 0;
|
|
52
|
+
for (const seq of sequences) {
|
|
53
|
+
if (seq.length < 2)
|
|
54
|
+
continue;
|
|
55
|
+
const t0 = measure ? now() : 0;
|
|
56
|
+
const { logits } = model.forward(seq);
|
|
57
|
+
if (measure)
|
|
58
|
+
elapsed += now() - t0;
|
|
59
|
+
scoreInto(acc, logits, nextTokenTargets(seq), topK);
|
|
60
|
+
scored++;
|
|
61
|
+
}
|
|
62
|
+
return finalize(acc, scored, topK, measure ? elapsed : undefined);
|
|
63
|
+
}
|
|
64
|
+
/** Benchmark a model whose forward pass is asynchronous (e.g. a WebGPU backend). */
|
|
65
|
+
export async function benchmarkModelAsync(model, sequences, opts = {}) {
|
|
66
|
+
const topK = opts.topK ?? 5;
|
|
67
|
+
const measure = opts.measureLatency ?? true;
|
|
68
|
+
const now = opts.now ?? defaultNow;
|
|
69
|
+
const acc = newAccumulator();
|
|
70
|
+
let scored = 0;
|
|
71
|
+
let elapsed = 0;
|
|
72
|
+
for (const seq of sequences) {
|
|
73
|
+
if (seq.length < 2)
|
|
74
|
+
continue;
|
|
75
|
+
const t0 = measure ? now() : 0;
|
|
76
|
+
const { logits } = await model.forward(seq);
|
|
77
|
+
if (measure)
|
|
78
|
+
elapsed += now() - t0;
|
|
79
|
+
scoreInto(acc, logits, nextTokenTargets(seq), topK);
|
|
80
|
+
scored++;
|
|
81
|
+
}
|
|
82
|
+
return finalize(acc, scored, topK, measure ? elapsed : undefined);
|
|
83
|
+
}
|
|
84
|
+
/** A/B two models on the same eval set. Lower perplexity wins (the primary metric). */
|
|
85
|
+
export function compareModels(candidate, baseline, sequences, opts = {}) {
|
|
86
|
+
return compareReports(benchmarkModel(candidate, sequences, opts), benchmarkModel(baseline, sequences, opts));
|
|
87
|
+
}
|
|
88
|
+
/** Build a {@link ComparisonReport} from two already-computed scorecards. */
|
|
89
|
+
export function compareReports(candidate, baseline) {
|
|
90
|
+
const perplexityDelta = candidate.perplexity - baseline.perplexity;
|
|
91
|
+
const perplexityRatio = baseline.perplexity > 0 ? candidate.perplexity / baseline.perplexity : Infinity;
|
|
92
|
+
const top1Delta = candidate.top1Accuracy - baseline.top1Accuracy;
|
|
93
|
+
// A small relative band counts as a tie so noise doesn't flip the verdict.
|
|
94
|
+
const tieBand = 0.005;
|
|
95
|
+
let winner;
|
|
96
|
+
if (Math.abs(perplexityRatio - 1) <= tieBand)
|
|
97
|
+
winner = "tie";
|
|
98
|
+
else
|
|
99
|
+
winner = perplexityDelta < 0 ? "candidate" : "baseline";
|
|
100
|
+
const pct = ((1 - perplexityRatio) * 100).toFixed(1);
|
|
101
|
+
const summary = winner === "tie"
|
|
102
|
+
? `Tie: perplexity ${candidate.perplexity.toFixed(2)} vs ${baseline.perplexity.toFixed(2)}`
|
|
103
|
+
: winner === "candidate"
|
|
104
|
+
? `Candidate wins: ${pct}% lower perplexity (${candidate.perplexity.toFixed(2)} vs ${baseline.perplexity.toFixed(2)})`
|
|
105
|
+
: `Baseline wins: candidate ${(-Number(pct)).toFixed(1)}% higher perplexity (${candidate.perplexity.toFixed(2)} vs ${baseline.perplexity.toFixed(2)})`;
|
|
106
|
+
return { candidate, baseline, perplexityDelta, perplexityRatio, top1Delta, winner, summary };
|
|
107
|
+
}
|
|
108
|
+
/** Split a corpus into next-token training sequences (one per sentence). */
|
|
109
|
+
export function corpusToSequences(corpus, codec) {
|
|
110
|
+
return corpus
|
|
111
|
+
.split(/(?<=\.)\s+/)
|
|
112
|
+
.map((s) => codec.encode(s.trim()))
|
|
113
|
+
.filter((ids) => ids.length >= 2);
|
|
114
|
+
}
|
|
115
|
+
/** Benchmark an existing model against a raw-text corpus (tokenized per sentence). */
|
|
116
|
+
export function benchmarkText(model, codec, corpus, opts = {}) {
|
|
117
|
+
return benchmarkModel(model, corpusToSequences(corpus, codec), opts);
|
|
118
|
+
}
|
|
119
|
+
/** Deterministic Fisher–Yates shuffle (in place) driven by a seeded RNG. */
|
|
120
|
+
function shuffle(arr, rng) {
|
|
121
|
+
for (let i = arr.length - 1; i > 0; i--) {
|
|
122
|
+
const j = Math.floor(rng.next() * (i + 1));
|
|
123
|
+
const tmp = arr[i];
|
|
124
|
+
arr[i] = arr[j];
|
|
125
|
+
arr[j] = tmp;
|
|
126
|
+
}
|
|
127
|
+
return arr;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Train a fresh `EvermindLM` on a corpus and benchmark it on a held-out slice —
|
|
131
|
+
* the canonical "build + score a model from text" path. A real benchmark must
|
|
132
|
+
* score data the model never trained on, so `heldOutRatio` is clamped to leave
|
|
133
|
+
* at least one eval sequence and one train sequence.
|
|
134
|
+
*/
|
|
135
|
+
export function trainAndBenchmark(corpus, opts = {}) {
|
|
136
|
+
const seed = opts.seed ?? 7;
|
|
137
|
+
const tok = new BPETokenizer();
|
|
138
|
+
tok.train(corpus, { numMerges: opts.numMerges ?? 100 });
|
|
139
|
+
const all = corpusToSequences(corpus, tok);
|
|
140
|
+
if (all.length < 2) {
|
|
141
|
+
throw new Error(`corpus produced ${all.length} trainable sequence(s); need at least 2 to hold out an eval split (add more sentences)`);
|
|
142
|
+
}
|
|
143
|
+
// Deterministic split: shuffle by seed, reserve heldOutRatio for eval.
|
|
144
|
+
const order = shuffle([...all], new SeededRng((seed >>> 0) || 1));
|
|
145
|
+
const ratio = Math.min(0.9, Math.max(0.05, opts.heldOutRatio ?? 0.25));
|
|
146
|
+
let evalCount = Math.round(order.length * ratio);
|
|
147
|
+
evalCount = Math.max(1, Math.min(order.length - 1, evalCount));
|
|
148
|
+
const evalSeqs = order.slice(0, evalCount);
|
|
149
|
+
const trainSeqs = order.slice(evalCount);
|
|
150
|
+
const model = new EvermindLM({
|
|
151
|
+
vocabSize: tok.vocabSize,
|
|
152
|
+
dModel: opts.dModel ?? 32,
|
|
153
|
+
numLayers: opts.numLayers ?? 2,
|
|
154
|
+
hiddenDim: opts.hiddenDim ?? 48,
|
|
155
|
+
seed,
|
|
156
|
+
});
|
|
157
|
+
const epochs = opts.epochs ?? 30;
|
|
158
|
+
const history = new EvermindLMTrainer(model, { lr: opts.lr ?? 0.03, epochs }).fit(trainSeqs);
|
|
159
|
+
const report = benchmarkModel(model, evalSeqs, { topK: opts.topK ?? 5, measureLatency: true });
|
|
160
|
+
const sample = model.generateText(opts.prompt ?? "The", tok, { maxNewTokens: 8, temperature: 0 });
|
|
161
|
+
return {
|
|
162
|
+
...report,
|
|
163
|
+
trainSequences: trainSeqs.length,
|
|
164
|
+
evalSequences: evalSeqs.length,
|
|
165
|
+
initialTrainLoss: history[0] ?? 0,
|
|
166
|
+
finalTrainLoss: history.at(-1) ?? 0,
|
|
167
|
+
vocabSize: tok.vocabSize,
|
|
168
|
+
sample,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.js","sourceRoot":"","sources":["../../src/bench/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EA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IAAI,CAAC,MAAM,IAAI,EAAE;QACzB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,CAAC;QAC9B,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;QAC/B,IAAI;KACL,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAE7F,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/F,MAAM,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;IAElG,OAAO;QACL,GAAG,MAAM;QACT,cAAc,EAAE,SAAS,CAAC,MAAM;QAChC,aAAa,EAAE,QAAQ,CAAC,MAAM;QAC9B,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QACjC,cAAc,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACnC,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bench — the Evermind benchmarking harness.
|
|
3
|
+
*
|
|
4
|
+
* Measures a trained model on held-out data (perplexity, bits-per-token,
|
|
5
|
+
* next-token accuracy, throughput), A/Bs two models, and offers a one-call
|
|
6
|
+
* train-and-score path the Studio drives in the browser.
|
|
7
|
+
*/
|
|
8
|
+
export { benchmarkModel, benchmarkModelAsync, benchmarkText, compareModels, compareReports, corpusToSequences, trainAndBenchmark, } from "./harness.js";
|
|
9
|
+
export { argmax, topKIndices, perplexity, bitsPerToken, newAccumulator, scoreInto, LN2, } from "./metrics.js";
|
|
10
|
+
export type { LogitsModel, AsyncLogitsModel, BenchmarkOptions, BenchmarkReport, ComparisonReport, TrainAndBenchmarkOptions, TrainAndBenchmarkResult, } from "./types.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bench/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,MAAM,EACN,WAAW,EACX,UAAU,EACV,YAAY,EACZ,cAAc,EACd,SAAS,EACT,GAAG,GACJ,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bench — the Evermind benchmarking harness.
|
|
3
|
+
*
|
|
4
|
+
* Measures a trained model on held-out data (perplexity, bits-per-token,
|
|
5
|
+
* next-token accuracy, throughput), A/Bs two models, and offers a one-call
|
|
6
|
+
* train-and-score path the Studio drives in the browser.
|
|
7
|
+
*/
|
|
8
|
+
export { benchmarkModel, benchmarkModelAsync, benchmarkText, compareModels, compareReports, corpusToSequences, trainAndBenchmark, } from "./harness.js";
|
|
9
|
+
export { argmax, topKIndices, perplexity, bitsPerToken, newAccumulator, scoreInto, LN2, } from "./metrics.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bench/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,MAAM,EACN,WAAW,EACX,UAAU,EACV,YAAY,EACZ,cAAc,EACd,SAAS,EACT,GAAG,GACJ,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bench/metrics.ts — pure scoring primitives over per-position logits.
|
|
3
|
+
*
|
|
4
|
+
* These are the building blocks the harness composes. They are exact, allocation
|
|
5
|
+
* -light, and numerically stable (cross-entropy reuses the engine's stable
|
|
6
|
+
* log-sum-exp). Nothing here trains or mutates the model — benchmarking is a
|
|
7
|
+
* read-only forward pass over held-out data.
|
|
8
|
+
*/
|
|
9
|
+
/** Natural log of 2 — used to convert nats → bits. */
|
|
10
|
+
export declare const LN2: number;
|
|
11
|
+
/**
|
|
12
|
+
* Indices of the `k` largest logits, descending. O(V·k) — fine for the small
|
|
13
|
+
* top-k used in accuracy scoring; avoids a full sort of the vocab per position.
|
|
14
|
+
*/
|
|
15
|
+
export declare function topKIndices(logits: Float32Array, k: number): number[];
|
|
16
|
+
/** Index of the single largest logit (argmax). */
|
|
17
|
+
export declare function argmax(logits: Float32Array): number;
|
|
18
|
+
/** Perplexity from a mean cross-entropy (nats). */
|
|
19
|
+
export declare function perplexity(meanCrossEntropy: number): number;
|
|
20
|
+
/** Bits-per-token from a mean cross-entropy (nats). */
|
|
21
|
+
export declare function bitsPerToken(meanCrossEntropy: number): number;
|
|
22
|
+
/** Accumulator over predicted positions — cross-entropy + top-1/top-k hits. */
|
|
23
|
+
export interface ScoreAccumulator {
|
|
24
|
+
tokens: number;
|
|
25
|
+
ceSum: number;
|
|
26
|
+
top1Hits: number;
|
|
27
|
+
topKHits: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function newAccumulator(): ScoreAccumulator;
|
|
30
|
+
/**
|
|
31
|
+
* Score one (logits, targets) pair into the accumulator. `logits[t]` predicts
|
|
32
|
+
* `targets[t]`; positions with an out-of-range target are skipped. The caller
|
|
33
|
+
* aligns logits/targets (next-token: logits[0..T-2] predict tokens[1..T-1]).
|
|
34
|
+
*/
|
|
35
|
+
export declare function scoreInto(acc: ScoreAccumulator, logits: Float32Array[], targets: number[], k: number): void;
|
|
36
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/bench/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,sDAAsD;AACtD,eAAO,MAAM,GAAG,QAAW,CAAC;AAE5B;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAqBrE;AAED,kDAAkD;AAClD,wBAAgB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAUnD;AAED,mDAAmD;AACnD,wBAAgB,UAAU,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,cAAc,IAAI,gBAAgB,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,EAAE,MAAM,EAAE,EACjB,CAAC,EAAE,MAAM,GACR,IAAI,CAWN"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bench/metrics.ts — pure scoring primitives over per-position logits.
|
|
3
|
+
*
|
|
4
|
+
* These are the building blocks the harness composes. They are exact, allocation
|
|
5
|
+
* -light, and numerically stable (cross-entropy reuses the engine's stable
|
|
6
|
+
* log-sum-exp). Nothing here trains or mutates the model — benchmarking is a
|
|
7
|
+
* read-only forward pass over held-out data.
|
|
8
|
+
*/
|
|
9
|
+
import { crossEntropyLoss } from "../training/autograd.js";
|
|
10
|
+
/** Natural log of 2 — used to convert nats → bits. */
|
|
11
|
+
export const LN2 = Math.LN2;
|
|
12
|
+
/**
|
|
13
|
+
* Indices of the `k` largest logits, descending. O(V·k) — fine for the small
|
|
14
|
+
* top-k used in accuracy scoring; avoids a full sort of the vocab per position.
|
|
15
|
+
*/
|
|
16
|
+
export function topKIndices(logits, k) {
|
|
17
|
+
const n = logits.length;
|
|
18
|
+
const kk = Math.max(1, Math.min(k, n));
|
|
19
|
+
const idx = [];
|
|
20
|
+
const used = new Uint8Array(n);
|
|
21
|
+
for (let s = 0; s < kk; s++) {
|
|
22
|
+
let best = -1;
|
|
23
|
+
let bestVal = -Infinity;
|
|
24
|
+
for (let i = 0; i < n; i++) {
|
|
25
|
+
if (used[i])
|
|
26
|
+
continue;
|
|
27
|
+
const v = logits[i];
|
|
28
|
+
if (v > bestVal) {
|
|
29
|
+
bestVal = v;
|
|
30
|
+
best = i;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (best < 0)
|
|
34
|
+
break;
|
|
35
|
+
used[best] = 1;
|
|
36
|
+
idx.push(best);
|
|
37
|
+
}
|
|
38
|
+
return idx;
|
|
39
|
+
}
|
|
40
|
+
/** Index of the single largest logit (argmax). */
|
|
41
|
+
export function argmax(logits) {
|
|
42
|
+
let best = 0;
|
|
43
|
+
let bestVal = -Infinity;
|
|
44
|
+
for (let i = 0; i < logits.length; i++) {
|
|
45
|
+
if (logits[i] > bestVal) {
|
|
46
|
+
bestVal = logits[i];
|
|
47
|
+
best = i;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return best;
|
|
51
|
+
}
|
|
52
|
+
/** Perplexity from a mean cross-entropy (nats). */
|
|
53
|
+
export function perplexity(meanCrossEntropy) {
|
|
54
|
+
return Math.exp(meanCrossEntropy);
|
|
55
|
+
}
|
|
56
|
+
/** Bits-per-token from a mean cross-entropy (nats). */
|
|
57
|
+
export function bitsPerToken(meanCrossEntropy) {
|
|
58
|
+
return meanCrossEntropy / LN2;
|
|
59
|
+
}
|
|
60
|
+
export function newAccumulator() {
|
|
61
|
+
return { tokens: 0, ceSum: 0, top1Hits: 0, topKHits: 0 };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Score one (logits, targets) pair into the accumulator. `logits[t]` predicts
|
|
65
|
+
* `targets[t]`; positions with an out-of-range target are skipped. The caller
|
|
66
|
+
* aligns logits/targets (next-token: logits[0..T-2] predict tokens[1..T-1]).
|
|
67
|
+
*/
|
|
68
|
+
export function scoreInto(acc, logits, targets, k) {
|
|
69
|
+
const n = Math.min(logits.length, targets.length);
|
|
70
|
+
for (let t = 0; t < n; t++) {
|
|
71
|
+
const target = targets[t];
|
|
72
|
+
const lg = logits[t];
|
|
73
|
+
if (target < 0 || target >= lg.length)
|
|
74
|
+
continue;
|
|
75
|
+
acc.ceSum += crossEntropyLoss(lg, target);
|
|
76
|
+
if (argmax(lg) === target)
|
|
77
|
+
acc.top1Hits++;
|
|
78
|
+
if (topKIndices(lg, k).includes(target))
|
|
79
|
+
acc.topKHits++;
|
|
80
|
+
acc.tokens++;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/bench/metrics.ts"],"names":[],"mappings":"AAAA;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B,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,MAAM;YAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC1C,IAAI,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;QACxD,GAAG,CAAC,MAAM,EAAE,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bench/types.ts — public types for the Evermind benchmarking harness.
|
|
3
|
+
*
|
|
4
|
+
* Benchmarking answers the question the marketplace (and the "beats a frozen
|
|
5
|
+
* LLM" thesis) actually rests on: *how good is this model?* The harness measures
|
|
6
|
+
* a trained model on held-out data with the standard language-model yardsticks —
|
|
7
|
+
* perplexity, bits-per-token, and next-token accuracy — plus generation
|
|
8
|
+
* throughput, and can A/B two models (e.g. a quantized vs full-precision build,
|
|
9
|
+
* or a freshly-adapted vs prior checkpoint).
|
|
10
|
+
*
|
|
11
|
+
* The metrics operate on any object that can produce per-position logits from a
|
|
12
|
+
* token sequence — the engine's `EvermindLM` satisfies {@link LogitsModel}
|
|
13
|
+
* directly — so the harness is model-agnostic and dependency-free.
|
|
14
|
+
*/
|
|
15
|
+
/** The minimal surface a model must expose to be benchmarked: per-position logits. */
|
|
16
|
+
export interface LogitsModel {
|
|
17
|
+
/** Run the model over a token sequence; returns one logit vector per position. */
|
|
18
|
+
forward(tokens: number[]): {
|
|
19
|
+
logits: Float32Array[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** A model whose forward pass is asynchronous (e.g. a WebGPU backend). */
|
|
23
|
+
export interface AsyncLogitsModel {
|
|
24
|
+
forward(tokens: number[]): Promise<{
|
|
25
|
+
logits: Float32Array[];
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/** Knobs for a benchmark run. */
|
|
29
|
+
export interface BenchmarkOptions {
|
|
30
|
+
/** k for top-k next-token accuracy. Default 5. */
|
|
31
|
+
topK?: number;
|
|
32
|
+
/** Measure forward throughput (tokens/sec). Default true. */
|
|
33
|
+
measureLatency?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Monotonic clock in milliseconds, injectable for deterministic tests.
|
|
36
|
+
* Defaults to `performance.now()` when available, else `Date.now()`.
|
|
37
|
+
*/
|
|
38
|
+
now?: () => number;
|
|
39
|
+
}
|
|
40
|
+
/** The scorecard a benchmark run produces. */
|
|
41
|
+
export interface BenchmarkReport {
|
|
42
|
+
/** Number of evaluated sequences. */
|
|
43
|
+
sequences: number;
|
|
44
|
+
/** Number of predicted positions (next-token targets) scored. */
|
|
45
|
+
tokens: number;
|
|
46
|
+
/** Mean next-token cross-entropy, in nats. Lower is better. */
|
|
47
|
+
crossEntropy: number;
|
|
48
|
+
/** Perplexity = exp(crossEntropy). Lower is better; 1.0 is perfect. */
|
|
49
|
+
perplexity: number;
|
|
50
|
+
/** Bits per token = crossEntropy / ln(2). Lower is better. */
|
|
51
|
+
bitsPerToken: number;
|
|
52
|
+
/** Fraction of positions where the argmax prediction was correct (0..1). */
|
|
53
|
+
top1Accuracy: number;
|
|
54
|
+
/** Fraction of positions where the true token was in the top-k (0..1). */
|
|
55
|
+
topKAccuracy: number;
|
|
56
|
+
/** The k used for {@link topKAccuracy}. */
|
|
57
|
+
topK: number;
|
|
58
|
+
/** Forward throughput in tokens/sec, when {@link BenchmarkOptions.measureLatency}. */
|
|
59
|
+
tokensPerSecond?: number;
|
|
60
|
+
/** Wall-clock spent in the forward passes (ms), when measured. */
|
|
61
|
+
elapsedMs?: number;
|
|
62
|
+
}
|
|
63
|
+
/** The result of A/B-ing two models on the same eval set. */
|
|
64
|
+
export interface ComparisonReport {
|
|
65
|
+
candidate: BenchmarkReport;
|
|
66
|
+
baseline: BenchmarkReport;
|
|
67
|
+
/** candidate.perplexity − baseline.perplexity (negative = candidate better). */
|
|
68
|
+
perplexityDelta: number;
|
|
69
|
+
/** candidate.perplexity / baseline.perplexity (<1 = candidate better). */
|
|
70
|
+
perplexityRatio: number;
|
|
71
|
+
/** candidate.top1Accuracy − baseline.top1Accuracy (positive = candidate better). */
|
|
72
|
+
top1Delta: number;
|
|
73
|
+
/** Which model won on perplexity (the primary metric). */
|
|
74
|
+
winner: "candidate" | "baseline" | "tie";
|
|
75
|
+
/** Human-readable one-liner. */
|
|
76
|
+
summary: string;
|
|
77
|
+
}
|
|
78
|
+
/** Options for {@link trainAndBenchmark}: train a fresh EvermindLM, then score it. */
|
|
79
|
+
export interface TrainAndBenchmarkOptions {
|
|
80
|
+
/** BPE merges to learn for the tokenizer. Default 100. */
|
|
81
|
+
numMerges?: number;
|
|
82
|
+
/** Model channel dimension. Default 32. */
|
|
83
|
+
dModel?: number;
|
|
84
|
+
/** Number of (conv + MoE) blocks. Default 2. */
|
|
85
|
+
numLayers?: number;
|
|
86
|
+
/** MoE expert FFN hidden width. Default 48. */
|
|
87
|
+
hiddenDim?: number;
|
|
88
|
+
/** Training epochs. Default 30. */
|
|
89
|
+
epochs?: number;
|
|
90
|
+
/** AdamW learning rate. Default 0.03. */
|
|
91
|
+
lr?: number;
|
|
92
|
+
/** Deterministic seed (model init + held-out split). Default 7. */
|
|
93
|
+
seed?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Fraction of sequences reserved for evaluation (never trained on). Default
|
|
96
|
+
* 0.25. A real benchmark must score held-out data, so this is enforced > 0.
|
|
97
|
+
*/
|
|
98
|
+
heldOutRatio?: number;
|
|
99
|
+
/** k for top-k accuracy. Default 5. */
|
|
100
|
+
topK?: number;
|
|
101
|
+
/** Prompt used to capture a qualitative generation sample. Default "The". */
|
|
102
|
+
prompt?: string;
|
|
103
|
+
}
|
|
104
|
+
/** {@link trainAndBenchmark} result: the held-out scorecard plus training context. */
|
|
105
|
+
export interface TrainAndBenchmarkResult extends BenchmarkReport {
|
|
106
|
+
/** Sequences used for training. */
|
|
107
|
+
trainSequences: number;
|
|
108
|
+
/** Held-out sequences used for evaluation. */
|
|
109
|
+
evalSequences: number;
|
|
110
|
+
/** Final-epoch mean training loss (nats). */
|
|
111
|
+
finalTrainLoss: number;
|
|
112
|
+
/** First-epoch mean training loss (nats) — pairs with final to show the drop. */
|
|
113
|
+
initialTrainLoss: number;
|
|
114
|
+
/** Learned tokenizer vocabulary size. */
|
|
115
|
+
vocabSize: number;
|
|
116
|
+
/** A short greedy generation from {@link TrainAndBenchmarkOptions.prompt}. */
|
|
117
|
+
sample: string;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/bench/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,kFAAkF;IAClF,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG;QAAE,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;CACvD;AAED,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC,CAAC;CAChE;AAED,iCAAiC;AACjC,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,8CAA8C;AAC9C,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,UAA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sF;AACtF,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,iFAAiF;IACjF,gBAAgB,EAAE,MAAM,CAAC;IACzB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bench/types.ts — public types for the Evermind benchmarking harness.
|
|
3
|
+
*
|
|
4
|
+
* Benchmarking answers the question the marketplace (and the "beats a frozen
|
|
5
|
+
* LLM" thesis) actually rests on: *how good is this model?* The harness measures
|
|
6
|
+
* a trained model on held-out data with the standard language-model yardsticks —
|
|
7
|
+
* perplexity, bits-per-token, and next-token accuracy — plus generation
|
|
8
|
+
* throughput, and can A/B two models (e.g. a quantized vs full-precision build,
|
|
9
|
+
* or a freshly-adapted vs prior checkpoint).
|
|
10
|
+
*
|
|
11
|
+
* The metrics operate on any object that can produce per-position logits from a
|
|
12
|
+
* token sequence — the engine's `EvermindLM` satisfies {@link LogitsModel}
|
|
13
|
+
* directly — so the harness is model-agnostic and dependency-free.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bench/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* export/gguf.ts — export weights to a GGUF v3 container (the llama.cpp format).
|
|
3
|
+
*
|
|
4
|
+
* Emits a spec-valid GGUF file: magic + version, KV metadata (architecture, dims,
|
|
5
|
+
* expert counts…), aligned tensor-info table, then aligned tensor data. ggml
|
|
6
|
+
* stores dimensions innermost-first, so row-major shapes are reversed here.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: GGUF is a *container*. llama.cpp can only RUN a file whose
|
|
9
|
+
* `general.architecture` it has a graph for; "evermind" is custom, so this file
|
|
10
|
+
* is a valid, inspectable artifact (gguf tooling reads it) but won't execute in
|
|
11
|
+
* stock llama.cpp until the architecture is upstreamed. It exists so the same
|
|
12
|
+
* weights can travel through GGUF-native tooling. For an executable export use
|
|
13
|
+
* {@link ./onnx} or {@link ./safetensors}.
|
|
14
|
+
*/
|
|
15
|
+
import type { EvermindLM } from "../lm/evermind_lm.js";
|
|
16
|
+
export interface GgufOptions {
|
|
17
|
+
name?: string;
|
|
18
|
+
/** Store tensors as float16 (ggml type F16). Default false (F32). */
|
|
19
|
+
fp16?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Export a trained LM to GGUF bytes. */
|
|
22
|
+
export declare function exportGguf(lm: EvermindLM, opts?: GgufOptions): Uint8Array;
|
|
23
|
+
//# sourceMappingURL=gguf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gguf.d.ts","sourceRoot":"","sources":["../../src/export/gguf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAevD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AA+DD,yCAAyC;AACzC,wBAAgB,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,GAAE,WAAgB,GAAG,UAAU,CAqE7E"}
|