doppler-gpu 0.4.14 → 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 (222) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +83 -52
  3. package/package.json +25 -2
  4. package/src/cli/doppler-cli.js +253 -94
  5. package/src/cli/runtime-profiles.js +3 -7
  6. package/src/client/doppler-api.d.ts +28 -0
  7. package/src/client/doppler-api.js +2 -0
  8. package/src/client/inspection.d.ts +122 -0
  9. package/src/client/inspection.js +343 -0
  10. package/src/client/runtime/index.d.ts +54 -0
  11. package/src/client/runtime/index.js +190 -18
  12. package/src/client/runtime/model-manager.d.ts +0 -4
  13. package/src/client/runtime/model-manager.js +0 -28
  14. package/src/client/runtime/model-session.d.ts +116 -1
  15. package/src/client/runtime/model-session.js +351 -1
  16. package/src/client/runtime/model-source.d.ts +10 -1
  17. package/src/client/runtime/scoped-session.d.ts +117 -0
  18. package/src/client/runtime/scoped-session.js +257 -0
  19. package/src/client/runtime/types.d.ts +0 -1
  20. package/src/client/runtime/types.js +0 -1
  21. package/src/config/evidence/boundary-evidence-policy.json +54 -0
  22. package/src/config/evidence/source-intake-policy.json +122 -0
  23. package/src/config/inspection/observation-policies.json +80 -0
  24. package/src/config/param-validator.js +21 -36
  25. package/src/config/runtime/compute/f16-activations.json +1 -0
  26. package/src/config/runtime/compute/f16-batched.json +1 -0
  27. package/src/config/runtime/default.json +1 -0
  28. package/src/config/runtime/diagnostics/debug-logits.json +1 -0
  29. package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +1 -0
  30. package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +1 -0
  31. package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +1 -0
  32. package/src/config/runtime/experiments/bench/gemma4-bench-q4k.json +1 -0
  33. package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +1 -0
  34. package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +1 -0
  35. package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +1 -1
  36. package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +1 -3
  37. package/src/config/runtime/experiments/debug/gemma4-e2b-browser-diagnose-q4k.json +1 -1
  38. package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +1 -1
  39. package/src/config/runtime/experiments/verify/gemma3-verify.json +1 -3
  40. package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +1 -3
  41. package/src/config/runtime/experiments/verify/lfm2-verify.json +1 -3
  42. package/src/config/runtime/experiments/verify/translategemma-verify.json +1 -3
  43. package/src/config/runtime/model/gemma2-debug.json +1 -0
  44. package/src/config/runtime/model/gemma2-pipeline-debug.json +1 -0
  45. package/src/config/runtime/model/gemma2-pipeline.json +1 -0
  46. package/src/config/runtime/model/gemma3-layer-probe.json +1 -0
  47. package/src/config/runtime/model/qwen3-5-layer-probe.json +1 -0
  48. package/src/config/runtime/model/qwen3-5-layer3-boundary-probe.json +1 -0
  49. package/src/config/runtime/model/qwen3-5-linear-attn-debug.json +1 -0
  50. package/src/config/runtime/optimization-candidates/registry.json +5 -0
  51. package/src/config/runtime/platform/metal-apple-q4k.json +1 -0
  52. package/src/config/runtime/profiles/default.json +1 -0
  53. package/src/config/runtime/profiles/diffusiongemma-26b-a4b-throughput.json +1 -0
  54. package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-overlapped-probe.json +1 -0
  55. package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-probe.json +1 -0
  56. package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-b4.json +1 -3
  57. package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-single.json +1 -3
  58. package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +1 -5
  59. package/src/config/runtime/profiles/gemma4-e2b-baseline-probe.json +1 -3
  60. package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-probe.json +1 -3
  61. package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-test.json +1 -0
  62. package/src/config/runtime/profiles/gemma4-e2b-int4ple-baseline-probe.json +1 -5
  63. package/src/config/runtime/profiles/gemma4-e2b-int4ple-f16a-probe.json +1 -5
  64. package/src/config/runtime/profiles/gemma4-e2b-int4ple-reference-export.json +1 -3
  65. package/src/config/runtime/profiles/gemma4-e2b-int4ple-retain-q4k-probe.json +1 -5
  66. package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +1 -0
  67. package/src/config/runtime/profiles/gemma4-e2b-prefill-profile.json +1 -3
  68. package/src/config/runtime/profiles/gemma4-e2b-throughput-probe.json +1 -0
  69. package/src/config/runtime/profiles/low-memory.json +1 -0
  70. package/src/config/runtime/profiles/production.json +1 -3
  71. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-attn128-candidate.json +1 -0
  72. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-maxbatch64-candidate.json +1 -0
  73. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-normed-ffn-candidate.json +1 -0
  74. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-overlap-ringtokens1-candidate.json +1 -0
  75. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-parity.json +1 -0
  76. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-sequential-candidate.json +1 -0
  77. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-throughput.json +1 -0
  78. package/src/config/runtime/profiles/qwen-3-5-0-8b-prefill-profile.json +1 -3
  79. package/src/config/runtime/profiles/qwen-3-5-0-8b-throughput-probe.json +1 -0
  80. package/src/config/runtime/profiles/qwen-3-5-2b-f16-primary-throughput.json +1 -5
  81. package/src/config/runtime/profiles/qwen-3-5-2b-metal-parity.json +1 -0
  82. package/src/config/runtime/profiles/qwen-3-5-2b-metal-throughput.json +1 -0
  83. package/src/config/runtime/profiles/qwen-3-5-9b-metal-correctness.json +1 -0
  84. package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-stability.json +1 -3
  85. package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-throughput.json +1 -0
  86. package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-stability.json +1 -0
  87. package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-throughput.json +1 -0
  88. package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +1 -5
  89. package/src/config/runtime/profiles/rerank-stability.json +1 -3
  90. package/src/config/runtime/profiles/rerank-throughput.json +1 -3
  91. package/src/config/runtime/profiles/simulation.json +1 -3
  92. package/src/config/runtime/profiles/throughput.json +1 -3
  93. package/src/config/runtime/profiles/trace-layers.json +1 -3
  94. package/src/config/runtime/profiles/translategemma-1b-nativekd2-q4k-rdna3-throughput-probe.json +1 -0
  95. package/src/config/runtime/profiles/turboquant-contiguous-prod.json +1 -0
  96. package/src/config/runtime/profiles/turboquant-contiguous.json +1 -0
  97. package/src/config/runtime/profiles/turboquant.json +1 -0
  98. package/src/config/runtime/profiles/vector-stability.json +1 -3
  99. package/src/config/runtime/profiles/vector-throughput.json +1 -0
  100. package/src/config/runtime/profiles/verbose-trace.json +1 -3
  101. package/src/config/runtime/tiers/gemma4-128gb.json +1 -0
  102. package/src/config/runtime/tiers/gemma4-16gb.json +1 -0
  103. package/src/config/runtime/tiers/gemma4-24gb.json +1 -0
  104. package/src/config/runtime/tiers/gemma4-32gb.json +1 -0
  105. package/src/config/schema/benchmark.schema.d.ts +7 -0
  106. package/src/config/schema/benchmark.schema.js +5 -0
  107. package/src/config/schema/index.d.ts +8 -16
  108. package/src/config/schema/index.js +5 -8
  109. package/src/config/schema/kernel-thresholds.schema.d.ts +0 -12
  110. package/src/config/schema/kernel-thresholds.schema.js +0 -12
  111. package/src/config/schema/kernel-warmup.schema.d.ts +1 -3
  112. package/src/config/schema/kernel-warmup.schema.js +0 -1
  113. package/src/config/schema/runtime-profile.schema.d.ts +24 -0
  114. package/src/config/schema/runtime-profile.schema.js +92 -0
  115. package/src/config/schema/shared-runtime.schema.d.ts +1 -4
  116. package/src/config/schema/shared-runtime.schema.js +0 -2
  117. package/src/config/schema/tooling.schema.d.ts +8 -5
  118. package/src/config/schema/tooling.schema.js +3 -2
  119. package/src/debug/tensor.d.ts +2 -0
  120. package/src/debug/tensor.js +21 -2
  121. package/src/gpu/command-recorder.d.ts +5 -0
  122. package/src/gpu/command-recorder.js +17 -0
  123. package/src/gpu/kernel-runtime.js +2 -10
  124. package/src/gpu/kernels/index.d.ts +0 -2
  125. package/src/gpu/kernels/index.js +0 -2
  126. package/src/gpu/kernels/kernel-prewarm.d.ts +3 -0
  127. package/src/gpu/kernels/kernel-prewarm.js +60 -0
  128. package/src/gpu/kernels/utils.d.ts +2 -4
  129. package/src/gpu/kernels/utils.js +2 -4
  130. package/src/index.d.ts +13 -1
  131. package/src/index.js +7 -1
  132. package/src/inference/browser-harness-model-helpers.js +4 -0
  133. package/src/inference/browser-harness-runtime-helpers.js +25 -10
  134. package/src/inference/browser-harness-text-helpers.js +4 -1
  135. package/src/inference/browser-harness.d.ts +4 -0
  136. package/src/inference/browser-harness.js +91 -4
  137. package/src/inference/observation-context.d.ts +22 -0
  138. package/src/inference/observation-context.js +41 -0
  139. package/src/inference/pipelines/text/attention/attn-config.js +1 -1
  140. package/src/inference/pipelines/text/attention/executor-immediate.js +42 -0
  141. package/src/inference/pipelines/text/attention/executor-recorded.js +29 -0
  142. package/src/inference/pipelines/text/attention/index.js +7 -0
  143. package/src/inference/pipelines/text/attention/interpreter.js +1334 -0
  144. package/src/inference/pipelines/text/attention/plan.d.ts +36 -0
  145. package/src/inference/pipelines/text/attention/plan.js +328 -0
  146. package/src/inference/pipelines/text/attention/receipt.js +60 -0
  147. package/src/inference/pipelines/text/attention/record.js +8 -1278
  148. package/src/inference/pipelines/text/attention/run.js +8 -1386
  149. package/src/inference/pipelines/text/generator-decode-policy.js +4 -1
  150. package/src/inference/pipelines/text/generator-helpers.js +2 -0
  151. package/src/inference/pipelines/text/generator-steps.js +32 -15
  152. package/src/inference/pipelines/text/generator.js +10 -5
  153. package/src/inference/pipelines/text/init.d.ts +3 -0
  154. package/src/inference/pipelines/text/layer-plan-gpu.js +2 -0
  155. package/src/inference/pipelines/text/layer.js +2 -0
  156. package/src/inference/pipelines/text/model-load.d.ts +0 -1
  157. package/src/inference/pipelines/text/model-load.js +2 -11
  158. package/src/inference/pipelines/text/probes.js +10 -0
  159. package/src/inference/pipelines/text/resolved-runtime-session.d.ts +56 -0
  160. package/src/inference/pipelines/text/resolved-runtime-session.js +175 -0
  161. package/src/inference/pipelines/text/state.d.ts +6 -0
  162. package/src/inference/pipelines/text/state.js +3 -0
  163. package/src/inference/pipelines/text/types.d.ts +6 -0
  164. package/src/inference/pipelines/text.js +16 -1
  165. package/src/inference/refactor-receipt.d.ts +49 -0
  166. package/src/inference/refactor-receipt.js +188 -0
  167. package/src/inference/resource-scope.d.ts +33 -0
  168. package/src/inference/resource-scope.js +168 -0
  169. package/src/inference/test-harness.d.ts +3 -0
  170. package/src/inference/test-harness.js +1 -0
  171. package/src/storage/model-cache.d.ts +53 -0
  172. package/src/storage/model-cache.js +550 -0
  173. package/src/tooling/boundary-evidence.d.ts +51 -0
  174. package/src/tooling/boundary-evidence.js +408 -0
  175. package/src/tooling/browser-command-runner.js +4 -4
  176. package/src/tooling/command-context.d.ts +25 -0
  177. package/src/tooling/command-context.js +53 -0
  178. package/src/tooling/command-runner-shared.js +22 -5
  179. package/src/tooling/demo-receipts.d.ts +56 -0
  180. package/src/tooling/demo-receipts.js +113 -0
  181. package/src/tooling/diagnose-runner.js +2 -2
  182. package/src/tooling/execution-cost-ledger.d.ts +21 -0
  183. package/src/tooling/execution-cost-ledger.js +199 -0
  184. package/src/tooling/node-command-runner.js +2 -2
  185. package/src/tooling/opfs-cache.d.ts +11 -49
  186. package/src/tooling/opfs-cache.js +4 -510
  187. package/src/tooling/precision-replay-math.d.ts +42 -0
  188. package/src/tooling/precision-replay-math.js +174 -0
  189. package/src/tooling/program-bundle-parity.d.ts +3 -0
  190. package/src/tooling/program-bundle-parity.js +8 -0
  191. package/src/tooling/program-bundle.d.ts +1 -52
  192. package/src/tooling/program-bundle.js +0 -139
  193. package/src/tooling/registered-variant-calibration.d.ts +24 -0
  194. package/src/tooling/registered-variant-calibration.js +286 -0
  195. package/src/tooling/runtime-input-composition.js +105 -53
  196. package/src/tooling/runtime-intent.js +41 -0
  197. package/src/tooling/runtime-optimization-index.d.ts +6 -0
  198. package/src/tooling/runtime-optimization-index.js +72 -0
  199. package/src/tooling/runtime-optimization.d.ts +47 -6
  200. package/src/tooling/runtime-optimization.js +559 -40
  201. package/src/tooling/source-intake.d.ts +49 -0
  202. package/src/tooling/source-intake.js +414 -0
  203. package/src/tooling-exports/evidence.d.ts +34 -0
  204. package/src/tooling-exports/evidence.js +34 -0
  205. package/src/tooling-exports/runtime.d.ts +7 -0
  206. package/src/tooling-exports/runtime.js +7 -0
  207. package/src/tooling-exports.d.ts +11 -0
  208. package/src/tooling-exports.js +6 -3
  209. package/src/tooling-exports.shared.d.ts +32 -0
  210. package/src/tooling-exports.shared.js +31 -0
  211. package/src/version.js +1 -1
  212. package/src/config/schema/tuner.schema.d.ts +0 -39
  213. package/src/config/schema/tuner.schema.js +0 -13
  214. package/src/gpu/kernel-tuner/benchmarks.js +0 -902
  215. package/src/gpu/kernel-tuner/cache.js +0 -145
  216. package/src/gpu/kernel-tuner/index.js +0 -38
  217. package/src/gpu/kernel-tuner/tuner.js +0 -247
  218. package/src/gpu/kernel-tuner.js +0 -12
  219. package/src/gpu/kernels/kernel-tuning.d.ts +0 -42
  220. package/src/gpu/kernels/kernel-tuning.js +0 -158
  221. package/src/gpu/profiler.js +0 -382
  222. package/src/inference/pipelines/text/attention/output-gate-fusion.js +0 -37
