@simulatte/doppler 0.1.4 → 0.1.6

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 (199) hide show
  1. package/README.md +26 -10
  2. package/package.json +30 -6
  3. package/src/client/doppler-api.browser.d.ts +1 -0
  4. package/src/client/doppler-api.browser.js +288 -0
  5. package/src/client/doppler-api.js +1 -1
  6. package/src/client/doppler-provider/types.js +1 -1
  7. package/src/config/execution-contract-check.d.ts +33 -0
  8. package/src/config/execution-contract-check.js +72 -0
  9. package/src/config/execution-v0-contract-check.d.ts +94 -0
  10. package/src/config/execution-v0-contract-check.js +251 -0
  11. package/src/config/execution-v0-graph-contract-check.d.ts +20 -0
  12. package/src/config/execution-v0-graph-contract-check.js +64 -0
  13. package/src/config/kernel-path-contract-check.d.ts +76 -0
  14. package/src/config/kernel-path-contract-check.js +479 -0
  15. package/src/config/kernel-path-loader.d.ts +16 -0
  16. package/src/config/kernel-path-loader.js +54 -0
  17. package/src/config/kernels/kernel-ref-digests.js +39 -27
  18. package/src/config/kernels/registry.json +598 -2
  19. package/src/config/loader.js +81 -48
  20. package/src/config/merge-contract-check.d.ts +16 -0
  21. package/src/config/merge-contract-check.js +321 -0
  22. package/src/config/merge-helpers.d.ts +58 -0
  23. package/src/config/merge-helpers.js +54 -0
  24. package/src/config/merge.js +21 -6
  25. package/src/config/presets/models/janus-text.json +2 -0
  26. package/src/config/presets/models/qwen3.json +9 -2
  27. package/src/config/presets/models/transformer.json +5 -0
  28. package/src/config/quantization-contract-check.d.ts +12 -0
  29. package/src/config/quantization-contract-check.js +91 -0
  30. package/src/config/required-inference-fields-contract-check.d.ts +24 -0
  31. package/src/config/required-inference-fields-contract-check.js +237 -0
  32. package/src/config/schema/browser-suite-metrics.schema.d.ts +17 -0
  33. package/src/config/schema/browser-suite-metrics.schema.js +46 -0
  34. package/src/config/schema/conversion-report.schema.d.ts +40 -0
  35. package/src/config/schema/conversion-report.schema.js +108 -0
  36. package/src/config/schema/doppler.schema.js +12 -18
  37. package/src/config/schema/index.d.ts +22 -0
  38. package/src/config/schema/index.js +18 -0
  39. package/src/config/schema/inference-defaults.schema.js +3 -0
  40. package/src/config/schema/inference.schema.d.ts +9 -0
  41. package/src/config/schema/kernel-path.schema.d.ts +6 -0
  42. package/src/config/schema/manifest.schema.d.ts +6 -0
  43. package/src/config/schema/manifest.schema.js +3 -0
  44. package/src/converter/core.d.ts +10 -0
  45. package/src/converter/core.js +27 -2
  46. package/src/converter/parsers/diffusion.js +63 -3
  47. package/src/converter/rope-config.js +42 -0
  48. package/src/gpu/device.js +58 -0
  49. package/src/gpu/kernels/attention.js +98 -0
  50. package/src/gpu/kernels/bias_add.wgsl +8 -6
  51. package/src/gpu/kernels/bias_add_f16.wgsl +8 -5
  52. package/src/gpu/kernels/conv2d.js +1 -1
  53. package/src/gpu/kernels/conv2d.wgsl +7 -8
  54. package/src/gpu/kernels/conv2d_f16.wgsl +7 -8
  55. package/src/gpu/kernels/depthwise_conv2d.d.ts +29 -0
  56. package/src/gpu/kernels/depthwise_conv2d.js +99 -0
  57. package/src/gpu/kernels/depthwise_conv2d.wgsl +55 -0
  58. package/src/gpu/kernels/depthwise_conv2d_f16.wgsl +59 -0
  59. package/src/gpu/kernels/grouped_pointwise_conv2d.d.ts +27 -0
  60. package/src/gpu/kernels/grouped_pointwise_conv2d.js +93 -0
  61. package/src/gpu/kernels/grouped_pointwise_conv2d.wgsl +44 -0
  62. package/src/gpu/kernels/grouped_pointwise_conv2d_f16.wgsl +48 -0
  63. package/src/gpu/kernels/index.d.ts +30 -0
  64. package/src/gpu/kernels/index.js +25 -0
  65. package/src/gpu/kernels/matmul.js +25 -0
  66. package/src/gpu/kernels/pixel_shuffle.js +1 -1
  67. package/src/gpu/kernels/pixel_shuffle.wgsl +4 -5
  68. package/src/gpu/kernels/pixel_shuffle_f16.wgsl +4 -5
  69. package/src/gpu/kernels/relu.d.ts +18 -0
  70. package/src/gpu/kernels/relu.js +58 -0
  71. package/src/gpu/kernels/relu.wgsl +22 -0
  72. package/src/gpu/kernels/relu_f16.wgsl +24 -0
  73. package/src/gpu/kernels/repeat_channels.d.ts +21 -0
  74. package/src/gpu/kernels/repeat_channels.js +60 -0
  75. package/src/gpu/kernels/repeat_channels.wgsl +28 -0
  76. package/src/gpu/kernels/repeat_channels_f16.wgsl +30 -0
  77. package/src/gpu/kernels/residual.js +44 -8
  78. package/src/gpu/kernels/residual.wgsl +6 -3
  79. package/src/gpu/kernels/residual_f16.wgsl +2 -1
  80. package/src/gpu/kernels/residual_f16_vec4.wgsl +2 -1
  81. package/src/gpu/kernels/residual_vec4.wgsl +2 -1
  82. package/src/gpu/kernels/rmsnorm.js +58 -6
  83. package/src/gpu/kernels/rmsnorm.wgsl +14 -6
  84. package/src/gpu/kernels/rmsnorm_f16.wgsl +10 -2
  85. package/src/gpu/kernels/rope.d.ts +2 -0
  86. package/src/gpu/kernels/rope.js +11 -1
  87. package/src/gpu/kernels/rope.wgsl +56 -40
  88. package/src/gpu/kernels/sana_linear_attention.d.ts +27 -0
  89. package/src/gpu/kernels/sana_linear_attention.js +121 -0
  90. package/src/gpu/kernels/sana_linear_attention_apply.wgsl +43 -0
  91. package/src/gpu/kernels/sana_linear_attention_apply_f16.wgsl +46 -0
  92. package/src/gpu/kernels/sana_linear_attention_summary.wgsl +51 -0
  93. package/src/gpu/kernels/sana_linear_attention_summary_f16.wgsl +53 -0
  94. package/src/gpu/kernels/silu.d.ts +1 -0
  95. package/src/gpu/kernels/silu.js +32 -14
  96. package/src/gpu/kernels/silu.wgsl +19 -9
  97. package/src/gpu/kernels/silu_f16.wgsl +19 -9
  98. package/src/gpu/kernels/transpose.js +15 -2
  99. package/src/gpu/kernels/transpose.wgsl +5 -6
  100. package/src/gpu/kernels/upsample2d.js +2 -1
  101. package/src/gpu/kernels/upsample2d.wgsl +6 -9
  102. package/src/gpu/kernels/upsample2d_f16.wgsl +6 -9
  103. package/src/gpu/kernels/utils.js +16 -1
  104. package/src/index-browser.d.ts +1 -1
  105. package/src/index-browser.js +2 -2
  106. package/src/index.js +1 -1
  107. package/src/inference/browser-harness.js +109 -23
  108. package/src/inference/pipelines/diffusion/init.js +14 -0
  109. package/src/inference/pipelines/diffusion/pipeline.js +215 -77
  110. package/src/inference/pipelines/diffusion/sana-transformer.d.ts +53 -0
  111. package/src/inference/pipelines/diffusion/sana-transformer.js +738 -0
  112. package/src/inference/pipelines/diffusion/scheduler.d.ts +17 -1
  113. package/src/inference/pipelines/diffusion/scheduler.js +91 -3
  114. package/src/inference/pipelines/diffusion/text-encoder-gpu.d.ts +11 -4
  115. package/src/inference/pipelines/diffusion/text-encoder-gpu.js +282 -0
  116. package/src/inference/pipelines/diffusion/text-encoder.js +18 -1
  117. package/src/inference/pipelines/diffusion/types.d.ts +4 -0
  118. package/src/inference/pipelines/diffusion/vae.js +782 -78
  119. package/src/inference/pipelines/text/attention/record.js +11 -2
  120. package/src/inference/pipelines/text/attention/run.js +11 -2
  121. package/src/inference/pipelines/text/chat-format.js +25 -1
  122. package/src/inference/pipelines/text/config.d.ts +9 -0
  123. package/src/inference/pipelines/text/config.js +69 -2
  124. package/src/inference/pipelines/text/execution-plan.js +23 -31
  125. package/src/inference/pipelines/text/execution-v0.js +43 -95
  126. package/src/inference/pipelines/text/ffn/standard.js +3 -0
  127. package/src/inference/pipelines/text/init.d.ts +4 -0
  128. package/src/inference/pipelines/text/init.js +56 -9
  129. package/src/inference/pipelines/text/layer.js +11 -0
  130. package/src/inference/pipelines/text.js +4 -0
  131. package/src/inference/tokenizers/bundled.js +156 -33
  132. package/src/rules/execution-rules-contract-check.d.ts +17 -0
  133. package/src/rules/execution-rules-contract-check.js +245 -0
  134. package/src/rules/kernels/depthwise-conv2d.rules.json +6 -0
  135. package/src/rules/kernels/grouped-pointwise-conv2d.rules.json +6 -0
  136. package/src/rules/kernels/relu.rules.json +6 -0
  137. package/src/rules/kernels/repeat-channels.rules.json +6 -0
  138. package/src/rules/kernels/sana-linear-attention.rules.json +6 -0
  139. package/src/rules/layer-pattern-contract-check.d.ts +17 -0
  140. package/src/rules/layer-pattern-contract-check.js +231 -0
  141. package/src/rules/rule-registry.d.ts +28 -0
  142. package/src/rules/rule-registry.js +38 -0
  143. package/src/rules/tooling/command-runtime.rules.json +18 -0
  144. package/src/tooling/command-api.d.ts +27 -1
  145. package/src/tooling/command-api.js +142 -3
  146. package/src/tooling/conversion-config-materializer.d.ts +24 -0
  147. package/src/tooling/conversion-config-materializer.js +99 -0
  148. package/src/tooling/lean-execution-contract-runner.d.ts +43 -0
  149. package/src/tooling/lean-execution-contract-runner.js +158 -0
  150. package/src/tooling/node-browser-command-runner.d.ts +4 -0
  151. package/src/tooling/node-browser-command-runner.js +58 -3
  152. package/src/tooling/node-command-runner.js +15 -0
  153. package/src/tooling/node-convert.d.ts +10 -0
  154. package/src/tooling/node-converter.js +59 -0
  155. package/src/tooling/node-webgpu.js +11 -89
  156. package/src/training/checkpoint-watch.d.ts +7 -0
  157. package/src/training/checkpoint-watch.js +106 -0
  158. package/src/training/checkpoint.d.ts +6 -1
  159. package/src/training/checkpoint.js +12 -2
  160. package/src/training/distillation/artifacts.d.ts +71 -0
  161. package/src/training/distillation/artifacts.js +132 -0
  162. package/src/training/distillation/checkpoint-watch.d.ts +10 -0
  163. package/src/training/distillation/checkpoint-watch.js +57 -0
  164. package/src/training/distillation/dataset.d.ts +59 -0
  165. package/src/training/distillation/dataset.js +337 -0
  166. package/src/training/distillation/eval.d.ts +34 -0
  167. package/src/training/distillation/eval.js +310 -0
  168. package/src/training/distillation/index.d.ts +29 -0
  169. package/src/training/distillation/index.js +29 -0
  170. package/src/training/distillation/runtime.d.ts +20 -0
  171. package/src/training/distillation/runtime.js +121 -0
  172. package/src/training/distillation/scoreboard.d.ts +6 -0
  173. package/src/training/distillation/scoreboard.js +8 -0
  174. package/src/training/distillation/stage-a.d.ts +45 -0
  175. package/src/training/distillation/stage-a.js +338 -0
  176. package/src/training/distillation/stage-b.d.ts +24 -0
  177. package/src/training/distillation/stage-b.js +20 -0
  178. package/src/training/index.d.ts +10 -0
  179. package/src/training/index.js +10 -0
  180. package/src/training/lora-pipeline.d.ts +40 -0
  181. package/src/training/lora-pipeline.js +796 -0
  182. package/src/training/operator-artifacts.d.ts +62 -0
  183. package/src/training/operator-artifacts.js +140 -0
  184. package/src/training/operator-command.d.ts +5 -0
  185. package/src/training/operator-command.js +453 -0
  186. package/src/training/operator-eval.d.ts +48 -0
  187. package/src/training/operator-eval.js +230 -0
  188. package/src/training/operator-scoreboard.d.ts +5 -0
  189. package/src/training/operator-scoreboard.js +44 -0
  190. package/src/training/runner.d.ts +52 -0
  191. package/src/training/runner.js +29 -4
  192. package/src/training/suite.d.ts +112 -0
  193. package/src/training/suite.js +9 -9
  194. package/src/training/workloads.d.ts +164 -0
  195. package/src/training/workloads.js +539 -0
  196. package/src/version.d.ts +2 -0
  197. package/src/version.js +2 -0
  198. package/tools/convert-safetensors-node.js +47 -0
  199. package/tools/doppler-cli.js +252 -41
