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,49 @@
1
+ export declare const SOURCE_INTAKE_SCHEMA: 'doppler.source-intake/v1';
2
+ export declare const SOURCE_INTAKE_CONVERSION_SKELETON_SCHEMA:
3
+ 'doppler.source-intake-conversion-skeleton/v1';
4
+ export declare const SOURCE_INTAKE_CONTRACT_TEST_SCHEMA:
5
+ 'doppler.source-intake-contract-test/v1';
6
+
7
+ export interface SourceIntakePolicy {
8
+ schema: 'doppler.source-intake-policy/v1';
9
+ facts: Array<{
10
+ factId: string;
11
+ sourcePointers: string[];
12
+ owner: string;
13
+ verificationBoundary?: string;
14
+ }>;
15
+ requiredFacts: string[];
16
+ architectureKeyPattern: string;
17
+ }
18
+
19
+ export interface SourceIntakeFact {
20
+ factId: string;
21
+ source: { file: string | null; jsonPointer: string | null; value: unknown };
22
+ owner: string;
23
+ proposal: unknown;
24
+ confidence: 'direct' | 'derived' | 'family-inferred' | 'ambiguous' | 'unsupported';
25
+ status: 'accepted' | 'unresolved';
26
+ verification: { kind: 'boundary-pack' | 'contract-test'; boundary: string | null };
27
+ note?: string;
28
+ }
29
+
30
+ export interface SourceIntakeReport {
31
+ schema: 'doppler.source-intake/v1';
32
+ ok: boolean;
33
+ source: Record<string, unknown>;
34
+ facts: SourceIntakeFact[];
35
+ summary: Record<string, unknown>;
36
+ digest: string;
37
+ }
38
+
39
+ export declare function inspectSourceModel(options: {
40
+ sourceDir: string;
41
+ policy: SourceIntakePolicy;
42
+ familyIntake?: SourceIntakeReport | null;
43
+ }): Promise<{
44
+ report: SourceIntakeReport;
45
+ artifacts: {
46
+ conversion: Record<string, unknown>;
47
+ contractTests: Record<string, unknown>;
48
+ };
49
+ }>;
@@ -0,0 +1,414 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { parseSafetensorsHeader } from '../formats/safetensors/types.js';
4
+ import { computeCanonicalSha256 } from '../utils/canonical-hash.js';
5
+ import { sha256Hex } from '../utils/sha256.js';
6
+
7
+ export const SOURCE_INTAKE_SCHEMA = 'doppler.source-intake/v1';
8
+ export const SOURCE_INTAKE_CONVERSION_SKELETON_SCHEMA =
9
+ 'doppler.source-intake-conversion-skeleton/v1';
10
+ export const SOURCE_INTAKE_CONTRACT_TEST_SCHEMA =
11
+ 'doppler.source-intake-contract-test/v1';
12
+
13
+ const CONFIDENCE = new Set([
14
+ 'direct',
15
+ 'derived',
16
+ 'family-inferred',
17
+ 'ambiguous',
18
+ 'unsupported',
19
+ ]);
20
+
21
+ function isObject(value) {
22
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
23
+ }
24
+
25
+ function pointerValue(value, pointer) {
26
+ const parts = pointer.split('/').slice(1).map((part) => (
27
+ part.replaceAll('~1', '/').replaceAll('~0', '~')
28
+ ));
29
+ let current = value;
30
+ for (const part of parts) {
31
+ if (!isObject(current) && !Array.isArray(current)) return undefined;
32
+ if (!Object.hasOwn(current, part)) return undefined;
33
+ current = current[part];
34
+ }
35
+ return current;
36
+ }
37
+
38
+ function setOwnedValue(target, owner, value) {
39
+ const parts = owner.split('.');
40
+ let current = target;
41
+ for (let index = 0; index < parts.length - 1; index += 1) {
42
+ current[parts[index]] ??= {};
43
+ current = current[parts[index]];
44
+ }
45
+ current[parts.at(-1)] = value;
46
+ }
47
+
48
+ function createFact({
49
+ factId,
50
+ file = null,
51
+ jsonPointer = null,
52
+ value = null,
53
+ owner,
54
+ proposal = value,
55
+ confidence,
56
+ status = confidence === 'direct' || confidence === 'derived' ? 'accepted' : 'unresolved',
57
+ verificationBoundary = null,
58
+ note = null,
59
+ }) {
60
+ if (!CONFIDENCE.has(confidence)) {
61
+ throw new Error(`source intake: invalid confidence "${confidence}" for ${factId}`);
62
+ }
63
+ return {
64
+ factId,
65
+ source: { file, jsonPointer, value },
66
+ owner,
67
+ proposal,
68
+ confidence,
69
+ status,
70
+ verification: verificationBoundary
71
+ ? { kind: 'boundary-pack', boundary: verificationBoundary }
72
+ : { kind: 'contract-test', boundary: null },
73
+ ...(note ? { note } : {}),
74
+ };
75
+ }
76
+
77
+ async function readOptionalJson(sourceDir, filename) {
78
+ const filePath = path.join(sourceDir, filename);
79
+ try {
80
+ const raw = await fs.readFile(filePath, 'utf8');
81
+ return {
82
+ filename,
83
+ raw,
84
+ value: JSON.parse(raw),
85
+ digest: `sha256:${sha256Hex(raw)}`,
86
+ };
87
+ } catch (error) {
88
+ if (error?.code === 'ENOENT') return null;
89
+ throw new Error(`source intake: unable to read ${filename}: ${error.message}`);
90
+ }
91
+ }
92
+
93
+ async function readSafetensorsHeader(filePath) {
94
+ const handle = await fs.open(filePath, 'r');
95
+ try {
96
+ const prefix = new Uint8Array(8);
97
+ const prefixRead = await handle.read(prefix, 0, 8, 0);
98
+ if (prefixRead.bytesRead !== 8) {
99
+ throw new Error('header prefix is shorter than 8 bytes');
100
+ }
101
+ const headerSize = Number(new DataView(prefix.buffer).getBigUint64(0, true));
102
+ const bytes = new Uint8Array(8 + headerSize);
103
+ bytes.set(prefix);
104
+ const headerRead = await handle.read(bytes, 8, headerSize, 8);
105
+ if (headerRead.bytesRead !== headerSize) {
106
+ throw new Error(`header is truncated (${headerRead.bytesRead}/${headerSize} bytes)`);
107
+ }
108
+ return parseSafetensorsHeader(bytes.buffer);
109
+ } finally {
110
+ await handle.close();
111
+ }
112
+ }
113
+
114
+ function classifyTensor(name) {
115
+ const rules = [
116
+ ['token_embedding', /(embed_tokens|tok_embeddings|word_embeddings)\.weight$/],
117
+ ['output_head', /(^|\.)(lm_head|output)\.weight$/],
118
+ ['attention_q', /\.(q_proj|wq)\.weight$/],
119
+ ['attention_k', /\.(k_proj|wk)\.weight$/],
120
+ ['attention_v', /\.(v_proj|wv)\.weight$/],
121
+ ['attention_output', /\.(o_proj|wo)\.weight$/],
122
+ ['ffn_gate', /\.(gate_proj|w1)\.weight$/],
123
+ ['ffn_up', /\.(up_proj|w3)\.weight$/],
124
+ ['ffn_down', /\.(down_proj|w2)\.weight$/],
125
+ ['normalization', /(norm|layernorm)\.weight$/],
126
+ ];
127
+ return rules.find(([, pattern]) => pattern.test(name))?.[0] ?? 'unknown';
128
+ }
129
+
130
+ function tensorLayerIndex(name) {
131
+ const match = name.match(/(?:layers?|blocks?|h)\.(\d+)\./);
132
+ return match ? Number(match[1]) : null;
133
+ }
134
+
135
+ async function collectTensorInventory(sourceDir) {
136
+ const entries = await fs.readdir(sourceDir, { withFileTypes: true });
137
+ const filenames = entries
138
+ .filter((entry) => entry.isFile() && entry.name.endsWith('.safetensors'))
139
+ .map((entry) => entry.name)
140
+ .sort();
141
+ const tensors = [];
142
+ const shards = [];
143
+ for (const filename of filenames) {
144
+ const parsed = await readSafetensorsHeader(path.join(sourceDir, filename));
145
+ shards.push({
146
+ file: filename,
147
+ headerDigest: computeCanonicalSha256({
148
+ metadata: parsed.metadata,
149
+ tensors: parsed.tensors.map(({ name, dtype, shape, size }) => ({ name, dtype, shape, size })),
150
+ }),
151
+ tensorCount: parsed.tensors.length,
152
+ });
153
+ for (const tensor of parsed.tensors) {
154
+ tensors.push({
155
+ file: filename,
156
+ name: tensor.name,
157
+ dtype: tensor.dtype,
158
+ shape: tensor.shape,
159
+ byteLength: tensor.size,
160
+ role: classifyTensor(tensor.name),
161
+ layerIndex: tensorLayerIndex(tensor.name),
162
+ });
163
+ }
164
+ }
165
+ return { shards, tensors };
166
+ }
167
+
168
+ function collectDirectFacts(policy, sources) {
169
+ const facts = [];
170
+ for (const entry of policy.facts) {
171
+ let match = null;
172
+ for (const source of sources) {
173
+ for (const jsonPointer of entry.sourcePointers) {
174
+ const value = pointerValue(source.value, jsonPointer);
175
+ if (value !== undefined) {
176
+ match = { source, jsonPointer, value };
177
+ break;
178
+ }
179
+ }
180
+ if (match) break;
181
+ }
182
+ if (!match) continue;
183
+ facts.push(createFact({
184
+ factId: entry.factId,
185
+ file: match.source.filename,
186
+ jsonPointer: match.jsonPointer,
187
+ value: match.value,
188
+ owner: entry.owner,
189
+ confidence: 'direct',
190
+ verificationBoundary: entry.verificationBoundary,
191
+ }));
192
+ }
193
+ return facts;
194
+ }
195
+
196
+ function addDerivedFacts(facts) {
197
+ const byId = new Map(facts.map((fact) => [fact.factId, fact]));
198
+ if (!byId.has('architecture.attention.head_dim')) {
199
+ const hiddenSize = byId.get('architecture.hidden_size')?.proposal;
200
+ const queryHeads = byId.get('architecture.attention.query_heads')?.proposal;
201
+ if (Number.isInteger(hiddenSize) && Number.isInteger(queryHeads) && hiddenSize % queryHeads === 0) {
202
+ facts.push(createFact({
203
+ factId: 'architecture.attention.head_dim',
204
+ owner: 'manifest.architecture.headDim',
205
+ proposal: hiddenSize / queryHeads,
206
+ confidence: 'derived',
207
+ note: 'Derived as hidden_size / num_attention_heads.',
208
+ }));
209
+ }
210
+ }
211
+ }
212
+
213
+ function addRequiredFacts(policy, facts) {
214
+ const existing = new Set(facts.map((fact) => fact.factId));
215
+ for (const factId of policy.requiredFacts) {
216
+ if (existing.has(factId)) continue;
217
+ const entry = policy.facts.find((candidate) => candidate.factId === factId);
218
+ facts.push(createFact({
219
+ factId,
220
+ owner: entry?.owner ?? 'unassigned',
221
+ confidence: 'unsupported',
222
+ note: 'Required source fact was not found in the inspected source files.',
223
+ }));
224
+ }
225
+ }
226
+
227
+ function addFamilyInferences(facts, familyIntake) {
228
+ if (!familyIntake) return;
229
+ if (familyIntake.schema !== SOURCE_INTAKE_SCHEMA) {
230
+ throw new Error(`source intake: family intake must use ${SOURCE_INTAKE_SCHEMA}`);
231
+ }
232
+ const { digest, ...core } = familyIntake;
233
+ if (computeCanonicalSha256(core) !== digest) {
234
+ throw new Error('source intake: family intake digest does not match its payload');
235
+ }
236
+ const existing = new Set(facts.map((fact) => fact.factId));
237
+ for (const familyFact of familyIntake.facts ?? []) {
238
+ if (existing.has(familyFact.factId) || familyFact.status !== 'accepted') continue;
239
+ facts.push(createFact({
240
+ factId: familyFact.factId,
241
+ file: familyFact.source?.file ?? null,
242
+ jsonPointer: familyFact.source?.jsonPointer ?? null,
243
+ value: familyFact.source?.value ?? null,
244
+ owner: familyFact.owner,
245
+ proposal: familyFact.proposal,
246
+ confidence: 'family-inferred',
247
+ verificationBoundary: familyFact.verification?.boundary ?? null,
248
+ note: `Inherited only as a reviewable proposal from ${familyIntake.source?.digest ?? 'family intake'}.`,
249
+ }));
250
+ }
251
+ }
252
+
253
+ function addTensorFacts(facts, inventory) {
254
+ const roles = {};
255
+ for (const tensor of inventory.tensors) {
256
+ roles[tensor.role] ??= [];
257
+ roles[tensor.role].push(tensor);
258
+ }
259
+ const layerIndices = inventory.tensors
260
+ .map((tensor) => tensor.layerIndex)
261
+ .filter((value) => value !== null);
262
+ const observedLayers = new Set(layerIndices).size;
263
+ const configuredLayers = facts.find((fact) => fact.factId === 'architecture.layer_count')?.proposal;
264
+ facts.push(createFact({
265
+ factId: 'checkpoint.tensor_inventory',
266
+ owner: 'converter.tensorMappings',
267
+ proposal: {
268
+ tensorCount: inventory.tensors.length,
269
+ shardCount: inventory.shards.length,
270
+ roles: Object.fromEntries(
271
+ Object.entries(roles).map(([role, tensors]) => [role, tensors.length])
272
+ ),
273
+ observedLayerCount: observedLayers,
274
+ },
275
+ confidence: inventory.tensors.length > 0 ? 'direct' : 'unsupported',
276
+ note: inventory.tensors.length > 0
277
+ ? 'Derived directly from SafeTensors headers without reading tensor payloads.'
278
+ : 'No SafeTensors files were found.',
279
+ }));
280
+ if (Number.isInteger(configuredLayers) && observedLayers > 0 && configuredLayers !== observedLayers) {
281
+ facts.push(createFact({
282
+ factId: 'checkpoint.layer_pattern_mismatch',
283
+ owner: 'converter.tensorMappings',
284
+ proposal: { configuredLayers, observedLayers },
285
+ confidence: 'ambiguous',
286
+ note: 'Configured layer count does not match layer indices in SafeTensors headers.',
287
+ }));
288
+ }
289
+ if (!roles.output_head?.length) {
290
+ const tied = facts.find((fact) => fact.factId === 'architecture.tie_word_embeddings')?.proposal;
291
+ facts.push(createFact({
292
+ factId: 'checkpoint.output_head',
293
+ owner: 'converter.tensorMappings.outputHead',
294
+ proposal: tied === true ? 'tied-token-embedding' : null,
295
+ confidence: tied === true ? 'derived' : 'ambiguous',
296
+ verificationBoundary: 'model.logits',
297
+ note: tied === true
298
+ ? 'No output-head tensor exists; source config explicitly ties word embeddings.'
299
+ : 'No output-head tensor exists and tied embeddings are not explicit.',
300
+ }));
301
+ }
302
+ }
303
+
304
+ function collectUnknownArchitectureFacts(policy, config, facts) {
305
+ const claimedPointers = new Set(
306
+ policy.facts.flatMap((entry) => entry.sourcePointers)
307
+ );
308
+ const architecturePattern = new RegExp(policy.architectureKeyPattern, 'i');
309
+ for (const [key, value] of Object.entries(config.value)) {
310
+ const pointer = `/${key}`;
311
+ if (claimedPointers.has(pointer) || !architecturePattern.test(key)) continue;
312
+ if (key.endsWith('_config') && isObject(value)) continue;
313
+ facts.push(createFact({
314
+ factId: `source.unmapped.${key}`,
315
+ file: config.filename,
316
+ jsonPointer: pointer,
317
+ value,
318
+ owner: 'unassigned',
319
+ confidence: 'ambiguous',
320
+ note: 'Architecture-relevant source field has no Doppler intake owner mapping.',
321
+ }));
322
+ }
323
+ }
324
+
325
+ function buildProposedArtifacts(facts, sourceDigest) {
326
+ const accepted = facts.filter((fact) => fact.status === 'accepted');
327
+ const conversion = {
328
+ schema: SOURCE_INTAKE_CONVERSION_SKELETON_SCHEMA,
329
+ sourceIntakeDigest: sourceDigest,
330
+ completeness: 'skeleton',
331
+ acceptedFactCount: accepted.length,
332
+ unresolvedFactIds: facts
333
+ .filter((fact) => fact.status !== 'accepted')
334
+ .map((fact) => fact.factId),
335
+ proposal: {},
336
+ };
337
+ for (const fact of accepted) {
338
+ if (fact.owner === 'unassigned' || fact.factId === 'checkpoint.tensor_inventory') continue;
339
+ setOwnedValue(conversion.proposal, fact.owner, fact.proposal);
340
+ }
341
+ const contractTests = {
342
+ schema: SOURCE_INTAKE_CONTRACT_TEST_SCHEMA,
343
+ sourceIntakeDigest: sourceDigest,
344
+ assertions: accepted.map((fact) => ({
345
+ factId: fact.factId,
346
+ owner: fact.owner,
347
+ expected: fact.proposal,
348
+ verification: fact.verification,
349
+ })),
350
+ };
351
+ return { conversion, contractTests };
352
+ }
353
+
354
+ export async function inspectSourceModel({
355
+ sourceDir,
356
+ policy,
357
+ familyIntake = null,
358
+ }) {
359
+ if (!sourceDir) throw new Error('source intake: sourceDir is required');
360
+ if (policy?.schema !== 'doppler.source-intake-policy/v1') {
361
+ throw new Error('source intake: a doppler.source-intake-policy/v1 policy is required');
362
+ }
363
+ const resolvedSourceDir = path.resolve(sourceDir);
364
+ const config = await readOptionalJson(resolvedSourceDir, 'config.json');
365
+ if (!config) throw new Error(`source intake: config.json not found in ${resolvedSourceDir}`);
366
+ const optionalSources = await Promise.all([
367
+ readOptionalJson(resolvedSourceDir, 'generation_config.json'),
368
+ readOptionalJson(resolvedSourceDir, 'tokenizer_config.json'),
369
+ ]);
370
+ const sources = [config, ...optionalSources.filter(Boolean)];
371
+ const inventory = await collectTensorInventory(resolvedSourceDir);
372
+ const facts = collectDirectFacts(policy, sources);
373
+ addDerivedFacts(facts);
374
+ addFamilyInferences(facts, familyIntake);
375
+ addRequiredFacts(policy, facts);
376
+ addTensorFacts(facts, inventory);
377
+ collectUnknownArchitectureFacts(policy, config, facts);
378
+ facts.sort((left, right) => left.factId.localeCompare(right.factId));
379
+
380
+ const sourceIdentity = {
381
+ directory: resolvedSourceDir,
382
+ files: sources.map(({ filename, digest }) => ({ file: filename, digest })),
383
+ safetensors: inventory.shards,
384
+ };
385
+ sourceIdentity.digest = computeCanonicalSha256(sourceIdentity);
386
+ const unresolved = facts.filter((fact) => fact.status !== 'accepted');
387
+ const reportCore = {
388
+ schema: SOURCE_INTAKE_SCHEMA,
389
+ ok: unresolved.every((fact) => (
390
+ fact.confidence !== 'ambiguous' && fact.confidence !== 'unsupported'
391
+ )),
392
+ source: sourceIdentity,
393
+ facts,
394
+ summary: {
395
+ accepted: facts.length - unresolved.length,
396
+ unresolved: unresolved.length,
397
+ blockers: unresolved.filter((fact) => (
398
+ fact.confidence === 'ambiguous' || fact.confidence === 'unsupported'
399
+ )).length,
400
+ familyInferences: unresolved.filter((fact) => fact.confidence === 'family-inferred').length,
401
+ unknownTensorNames: inventory.tensors
402
+ .filter((tensor) => tensor.role === 'unknown')
403
+ .map((tensor) => tensor.name),
404
+ },
405
+ };
406
+ const report = {
407
+ ...reportCore,
408
+ digest: computeCanonicalSha256(reportCore),
409
+ };
410
+ return {
411
+ report,
412
+ artifacts: buildProposedArtifacts(facts, report.digest),
413
+ };
414
+ }
@@ -0,0 +1,34 @@
1
+ export {
2
+ assertComparableFingerprints,
3
+ buildComparisonFingerprint,
4
+ listObservationPolicies,
5
+ resolveObservationPolicy,
6
+ } from '../client/inspection.js';
7
+ export {
8
+ DEMO_CONTRACT_RECEIPT_SCHEMA,
9
+ DEMO_HARDWARE_RECEIPT_SCHEMA,
10
+ validateDemoContractReceipt,
11
+ validateDemoHardwareReceipt,
12
+ } from '../tooling/demo-receipts.js';
13
+ export {
14
+ SOURCE_BOUNDARY_PACK_SCHEMA,
15
+ RUNTIME_BOUNDARY_CAPTURE_SCHEMA,
16
+ BOUNDARY_COMPARISON_RECEIPT_SCHEMA,
17
+ DETERMINISTIC_TOKEN_EVIDENCE_SCHEMA,
18
+ BOUNDARY_PROVIDER_CAPTURE_SCHEMA,
19
+ buildRuntimeBoundaryCapture,
20
+ buildSourceBoundaryPack,
21
+ buildSourceBoundaryPackFromProviderCapture,
22
+ buildDeterministicTokenEvidenceFromReferenceTranscript,
23
+ compareBoundaryEvidence,
24
+ } from '../tooling/boundary-evidence.js';
25
+ export {
26
+ TOKEN_COST_LEDGER_SCHEMA,
27
+ isExecutionObservationRequested,
28
+ buildTokenCostLedger,
29
+ classifyTokenCostLedger,
30
+ } from '../tooling/execution-cost-ledger.js';
31
+ export {
32
+ buildModeScoreMaps,
33
+ sortTokenIdsByScore,
34
+ } from '../tooling/precision-replay-math.js';
@@ -0,0 +1,34 @@
1
+ export {
2
+ assertComparableFingerprints,
3
+ buildComparisonFingerprint,
4
+ listObservationPolicies,
5
+ resolveObservationPolicy,
6
+ } from '../client/inspection.js';
7
+ export {
8
+ DEMO_CONTRACT_RECEIPT_SCHEMA,
9
+ DEMO_HARDWARE_RECEIPT_SCHEMA,
10
+ validateDemoContractReceipt,
11
+ validateDemoHardwareReceipt,
12
+ } from '../tooling/demo-receipts.js';
13
+ export {
14
+ SOURCE_BOUNDARY_PACK_SCHEMA,
15
+ RUNTIME_BOUNDARY_CAPTURE_SCHEMA,
16
+ BOUNDARY_COMPARISON_RECEIPT_SCHEMA,
17
+ DETERMINISTIC_TOKEN_EVIDENCE_SCHEMA,
18
+ BOUNDARY_PROVIDER_CAPTURE_SCHEMA,
19
+ buildRuntimeBoundaryCapture,
20
+ buildSourceBoundaryPack,
21
+ buildSourceBoundaryPackFromProviderCapture,
22
+ buildDeterministicTokenEvidenceFromReferenceTranscript,
23
+ compareBoundaryEvidence,
24
+ } from '../tooling/boundary-evidence.js';
25
+ export {
26
+ TOKEN_COST_LEDGER_SCHEMA,
27
+ isExecutionObservationRequested,
28
+ buildTokenCostLedger,
29
+ classifyTokenCostLedger,
30
+ } from '../tooling/execution-cost-ledger.js';
31
+ export {
32
+ buildModeScoreMaps,
33
+ sortTokenIdsByScore,
34
+ } from '../tooling/precision-replay-math.js';
@@ -0,0 +1,7 @@
1
+ export { getRuntimeConfig, setRuntimeConfig } from '../config/runtime.js';
2
+ export {
3
+ loadRuntimeConfigFromUrl,
4
+ applyRuntimeConfigFromUrl,
5
+ loadRuntimeProfile,
6
+ applyRuntimeProfile,
7
+ } from '../inference/browser-harness-runtime-helpers.js';
@@ -0,0 +1,7 @@
1
+ export { getRuntimeConfig, setRuntimeConfig } from '../config/runtime.js';
2
+ export {
3
+ loadRuntimeConfigFromUrl,
4
+ applyRuntimeConfigFromUrl,
5
+ loadRuntimeProfile,
6
+ applyRuntimeProfile,
7
+ } from '../inference/browser-harness-runtime-helpers.js';
@@ -9,6 +9,17 @@
9
9
 
