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,117 @@
1
+ import type { ChatMessage } from '../../inference/pipelines/text/chat-format.js';
2
+ import type { SequenceEncodeOptions, SequenceEncodeResult } from '../../inference/pipelines/text/types.d.ts';
3
+ import type {
4
+ DopplerGenerateOptions,
5
+ DopplerGenerationEvidence,
6
+ DopplerModelHandle,
7
+ DopplerModelInspectionReceipt,
8
+ } from './model-session.js';
9
+ import type { DopplerPersistentCacheReceipt } from './model-source.js';
10
+
11
+ export type DopplerPromptInput = string | ChatMessage[] | { messages: ChatMessage[] };
12
+ export type DopplerCapability =
13
+ | 'generate'
14
+ | 'stream'
15
+ | 'embed'
16
+ | 'sequence'
17
+ | 'inspect'
18
+ | 'lora'
19
+ | 'advanced';
20
+ export type DopplerObservationTier = 'always' | 'guided-quality' | 'deep-xray';
21
+ export type DopplerObservationPolicyId =
22
+ | 'demo/always-on'
23
+ | 'demo/guided-quality'
24
+ | 'demo/deep-xray';
25
+
26
+ export interface DopplerScopedGenerateOptions extends DopplerGenerateOptions {
27
+ observe?: DopplerObservationTier | DopplerObservationPolicyId;
28
+ observationPolicy?: DopplerObservationTier | DopplerObservationPolicyId;
29
+ }
30
+
31
+ export interface DopplerGenerationResult {
32
+ schema: 'doppler.generation-result/v1';
33
+ outputText: string;
34
+ content: string;
35
+ tokenIds: number[];
36
+ usage: {
37
+ promptTokens: number | null;
38
+ completionTokens: number;
39
+ totalTokens: number | null;
40
+ };
41
+ observation: {
42
+ policyId: DopplerObservationPolicyId;
43
+ tier: DopplerObservationTier;
44
+ executionClassification: 'representative' | 'observed' | 'deep-diagnostic';
45
+ executionChanged: boolean;
46
+ unavailable: string[];
47
+ deepEvidenceAvailable: boolean | null;
48
+ };
49
+ fingerprint: {
50
+ modelId: string | null;
51
+ manifestHash: string | null;
52
+ tokenizerHash: string | null;
53
+ executionPlanId: string | null;
54
+ kernelPathId: string | null;
55
+ runtimeProfileHash: string | null;
56
+ backendIdentityHash: string | null;
57
+ observationPolicyId: DopplerObservationPolicyId;
58
+ };
59
+ inspectionReceipt: DopplerModelInspectionReceipt | null;
60
+ evidence: DopplerGenerationEvidence;
61
+ }
62
+
63
+ export type DopplerGenerationEvent =
64
+ | {
65
+ schema: 'doppler.generation-event/v1';
66
+ type: 'text-delta';
67
+ text: string;
68
+ observationPolicyId: DopplerObservationPolicyId;
69
+ }
70
+ | {
71
+ schema: 'doppler.generation-event/v1';
72
+ type: 'complete';
73
+ outputText: string;
74
+ observationPolicyId: DopplerObservationPolicyId;
75
+ };
76
+
77
+ export interface DopplerScopedModelSession {
78
+ readonly schema: 'doppler.scoped-session/v1';
79
+ readonly capabilities: Readonly<Record<DopplerCapability, boolean>>;
80
+ readonly closed: boolean;
81
+ readonly loaded: boolean;
82
+ readonly modelId: string;
83
+ readonly manifestHash: string | null;
84
+ readonly persistentCache: DopplerPersistentCacheReceipt | null;
85
+ readonly manifest: unknown;
86
+ readonly activeLoRA: string | null;
87
+ readonly deviceInfo: Record<string, unknown> | null;
88
+ readonly advanced: DopplerModelHandle['advanced'];
89
+ supports(capability: DopplerCapability): boolean;
90
+ require(capability: DopplerCapability): true;
91
+ generate(input: DopplerPromptInput, options?: DopplerScopedGenerateOptions): Promise<DopplerGenerationResult>;
92
+ stream(input: DopplerPromptInput, options?: DopplerScopedGenerateOptions): AsyncGenerator<DopplerGenerationEvent, void, void>;
93
+ inspect(
94
+ input: string,
95
+ options?: DopplerScopedGenerateOptions & {
96
+ topKSize?: number;
97
+ onEvent?: (event: { type: 'inspection-complete'; receipt: DopplerModelInspectionReceipt }) => void;
98
+ }
99
+ ): Promise<DopplerModelInspectionReceipt>;
100
+ embed(input: string, options?: Record<string, unknown>): Promise<unknown>;
101
+ encodeSequence(sequence: string, options?: SequenceEncodeOptions): Promise<SequenceEncodeResult>;
102
+ loadLoRA(adapter: unknown, options?: Record<string, unknown>): Promise<void>;
103
+ unloadLoRA(): Promise<void>;
104
+ resetGenerationState(): void;
105
+ close(): Promise<void>;
106
+ }
107
+
108
+ export declare const OBSERVATION_POLICIES: Readonly<Record<
109
+ DopplerObservationTier,
110
+ {
111
+ id: DopplerObservationPolicyId;
112
+ tier: DopplerObservationTier;
113
+ executionClassification: 'representative' | 'observed' | 'deep-diagnostic';
114
+ }
115
+ >>;
116
+
117
+ export declare function createScopedModelSession(handle: DopplerModelHandle): DopplerScopedModelSession;
@@ -0,0 +1,257 @@
1
+ const SESSION_SCHEMA = 'doppler.scoped-session/v1';
2
+ const RESULT_SCHEMA = 'doppler.generation-result/v1';
3
+ const EVENT_SCHEMA = 'doppler.generation-event/v1';
4
+
5
+ const OBSERVATION_POLICIES = Object.freeze({
6
+ always: Object.freeze({
7
+ id: 'demo/always-on',
8
+ tier: 'always',
9
+ executionClassification: 'representative',
10
+ }),
11
+ 'guided-quality': Object.freeze({
12
+ id: 'demo/guided-quality',
13
+ tier: 'guided-quality',
14
+ executionClassification: 'observed',
15
+ }),
16
+ 'deep-xray': Object.freeze({
17
+ id: 'demo/deep-xray',
18
+ tier: 'deep-xray',
19
+ executionClassification: 'deep-diagnostic',
20
+ }),
21
+ });
22
+
23
+ function resolveObservationPolicy(value = 'always') {
24
+ const key = String(value || 'always').trim();
25
+ const policy = OBSERVATION_POLICIES[key]
26
+ || Object.values(OBSERVATION_POLICIES).find((entry) => entry.id === key);
27
+ if (!policy) {
28
+ throw new Error(
29
+ `Unsupported Doppler observation policy "${key}". `
30
+ + `Expected one of: ${Object.keys(OBSERVATION_POLICIES).join(', ')}.`
31
+ );
32
+ }
33
+ return policy;
34
+ }
35
+
36
+ function capabilityMap(handle) {
37
+ const specializedModel = handle?.supportsEmbedding === true || handle?.supportsSequence === true;
38
+ return Object.freeze({
39
+ generate: !specializedModel && typeof handle?.generateWithEvidence === 'function',
40
+ stream: !specializedModel && typeof handle?.generate === 'function',
41
+ embed: handle?.supportsEmbedding === true && typeof handle?.embed === 'function',
42
+ sequence: handle?.supportsSequence === true && typeof handle?.encodeSequence === 'function',
43
+ inspect: typeof handle?.inspect?.generate === 'function',
44
+ lora: typeof handle?.loadLoRA === 'function' && typeof handle?.unloadLoRA === 'function',
45
+ advanced: handle?.advanced && typeof handle.advanced === 'object',
46
+ });
47
+ }
48
+
49
+ function buildObservation(policy, evidence, inspectionReceipt = null) {
50
+ const statsAvailable = Boolean(evidence?.stats && typeof evidence.stats === 'object');
51
+ return {
52
+ policyId: policy.id,
53
+ tier: policy.tier,
54
+ executionClassification: policy.executionClassification,
55
+ executionChanged: inspectionReceipt?.policy?.modifiesExecution === true,
56
+ unavailable: policy.tier === 'guided-quality' && !inspectionReceipt?.quality
57
+ ? ['token-surprisal', 'word-surprisal', 'rolling-perplexity']
58
+ : [],
59
+ deepEvidenceAvailable: policy.tier === 'deep-xray' ? statsAvailable : null,
60
+ };
61
+ }
62
+
63
+ function buildGenerationResult(evidence, policy, inspectionReceipt = null) {
64
+ const outputText = String(evidence?.outputText ?? '');
65
+ const tokenIds = Array.from(evidence?.tokenIds || [], Number);
66
+ return {
67
+ schema: RESULT_SCHEMA,
68
+ outputText,
69
+ content: outputText,
70
+ tokenIds,
71
+ usage: {
72
+ promptTokens: null,
73
+ completionTokens: tokenIds.length,
74
+ totalTokens: null,
75
+ },
76
+ observation: buildObservation(policy, evidence, inspectionReceipt),
77
+ fingerprint: inspectionReceipt?.fingerprint || {
78
+ modelId: evidence?.runtimeProfile?.model?.modelId ?? null,
79
+ manifestHash: evidence?.runtimeProfile?.model?.manifestHash ?? null,
80
+ tokenizerHash: evidence?.stats?.tokenizerHash ?? null,
81
+ executionPlanId: evidence?.backendIdentity?.executionPlanId ?? null,
82
+ kernelPathId: evidence?.backendIdentity?.kernelPathId ?? null,
83
+ runtimeProfileHash: evidence?.runtimeProfileHash ?? null,
84
+ backendIdentityHash: evidence?.backendIdentityHash ?? null,
85
+ observationPolicyId: policy.id,
86
+ },
87
+ inspectionReceipt,
88
+ evidence,
89
+ };
90
+ }
91
+
92
+ export function createScopedModelSession(handle) {
93
+ if (!handle || typeof handle !== 'object') {
94
+ throw new Error('createScopedModelSession requires a Doppler model handle.');
95
+ }
96
+ let closed = false;
97
+ const capabilities = capabilityMap(handle);
98
+
99
+ function requireOpen() {
100
+ if (closed) {
101
+ throw new Error('Doppler scoped session is closed.');
102
+ }
103
+ }
104
+
105
+ function supports(capability) {
106
+ return capabilities[String(capability || '')] === true;
107
+ }
108
+
109
+ function requireCapability(capability) {
110
+ requireOpen();
111
+ if (!supports(capability)) {
112
+ throw new Error(
113
+ `Doppler model "${handle.modelId || 'unknown'}" does not support "${capability}".`
114
+ );
115
+ }
116
+ return true;
117
+ }
118
+
119
+ const session = {
120
+ schema: SESSION_SCHEMA,
121
+ capabilities,
122
+ supports,
123
+ require: requireCapability,
124
+ async generate(input, options = {}) {
125
+ requireCapability('generate');
126
+ const policy = resolveObservationPolicy(options.observe);
127
+ const {
128
+ observe: _observe,
129
+ observationPolicy: _observationPolicy,
130
+ ...generationOptions
131
+ } = options;
132
+ if (
133
+ typeof input === 'string'
134
+ && policy.tier === 'always'
135
+ && typeof handle.inspect?.generate === 'function'
136
+ ) {
137
+ const inspectionReceipt = await handle.inspect.generate(input, {
138
+ policyId: policy.id,
139
+ generation: generationOptions,
140
+ });
141
+ return buildGenerationResult(
142
+ inspectionReceipt.generationEvidence,
143
+ policy,
144
+ inspectionReceipt
145
+ );
146
+ }
147
+ const evidence = await handle.generateWithEvidence(input, generationOptions);
148
+ return buildGenerationResult(evidence, policy);
149
+ },
150
+ async *stream(input, options = {}) {
151
+ requireCapability('stream');
152
+ const policy = resolveObservationPolicy(options.observe);
153
+ const {
154
+ observe: _observe,
155
+ observationPolicy: _observationPolicy,
156
+ ...generationOptions
157
+ } = options;
158
+ let outputText = '';
159
+ for await (const text of handle.generate(input, generationOptions)) {
160
+ const delta = String(text ?? '');
161
+ outputText += delta;
162
+ yield {
163
+ schema: EVENT_SCHEMA,
164
+ type: 'text-delta',
165
+ text: delta,
166
+ observationPolicyId: policy.id,
167
+ };
168
+ }
169
+ yield {
170
+ schema: EVENT_SCHEMA,
171
+ type: 'complete',
172
+ outputText,
173
+ observationPolicyId: policy.id,
174
+ };
175
+ },
176
+ async inspect(input, options = {}) {
177
+ requireCapability('inspect');
178
+ const observationPolicy = options.observationPolicy ?? options.observe ?? 'guided-quality';
179
+ const policy = resolveObservationPolicy(observationPolicy);
180
+ if (typeof handle.inspect?.generate !== 'function') {
181
+ throw new Error('Loaded Doppler handle does not expose semantic inspection.');
182
+ }
183
+ const {
184
+ observe: _observe,
185
+ observationPolicy: _observationPolicy,
186
+ topKSize,
187
+ onEvent,
188
+ ...generation
189
+ } = options;
190
+ return handle.inspect.generate(input, {
191
+ policyId: policy.id,
192
+ generation,
193
+ topKSize,
194
+ onEvent,
195
+ });
196
+ },
197
+ async embed(input, options = {}) {
198
+ requireCapability('embed');
199
+ return handle.embed(input, options);
200
+ },
201
+ async encodeSequence(sequence, options = {}) {
202
+ requireCapability('sequence');
203
+ return handle.encodeSequence(sequence, options);
204
+ },
205
+ async loadLoRA(adapter, options = {}) {
206
+ requireCapability('lora');
207
+ return handle.loadLoRA(adapter, options);
208
+ },
209
+ async unloadLoRA() {
210
+ requireCapability('lora');
211
+ return handle.unloadLoRA();
212
+ },
213
+ resetGenerationState() {
214
+ requireOpen();
215
+ return handle.resetGenerationState();
216
+ },
217
+ async close() {
218
+ if (closed) return;
219
+ closed = true;
220
+ await handle.unload();
221
+ },
222
+ async [Symbol.asyncDispose]() {
223
+ await session.close();
224
+ },
225
+ get closed() {
226
+ return closed;
227
+ },
228
+ get loaded() {
229
+ return !closed && handle.loaded === true;
230
+ },
231
+ get modelId() {
232
+ return handle.modelId;
233
+ },
234
+ get manifestHash() {
235
+ return handle.manifestHash ?? null;
236
+ },
237
+ get persistentCache() {
238
+ return handle.persistentCache ?? null;
239
+ },
240
+ get manifest() {
241
+ return handle.manifest ?? null;
242
+ },
243
+ get activeLoRA() {
244
+ return handle.activeLoRA ?? null;
245
+ },
246
+ get deviceInfo() {
247
+ return handle.deviceInfo ?? null;
248
+ },
249
+ get advanced() {
250
+ requireCapability('advanced');
251
+ return handle.advanced;
252
+ },
253
+ };
254
+ return session;
255
+ }
256
+
257
+ export { OBSERVATION_POLICIES };
@@ -78,7 +78,6 @@ export interface DopplerCapabilitiesType {
78
78
  initialized: boolean;
79
79
  currentModelId: string | null;
80
80
  kernelsWarmed: boolean;
81
- kernelsTuned: boolean;
82
81
  lastModelEstimate: ModelEstimate | null;
83
82
  bridgeClient?: ExtensionBridgeClient | null;
84
83
  localPath?: string | null;
@@ -12,6 +12,5 @@ export const DopplerCapabilities = {
12
12
  initialized: false,
13
13
  currentModelId: null,
14
14
  kernelsWarmed: false,
15
- kernelsTuned: false,
16
15
  lastModelEstimate: null,
17
16
  };
@@ -0,0 +1,54 @@
1
+ {
2
+ "schema": "doppler.boundary-evidence-policy/v1",
3
+ "boundaries": [
4
+ {
5
+ "idTemplate": "model.embedding.output",
6
+ "stages": ["embed.out"]
7
+ },
8
+ {
9
+ "idTemplate": "layer.{L}.attention.q.pre_rope",
10
+ "stages": ["attn.q_norm", "attn.q_proj"]
11
+ },
12
+ {
13
+ "idTemplate": "layer.{L}.attention.k.pre_rope",
14
+ "stages": ["attn.k_norm", "attn.k_proj"]
15
+ },
16
+ {
17
+ "idTemplate": "layer.{L}.attention.q.post_rope",
18
+ "stages": ["attn.q_rope"]
19
+ },
20
+ {
21
+ "idTemplate": "layer.{L}.attention.k.post_rope",
22
+ "stages": ["attn.k_rope"]
23
+ },
24
+ {
25
+ "idTemplate": "layer.{L}.attention.output",
26
+ "stages": ["attn.out", "attn.o_proj", "attn.core_out"]
27
+ },
28
+ {
29
+ "idTemplate": "layer.{L}.ffn.output",
30
+ "stages": ["ffn.out"]
31
+ },
32
+ {
33
+ "idTemplate": "model.logits",
34
+ "stages": ["logits.final", "logits.out"]
35
+ }
36
+ ],
37
+ "tolerancePolicies": {
38
+ "doppler.boundary-tolerance/source-f32-v1": {
39
+ "absolute": 0.00001,
40
+ "relative": 0.00001,
41
+ "requireDtypeMatch": true
42
+ },
43
+ "doppler.boundary-tolerance/source-f16-v1": {
44
+ "absolute": 0.002,
45
+ "relative": 0.002,
46
+ "requireDtypeMatch": false
47
+ },
48
+ "doppler.boundary-tolerance/quantized-v1": {
49
+ "absolute": 0.05,
50
+ "relative": 0.05,
51
+ "requireDtypeMatch": false
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,122 @@
1
+ {
2
+ "schema": "doppler.source-intake-policy/v1",
3
+ "facts": [
4
+ {
5
+ "factId": "architecture.model_type",
6
+ "sourcePointers": ["/model_type", "/text_config/model_type"],
7
+ "owner": "conversion.modelType"
8
+ },
9
+ {
10
+ "factId": "architecture.hidden_size",
11
+ "sourcePointers": ["/hidden_size", "/text_config/hidden_size"],
12
+ "owner": "manifest.architecture.hiddenSize"
13
+ },
14
+ {
15
+ "factId": "architecture.intermediate_size",
16
+ "sourcePointers": ["/intermediate_size", "/text_config/intermediate_size"],
17
+ "owner": "manifest.architecture.intermediateSize"
18
+ },
19
+ {
20
+ "factId": "architecture.layer_count",
21
+ "sourcePointers": ["/num_hidden_layers", "/text_config/num_hidden_layers"],
22
+ "owner": "manifest.architecture.numLayers"
23
+ },
24
+ {
25
+ "factId": "architecture.attention.query_heads",
26
+ "sourcePointers": ["/num_attention_heads", "/text_config/num_attention_heads"],
27
+ "owner": "manifest.architecture.numAttentionHeads"
28
+ },
29
+ {
30
+ "factId": "architecture.attention.kv_heads",
31
+ "sourcePointers": ["/num_key_value_heads", "/text_config/num_key_value_heads"],
32
+ "owner": "manifest.architecture.numKeyValueHeads"
33
+ },
34
+ {
35
+ "factId": "architecture.attention.head_dim",
36
+ "sourcePointers": ["/head_dim", "/text_config/head_dim"],
37
+ "owner": "manifest.architecture.headDim"
38
+ },
39
+ {
40
+ "factId": "architecture.vocab_size",
41
+ "sourcePointers": ["/vocab_size", "/text_config/vocab_size"],
42
+ "owner": "manifest.architecture.vocabSize"
43
+ },
44
+ {
45
+ "factId": "architecture.max_position_embeddings",
46
+ "sourcePointers": ["/max_position_embeddings", "/text_config/max_position_embeddings"],
47
+ "owner": "manifest.architecture.maxSeqLen"
48
+ },
49
+ {
50
+ "factId": "architecture.activation",
51
+ "sourcePointers": ["/hidden_act", "/hidden_activation", "/text_config/hidden_act", "/text_config/hidden_activation"],
52
+ "owner": "manifest.inference.ffn.activation",
53
+ "verificationBoundary": "layer.0.ffn.output"
54
+ },
55
+ {
56
+ "factId": "architecture.normalization.epsilon",
57
+ "sourcePointers": ["/rms_norm_eps", "/layer_norm_eps", "/text_config/rms_norm_eps", "/text_config/layer_norm_eps"],
58
+ "owner": "manifest.inference.normalization.epsilon",
59
+ "verificationBoundary": "layer.0.attention.q.pre_rope"
60
+ },
61
+ {
62
+ "factId": "architecture.rope.theta",
63
+ "sourcePointers": ["/rope_theta", "/text_config/rope_theta"],
64
+ "owner": "manifest.inference.rope.ropeTheta",
65
+ "verificationBoundary": "layer.0.attention.q.post_rope"
66
+ },
67
+ {
68
+ "factId": "architecture.rope.scaling",
69
+ "sourcePointers": ["/rope_scaling", "/text_config/rope_scaling"],
70
+ "owner": "manifest.inference.rope.scaling",
71
+ "verificationBoundary": "layer.0.attention.q.post_rope"
72
+ },
73
+ {
74
+ "factId": "architecture.attention.sliding_window",
75
+ "sourcePointers": ["/sliding_window", "/text_config/sliding_window"],
76
+ "owner": "manifest.inference.attention.slidingWindow",
77
+ "verificationBoundary": "layer.0.attention.output"
78
+ },
79
+ {
80
+ "factId": "architecture.attention.bias",
81
+ "sourcePointers": ["/attention_bias", "/text_config/attention_bias"],
82
+ "owner": "manifest.inference.attention.attentionBias",
83
+ "verificationBoundary": "layer.0.attention.output"
84
+ },
85
+ {
86
+ "factId": "architecture.layer_pattern",
87
+ "sourcePointers": ["/layer_types", "/text_config/layer_types"],
88
+ "owner": "manifest.inference.layerPattern.layerTypes",
89
+ "verificationBoundary": "layer.0.attention.output"
90
+ },
91
+ {
92
+ "factId": "architecture.tie_word_embeddings",
93
+ "sourcePointers": ["/tie_word_embeddings", "/text_config/tie_word_embeddings"],
94
+ "owner": "manifest.inference.output.tieWordEmbeddings",
95
+ "verificationBoundary": "model.logits"
96
+ },
97
+ {
98
+ "factId": "tokenizer.bos_token_id",
99
+ "sourcePointers": ["/bos_token_id"],
100
+ "owner": "manifest.tokenizer.bosTokenId"
101
+ },
102
+ {
103
+ "factId": "tokenizer.eos_token_id",
104
+ "sourcePointers": ["/eos_token_id"],
105
+ "owner": "manifest.tokenizer.eosTokenId"
106
+ },
107
+ {
108
+ "factId": "tokenizer.pad_token_id",
109
+ "sourcePointers": ["/pad_token_id"],
110
+ "owner": "manifest.tokenizer.padTokenId"
111
+ }
112
+ ],
113
+ "requiredFacts": [
114
+ "architecture.model_type",
115
+ "architecture.hidden_size",
116
+ "architecture.intermediate_size",
117
+ "architecture.layer_count",
118
+ "architecture.attention.query_heads",
119
+ "architecture.vocab_size"
120
+ ],
121
+ "architectureKeyPattern": "(attention|head|hidden|layer|norm|rope|rotary|position|sliding|activation|expert|moe|vocab|embedding|architecture|model_type)"
122
+ }
@@ -0,0 +1,80 @@
1
+ {
2
+ "$schema": "../schema/observation-policy-registry.schema.json",
3
+ "schema": "doppler.observation-policy-registry/v1",
4
+ "defaultPolicyId": "demo/always-on",
5
+ "policies": [
6
+ {
7
+ "id": "demo/always-on",
8
+ "label": "Always-on evidence",
9
+ "modifiesExecution": false,
10
+ "performanceRepresentative": true,
11
+ "requiredCaptures": [
12
+ "artifact-identity",
13
+ "prompt-token-ids",
14
+ "generated-token-ids",
15
+ "wall-timing"
16
+ ],
17
+ "allowedClaimTypes": [
18
+ "execution-identity",
19
+ "coarse-performance"
20
+ ],
21
+ "gpuTimestampQueries": false,
22
+ "perplexity": null
23
+ },
24
+ {
25
+ "id": "demo/guided-quality",
26
+ "label": "Guided quality inspection",
27
+ "modifiesExecution": true,
28
+ "performanceRepresentative": false,
29
+ "requiredCaptures": [
30
+ "artifact-identity",
31
+ "prompt-token-ids",
32
+ "generated-token-ids",
33
+ "selected-token-probabilities",
34
+ "top-candidates",
35
+ "word-quality"
36
+ ],
37
+ "allowedClaimTypes": [
38
+ "quality-inspection"
39
+ ],
40
+ "gpuTimestampQueries": false,
41
+ "perplexity": {
42
+ "wordSegmentation": "doppler.word-segmentation/unicode-whitespace-v1",
43
+ "aggregation": "doppler.perplexity/summed-word-surprisal-v1",
44
+ "rollingWindow": {
45
+ "unit": "words",
46
+ "size": 8
47
+ }
48
+ }
49
+ },
50
+ {
51
+ "id": "demo/deep-xray",
52
+ "label": "Deep X-Ray",
53
+ "modifiesExecution": true,
54
+ "performanceRepresentative": false,
55
+ "requiredCaptures": [
56
+ "artifact-identity",
57
+ "prompt-token-ids",
58
+ "generated-token-ids",
59
+ "selected-token-probabilities",
60
+ "top-candidates",
61
+ "word-quality",
62
+ "execution-plan",
63
+ "operator-diagnostics",
64
+ "gpu-timestamps"
65
+ ],
66
+ "allowedClaimTypes": [
67
+ "diagnostic"
68
+ ],
69
+ "gpuTimestampQueries": true,
70
+ "perplexity": {
71
+ "wordSegmentation": "doppler.word-segmentation/unicode-whitespace-v1",
72
+ "aggregation": "doppler.perplexity/summed-word-surprisal-v1",
73
+ "rollingWindow": {
74
+ "unit": "words",
75
+ "size": 8
76
+ }
77
+ }
78
+ }
79
+ ]
80
+ }