@@ -0,0 +1,94 @@
1
+ import type {
2
+ ExecutionV0ComputeDefaultsSchema,
3
+ ExecutionV0KernelProfileSchema,
4
+ ExecutionV0KernelRefSchema,
5
+ ExecutionV0KVIO,
6
+ ExecutionV0PrecisionSchema,
7
+ ExecutionV0SessionDefaultsSchema,
8
+ ExecutionV0StepSchema,
9
+ } from './schema/execution-v0.schema.js';
10
+
11
+ export interface ExecutionV0ContractCheckResult {
12
+ id: string;
13
+ ok: boolean;
14
+ }
15
+
16
+ export interface ExecutionV0ContractPerStep {
17
+ precision: {
18
+ inputDtype: string | null;
19
+ mathDtype: string | null;
20
+ accumDtype: string | null;
21
+ outputDtype: string | null;
22
+ };
23
+ precisionSources: {
24
+ inputDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
25
+ mathDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
26
+ accumDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
27
+ outputDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
28
+ };
29
+ resolvedPrecision?: {
30
+ inputDtype: 'f16' | 'f32' | null;
31
+ mathDtype: 'f16' | 'f32';
32
+ accumDtype: 'f16' | 'f32';
33
+ outputDtype: 'f16' | 'f32';
34
+ };
35
+ kvIO?: ExecutionV0KVIO;
36
+ kvIOSource?: 'manifest' | 'kernelProfile' | 'sessionDefault';
37
+ }
38
+
39
+ export interface ExecutionV0ContractArtifact {
40
+ schemaVersion: 1;
41
+ source: 'doppler';
42
+ ok: boolean;
43
+ checks: ExecutionV0ContractCheckResult[];
44
+ errors: string[];
45
+ stats: {
46
+ kernelProfiles: number;
47
+ pinnedSteps: number;
48
+ };
49
+ perStep: Record<string, ExecutionV0ContractPerStep>;
50
+ }
51
+
52
+ export declare function normalizeExecutionV0Dtype(value: unknown, label: string): 'f16' | 'f32';
53
+ export declare function buildExecutionV0KernelProfileKey(
54
+ kernelRef: ExecutionV0KernelRefSchema | null | undefined
55
+ ): string | null;
56
+ export declare function indexExecutionV0KernelProfiles(
57
+ sessionDefaults?: Partial<ExecutionV0SessionDefaultsSchema> | null
58
+ ): Map<string, ExecutionV0KernelProfileSchema>;
59
+ export declare function resolveExecutionV0KernelProfile(
60
+ profileIndex: Map<string, ExecutionV0KernelProfileSchema>,
61
+ step: Partial<ExecutionV0StepSchema>
62
+ ): ExecutionV0KernelProfileSchema | null;
63
+ export declare function resolveExecutionV0Precision(
64
+ step: Partial<ExecutionV0StepSchema>,
65
+ profile: ExecutionV0KernelProfileSchema | null,
66
+ sessionDefaults?: Partial<ExecutionV0SessionDefaultsSchema> | null
67
+ ): {
68
+ precision: {
69
+ inputDtype: 'f16' | 'f32' | null;
70
+ mathDtype: 'f16' | 'f32';
71
+ accumDtype: 'f16' | 'f32';
72
+ outputDtype: 'f16' | 'f32';
73
+ };
74
+ sources: {
75
+ inputDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
76
+ mathDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
77
+ accumDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
78
+ outputDtype: 'manifest' | 'kernelProfile' | 'sessionDefault' | 'derived';
79
+ };
80
+ };
81
+ export declare function resolveExecutionV0KVIO(
82
+ step: Partial<ExecutionV0StepSchema>,
83
+ profile: ExecutionV0KernelProfileSchema | null,
84
+ sessionDefaults?: Partial<ExecutionV0SessionDefaultsSchema> | null
85
+ ): {
86
+ value: ExecutionV0KVIO;
87
+ source: 'manifest' | 'kernelProfile' | 'sessionDefault';
88
+ };
89
+ export declare function buildExecutionV0ContractArtifact(
90
+ manifestInference: Record<string, unknown> | null | undefined,
91
+ options?: {
92
+ modelId?: string;
93
+ }
94
+ ): ExecutionV0ContractArtifact | null;
@@ -0,0 +1,251 @@
1
+ import {
2
+ DEFAULT_EXECUTION_V0_COMPUTE_DEFAULTS,
3
+ isExecutionV0Digest,
4
+ isExecutionV0Semver,
5
+ } from './schema/execution-v0.schema.js';
6
+
7
+ function normalizeDtype(value, label) {
8
+ const normalized = String(value ?? '').trim().toLowerCase();
9
+ if (normalized !== 'f16' && normalized !== 'f32') {
10
+ throw new Error(`[ExecutionV0Contract] ${label} must be "f16" or "f32"; got "${value}"`);
11
+ }
12
+ return normalized;
13
+ }
14
+
15
+ function buildKernelProfileKey(kernelRef) {
16
+ if (!kernelRef) return null;
17
+ return `${kernelRef.id}|${kernelRef.version}|${kernelRef.digest}`;
18
+ }
19
+
20
+ function assertExecutionV0KernelRef(kernelRef, label) {
21
+ if (!kernelRef || typeof kernelRef !== 'object' || Array.isArray(kernelRef)) {
22
+ throw new Error(`[ExecutionV0Contract] ${label} is required.`);
23
+ }
24
+ if (typeof kernelRef.id !== 'string' || kernelRef.id.trim().length === 0) {
25
+ throw new Error(`[ExecutionV0Contract] ${label}.id is required.`);
26
+ }
27
+ if (!isExecutionV0Semver(kernelRef.version)) {
28
+ throw new Error(`[ExecutionV0Contract] ${label}.version must be semver.`);
29
+ }
30
+ if (!isExecutionV0Digest(kernelRef.digest)) {
31
+ throw new Error(`[ExecutionV0Contract] ${label}.digest must match sha256:<64-hex>.`);
32
+ }
33
+ }
34
+
35
+ function createPrecisionSources(step, profile) {
36
+ return {
37
+ inputDtype: step.precision?.inputDtype != null
38
+ ? 'manifest'
39
+ : profile?.precision?.inputDtype != null
40
+ ? 'kernelProfile'
41
+ : 'derived',
42
+ mathDtype: step.precision?.mathDtype != null
43
+ ? 'manifest'
44
+ : profile?.precision?.mathDtype != null
45
+ ? 'kernelProfile'
46
+ : 'sessionDefault',
47
+ accumDtype: step.precision?.accumDtype != null
48
+ ? 'manifest'
49
+ : profile?.precision?.accumDtype != null
50
+ ? 'kernelProfile'
51
+ : 'sessionDefault',
52
+ outputDtype: step.precision?.outputDtype != null
53
+ ? 'manifest'
54
+ : profile?.precision?.outputDtype != null
55
+ ? 'kernelProfile'
56
+ : 'sessionDefault',
57
+ };
58
+ }
59
+
60
+ export function normalizeExecutionV0Dtype(value, label) {
61
+ return normalizeDtype(value, label);
62
+ }
63
+
64
+ export function buildExecutionV0KernelProfileKey(kernelRef) {
65
+ return buildKernelProfileKey(kernelRef);
66
+ }
67
+
68
+ export function indexExecutionV0KernelProfiles(sessionDefaults = {}) {
69
+ const byKey = new Map();
70
+ const profiles = sessionDefaults?.compute?.kernelProfiles ?? [];
71
+ for (const profile of profiles) {
72
+ assertExecutionV0KernelRef(profile?.kernelRef, 'sessionDefaults.compute.kernelProfiles[].kernelRef');
73
+ const key = buildKernelProfileKey(profile?.kernelRef);
74
+ if (byKey.has(key)) {
75
+ throw new Error(
76
+ `[ExecutionV0Contract] duplicate kernel profile for ${profile.kernelRef.id}@${profile.kernelRef.version} ` +
77
+ `(${profile.kernelRef.digest}). Expected exactly one pinned profile per kernelRef.`
78
+ );
79
+ }
80
+ byKey.set(key, profile);
81
+ }
82
+ return byKey;
83
+ }
84
+
85
+ export function resolveExecutionV0KernelProfile(profileIndex, step) {
86
+ const key = buildKernelProfileKey(step?.kernelRef);
87
+ if (!key) return null;
88
+ return profileIndex.get(key) ?? null;
89
+ }
90
+
91
+ export function resolveExecutionV0Precision(step, profile, sessionDefaults = {}) {
92
+ const defaults = {
93
+ ...DEFAULT_EXECUTION_V0_COMPUTE_DEFAULTS,
94
+ ...(sessionDefaults?.compute?.defaults ?? {}),
95
+ };
96
+ const precision = {
97
+ inputDtype: step.precision?.inputDtype
98
+ ?? profile?.precision?.inputDtype
99
+ ?? null,
100
+ mathDtype: step.precision?.mathDtype
101
+ ?? profile?.precision?.mathDtype
102
+ ?? defaults.mathDtype,
103
+ accumDtype: step.precision?.accumDtype
104
+ ?? profile?.precision?.accumDtype
105
+ ?? defaults.accumDtype,
106
+ outputDtype: step.precision?.outputDtype
107
+ ?? profile?.precision?.outputDtype
108
+ ?? defaults.outputDtype,
109
+ };
110
+ return {
111
+ precision,
112
+ sources: createPrecisionSources(step, profile),
113
+ };
114
+ }
115
+
116
+ export function resolveExecutionV0KVIO(step, profile, sessionDefaults = {}) {
117
+ if (step.kvIO) {
118
+ return {
119
+ value: {
120
+ readDtype: normalizeDtype(step.kvIO.readDtype, `${step.id}.kvIO.readDtype`),
121
+ writeDtype: normalizeDtype(step.kvIO.writeDtype, `${step.id}.kvIO.writeDtype`),
122
+ },
123
+ source: 'manifest',
124
+ };
125
+ }
126
+ if (profile?.kvIO) {
127
+ return {
128
+ value: {
129
+ readDtype: normalizeDtype(profile.kvIO.readDtype, `${step.id}.profile.kvIO.readDtype`),
130
+ writeDtype: normalizeDtype(profile.kvIO.writeDtype, `${step.id}.profile.kvIO.writeDtype`),
131
+ },
132
+ source: 'kernelProfile',
133
+ };
134
+ }
135
+ const defaults = {
136
+ ...DEFAULT_EXECUTION_V0_COMPUTE_DEFAULTS,
137
+ ...(sessionDefaults?.compute?.defaults ?? {}),
138
+ };
139
+ const kvDtype = normalizeDtype(
140
+ sessionDefaults?.kvcache?.kvDtype ?? defaults.activationDtype,
141
+ `${step.id}.sessionDefaults.kvcache.kvDtype`
142
+ );
143
+ return {
144
+ value: { readDtype: kvDtype, writeDtype: kvDtype },
145
+ source: 'sessionDefault',
146
+ };
147
+ }
148
+
149
+ export function buildExecutionV0ContractArtifact(manifestInference, options = {}) {
150
+ if (!manifestInference?.execution || !Array.isArray(manifestInference.execution.steps)) {
151
+ return null;
152
+ }
153
+
154
+ const modelId = String(options.modelId ?? 'model');
155
+ const checks = [];
156
+ const errors = [];
157
+ const perStep = {};
158
+ const sessionDefaults = manifestInference.sessionDefaults ?? {};
159
+ let profileIndex;
160
+
161
+ try {
162
+ profileIndex = indexExecutionV0KernelProfiles(sessionDefaults);
163
+ } catch (error) {
164
+ errors.push(error instanceof Error ? error.message : String(error));
165
+ checks.push({ id: `${modelId}.kernelProfilePinning`, ok: false });
166
+ checks.push({ id: `${modelId}.precisionPrecedence`, ok: false });
167
+ checks.push({ id: `${modelId}.kvIOPrecedence`, ok: false });
168
+ return {
169
+ schemaVersion: 1,
170
+ source: 'doppler',
171
+ ok: false,
172
+ checks,
173
+ errors,
174
+ stats: {
175
+ kernelProfiles: sessionDefaults?.compute?.kernelProfiles?.length ?? 0,
176
+ pinnedSteps: 0,
177
+ },
178
+ perStep,
179
+ };
180
+ }
181
+
182
+ let pinningOk = true;
183
+ let precisionOk = true;
184
+ let kvOk = true;
185
+ let pinnedSteps = 0;
186
+
187
+ for (const step of manifestInference.execution.steps) {
188
+ if (!step || typeof step !== 'object') continue;
189
+ if (step.op === 'cast') continue;
190
+ if (!step.kernelRef) {
191
+ pinningOk = false;
192
+ precisionOk = false;
193
+ errors.push(`[ExecutionV0Contract] step "${step.id ?? 'unknown'}" requires kernelRef.`);
194
+ continue;
195
+ }
196
+ const profile = resolveExecutionV0KernelProfile(profileIndex, step);
197
+ if (!profile) {
198
+ pinningOk = false;
199
+ precisionOk = false;
200
+ errors.push(
201
+ `[ExecutionV0Contract] step "${step.id ?? 'unknown'}" kernelRef ` +
202
+ `${step.kernelRef.id}@${step.kernelRef.version} (${step.kernelRef.digest}) is unresolved.`
203
+ );
204
+ continue;
205
+ }
206
+ pinnedSteps += 1;
207
+ const { precision, sources } = resolveExecutionV0Precision(step, profile, sessionDefaults);
208
+ perStep[step.id] = {
209
+ precision,
210
+ precisionSources: sources,
211
+ };
212
+ try {
213
+ perStep[step.id].resolvedPrecision = {
214
+ inputDtype: precision.inputDtype == null ? null : normalizeDtype(precision.inputDtype, `${step.id}.precision.inputDtype`),
215
+ mathDtype: normalizeDtype(precision.mathDtype, `${step.id}.precision.mathDtype`),
216
+ accumDtype: normalizeDtype(precision.accumDtype, `${step.id}.precision.accumDtype`),
217
+ outputDtype: normalizeDtype(precision.outputDtype, `${step.id}.precision.outputDtype`),
218
+ };
219
+ } catch (error) {
220
+ precisionOk = false;
221
+ errors.push(error instanceof Error ? error.message : String(error));
222
+ }
223
+ if (step.op === 'attention') {
224
+ try {
225
+ const kvIO = resolveExecutionV0KVIO(step, profile, sessionDefaults);
226
+ perStep[step.id].kvIO = kvIO.value;
227
+ perStep[step.id].kvIOSource = kvIO.source;
228
+ } catch (error) {
229
+ kvOk = false;
230
+ errors.push(error instanceof Error ? error.message : String(error));
231
+ }
232
+ }
233
+ }
234
+
235
+ checks.push({ id: `${modelId}.kernelProfilePinning`, ok: pinningOk });
236
+ checks.push({ id: `${modelId}.precisionPrecedence`, ok: precisionOk });
237
+ checks.push({ id: `${modelId}.kvIOPrecedence`, ok: kvOk });
238
+
239
+ return {
240
+ schemaVersion: 1,
241
+ source: 'doppler',
242
+ ok: errors.length === 0,
243
+ checks,
244
+ errors,
245
+ stats: {
246
+ kernelProfiles: sessionDefaults?.compute?.kernelProfiles?.length ?? 0,
247
+ pinnedSteps,
248
+ },
249
+ perStep,
250
+ };
251
+ }
@@ -0,0 +1,20 @@
1
+ export interface ExecutionV0GraphContractCheckResult {
2
+ id: string;
3
+ ok: boolean;
4
+ }
5
+
6
+ export interface ExecutionV0GraphContractArtifact {
7
+ schemaVersion: 1;
8
+ source: 'doppler';
9
+ ok: boolean;
10
+ checks: ExecutionV0GraphContractCheckResult[];
11
+ errors: string[];
12
+ stats: {
13
+ prefillSteps: number;
14
+ decodeSteps: number;
15
+ };
16
+ }
17
+
18
+ export declare function buildExecutionV0GraphContractArtifact(
19
+ options?: Record<string, unknown>
20
+ ): ExecutionV0GraphContractArtifact | null;
@@ -0,0 +1,64 @@
1
+ import { compileExecutionV0 } from '../inference/pipelines/text/execution-v0.js';
2
+
3
+ function classifyGraphError(error) {
4
+ const message = error instanceof Error ? error.message : String(error);
5
+ if (message.includes('reads slot "') && message.includes('before it is produced')) {
6
+ return {
7
+ slotGraphOk: false,
8
+ phaseBoundaryOk: true,
9
+ error: message,
10
+ };
11
+ }
12
+ if (message.includes('reads carried slot "') && message.includes('Add explicit cast at phase boundary')) {
13
+ return {
14
+ slotGraphOk: true,
15
+ phaseBoundaryOk: false,
16
+ error: message,
17
+ };
18
+ }
19
+ return {
20
+ slotGraphOk: false,
21
+ phaseBoundaryOk: false,
22
+ error: message,
23
+ };
24
+ }
25
+
26
+ export function buildExecutionV0GraphContractArtifact(options = {}) {
27
+ const modelId = String(options.modelId ?? 'model');
28
+ try {
29
+ const compiled = compileExecutionV0(options);
30
+ if (!compiled) {
31
+ return null;
32
+ }
33
+ return {
34
+ schemaVersion: 1,
35
+ source: 'doppler',
36
+ ok: true,
37
+ checks: [
38
+ { id: `${modelId}.slotGraph`, ok: true },
39
+ { id: `${modelId}.phaseBoundary`, ok: true },
40
+ ],
41
+ errors: [],
42
+ stats: {
43
+ prefillSteps: compiled.resolvedSteps.prefill.length,
44
+ decodeSteps: compiled.resolvedSteps.decode.length,
45
+ },
46
+ };
47
+ } catch (error) {
48
+ const classified = classifyGraphError(error);
49
+ return {
50
+ schemaVersion: 1,
51
+ source: 'doppler',
52
+ ok: false,
53
+ checks: [
54
+ { id: `${modelId}.slotGraph`, ok: classified.slotGraphOk },
55
+ { id: `${modelId}.phaseBoundary`, ok: classified.phaseBoundaryOk },
56
+ ],
57
+ errors: [classified.error],
58
+ stats: {
59
+ prefillSteps: 0,
60
+ decodeSteps: 0,
61
+ },
62
+ };
63
+ }
64
+ }
@@ -0,0 +1,76 @@
1
+ export interface KernelPathContractEntryFacts {
2
+ id: string;
3
+ aliasOf: string | null;
4
+ hasFile: boolean;
5
+ }
6
+
7
+ export interface KernelPathFallbackMappingFacts {
8
+ primaryKernelPathId: string;
9
+ fallbackKernelPathId: string;
10
+ primaryActivationDtype: 'f16' | 'f32';
11
+ fallbackActivationDtype: 'f16' | 'f32' | null;
12
+ }
13
+
14
+ export interface KernelPathContractFacts {
15
+ registryId: string;
16
+ entries: KernelPathContractEntryFacts[];
17
+ fallbackMappings: KernelPathFallbackMappingFacts[];
18
+ fallbackRules?: Array<{
19
+ matchKernelPathId: string | null;
20
+ value: string | null;
21
+ isDefault: boolean;
22
+ }>;
23
+ autoSelectRules?: Array<{
24
+ matchKernelPathRef: string | null;
25
+ allowCapabilityAutoSelection: boolean | null;
26
+ hasSubgroups: boolean | null;
27
+ valueKind: 'string' | 'context';
28
+ value: string;
29
+ isDefault: boolean;
30
+ }>;
31
+ }
32
+
33
+ export interface KernelPathContractCheckResult {
34
+ id: string;
35
+ ok: boolean;
36
+ }
37
+
38
+ export interface KernelPathContractValidationResult {
39
+ ok: boolean;
40
+ errors: string[];
41
+ checks: KernelPathContractCheckResult[];
42
+ }
43
+
44
+ export interface KernelPathContractArtifact {
45
+ schemaVersion: 1;
46
+ source: 'doppler';
47
+ ok: boolean;
48
+ checks: KernelPathContractCheckResult[];
49
+ errors: string[];
50
+ stats: {
51
+ totalEntries: number;
52
+ aliasEntries: number;
53
+ canonicalEntries: number;
54
+ fallbackMappings: number;
55
+ fallbackRules: number;
56
+ autoSelectRules: number;
57
+ };
58
+ }
59
+
60
+ export declare function extractKernelPathContractFacts(
61
+ input: Record<string, unknown> | unknown[],
62
+ options?: {
63
+ registryId?: string;
64
+ }
65
+ ): KernelPathContractFacts;
66
+
67
+ export declare function validateKernelPathContractFacts(
68
+ facts: KernelPathContractFacts
69
+ ): KernelPathContractValidationResult;
70
+
71
+ export declare function buildKernelPathContractArtifact(
72
+ input: Record<string, unknown> | unknown[],
73
+ options?: {
74
+ registryId?: string;
75
+ }
76
+ ): KernelPathContractArtifact;