10
10
  // Shared browser-safe tooling exports.
11
11
  export * from './tooling-exports.shared.js';
12
+ export {
13
+ SOURCE_INTAKE_SCHEMA,
14
+ SOURCE_INTAKE_CONVERSION_SKELETON_SCHEMA,
15
+ SOURCE_INTAKE_CONTRACT_TEST_SCHEMA,
16
+ inspectSourceModel,
17
+ } from './tooling/source-intake.js';
18
+ export type {
19
+ SourceIntakePolicy,
20
+ SourceIntakeFact,
21
+ SourceIntakeReport,
22
+ } from './tooling/source-intake.js';
12
23
 
13
24
  // Node-only tooling exports.
14
25
  export { runNodeCommand, normalizeNodeCommand, hasNodeWebGPUSupport } from './tooling/node-command-runner.js';
@@ -1,6 +1,12 @@
1
1
 
2
2
  // Shared browser-safe tooling exports.
3
3
  export * from './tooling-exports.shared.js';
4
+ export {
5
+ SOURCE_INTAKE_SCHEMA,
6
+ SOURCE_INTAKE_CONVERSION_SKELETON_SCHEMA,
7
+ SOURCE_INTAKE_CONTRACT_TEST_SCHEMA,
8
+ inspectSourceModel,
9
+ } from './tooling/source-intake.js';
4
10
 
