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.
Files changed (221) hide show
  1. package/README.md +9 -0
  2. package/package.json +25 -2
  3. package/src/cli/doppler-cli.js +253 -94
  4. package/src/cli/runtime-profiles.js +3 -7
  5. package/src/client/doppler-api.d.ts +28 -0
  6. package/src/client/doppler-api.js +2 -0
  7. package/src/client/inspection.d.ts +122 -0
  8. package/src/client/inspection.js +343 -0
  9. package/src/client/runtime/index.d.ts +54 -0
  10. package/src/client/runtime/index.js +190 -18
  11. package/src/client/runtime/model-manager.d.ts +0 -4
  12. package/src/client/runtime/model-manager.js +0 -28
  13. package/src/client/runtime/model-session.d.ts +48 -1
  14. package/src/client/runtime/model-session.js +149 -30
  15. package/src/client/runtime/model-source.d.ts +10 -1
  16. package/src/client/runtime/scoped-session.d.ts +117 -0
  17. package/src/client/runtime/scoped-session.js +257 -0
  18. package/src/client/runtime/types.d.ts +0 -1
  19. package/src/client/runtime/types.js +0 -1
  20. package/src/config/evidence/boundary-evidence-policy.json +54 -0
  21. package/src/config/evidence/source-intake-policy.json +122 -0
  22. package/src/config/inspection/observation-policies.json +80 -0
  23. package/src/config/param-validator.js +21 -36
  24. package/src/config/runtime/compute/f16-activations.json +1 -0
  25. package/src/config/runtime/compute/f16-batched.json +1 -0
  26. package/src/config/runtime/default.json +1 -0
  27. package/src/config/runtime/diagnostics/debug-logits.json +1 -0
  28. package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +1 -0
  29. package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +1 -0
  30. package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +1 -0
  31. package/src/config/runtime/experiments/bench/gemma4-bench-q4k.json +1 -0
  32. package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +1 -0
  33. package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +1 -0
  34. package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +1 -1
  35. package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +1 -3
  36. package/src/config/runtime/experiments/debug/gemma4-e2b-browser-diagnose-q4k.json +1 -1
  37. package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +1 -1
  38. package/src/config/runtime/experiments/verify/gemma3-verify.json +1 -3
  39. package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +1 -3
  40. package/src/config/runtime/experiments/verify/lfm2-verify.json +1 -3
  41. package/src/config/runtime/experiments/verify/translategemma-verify.json +1 -3
  42. package/src/config/runtime/model/gemma2-debug.json +1 -0
  43. package/src/config/runtime/model/gemma2-pipeline-debug.json +1 -0
  44. package/src/config/runtime/model/gemma2-pipeline.json +1 -0
  45. package/src/config/runtime/model/gemma3-layer-probe.json +1 -0
  46. package/src/config/runtime/model/qwen3-5-layer-probe.json +1 -0
  47. package/src/config/runtime/model/qwen3-5-layer3-boundary-probe.json +1 -0
  48. package/src/config/runtime/model/qwen3-5-linear-attn-debug.json +1 -0
  49. package/src/config/runtime/optimization-candidates/registry.json +5 -0
  50. package/src/config/runtime/platform/metal-apple-q4k.json +1 -0
  51. package/src/config/runtime/profiles/default.json +1 -0
  52. package/src/config/runtime/profiles/diffusiongemma-26b-a4b-throughput.json +1 -0
  53. package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-overlapped-probe.json +1 -0
  54. package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-probe.json +1 -0
  55. package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-b4.json +1 -3
  56. package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-single.json +1 -3
  57. package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +1 -5
  58. package/src/config/runtime/profiles/gemma4-e2b-baseline-probe.json +1 -3
  59. package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-probe.json +1 -3
  60. package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-test.json +1 -0
  61. package/src/config/runtime/profiles/gemma4-e2b-int4ple-baseline-probe.json +1 -5
  62. package/src/config/runtime/profiles/gemma4-e2b-int4ple-f16a-probe.json +1 -5
  63. package/src/config/runtime/profiles/gemma4-e2b-int4ple-reference-export.json +1 -3
  64. package/src/config/runtime/profiles/gemma4-e2b-int4ple-retain-q4k-probe.json +1 -5
  65. package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +1 -0
  66. package/src/config/runtime/profiles/gemma4-e2b-prefill-profile.json +1 -3
  67. package/src/config/runtime/profiles/gemma4-e2b-throughput-probe.json +1 -0
  68. package/src/config/runtime/profiles/low-memory.json +1 -0
  69. package/src/config/runtime/profiles/production.json +1 -3
  70. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-attn128-candidate.json +1 -0
  71. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-maxbatch64-candidate.json +1 -0
  72. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-normed-ffn-candidate.json +1 -0
  73. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-overlap-ringtokens1-candidate.json +1 -0
  74. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-parity.json +1 -0
  75. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-sequential-candidate.json +1 -0
  76. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-throughput.json +1 -0
  77. package/src/config/runtime/profiles/qwen-3-5-0-8b-prefill-profile.json +1 -3
  78. package/src/config/runtime/profiles/qwen-3-5-0-8b-throughput-probe.json +1 -0
  79. package/src/config/runtime/profiles/qwen-3-5-2b-f16-primary-throughput.json +1 -5
  80. package/src/config/runtime/profiles/qwen-3-5-2b-metal-parity.json +1 -0
  81. package/src/config/runtime/profiles/qwen-3-5-2b-metal-throughput.json +1 -0
  82. package/src/config/runtime/profiles/qwen-3-5-9b-metal-correctness.json +1 -0
  83. package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-stability.json +1 -3
  84. package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-throughput.json +1 -0
  85. package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-stability.json +1 -0
  86. package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-throughput.json +1 -0
  87. package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +1 -5
  88. package/src/config/runtime/profiles/rerank-stability.json +1 -3
  89. package/src/config/runtime/profiles/rerank-throughput.json +1 -3
  90. package/src/config/runtime/profiles/simulation.json +1 -3
  91. package/src/config/runtime/profiles/throughput.json +1 -3
  92. package/src/config/runtime/profiles/trace-layers.json +1 -3
  93. package/src/config/runtime/profiles/translategemma-1b-nativekd2-q4k-rdna3-throughput-probe.json +1 -0
  94. package/src/config/runtime/profiles/turboquant-contiguous-prod.json +1 -0
  95. package/src/config/runtime/profiles/turboquant-contiguous.json +1 -0
  96. package/src/config/runtime/profiles/turboquant.json +1 -0
  97. package/src/config/runtime/profiles/vector-stability.json +1 -3
  98. package/src/config/runtime/profiles/vector-throughput.json +1 -0
  99. package/src/config/runtime/profiles/verbose-trace.json +1 -3
  100. package/src/config/runtime/tiers/gemma4-128gb.json +1 -0
  101. package/src/config/runtime/tiers/gemma4-16gb.json +1 -0
  102. package/src/config/runtime/tiers/gemma4-24gb.json +1 -0
  103. package/src/config/runtime/tiers/gemma4-32gb.json +1 -0
  104. package/src/config/schema/benchmark.schema.d.ts +7 -0
  105. package/src/config/schema/benchmark.schema.js +5 -0
  106. package/src/config/schema/index.d.ts +8 -16
  107. package/src/config/schema/index.js +5 -8
  108. package/src/config/schema/kernel-thresholds.schema.d.ts +0 -12
  109. package/src/config/schema/kernel-thresholds.schema.js +0 -12
  110. package/src/config/schema/kernel-warmup.schema.d.ts +1 -3
  111. package/src/config/schema/kernel-warmup.schema.js +0 -1
  112. package/src/config/schema/runtime-profile.schema.d.ts +24 -0
  113. package/src/config/schema/runtime-profile.schema.js +92 -0
  114. package/src/config/schema/shared-runtime.schema.d.ts +1 -4
  115. package/src/config/schema/shared-runtime.schema.js +0 -2
  116. package/src/config/schema/tooling.schema.d.ts +8 -5
  117. package/src/config/schema/tooling.schema.js +3 -2
  118. package/src/debug/tensor.d.ts +2 -0
  119. package/src/debug/tensor.js +21 -2
  120. package/src/gpu/command-recorder.d.ts +5 -0
  121. package/src/gpu/command-recorder.js +17 -0
  122. package/src/gpu/kernel-runtime.js +2 -10
  123. package/src/gpu/kernels/index.d.ts +0 -2
  124. package/src/gpu/kernels/index.js +0 -2
  125. package/src/gpu/kernels/kernel-prewarm.d.ts +3 -0
  126. package/src/gpu/kernels/kernel-prewarm.js +60 -0
  127. package/src/gpu/kernels/utils.d.ts +2 -4
  128. package/src/gpu/kernels/utils.js +2 -4
  129. package/src/index.d.ts +13 -1
  130. package/src/index.js +7 -1
  131. package/src/inference/browser-harness-model-helpers.js +4 -0
  132. package/src/inference/browser-harness-runtime-helpers.js +25 -10
  133. package/src/inference/browser-harness-text-helpers.js +4 -1
  134. package/src/inference/browser-harness.d.ts +4 -0
  135. package/src/inference/browser-harness.js +91 -4
  136. package/src/inference/observation-context.d.ts +22 -0
  137. package/src/inference/observation-context.js +41 -0
  138. package/src/inference/pipelines/text/attention/attn-config.js +1 -1
  139. package/src/inference/pipelines/text/attention/executor-immediate.js +42 -0
  140. package/src/inference/pipelines/text/attention/executor-recorded.js +29 -0
  141. package/src/inference/pipelines/text/attention/index.js +7 -0
  142. package/src/inference/pipelines/text/attention/interpreter.js +1334 -0
  143. package/src/inference/pipelines/text/attention/plan.d.ts +36 -0
  144. package/src/inference/pipelines/text/attention/plan.js +328 -0
  145. package/src/inference/pipelines/text/attention/receipt.js +60 -0
  146. package/src/inference/pipelines/text/attention/record.js +8 -1278
  147. package/src/inference/pipelines/text/attention/run.js +8 -1386
  148. package/src/inference/pipelines/text/generator-decode-policy.js +4 -1
  149. package/src/inference/pipelines/text/generator-helpers.js +2 -0
  150. package/src/inference/pipelines/text/generator-steps.js +32 -15
  151. package/src/inference/pipelines/text/generator.js +10 -5
  152. package/src/inference/pipelines/text/init.d.ts +3 -0
  153. package/src/inference/pipelines/text/layer-plan-gpu.js +2 -0
  154. package/src/inference/pipelines/text/layer.js +2 -0
  155. package/src/inference/pipelines/text/model-load.d.ts +0 -1
  156. package/src/inference/pipelines/text/model-load.js +2 -11
  157. package/src/inference/pipelines/text/probes.js +10 -0
  158. package/src/inference/pipelines/text/resolved-runtime-session.d.ts +56 -0
  159. package/src/inference/pipelines/text/resolved-runtime-session.js +175 -0
  160. package/src/inference/pipelines/text/state.d.ts +6 -0
  161. package/src/inference/pipelines/text/state.js +3 -0
  162. package/src/inference/pipelines/text/types.d.ts +6 -0
  163. package/src/inference/pipelines/text.js +16 -1
  164. package/src/inference/refactor-receipt.d.ts +49 -0
  165. package/src/inference/refactor-receipt.js +188 -0
  166. package/src/inference/resource-scope.d.ts +33 -0
  167. package/src/inference/resource-scope.js +168 -0
  168. package/src/inference/test-harness.d.ts +3 -0
  169. package/src/inference/test-harness.js +1 -0
  170. package/src/storage/model-cache.d.ts +53 -0
  171. package/src/storage/model-cache.js +550 -0
  172. package/src/tooling/boundary-evidence.d.ts +51 -0
  173. package/src/tooling/boundary-evidence.js +408 -0
  174. package/src/tooling/browser-command-runner.js +4 -4
  175. package/src/tooling/command-context.d.ts +25 -0
  176. package/src/tooling/command-context.js +53 -0
  177. package/src/tooling/command-runner-shared.js +22 -5
  178. package/src/tooling/demo-receipts.d.ts +56 -0
  179. package/src/tooling/demo-receipts.js +113 -0
  180. package/src/tooling/diagnose-runner.js +2 -2
  181. package/src/tooling/execution-cost-ledger.d.ts +21 -0
  182. package/src/tooling/execution-cost-ledger.js +199 -0
  183. package/src/tooling/node-command-runner.js +2 -2
  184. package/src/tooling/opfs-cache.d.ts +11 -49
  185. package/src/tooling/opfs-cache.js +4 -510
  186. package/src/tooling/precision-replay-math.d.ts +42 -0
  187. package/src/tooling/precision-replay-math.js +174 -0
  188. package/src/tooling/program-bundle-parity.d.ts +3 -0
  189. package/src/tooling/program-bundle-parity.js +8 -0
  190. package/src/tooling/program-bundle.d.ts +1 -52
  191. package/src/tooling/program-bundle.js +0 -139
  192. package/src/tooling/registered-variant-calibration.d.ts +24 -0
  193. package/src/tooling/registered-variant-calibration.js +286 -0
  194. package/src/tooling/runtime-input-composition.js +105 -53
  195. package/src/tooling/runtime-intent.js +41 -0
  196. package/src/tooling/runtime-optimization-index.d.ts +6 -0
  197. package/src/tooling/runtime-optimization-index.js +72 -0
  198. package/src/tooling/runtime-optimization.d.ts +47 -6
  199. package/src/tooling/runtime-optimization.js +559 -40
  200. package/src/tooling/source-intake.d.ts +49 -0
  201. package/src/tooling/source-intake.js +414 -0
  202. package/src/tooling-exports/evidence.d.ts +34 -0
  203. package/src/tooling-exports/evidence.js +34 -0
  204. package/src/tooling-exports/runtime.d.ts +7 -0
  205. package/src/tooling-exports/runtime.js +7 -0
  206. package/src/tooling-exports.d.ts +11 -0
  207. package/src/tooling-exports.js +6 -3
  208. package/src/tooling-exports.shared.d.ts +32 -0
  209. package/src/tooling-exports.shared.js +31 -0
  210. package/src/version.js +1 -1
  211. package/src/config/schema/tuner.schema.d.ts +0 -39
  212. package/src/config/schema/tuner.schema.js +0 -13
  213. package/src/gpu/kernel-tuner/benchmarks.js +0 -902
  214. package/src/gpu/kernel-tuner/cache.js +0 -145
  215. package/src/gpu/kernel-tuner/index.js +0 -38
  216. package/src/gpu/kernel-tuner/tuner.js +0 -247
  217. package/src/gpu/kernel-tuner.js +0 -12
  218. package/src/gpu/kernels/kernel-tuning.d.ts +0 -42
  219. package/src/gpu/kernels/kernel-tuning.js +0 -158
  220. package/src/gpu/profiler.js +0 -382
  221. 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>>;