@@ -68,6 +68,11 @@ import {
68
68
  import { collectTrainingArtifactsFromSuiteResult } from './browser-harness-report-helpers.js';
69
69
  import { sha256Hex } from '../utils/sha256.js';
70
70
  import { stableSortObject } from '../utils/stable-sort-object.js';
71
+ import { assertCommandContextMatchesOptions } from '../tooling/command-context.js';
72
+ import {
73
+ buildTokenCostLedger,
74
+ isExecutionObservationRequested,
75
+ } from '../tooling/execution-cost-ledger.js';
71
76
 
72
77
  const TRAINING_SUITE_MODULE_PATH = '../experimental/training/suite.js';
73
78
  let trainingSuiteModulePromise = null;
@@ -434,6 +439,79 @@ export function resolveExecutionGraphHash(manifest) {
434
439
  return hashStableJson(execution);
435
440
  }
436
441
 
442
+ function resolveArtifactHash(manifest) {
443
+ const declaredDigest = manifest?.artifactIdentity?.artifactDigest;
444
+ if (typeof declaredDigest === 'string' && declaredDigest.trim()) {
445
+ return declaredDigest;
446
+ }
447
+ if (!Array.isArray(manifest?.shards) || manifest.shards.length === 0) {
448
+ return null;
449
+ }
450
+ return hashStableJson({
451
+ modelId: manifest.modelId ?? null,
452
+ artifactIdentity: manifest.artifactIdentity ?? null,
453
+ hashAlgorithm: manifest.hashAlgorithm ?? null,
454
+ totalSize: manifest.totalSize ?? null,
455
+ shards: manifest.shards.map((shard) => ({
456
+ index: shard?.index ?? null,
457
+ filename: shard?.filename ?? null,
458
+ size: shard?.size ?? null,
459
+ hash: shard?.hash ?? null,
460
+ blake3: shard?.blake3 ?? null,
461
+ offset: shard?.offset ?? null,
462
+ })),
463
+ tokenizer: manifest.tokenizer ?? null,
464
+ });
465
+ }
466
+
467
+ function resolveWrapperHash(manifest, metrics) {
468
+ const execution = manifest?.inference?.execution;
469
+ if (!execution || typeof execution !== 'object') {
470
+ return null;
471
+ }
472
+ return hashStableJson({
473
+ wrapperContract: 'doppler.text-execution-wrapper/v1',
474
+ kernelPathId: metrics?.kernelPathId ?? null,
475
+ kernelPathSource: metrics?.kernelPathSource ?? null,
476
+ executionPlan: metrics?.executionPlan ?? null,
477
+ preLayer: execution.preLayer ?? null,
478
+ prefill: execution.prefill ?? null,
479
+ decode: execution.decode ?? null,
480
+ postLayer: execution.postLayer ?? null,
481
+ policies: execution.policies ?? null,
482
+ });
483
+ }
484
+
485
+ function attachExecutionCostLedger(metrics, runtimeConfig, manifest) {
486
+ if (!isExecutionObservationRequested(runtimeConfig)) {
487
+ return metrics;
488
+ }
489
+ const device = resolveDeviceInfo();
490
+ const browser = {
491
+ userAgent: typeof navigator !== 'undefined' ? (navigator.userAgent || null) : null,
492
+ platform: typeof navigator !== 'undefined' ? (navigator.platform || null) : null,
493
+ vendor: typeof navigator !== 'undefined' ? (navigator.vendor || null) : null,
494
+ };
495
+ return {
496
+ ...metrics,
497
+ tokenCostLedger: buildTokenCostLedger({
498
+ metrics,
499
+ identity: {
500
+ artifactDigest: resolveArtifactHash(manifest),
501
+ manifestDigest: hashStableJson(manifest),
502
+ executionGraphDigest: resolveExecutionGraphHash(manifest),
503
+ runtimeConfigDigest: hashStableJson(runtimeConfig),
504
+ kernelSetDigest: manifest?.inference?.execution?.kernels
505
+ ? hashStableJson(manifest.inference.execution.kernels)
506
+ : null,
507
+ wrapperDigest: resolveWrapperHash(manifest, metrics),
508
+ },
509
+ device,
510
+ browser,
511
+ }),
512
+ };
513
+ }
514
+
437
515
  function buildPerStepTokenProof(tokenIds) {
438
516
  return tokenIds.map((tokenId, index) => ({
439
517
  index,
@@ -889,13 +967,13 @@ async function runInferenceSuite(options = {}) {
889
967
  firstTokenMs: timing.firstTokenMs,
890
968
  firstResponseMs: timing.firstResponseMs,
891
969
  });
892
- const metricsWithContracts = buildSuiteContractMetrics(
970
+ const metricsWithContracts = attachExecutionCostLedger(buildSuiteContractMetrics(
893
971
  options.suiteName || 'inference',
894
972
  loadDiagnostics
895
973
  ? { ...metricsWithTimingDiagnostics, load: loadDiagnostics }
896
974
  : metricsWithTimingDiagnostics,
897
975
  harness.manifest
898
- );
976
+ ), runtimeConfig, harness.manifest);
899
977
  return {
900
978
  ...summary,
901
979
  modelId: options.modelId || harness.manifest?.modelId || 'unknown',
@@ -1482,6 +1560,8 @@ async function runBenchSuite(options = {}) {
1482
1560
  let lastDecodeMode = null;
1483
1561
  let lastBatchGuardReason = null;
1484
1562
  let lastExecutionPlan = null;
1563
+ let lastPrefillProfileSteps = null;
1564
+ let lastDecodeProfileSteps = null;
1485
1565
  let lastGpuUniformCache = null;
1486
1566
  for (let i = 0; i < warmupRuns + timedRuns; i++) {
1487
1567
  harness.pipeline.reset?.();
@@ -1512,6 +1592,8 @@ async function runBenchSuite(options = {}) {
1512
1592
  lastDecodeMode = run?.phase?.decodeMode ?? null;
1513
1593
  lastBatchGuardReason = run?.phase?.batchGuardReason ?? null;
1514
1594
  lastExecutionPlan = run?.phase?.executionPlan ?? null;
1595
+ lastPrefillProfileSteps = run?.phase?.prefillProfileSteps ?? null;
1596
+ lastDecodeProfileSteps = run?.phase?.decodeProfileSteps ?? null;
1515
1597
  }
1516
1598
  if (i >= warmupRuns) {
1517
1599
  const phase = run?.phase ?? {};
@@ -1824,6 +1906,8 @@ async function runBenchSuite(options = {}) {
1824
1906
  decodeMode: lastDecodeMode,
1825
1907
  batchGuardReason: lastBatchGuardReason,
1826
1908
  executionPlan: lastExecutionPlan,
1909
+ prefillProfileSteps: lastPrefillProfileSteps,
1910
+ decodeProfileSteps: lastDecodeProfileSteps,
1827
1911
  generatedText,
1828
1912
  referenceTranscript: generatedReferenceTranscript,
1829
1913
  promptInput: generatedPromptInput,
@@ -1882,11 +1966,11 @@ async function runBenchSuite(options = {}) {
1882
1966
  firstTokenMs: timing.firstTokenMs,
1883
1967
  firstResponseMs: timing.firstResponseMs,
1884
1968
  });
1885
- const metricsWithContracts = buildSuiteContractMetrics(
1969
+ const metricsWithContracts = attachExecutionCostLedger(buildSuiteContractMetrics(
1886
1970
  'bench',
1887
1971
  loadDiagnostics ? { ...metrics, load: loadDiagnostics } : metrics,
1888
1972
  harness.manifest
1889
- );
1973
+ ), runtimeConfig, harness.manifest);
1890
1974
  return {
1891
1975
  ...summary,
1892
1976
  modelId: options.modelId || harness.manifest?.modelId || 'unknown',
@@ -1997,6 +2081,9 @@ async function withHarnessPhase(phase, context, run) {
1997
2081
 
1998
2082
  export async function runBrowserSuite(options = {}) {
1999
2083
  return runWithRuntimeIsolationForSuite(async () => {
2084
+ if (options.commandContext) {
2085
+ assertCommandContextMatchesOptions(options.commandContext, options);
2086
+ }
2000
2087
  const suiteTimestamp = resolveReportTimestamp(options.timestamp, 'runBrowserSuite timestamp');
2001
2088
  const harnessContext = resolveHarnessContext(options);
2002
2089
  const mode = resolveHarnessMode(options, harnessContext);
@@ -0,0 +1,22 @@
1
+ import type { RuntimeConfigSchema } from '../config/schema/index.js';
2
+ import type { CommandContext } from '../tooling/command-context.js';
3
+
4
+ export const OBSERVATION_CONTEXT_SCHEMA: 'doppler.observation-context/v1';
5
+
6
+ export interface ObservationContext {
7
+ readonly schema: typeof OBSERVATION_CONTEXT_SCHEMA;
8
+ readonly commandContext: CommandContext | null;
9
+ readonly diagnostics: 'off' | 'on_failure' | 'always';
10
+ readonly probes: ReadonlyArray<Readonly<Record<string, unknown>>>;
11
+ readonly tracing: {
12
+ readonly pipelineEnabled: boolean;
13
+ readonly layers: ReadonlyArray<number> | null;
14
+ readonly kernelTrace: Readonly<Record<string, unknown>> | null;
15
+ };
16
+ readonly receiptPolicy: 'off' | 'on_failure' | 'always';
17
+ }
18
+
19
+ export function createObservationContext(options: {
20
+ runtimeConfig: RuntimeConfigSchema;
21
+ commandContext?: CommandContext | null;
22
+ }): ObservationContext;
@@ -0,0 +1,41 @@
1
+ export const OBSERVATION_CONTEXT_SCHEMA = 'doppler.observation-context/v1';
2
+
3
+ function cloneJsonValue(value) {
4
+ if (value == null) {
5
+ return value;
6
+ }
7
+ return JSON.parse(JSON.stringify(value));
8
+ }
9
+
10
+ function deepFreeze(value) {
11
+ if (!value || typeof value !== 'object' || Object.isFrozen(value)) {
12
+ return value;
13
+ }
14
+ Object.freeze(value);
15
+ for (const entry of Object.values(value)) {
16
+ deepFreeze(entry);
17
+ }
18
+ return value;
19
+ }
20
+
21
+ export function createObservationContext(options = {}) {
22
+ const runtimeConfig = options.runtimeConfig;
23
+ if (!runtimeConfig?.shared?.tooling || !runtimeConfig?.shared?.debug) {
24
+ throw new Error(
25
+ '[ObservationContext] runtime.shared.tooling and runtime.shared.debug are required.'
26
+ );
27
+ }
28
+ const debug = runtimeConfig.shared.debug;
29
+ return deepFreeze({
30
+ schema: OBSERVATION_CONTEXT_SCHEMA,
31
+ commandContext: options.commandContext ?? null,
32
+ diagnostics: runtimeConfig.shared.tooling.diagnostics,
33
+ probes: cloneJsonValue(debug.probes ?? []),
34
+ tracing: {
35
+ pipelineEnabled: debug.pipeline?.enabled === true,
36
+ layers: cloneJsonValue(debug.pipeline?.layers ?? null),
37
+ kernelTrace: cloneJsonValue(debug.kernelTrace ?? null),
38
+ },
39
+ receiptPolicy: runtimeConfig.shared.tooling.refactorReceipts,
40
+ });
41
+ }
@@ -2,7 +2,7 @@ import { log } from '../../../../debug/index.js';
2
2
 
3
3
  /**
4
4
  * Required fields that must not be undefined on every AttnConfig instance.
5
- * These are the fields destructured by both run.js and record.js attention
5
+ * These are the fields consumed by both attention executor adapters
6
6
  * entry points. Optional fields (skipInputNorm, tokenIds, kernelPath,
7
7
  * disableRoPE) have defaults in the destructuring and are excluded.
8
8
  */
@@ -0,0 +1,42 @@
1
+ import { createCommandRecorder } from '../../../../gpu/command-recorder.js';
2
+ import { interpretAttentionWithRecorder } from './interpreter.js';
3
+
4
+ export async function runLayerAttentionGPU(
5
+ input,
6
+ layerWeights,
7
+ config,
8
+ state,
9
+ debug,
10
+ debugFlags,
11
+ getWeightBuffer,
12
+ getNormWeightBuffer,
13
+ debugCheckBuffer,
14
+ lora
15
+ ) {
16
+ const phase = config?.isPrefill ? 'prefill' : 'decode';
17
+ const layerIdx = Number.isInteger(config?.layerIdx) ? config.layerIdx : 'unknown';
18
+ const recorder = createCommandRecorder(
19
+ `attention_${phase}_layer_${layerIdx}`,
20
+ { recordLabels: debug === true }
21
+ );
22
+ try {
23
+ const result = await interpretAttentionWithRecorder(
24
+ recorder,
25
+ input,
26
+ layerWeights,
27
+ config,
28
+ state,
29
+ debug,
30
+ debugFlags,
31
+ getWeightBuffer,
32
+ getNormWeightBuffer,
33
+ debugCheckBuffer,
34
+ lora
35
+ );
36
+ recorder.submit();
37
+ return result;
38
+ } catch (error) {
39
+ recorder.abort();
40
+ throw error;
41
+ }
42
+ }
@@ -0,0 +1,29 @@
1
+ import { interpretAttentionWithRecorder } from './interpreter.js';
2
+
3
+ export async function recordLayerAttentionGPU(
4
+ recorder,
5
+ input,
6
+ layerWeights,
7
+ config,
8
+ state,
9
+ debug,
10
+ debugFlags,
11
+ getWeightBuffer,
12
+ getNormWeightBuffer,
13
+ debugCheckBuffer,
14
+ lora
15
+ ) {
16
+ return interpretAttentionWithRecorder(
17
+ recorder,
18
+ input,
19
+ layerWeights,
20
+ config,
21
+ state,
22
+ debug,
23
+ debugFlags,
24
+ getWeightBuffer,
25
+ getNormWeightBuffer,
26
+ debugCheckBuffer,
27
+ lora
28
+ );
29
+ }
@@ -13,5 +13,12 @@ export { runLayerAttentionGPU } from './run.js';
13
13
 
14
14
  // Record (batched submission)
15
15
  export { recordLayerAttentionGPU } from './record.js';
16
+ export {
17
+ ATTENTION_PLAN_SCHEMA,
18
+ resolveAttentionPlan,
19
+ bindAttentionPlan,
20
+ executeBoundAttentionPlan,
21
+ createAttentionExecutor,
22
+ } from './plan.js';
16
23
  export { runAttentionBDPA } from '../../../../gpu/kernel-selector.js';
17
24
  export { recordAttentionBDPA } from '../../../../gpu/kernel-selector.js';