5
11
  // Node-only tooling exports.
6
12
  export { runNodeCommand, normalizeNodeCommand, hasNodeWebGPUSupport } from './tooling/node-command-runner.js';
@@ -10,9 +16,6 @@ export {
10
16
  writeProgramBundle,
11
17
  loadProgramBundle,
12
18
  checkProgramBundleFile,
13
- exportReferenceReceipt,
14
- writeReferenceReceipt,
15
- REFERENCE_RECEIPT_SCHEMA_ID,
16
19
  } from './tooling/program-bundle.js';
17
20
  export {
18
21
  PROGRAM_BUNDLE_PARITY_SCHEMA_ID,
@@ -69,13 +69,45 @@ export {
69
69
  RUNTIME_OPTIMIZATION_CONTRACT_SCHEMA,
70
70
  RUNTIME_OPTIMIZATION_CANDIDATE_SCHEMA,
71
71
  RUNTIME_OPTIMIZATION_RECEIPT_SCHEMA,
72
+ RUNTIME_OPTIMIZATION_CANDIDATE_REGISTRY_SCHEMA,
72
73
  validateRuntimeOptimizationContract,
73
74
  hashRuntimeOptimizationContract,
74
75
  enumerateRuntimeOptimizationCandidates,
75
76
  validateRuntimeOptimizationCandidate,
76
77
  materializeRuntimeOptimizationCandidate,
78
+ validateRuntimeOptimizationCandidateRegistry,
77
79
  evaluateBrowserRuntimeOptimizationCandidate,
78
80
  } from './tooling/runtime-optimization.js';
81
+ export {
82
+ RUNTIME_OPTIMIZATION_RESULTS_INDEX_SCHEMA,
83
+ buildRuntimeOptimizationResultsIndex,
84
+ } from './tooling/runtime-optimization-index.js';
85
+ export {
86
+ SOURCE_BOUNDARY_PACK_SCHEMA,
87
+ RUNTIME_BOUNDARY_CAPTURE_SCHEMA,
88
+ BOUNDARY_COMPARISON_RECEIPT_SCHEMA,
89
+ DETERMINISTIC_TOKEN_EVIDENCE_SCHEMA,
90
+ BOUNDARY_PROVIDER_CAPTURE_SCHEMA,
91
+ buildRuntimeBoundaryCapture,
92
+ buildSourceBoundaryPack,
93
+ buildSourceBoundaryPackFromProviderCapture,
94
+ buildDeterministicTokenEvidenceFromReferenceTranscript,
95
+ compareBoundaryEvidence,
96
+ } from './tooling/boundary-evidence.js';
97
+ export type { BoundaryEvidence } from './tooling/boundary-evidence.js';
98
+ export {
99
+ TOKEN_COST_LEDGER_SCHEMA,
100
+ isExecutionObservationRequested,
101
+ buildTokenCostLedger,
102
+ classifyTokenCostLedger,
103
+ } from './tooling/execution-cost-ledger.js';
104
+ export {
105
+ REGISTERED_VARIANT_CALIBRATION_PLAN_SCHEMA,
106
+ REGISTERED_VARIANT_CALIBRATION_RECEIPT_SCHEMA,
107
+ digestRegisteredVariantDescriptor,
108
+ validateRegisteredVariantCalibrationPlan,
109
+ calibrateRegisteredVariants,
110
+ } from './tooling/registered-variant-calibration.js';
79
111
  export type {
80
112
  RuntimeOptimizationWorkload,
81
113
  RuntimeOptimizationDirection,
@@ -72,10 +72,41 @@ export {
72
72
  RUNTIME_OPTIMIZATION_CONTRACT_SCHEMA,
73
73
  RUNTIME_OPTIMIZATION_CANDIDATE_SCHEMA,
74
74
  RUNTIME_OPTIMIZATION_RECEIPT_SCHEMA,
75
+ RUNTIME_OPTIMIZATION_CANDIDATE_REGISTRY_SCHEMA,
75
76
  validateRuntimeOptimizationContract,
76
77
  hashRuntimeOptimizationContract,
77
78
  enumerateRuntimeOptimizationCandidates,
78
79
  validateRuntimeOptimizationCandidate,
79
80
  materializeRuntimeOptimizationCandidate,
81
+ validateRuntimeOptimizationCandidateRegistry,
80
82
  evaluateBrowserRuntimeOptimizationCandidate,
81
83
  } from './tooling/runtime-optimization.js';
84
+ export {
85
+ RUNTIME_OPTIMIZATION_RESULTS_INDEX_SCHEMA,
86
+ buildRuntimeOptimizationResultsIndex,
87
+ } from './tooling/runtime-optimization-index.js';
88
+ export {
89
+ SOURCE_BOUNDARY_PACK_SCHEMA,
90
+ RUNTIME_BOUNDARY_CAPTURE_SCHEMA,
91
+ BOUNDARY_COMPARISON_RECEIPT_SCHEMA,
92
+ DETERMINISTIC_TOKEN_EVIDENCE_SCHEMA,
93
+ BOUNDARY_PROVIDER_CAPTURE_SCHEMA,
94
+ buildRuntimeBoundaryCapture,
95
+ buildSourceBoundaryPack,
96
+ buildSourceBoundaryPackFromProviderCapture,
97
+ buildDeterministicTokenEvidenceFromReferenceTranscript,
98
+ compareBoundaryEvidence,
99
+ } from './tooling/boundary-evidence.js';
100
+ export {
101
+ TOKEN_COST_LEDGER_SCHEMA,
102
+ isExecutionObservationRequested,
103
+ buildTokenCostLedger,
104
+ classifyTokenCostLedger,
105
+ } from './tooling/execution-cost-ledger.js';
106
+ export {
107
+ REGISTERED_VARIANT_CALIBRATION_PLAN_SCHEMA,
108
+ REGISTERED_VARIANT_CALIBRATION_RECEIPT_SCHEMA,
109
+ digestRegisteredVariantDescriptor,
110
+ validateRegisteredVariantCalibrationPlan,
111
+ calibrateRegisteredVariants,
112
+ } from './tooling/registered-variant-calibration.js';
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const DOPPLER_VERSION = '0.4.15';
1
+ export const DOPPLER_VERSION = '0.5.1';
2
2
  export const DOPPLER_PROVIDER_VERSION = DOPPLER_VERSION;