doppler-gpu 0.4.15 → 0.5.1
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 +9 -0
- package/package.json +25 -2
- package/src/cli/doppler-cli.js +253 -94
- package/src/cli/runtime-profiles.js +3 -7
- package/src/client/doppler-api.d.ts +28 -0
- package/src/client/doppler-api.js +2 -0
- package/src/client/inspection.d.ts +122 -0
- package/src/client/inspection.js +343 -0
- package/src/client/runtime/index.d.ts +54 -0
- package/src/client/runtime/index.js +190 -18
- package/src/client/runtime/model-manager.d.ts +0 -4
- package/src/client/runtime/model-manager.js +0 -28
- package/src/client/runtime/model-session.d.ts +48 -1
- package/src/client/runtime/model-session.js +149 -30
- package/src/client/runtime/model-source.d.ts +10 -1
- package/src/client/runtime/scoped-session.d.ts +117 -0
- package/src/client/runtime/scoped-session.js +257 -0
- package/src/client/runtime/types.d.ts +0 -1
- package/src/client/runtime/types.js +0 -1
- package/src/config/evidence/boundary-evidence-policy.json +54 -0
- package/src/config/evidence/source-intake-policy.json +122 -0
- package/src/config/inspection/observation-policies.json +80 -0
- package/src/config/param-validator.js +21 -36
- package/src/config/runtime/compute/f16-activations.json +1 -0
- package/src/config/runtime/compute/f16-batched.json +1 -0
- package/src/config/runtime/default.json +1 -0
- package/src/config/runtime/diagnostics/debug-logits.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +1 -0
- package/src/config/runtime/experiments/bench/gemma4-bench-q4k.json +1 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +1 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +1 -0
- package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +1 -3
- package/src/config/runtime/experiments/debug/gemma4-e2b-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/verify/gemma3-verify.json +1 -3
- package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +1 -3
- package/src/config/runtime/experiments/verify/lfm2-verify.json +1 -3
- package/src/config/runtime/experiments/verify/translategemma-verify.json +1 -3
- package/src/config/runtime/model/gemma2-debug.json +1 -0
- package/src/config/runtime/model/gemma2-pipeline-debug.json +1 -0
- package/src/config/runtime/model/gemma2-pipeline.json +1 -0
- package/src/config/runtime/model/gemma3-layer-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-layer-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-layer3-boundary-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-linear-attn-debug.json +1 -0
- package/src/config/runtime/optimization-candidates/registry.json +5 -0
- package/src/config/runtime/platform/metal-apple-q4k.json +1 -0
- package/src/config/runtime/profiles/default.json +1 -0
- package/src/config/runtime/profiles/diffusiongemma-26b-a4b-throughput.json +1 -0
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-overlapped-probe.json +1 -0
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-b4.json +1 -3
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-single.json +1 -3
- package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-baseline-probe.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-probe.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-test.json +1 -0
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-baseline-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-f16a-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-reference-export.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-retain-q4k-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +1 -0
- package/src/config/runtime/profiles/gemma4-e2b-prefill-profile.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/low-memory.json +1 -0
- package/src/config/runtime/profiles/production.json +1 -3
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-attn128-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-maxbatch64-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-normed-ffn-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-overlap-ringtokens1-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-parity.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-sequential-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-prefill-profile.json +1 -3
- package/src/config/runtime/profiles/qwen-3-5-0-8b-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-2b-f16-primary-throughput.json +1 -5
- package/src/config/runtime/profiles/qwen-3-5-2b-metal-parity.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-2b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-9b-metal-correctness.json +1 -0
- package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-stability.json +1 -3
- package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-stability.json +1 -0
- package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +1 -5
- package/src/config/runtime/profiles/rerank-stability.json +1 -3
- package/src/config/runtime/profiles/rerank-throughput.json +1 -3
- package/src/config/runtime/profiles/simulation.json +1 -3
- package/src/config/runtime/profiles/throughput.json +1 -3
- package/src/config/runtime/profiles/trace-layers.json +1 -3
- package/src/config/runtime/profiles/translategemma-1b-nativekd2-q4k-rdna3-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous-prod.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous.json +1 -0
- package/src/config/runtime/profiles/turboquant.json +1 -0
- package/src/config/runtime/profiles/vector-stability.json +1 -3
- package/src/config/runtime/profiles/vector-throughput.json +1 -0
- package/src/config/runtime/profiles/verbose-trace.json +1 -3
- package/src/config/runtime/tiers/gemma4-128gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-16gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-24gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-32gb.json +1 -0
- package/src/config/schema/benchmark.schema.d.ts +7 -0
- package/src/config/schema/benchmark.schema.js +5 -0
- package/src/config/schema/index.d.ts +8 -16
- package/src/config/schema/index.js +5 -8
- package/src/config/schema/kernel-thresholds.schema.d.ts +0 -12
- package/src/config/schema/kernel-thresholds.schema.js +0 -12
- package/src/config/schema/kernel-warmup.schema.d.ts +1 -3
- package/src/config/schema/kernel-warmup.schema.js +0 -1
- package/src/config/schema/runtime-profile.schema.d.ts +24 -0
- package/src/config/schema/runtime-profile.schema.js +92 -0
- package/src/config/schema/shared-runtime.schema.d.ts +1 -4
- package/src/config/schema/shared-runtime.schema.js +0 -2
- package/src/config/schema/tooling.schema.d.ts +8 -5
- package/src/config/schema/tooling.schema.js +3 -2
- package/src/debug/tensor.d.ts +2 -0
- package/src/debug/tensor.js +21 -2
- package/src/gpu/command-recorder.d.ts +5 -0
- package/src/gpu/command-recorder.js +17 -0
- package/src/gpu/kernel-runtime.js +2 -10
- package/src/gpu/kernels/index.d.ts +0 -2
- package/src/gpu/kernels/index.js +0 -2
- package/src/gpu/kernels/kernel-prewarm.d.ts +3 -0
- package/src/gpu/kernels/kernel-prewarm.js +60 -0
- package/src/gpu/kernels/utils.d.ts +2 -4
- package/src/gpu/kernels/utils.js +2 -4
- package/src/index.d.ts +13 -1
- package/src/index.js +7 -1
- package/src/inference/browser-harness-model-helpers.js +4 -0
- package/src/inference/browser-harness-runtime-helpers.js +25 -10
- package/src/inference/browser-harness-text-helpers.js +4 -1
- package/src/inference/browser-harness.d.ts +4 -0
- package/src/inference/browser-harness.js +91 -4
- package/src/inference/observation-context.d.ts +22 -0
- package/src/inference/observation-context.js +41 -0
- package/src/inference/pipelines/text/attention/attn-config.js +1 -1
- package/src/inference/pipelines/text/attention/executor-immediate.js +42 -0
- package/src/inference/pipelines/text/attention/executor-recorded.js +29 -0
- package/src/inference/pipelines/text/attention/index.js +7 -0
- package/src/inference/pipelines/text/attention/interpreter.js +1334 -0
- package/src/inference/pipelines/text/attention/plan.d.ts +36 -0
- package/src/inference/pipelines/text/attention/plan.js +328 -0
- package/src/inference/pipelines/text/attention/receipt.js +60 -0
- package/src/inference/pipelines/text/attention/record.js +8 -1278
- package/src/inference/pipelines/text/attention/run.js +8 -1386
- package/src/inference/pipelines/text/generator-decode-policy.js +4 -1
- package/src/inference/pipelines/text/generator-helpers.js +2 -0
- package/src/inference/pipelines/text/generator-steps.js +32 -15
- package/src/inference/pipelines/text/generator.js +10 -5
- package/src/inference/pipelines/text/init.d.ts +3 -0
- package/src/inference/pipelines/text/layer-plan-gpu.js +2 -0
- package/src/inference/pipelines/text/layer.js +2 -0
- package/src/inference/pipelines/text/model-load.d.ts +0 -1
- package/src/inference/pipelines/text/model-load.js +2 -11
- package/src/inference/pipelines/text/probes.js +10 -0
- package/src/inference/pipelines/text/resolved-runtime-session.d.ts +56 -0
- package/src/inference/pipelines/text/resolved-runtime-session.js +175 -0
- package/src/inference/pipelines/text/state.d.ts +6 -0
- package/src/inference/pipelines/text/state.js +3 -0
- package/src/inference/pipelines/text/types.d.ts +6 -0
- package/src/inference/pipelines/text.js +16 -1
- package/src/inference/refactor-receipt.d.ts +49 -0
- package/src/inference/refactor-receipt.js +188 -0
- package/src/inference/resource-scope.d.ts +33 -0
- package/src/inference/resource-scope.js +168 -0
- package/src/inference/test-harness.d.ts +3 -0
- package/src/inference/test-harness.js +1 -0
- package/src/storage/model-cache.d.ts +53 -0
- package/src/storage/model-cache.js +550 -0
- package/src/tooling/boundary-evidence.d.ts +51 -0
- package/src/tooling/boundary-evidence.js +408 -0
- package/src/tooling/browser-command-runner.js +4 -4
- package/src/tooling/command-context.d.ts +25 -0
- package/src/tooling/command-context.js +53 -0
- package/src/tooling/command-runner-shared.js +22 -5
- package/src/tooling/demo-receipts.d.ts +56 -0
- package/src/tooling/demo-receipts.js +113 -0
- package/src/tooling/diagnose-runner.js +2 -2
- package/src/tooling/execution-cost-ledger.d.ts +21 -0
- package/src/tooling/execution-cost-ledger.js +199 -0
- package/src/tooling/node-command-runner.js +2 -2
- package/src/tooling/opfs-cache.d.ts +11 -49
- package/src/tooling/opfs-cache.js +4 -510
- package/src/tooling/precision-replay-math.d.ts +42 -0
- package/src/tooling/precision-replay-math.js +174 -0
- package/src/tooling/program-bundle-parity.d.ts +3 -0
- package/src/tooling/program-bundle-parity.js +8 -0
- package/src/tooling/program-bundle.d.ts +1 -52
- package/src/tooling/program-bundle.js +0 -139
- package/src/tooling/registered-variant-calibration.d.ts +24 -0
- package/src/tooling/registered-variant-calibration.js +286 -0
- package/src/tooling/runtime-input-composition.js +105 -53
- package/src/tooling/runtime-intent.js +41 -0
- package/src/tooling/runtime-optimization-index.d.ts +6 -0
- package/src/tooling/runtime-optimization-index.js +72 -0
- package/src/tooling/runtime-optimization.d.ts +47 -6
- package/src/tooling/runtime-optimization.js +559 -40
- package/src/tooling/source-intake.d.ts +49 -0
- package/src/tooling/source-intake.js +414 -0
- package/src/tooling-exports/evidence.d.ts +34 -0
- package/src/tooling-exports/evidence.js +34 -0
- package/src/tooling-exports/runtime.d.ts +7 -0
- package/src/tooling-exports/runtime.js +7 -0
- package/src/tooling-exports.d.ts +11 -0
- package/src/tooling-exports.js +6 -3
- package/src/tooling-exports.shared.d.ts +32 -0
- package/src/tooling-exports.shared.js +31 -0
- package/src/version.js +1 -1
- package/src/config/schema/tuner.schema.d.ts +0 -39
- package/src/config/schema/tuner.schema.js +0 -13
- package/src/gpu/kernel-tuner/benchmarks.js +0 -902
- package/src/gpu/kernel-tuner/cache.js +0 -145
- package/src/gpu/kernel-tuner/index.js +0 -38
- package/src/gpu/kernel-tuner/tuner.js +0 -247
- package/src/gpu/kernel-tuner.js +0 -12
- package/src/gpu/kernels/kernel-tuning.d.ts +0 -42
- package/src/gpu/kernels/kernel-tuning.js +0 -158
- package/src/gpu/profiler.js +0 -382
- package/src/inference/pipelines/text/attention/output-gate-fusion.js +0 -37
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { f16ToF32Bits, f32ToF16Bits } from '../inference/kv-cache/types.js';
|
|
2
|
+
|
|
3
|
+
export const PRECISION_REPLAY_MODES = Object.freeze([
|
|
4
|
+
'exact',
|
|
5
|
+
'f32_forward',
|
|
6
|
+
'f32_reverse',
|
|
7
|
+
'f32_tree64',
|
|
8
|
+
'f16_forward',
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const f32Scratch = new Float32Array(1);
|
|
12
|
+
|
|
13
|
+
export function roundF32(value) {
|
|
14
|
+
f32Scratch[0] = value;
|
|
15
|
+
return f32Scratch[0];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function roundF16(value) {
|
|
19
|
+
return f16ToF32Bits(f32ToF16Bits(value));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function exactDot(hidden, weights) {
|
|
23
|
+
let acc = 0;
|
|
24
|
+
for (let i = 0; i < hidden.length; i += 1) {
|
|
25
|
+
acc += hidden[i] * weights[i];
|
|
26
|
+
}
|
|
27
|
+
return acc;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function forwardDotF32(hidden, weights) {
|
|
31
|
+
let acc = 0;
|
|
32
|
+
for (let i = 0; i < hidden.length; i += 1) {
|
|
33
|
+
acc = roundF32(acc + roundF32(hidden[i] * weights[i]));
|
|
34
|
+
}
|
|
35
|
+
return acc;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function reverseDotF32(hidden, weights) {
|
|
39
|
+
let acc = 0;
|
|
40
|
+
for (let i = hidden.length - 1; i >= 0; i -= 1) {
|
|
41
|
+
acc = roundF32(acc + roundF32(hidden[i] * weights[i]));
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function tree64DotF32(hidden, weights) {
|
|
47
|
+
const width = 64;
|
|
48
|
+
const partial = new Float32Array(width);
|
|
49
|
+
for (let lane = 0; lane < width; lane += 1) {
|
|
50
|
+
let acc = 0;
|
|
51
|
+
for (let i = lane; i < hidden.length; i += width) {
|
|
52
|
+
acc = roundF32(acc + roundF32(hidden[i] * weights[i]));
|
|
53
|
+
}
|
|
54
|
+
partial[lane] = acc;
|
|
55
|
+
}
|
|
56
|
+
for (let stride = width >> 1; stride > 0; stride >>= 1) {
|
|
57
|
+
for (let lane = 0; lane < stride; lane += 1) {
|
|
58
|
+
partial[lane] = roundF32(partial[lane] + partial[lane + stride]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return partial[0];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function forwardDotF16(hidden, weights) {
|
|
65
|
+
let acc = 0;
|
|
66
|
+
for (let i = 0; i < hidden.length; i += 1) {
|
|
67
|
+
const product = roundF16(roundF16(hidden[i]) * roundF16(weights[i]));
|
|
68
|
+
acc = roundF16(roundF16(acc) + product);
|
|
69
|
+
}
|
|
70
|
+
return acc;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function scoreDotProductModes(hidden, weights) {
|
|
74
|
+
return {
|
|
75
|
+
exact: exactDot(hidden, weights),
|
|
76
|
+
f32_forward: forwardDotF32(hidden, weights),
|
|
77
|
+
f32_reverse: reverseDotF32(hidden, weights),
|
|
78
|
+
f32_tree64: tree64DotF32(hidden, weights),
|
|
79
|
+
f16_forward: forwardDotF16(hidden, weights),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function buildModeScoreMaps(hidden, rows) {
|
|
84
|
+
const perModeScores = {
|
|
85
|
+
exact: new Map(),
|
|
86
|
+
f32_forward: new Map(),
|
|
87
|
+
f32_reverse: new Map(),
|
|
88
|
+
f32_tree64: new Map(),
|
|
89
|
+
f16_forward: new Map(),
|
|
90
|
+
};
|
|
91
|
+
for (const [tokenId, row] of rows.entries()) {
|
|
92
|
+
const scores = scoreDotProductModes(hidden, row);
|
|
93
|
+
for (const mode of PRECISION_REPLAY_MODES) {
|
|
94
|
+
perModeScores[mode].set(tokenId, scores[mode]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return perModeScores;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function sortTokenIdsByScore(tokenIds, scoreMap) {
|
|
101
|
+
return [...tokenIds].sort((left, right) => {
|
|
102
|
+
const delta = scoreMap.get(right) - scoreMap.get(left);
|
|
103
|
+
if (delta !== 0) {
|
|
104
|
+
return delta;
|
|
105
|
+
}
|
|
106
|
+
return left - right;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function summarizeRanking(tokenIds, scoreMap, decodeToken, limit) {
|
|
111
|
+
const ranked = sortTokenIdsByScore(tokenIds, scoreMap);
|
|
112
|
+
const topIds = ranked.slice(0, Math.min(limit, ranked.length));
|
|
113
|
+
const winner = topIds[0] ?? null;
|
|
114
|
+
const runnerUp = topIds[1] ?? null;
|
|
115
|
+
return {
|
|
116
|
+
winnerTokenId: winner,
|
|
117
|
+
winnerText: winner == null ? null : decodeToken(winner),
|
|
118
|
+
winnerScore: winner == null ? null : scoreMap.get(winner),
|
|
119
|
+
winnerGap: winner == null || runnerUp == null ? null : scoreMap.get(winner) - scoreMap.get(runnerUp),
|
|
120
|
+
top: topIds.map((tokenId, index) => ({
|
|
121
|
+
rank: index + 1,
|
|
122
|
+
tokenId,
|
|
123
|
+
text: decodeToken(tokenId),
|
|
124
|
+
score: scoreMap.get(tokenId),
|
|
125
|
+
})),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function computeInversionCount(tokenIds, leftScoreMap, rightScoreMap) {
|
|
130
|
+
const leftRanked = sortTokenIdsByScore(tokenIds, leftScoreMap);
|
|
131
|
+
const rightRank = new Map(sortTokenIdsByScore(tokenIds, rightScoreMap).map((tokenId, index) => [tokenId, index]));
|
|
132
|
+
let inversions = 0;
|
|
133
|
+
for (let i = 0; i < leftRanked.length; i += 1) {
|
|
134
|
+
for (let j = i + 1; j < leftRanked.length; j += 1) {
|
|
135
|
+
if ((rightRank.get(leftRanked[i]) ?? 0) > (rightRank.get(leftRanked[j]) ?? 0)) {
|
|
136
|
+
inversions += 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return inversions;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function compareTokenSequences(left, right) {
|
|
144
|
+
const maxLength = Math.max(left.length, right.length);
|
|
145
|
+
const differingSteps = [];
|
|
146
|
+
for (let i = 0; i < maxLength; i += 1) {
|
|
147
|
+
if (left[i] !== right[i]) {
|
|
148
|
+
differingSteps.push(i);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let healedAtStep = null;
|
|
152
|
+
if (differingSteps.length > 0) {
|
|
153
|
+
for (let start = differingSteps[0] + 1; start < maxLength; start += 1) {
|
|
154
|
+
let suffixEqual = true;
|
|
155
|
+
for (let i = start; i < maxLength; i += 1) {
|
|
156
|
+
if (left[i] !== right[i]) {
|
|
157
|
+
suffixEqual = false;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (suffixEqual) {
|
|
162
|
+
healedAtStep = start;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
firstDifferentStep: differingSteps[0] ?? null,
|
|
169
|
+
lastDifferentStep: differingSteps[differingSteps.length - 1] ?? null,
|
|
170
|
+
differingStepCount: differingSteps.length,
|
|
171
|
+
healedAtStep,
|
|
172
|
+
persistsThroughEnd: differingSteps.length > 0 && healedAtStep == null,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -13,12 +13,15 @@ export interface ProgramBundleParityOptions {
|
|
|
13
13
|
|
|
14
14
|
export interface ProgramBundleParityResult {
|
|
15
15
|
schema: typeof PROGRAM_BUNDLE_PARITY_SCHEMA_ID;
|
|
16
|
+
authority: 'portability-diagnostic-only';
|
|
17
|
+
modelPromotionAuthority: false;
|
|
16
18
|
ok: boolean;
|
|
17
19
|
mode: 'contract' | 'execute';
|
|
18
20
|
bundleId: string;
|
|
19
21
|
modelId: string;
|
|
20
22
|
executionGraphHash: string;
|
|
21
23
|
reference: Record<string, unknown>;
|
|
24
|
+
tokenEvidence: Record<string, unknown>;
|
|
22
25
|
providers: Array<Record<string, unknown>>;
|
|
23
26
|
parityHash: string;
|
|
24
27
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import { loadProgramBundle } from './program-bundle.js';
|
|
4
|
+
import {
|
|
5
|
+
buildDeterministicTokenEvidenceFromReferenceTranscript,
|
|
6
|
+
} from './boundary-evidence.js';
|
|
4
7
|
import { sha256Hex } from '../utils/sha256.js';
|
|
5
8
|
import { stableSortObject } from '../utils/stable-sort-object.js';
|
|
6
9
|
|
|
@@ -189,12 +192,17 @@ export async function checkProgramBundleParity(options = {}) {
|
|
|
189
192
|
const ok = results.every((result) => result.ok === true);
|
|
190
193
|
return {
|
|
191
194
|
schema: PROGRAM_BUNDLE_PARITY_SCHEMA_ID,
|
|
195
|
+
authority: 'portability-diagnostic-only',
|
|
196
|
+
modelPromotionAuthority: false,
|
|
192
197
|
ok,
|
|
193
198
|
mode,
|
|
194
199
|
bundleId: bundle.bundleId,
|
|
195
200
|
modelId: bundle.modelId,
|
|
196
201
|
executionGraphHash: bundle.sources.executionGraph.hash,
|
|
197
202
|
reference: summarizeReference(bundle),
|
|
203
|
+
tokenEvidence: buildDeterministicTokenEvidenceFromReferenceTranscript(
|
|
204
|
+
bundle.referenceTranscript
|
|
205
|
+
),
|
|
198
206
|
providers: results,
|
|
199
207
|
parityHash: hashStableJson({
|
|
200
208
|
bundleId: bundle.bundleId,
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ProgramBundle,
|
|
3
|
-
ProgramBundleReferenceTranscript,
|
|
4
|
-
} from '../config/schema/program-bundle.schema.js';
|
|
5
|
-
|
|
6
|
-
export declare const REFERENCE_RECEIPT_SCHEMA_ID: 'doppler.reference-receipt/v1';
|
|
1
|
+
import type { ProgramBundle } from '../config/schema/program-bundle.schema.js';
|
|
7
2
|
|
|
8
3
|
export interface ProgramBundleExportOptions {
|
|
9
4
|
repoRoot?: string;
|
|
@@ -54,46 +49,6 @@ export interface ProgramBundleStorageArtifact {
|
|
|
54
49
|
manifestRaw: string | null;
|
|
55
50
|
}
|
|
56
51
|
|
|
57
|
-
export interface ReferenceReceiptExportOptions {
|
|
58
|
-
repoRoot?: string;
|
|
59
|
-
manifestPath?: string | null;
|
|
60
|
-
modelDir?: string | null;
|
|
61
|
-
referenceTranscriptPath?: string | null;
|
|
62
|
-
referenceTranscript?: ProgramBundleReferenceTranscript | null;
|
|
63
|
-
outputPath?: string | null;
|
|
64
|
-
receiptId?: string | null;
|
|
65
|
-
createdAtUtc?: string | null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface ProgramBundleReferenceReceipt {
|
|
69
|
-
schema: typeof REFERENCE_RECEIPT_SCHEMA_ID;
|
|
70
|
-
receiptId: string;
|
|
71
|
-
modelId: string;
|
|
72
|
-
createdAtUtc: string;
|
|
73
|
-
sources: {
|
|
74
|
-
manifest: {
|
|
75
|
-
path: string;
|
|
76
|
-
hash: string;
|
|
77
|
-
sizeBytes: number;
|
|
78
|
-
};
|
|
79
|
-
executionGraph: {
|
|
80
|
-
schema: string | null;
|
|
81
|
-
hash: string;
|
|
82
|
-
expandedStepHash: string;
|
|
83
|
-
};
|
|
84
|
-
weightSetHash: string | null;
|
|
85
|
-
referenceTranscript: {
|
|
86
|
-
path: string | null;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
referenceTranscript: ProgramBundleReferenceTranscript;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface ReferenceReceiptWriteResult {
|
|
93
|
-
outputPath: string;
|
|
94
|
-
receipt: ProgramBundleReferenceReceipt;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
52
|
export declare function resolveProgramBundleStorageArtifact(
|
|
98
53
|
manifest: Record<string, unknown>,
|
|
99
54
|
modelDir: string
|
|
@@ -104,9 +59,3 @@ export declare function writeProgramBundle(options?: ProgramBundleExportOptions)
|
|
|
104
59
|
export declare function loadProgramBundle(bundlePath: string): Promise<ProgramBundle>;
|
|
105
60
|
export declare function checkProgramBundleFile(bundlePath: string): Promise<ProgramBundleCheckResult>;
|
|
106
61
|
export declare function createProgramBundleCliDefaults(metaUrl: string): { repoRoot: string };
|
|
107
|
-
export declare function exportReferenceReceipt(
|
|
108
|
-
options?: ReferenceReceiptExportOptions
|
|
109
|
-
): Promise<ProgramBundleReferenceReceipt>;
|
|
110
|
-
export declare function writeReferenceReceipt(
|
|
111
|
-
options?: ReferenceReceiptExportOptions
|
|
112
|
-
): Promise<ReferenceReceiptWriteResult>;
|
|
@@ -978,142 +978,3 @@ export function createProgramBundleCliDefaults(metaUrl) {
|
|
|
978
978
|
repoRoot: path.resolve(path.dirname(fileURLToPath(metaUrl)), '..'),
|
|
979
979
|
};
|
|
980
980
|
}
|
|
981
|
-
|
|
982
|
-
export const REFERENCE_RECEIPT_SCHEMA_ID = 'doppler.reference-receipt/v1';
|
|
983
|
-
|
|
984
|
-
function requireTranscriptField(value, label) {
|
|
985
|
-
if (value === undefined || value === null) {
|
|
986
|
-
throw new Error(`reference receipt: ${label} is required on the referenceTranscript input.`);
|
|
987
|
-
}
|
|
988
|
-
return value;
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
function normalizeReferenceTranscriptInput(referenceTranscript, executionGraphHash) {
|
|
992
|
-
requirePlainObject(referenceTranscript, 'referenceTranscript');
|
|
993
|
-
if (referenceTranscript.schema !== PROGRAM_BUNDLE_REFERENCE_TRANSCRIPT_SCHEMA_ID) {
|
|
994
|
-
throw new Error(
|
|
995
|
-
`reference receipt: referenceTranscript.schema must be "${PROGRAM_BUNDLE_REFERENCE_TRANSCRIPT_SCHEMA_ID}".`
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
requirePlainObject(referenceTranscript.prompt, 'referenceTranscript.prompt');
|
|
999
|
-
requirePlainObject(referenceTranscript.output, 'referenceTranscript.output');
|
|
1000
|
-
requirePlainObject(referenceTranscript.tokens, 'referenceTranscript.tokens');
|
|
1001
|
-
const graphHashInTranscript = requireTranscriptField(
|
|
1002
|
-
referenceTranscript.executionGraphHash,
|
|
1003
|
-
'executionGraphHash'
|
|
1004
|
-
);
|
|
1005
|
-
if (graphHashInTranscript !== executionGraphHash) {
|
|
1006
|
-
throw new Error(
|
|
1007
|
-
`reference receipt: referenceTranscript.executionGraphHash (${graphHashInTranscript}) ` +
|
|
1008
|
-
`does not match manifest executionGraphHash (${executionGraphHash}).`
|
|
1009
|
-
);
|
|
1010
|
-
}
|
|
1011
|
-
return referenceTranscript;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
function buildWeightSetHashFromManifest(manifest) {
|
|
1015
|
-
const shards = manifest?.rdrr?.shards;
|
|
1016
|
-
if (!Array.isArray(shards) || shards.length === 0) return null;
|
|
1017
|
-
const normalized = shards
|
|
1018
|
-
.map((shard) => ({
|
|
1019
|
-
filename: String(shard?.filename ?? shard?.path ?? ''),
|
|
1020
|
-
hash: String(shard?.hash ?? shard?.sha256 ?? ''),
|
|
1021
|
-
size: Number.isFinite(shard?.size) ? Number(shard.size) : null,
|
|
1022
|
-
}))
|
|
1023
|
-
.filter((entry) => entry.filename && entry.hash);
|
|
1024
|
-
if (normalized.length === 0) return null;
|
|
1025
|
-
normalized.sort((left, right) => left.filename.localeCompare(right.filename));
|
|
1026
|
-
return hashStableJson(normalized);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
function resolveReferenceReceiptOptions(options = {}) {
|
|
1030
|
-
const repoRoot = path.resolve(options.repoRoot || process.cwd());
|
|
1031
|
-
const manifestPath = options.manifestPath
|
|
1032
|
-
? path.resolve(options.manifestPath)
|
|
1033
|
-
: (options.modelDir ? path.resolve(options.modelDir, 'manifest.json') : null);
|
|
1034
|
-
if (!manifestPath) {
|
|
1035
|
-
throw new Error('reference receipt: manifestPath or modelDir is required.');
|
|
1036
|
-
}
|
|
1037
|
-
const referenceTranscriptPath = options.referenceTranscriptPath
|
|
1038
|
-
? path.resolve(options.referenceTranscriptPath)
|
|
1039
|
-
: null;
|
|
1040
|
-
const referenceTranscript = options.referenceTranscript ?? null;
|
|
1041
|
-
if (!referenceTranscriptPath && !referenceTranscript) {
|
|
1042
|
-
throw new Error('reference receipt: referenceTranscriptPath or referenceTranscript is required.');
|
|
1043
|
-
}
|
|
1044
|
-
return {
|
|
1045
|
-
...options,
|
|
1046
|
-
repoRoot,
|
|
1047
|
-
manifestPath,
|
|
1048
|
-
referenceTranscriptPath,
|
|
1049
|
-
referenceTranscript,
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
export async function exportReferenceReceipt(options = {}) {
|
|
1054
|
-
const resolved = resolveReferenceReceiptOptions(options);
|
|
1055
|
-
const { raw: manifestRaw, json: manifest } = await readJsonFile(resolved.manifestPath, 'manifest');
|
|
1056
|
-
requirePlainObject(manifest, 'manifest');
|
|
1057
|
-
const modelId = requireString(manifest.modelId, 'manifest.modelId');
|
|
1058
|
-
const execution = manifest.inference?.execution;
|
|
1059
|
-
requirePlainObject(execution, 'manifest.inference.execution');
|
|
1060
|
-
|
|
1061
|
-
const expandedSteps = expandExecutionV1(execution);
|
|
1062
|
-
const executionGraphHash = hashStableJson(execution);
|
|
1063
|
-
const expandedStepHash = hashStableJson(expandedSteps);
|
|
1064
|
-
|
|
1065
|
-
let transcript = resolved.referenceTranscript;
|
|
1066
|
-
let transcriptSourcePath = null;
|
|
1067
|
-
if (!transcript) {
|
|
1068
|
-
const { json } = await readJsonFile(resolved.referenceTranscriptPath, 'reference transcript');
|
|
1069
|
-
transcript = json;
|
|
1070
|
-
transcriptSourcePath = toRepoRelativePath(resolved.referenceTranscriptPath, resolved.repoRoot);
|
|
1071
|
-
}
|
|
1072
|
-
const normalizedTranscript = normalizeReferenceTranscriptInput(transcript, executionGraphHash);
|
|
1073
|
-
|
|
1074
|
-
const manifestArtifact = {
|
|
1075
|
-
path: toRepoRelativePath(resolved.manifestPath, resolved.repoRoot),
|
|
1076
|
-
hash: `sha256:${sha256Hex(manifestRaw)}`,
|
|
1077
|
-
sizeBytes: Buffer.byteLength(manifestRaw),
|
|
1078
|
-
};
|
|
1079
|
-
|
|
1080
|
-
const weightSetHash = buildWeightSetHashFromManifest(manifest);
|
|
1081
|
-
|
|
1082
|
-
const receipt = {
|
|
1083
|
-
schema: REFERENCE_RECEIPT_SCHEMA_ID,
|
|
1084
|
-
receiptId:
|
|
1085
|
-
resolved.receiptId
|
|
1086
|
-
|| `${modelId}-${executionGraphHash.slice('sha256:'.length, 'sha256:'.length + 12)}`,
|
|
1087
|
-
modelId,
|
|
1088
|
-
createdAtUtc: resolved.createdAtUtc || new Date().toISOString(),
|
|
1089
|
-
sources: {
|
|
1090
|
-
manifest: manifestArtifact,
|
|
1091
|
-
executionGraph: {
|
|
1092
|
-
schema: manifest.inference?.schema ?? null,
|
|
1093
|
-
hash: executionGraphHash,
|
|
1094
|
-
expandedStepHash,
|
|
1095
|
-
},
|
|
1096
|
-
weightSetHash,
|
|
1097
|
-
referenceTranscript: transcriptSourcePath
|
|
1098
|
-
? { path: transcriptSourcePath }
|
|
1099
|
-
: { path: null },
|
|
1100
|
-
},
|
|
1101
|
-
referenceTranscript: normalizedTranscript,
|
|
1102
|
-
};
|
|
1103
|
-
|
|
1104
|
-
return receipt;
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
export async function writeReferenceReceipt(options = {}) {
|
|
1108
|
-
const outputPath = options.outputPath ? path.resolve(options.outputPath) : null;
|
|
1109
|
-
if (!outputPath) {
|
|
1110
|
-
throw new Error('reference receipt: outputPath is required.');
|
|
1111
|
-
}
|
|
1112
|
-
const receipt = await exportReferenceReceipt(options);
|
|
1113
|
-
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
1114
|
-
await fs.writeFile(outputPath, `${JSON.stringify(receipt, null, 2)}\n`, 'utf8');
|
|
1115
|
-
return {
|
|
1116
|
-
outputPath,
|
|
1117
|
-
receipt,
|
|
1118
|
-
};
|
|
1119
|
-
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const REGISTERED_VARIANT_CALIBRATION_PLAN_SCHEMA:
|
|
2
|
+
'doppler.registered-variant-calibration-plan/v1';
|
|
3
|
+
export declare const REGISTERED_VARIANT_CALIBRATION_RECEIPT_SCHEMA:
|
|
4
|
+
'doppler.registered-variant-calibration-receipt/v1';
|
|
5
|
+
|
|
6
|
+
export declare function digestRegisteredVariantDescriptor(
|
|
7
|
+
operation: string,
|
|
8
|
+
variantId: string,
|
|
9
|
+
descriptor: Record<string, unknown>
|
|
10
|
+
): string;
|
|
11
|
+
|
|
12
|
+
export declare function validateRegisteredVariantCalibrationPlan(
|
|
13
|
+
plan: Record<string, unknown>,
|
|
14
|
+
registry: Record<string, unknown>
|
|
15
|
+
): Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
export declare function calibrateRegisteredVariants(
|
|
18
|
+
plan: Record<string, unknown>,
|
|
19
|
+
options: {
|
|
20
|
+
registry: Record<string, unknown>;
|
|
21
|
+
runCorrectness(input: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
22
|
+
evaluatePerformance(input: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
): Promise<Record<string, unknown>>;
|