doppler-gpu 0.6.0 → 0.7.0

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 (1447) hide show
  1. package/CHANGELOG.md +100 -38
  2. package/README.md +47 -195
  3. package/models/catalog.json +108 -51
  4. package/package.json +99 -123
  5. package/src/capsule-runtime.d.ts +17 -8
  6. package/src/capsule-runtime.js +8 -3
  7. package/src/cli/cli-output.js +85 -9
  8. package/src/cli/doppler-cli.js +23 -21
  9. package/src/client/capsule-host.browser.js +7 -0
  10. package/src/client/capsule-host.d.ts +13 -0
  11. package/src/client/capsule-host.js +7 -0
  12. package/src/client/doppler-api.browser.js +1 -1
  13. package/src/client/doppler-api.d.ts +3 -0
  14. package/src/client/doppler-api.js +2 -1
  15. package/src/client/doppler-registry.js +6 -0
  16. package/src/client/inspection.d.ts +10 -1
  17. package/src/client/inspection.js +24 -12
  18. package/src/client/model-host/index.d.ts +3 -0
  19. package/src/client/model-host/index.js +73 -18
  20. package/src/client/model-host/model-session.d.ts +42 -17
  21. package/src/client/model-host/model-session.js +291 -150
  22. package/src/client/model-host/source-loading.js +910 -0
  23. package/src/client/provider.js +6 -6
  24. package/src/client/resident-partitions.d.ts +30 -0
  25. package/src/client/resident-partitions.js +114 -0
  26. package/src/client/runtime/capsule-acquisition.d.ts +17 -2
  27. package/src/client/runtime/capsule-artifact-source.js +23 -1
  28. package/src/client/runtime/capsule-operation-adapters.d.ts +3 -2
  29. package/src/client/runtime/capsule-operation-adapters.js +55 -18
  30. package/src/client/runtime/capsule-operation-deltas.js +44 -0
  31. package/src/client/runtime/capsule-operation-executor.d.ts +2 -2
  32. package/src/client/runtime/capsule-operation-executor.js +14 -7
  33. package/src/client/runtime/capsule-operation-stream.d.ts +10 -0
  34. package/src/client/runtime/capsule-operation-stream.js +81 -0
  35. package/src/client/runtime/capsule-piece-reader.js +88 -0
  36. package/src/client/runtime/capsule-program-adapter.js +51 -19
  37. package/src/client/runtime/capsule-session-execution.js +9 -5
  38. package/src/client/runtime/command-executor.d.ts +13 -0
  39. package/src/client/runtime/command-executor.js +54 -11
  40. package/src/client/runtime/composition-root.d.ts +41 -15
  41. package/src/client/runtime/composition-root.js +198 -61
  42. package/src/client/runtime/fetch-capsule-artifact-store.d.ts +3 -2
  43. package/src/client/runtime/fetch-capsule-artifact-store.js +56 -1
  44. package/src/client/runtime/lora.d.ts +22 -0
  45. package/src/client/runtime/lora.js +86 -26
  46. package/src/client/runtime/model-manager.js +10 -75
  47. package/src/client/runtime/model-source.d.ts +1 -0
  48. package/src/client/runtime/model-source.js +1 -1
  49. package/src/client/runtime/node-quickstart-cache.js +7 -2
  50. package/src/client/runtime/resource-binder.d.ts +1 -0
  51. package/src/client/runtime/resource-binder.js +20 -14
  52. package/src/client/runtime/scoped-session.d.ts +10 -0
  53. package/src/client/runtime/scoped-session.js +41 -3
  54. package/src/client/runtime/session-controller.d.ts +19 -16
  55. package/src/client/runtime/session-controller.js +128 -134
  56. package/src/client/runtime/verified-capsule-artifact-store.d.ts +27 -0
  57. package/src/client/runtime/verified-capsule-artifact-store.js +266 -40
  58. package/src/client/wrap-pipeline-handle.js +23 -17
  59. package/src/config/canonical-contract-codec.d.ts +10 -0
  60. package/src/config/canonical-contract-codec.js +144 -0
  61. package/src/config/canonical-generation-policy.d.ts +7 -0
  62. package/src/config/canonical-generation-policy.js +66 -0
  63. package/src/config/capsule-loading.d.ts +5 -1
  64. package/src/config/capsule-loading.js +1 -1
  65. package/src/config/capsule-loading.schema.json +63 -3
  66. package/src/config/capsule-operation.d.ts +10 -3
  67. package/src/config/capsule-operation.js +12 -2
  68. package/src/config/capsule-operations.json +27 -3
  69. package/src/config/capsule-release-contract.js +2 -29
  70. package/src/config/capsule-token-selection.d.ts +15 -0
  71. package/src/config/capsule-token-selection.js +39 -0
  72. package/src/config/capsule-token-selection.json +11 -0
  73. package/src/config/capsule-v2.d.ts +1 -0
  74. package/src/config/capsule-v2.js +14 -21
  75. package/src/config/choice-scoring-reference.js +66 -0
  76. package/src/config/choice-scoring.d.ts +21 -0
  77. package/src/config/choice-scoring.js +66 -0
  78. package/src/config/choice-scoring.json +8 -0
  79. package/src/config/conversion/amplify/amplify-120m-f16-af32.json +4 -4
  80. package/src/config/conversion/diffusiongemma/diffusiongemma-26b-a4b-it-q4k-ehf16-af16.json +9 -9
  81. package/src/config/conversion/embeddinggemma/google-embeddinggemma-300m-q4k-ehf16-af32.json +4 -4
  82. package/src/config/conversion/esm/esm2-t12-35m-ur50d-f32-af32.json +42 -20
  83. package/src/config/conversion/esmc/esmc-300m-f32-af32.json +260 -55
  84. package/src/config/conversion/gemma3/gemma-3-1b-it-f16-af32.json +17 -11
  85. package/src/config/conversion/gemma3/gemma-3-1b-it-q4k-ehf16-af32.json +10 -9
  86. package/src/config/conversion/gemma3/gemma-3-270m-it-f16-af32.json +7 -7
  87. package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af16.json +10 -10
  88. package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af32.json +9 -8
  89. package/src/config/conversion/gemma3/gemma-3-270m-it-w8a8-ehf16-af32.json +491 -0
  90. package/src/config/conversion/gemma3/translategemma-4b-1b-enes-q4k-ehf16-af32.json +6 -6
  91. package/src/config/conversion/gemma3/translategemma-4b-it-q4k-ehf16-af32.json +10 -9
  92. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af16.json +26 -10
  93. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af32.json +26 -10
  94. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-hq4k-af16.json +29 -13
  95. package/src/config/conversion/gemma4/gemma-4-12b-it-text-w4a16-ct-ehf16-af16.json +22 -6
  96. package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af16.json +28 -11
  97. package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af32.json +28 -11
  98. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af16-int4ple.json +28 -11
  99. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32-int4ple.json +26 -9
  100. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32.json +26 -9
  101. package/src/config/conversion/gemma4/gemma-4-moe-q4k-ehf16-af32.json +8 -7
  102. package/src/config/conversion/glmocr/glm-ocr-f16-af32.json +7 -7
  103. package/src/config/conversion/gpt-oss-20b-f16-xmxfp4.json +8 -7
  104. package/src/config/conversion/janus/janus-pro-1b-text-q4k-ehaf16.json +8 -7
  105. package/src/config/conversion/lfm2/lfm2.5-1.2b-instruct-q4k-ehf16-af32.json +20 -12
  106. package/src/config/conversion/minicpm/minicpm4-0-5b-f16-af32.json +7 -9
  107. package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-bf16-af32.json +7 -7
  108. package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-f16-af32.json +7 -7
  109. package/src/config/conversion/nucleotide-transformer/nucleotide-transformer-v2-50m-f32-af32.json +252 -53
  110. package/src/config/conversion/qwen3/qwen-3-4b-instruct-2507-q4k-ehf16-af32.json +501 -0
  111. package/src/config/conversion/qwen3/qwen-3-5-0-8b-canonical-f32.json +461 -0
  112. package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +11 -11
  113. package/src/config/conversion/qwen3/qwen-3-5-2b-q4k-ehaf16.json +11 -11
  114. package/src/config/conversion/qwen3/qwen-3-5-9b-f16-af32.json +7 -7
  115. package/src/config/conversion/qwen3/qwen-3-5-9b-q4k-ehaf16.json +11 -11
  116. package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-eaf16.json +11 -11
  117. package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-ehaf16.json +11 -11
  118. package/src/config/conversion/qwen3/qwen-3-6-35b-a3b-q4_0-passthrough.json +1218 -0
  119. package/src/config/conversion/qwen3/qwen-3-6-35b-a3b-text-q4k-ehf16-af32.json +581 -0
  120. package/src/config/conversion/qwen3/qwen-3-8-flash-next-text-q4k-ehf16-af32.json +1063 -0
  121. package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-f16-af32.json +11 -11
  122. package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-q4k-ehf16-af32.json +7 -7
  123. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-af32.json +18 -10
  124. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-true-logit-af32.json +10 -10
  125. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-q4k-ehf16-af32.json +18 -18
  126. package/src/config/conversion/qwen3/qwen3.8-27b-q4_0-passthrough.json +823 -0
  127. package/src/config/conversion/qwen3/qwen3.8-27b-text-f16-af32.json +11 -11
  128. package/src/config/conversion/qwen3/qwen3.8-27b-text-q4k-ehaf16.json +11 -11
  129. package/src/config/embedding-contract.d.ts +17 -0
  130. package/src/config/embedding-contract.js +12 -0
  131. package/src/config/embedding-reference.js +32 -0
  132. package/src/config/execution-registry-contract.d.ts +41 -0
  133. package/src/config/execution-registry-contract.js +171 -0
  134. package/src/config/generation-contract.d.ts +66 -0
  135. package/src/config/generation-contract.js +66 -0
  136. package/src/config/generation-contract.json +151 -0
  137. package/src/config/initial-execution-identity.d.ts +1 -1
  138. package/src/config/initial-execution-identity.js +9 -9
  139. package/src/config/inspection/activity-stages.json +14 -0
  140. package/src/config/inspection/observation-policies.json +123 -0
  141. package/src/config/kernel-path-loader.d.ts +37 -0
  142. package/src/config/kernel-path-loader.js +87 -12
  143. package/src/config/kernel-registry-contract.d.ts +78 -13
  144. package/src/config/kernel-registry-contract.js +110 -38
  145. package/src/config/kernels/backward-registry.json +1 -1
  146. package/src/config/kernels/registry.js +3 -47
  147. package/src/config/kernels/registry.json +31642 -7719
  148. package/src/config/layer-partition-plan.d.ts +93 -0
  149. package/src/config/layer-partition-plan.js +305 -0
  150. package/src/config/manifest-inference-validation.js +10 -0
  151. package/src/config/merge/execution-patches.js +14 -0
  152. package/src/config/merge.d.ts +4 -0
  153. package/src/config/merge.js +50 -0
  154. package/src/config/model-ir-v2.d.ts +1 -0
  155. package/src/config/model-ir-v2.js +5 -16
  156. package/src/config/model-ir.js +9 -14
  157. package/src/config/ordered-resident-qualification.d.ts +16 -0
  158. package/src/config/ordered-resident-qualification.js +62 -0
  159. package/src/config/param-categories.js +4 -0
  160. package/src/config/param-validator.js +64 -29
  161. package/src/config/production-release-evidence.js +2 -27
  162. package/src/config/production-release.js +2 -29
  163. package/src/config/quickstart-registry.json +57 -8
  164. package/src/config/reasoning-output.d.ts +6 -0
  165. package/src/config/reasoning-output.js +26 -0
  166. package/src/config/revocation-policy.js +1 -4
  167. package/src/config/rope-frequencies.js +9 -0
  168. package/src/config/runtime/profiles/demo-f16-comparison.json +20 -0
  169. package/src/config/runtime/profiles/flash-next-node-host-cache-qualification.json +21 -0
  170. package/src/config/runtime/profiles/flash-next-paged-qualification.json +23 -0
  171. package/src/config/runtime/profiles/flash-next-routed-f32kv-qualification.json +72 -0
  172. package/src/config/runtime/profiles/flash-next-routed-qualification.json +27 -0
  173. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-parity.json +51 -2
  174. package/src/config/runtime/profiles/qwen-3-5-0-8b-vulkan-parity.json +88 -0
  175. package/src/config/runtime/profiles/qwen-3-5-0-8b-vulkan-subgroup8.json +173 -0
  176. package/src/config/runtime/profiles/qwen-3-5-0-8b-vulkan-throughput.json +33 -0
  177. package/src/config/runtime/profiles/qwen-3-5-2b-metal-throughput.json +51 -2
  178. package/src/config/runtime/profiles/qwen-3-5-2b-vulkan-parity.json +15 -0
  179. package/src/config/runtime/profiles/qwen3-6-35b-a3b-q4_0-candidate.json +4491 -0
  180. package/src/config/runtime/profiles/qwen3-6-35b-a3b-q4_0-pooled-q8-common-diagnostic.json +4407 -0
  181. package/src/config/runtime/profiles/qwen3-6-35b-a3b-route-f32-candidate.json +17 -0
  182. package/src/config/runtime/profiles/qwen3-6-35b-a3b-route-f32-workspace-candidate.json +13 -0
  183. package/src/config/runtime.d.ts +6 -0
  184. package/src/config/runtime.js +51 -21
  185. package/src/config/schema/benchmark.schema.d.ts +1 -0
  186. package/src/config/schema/benchmark.schema.js +2 -0
  187. package/src/config/schema/conversion.schema.d.ts +5 -0
  188. package/src/config/schema/converter.schema.d.ts +10 -0
  189. package/src/config/schema/converter.schema.js +10 -0
  190. package/src/config/schema/debug.schema.d.ts +1 -0
  191. package/src/config/schema/doppler.schema.js +17 -9
  192. package/src/config/schema/emulation.schema.js +0 -77
  193. package/src/config/schema/execution-v1.schema.d.ts +32 -2
  194. package/src/config/schema/execution-v1.schema.js +8 -0
  195. package/src/config/schema/fp8.schema.d.ts +17 -0
  196. package/src/config/schema/fp8.schema.js +27 -0
  197. package/src/config/schema/hyper-connection-decoder.schema.d.ts +98 -0
  198. package/src/config/schema/hyper-connection-decoder.schema.js +213 -0
  199. package/src/config/schema/index.d.ts +2 -2
  200. package/src/config/schema/index.js +3 -0
  201. package/src/config/schema/inference.schema.d.ts +8 -2
  202. package/src/config/schema/kernel-registry.schema.d.ts +22 -7
  203. package/src/config/schema/kernel-registry.schema.js +13 -2
  204. package/src/config/schema/kernel-thresholds.schema.d.ts +3 -0
  205. package/src/config/schema/kernel-thresholds.schema.js +14 -3
  206. package/src/config/schema/kernel-warmup.schema.d.ts +15 -0
  207. package/src/config/schema/kernel-warmup.schema.js +3 -0
  208. package/src/config/schema/loading.schema.d.ts +41 -0
  209. package/src/config/schema/loading.schema.js +67 -0
  210. package/src/config/schema/manifest-rope.schema.d.ts +55 -0
  211. package/src/config/schema/manifest.schema.d.ts +47 -57
  212. package/src/config/schema/manifest.schema.js +41 -2
  213. package/src/config/schema/ngram-embedding.schema.d.ts +116 -0
  214. package/src/config/schema/ngram-embedding.schema.js +312 -0
  215. package/src/config/schema/program-bundle.schema.d.ts +1 -0
  216. package/src/config/schema/program-bundle.schema.js +8 -3
  217. package/src/config/schema/quantization-defaults.schema.d.ts +1 -1
  218. package/src/config/schema/quantization.schema.d.ts +2 -0
  219. package/src/config/schema/quantization.schema.js +2 -0
  220. package/src/config/schema/speculation-self.schema.d.ts +6 -1
  221. package/src/config/schema/speculation-self.schema.js +29 -2
  222. package/src/config/schema/w8a8.schema.d.ts +24 -0
  223. package/src/config/schema/w8a8.schema.js +38 -0
  224. package/src/config/source-packages/litert/gemma-4-e2b-it.json +7 -7
  225. package/src/config/supported-operations.json +105 -0
  226. package/src/config/target-plan.d.ts +16 -2
  227. package/src/config/target-plan.js +63 -16
  228. package/src/config/wgsl-language-contract.js +47 -0
  229. package/src/converter/artifact-identity.js +27 -47
  230. package/src/converter/capability-transform-resolver.js +80 -0
  231. package/src/converter/conversion-plan.js +14 -14
  232. package/src/converter/core.d.ts +2 -0
  233. package/src/converter/core.js +15 -16
  234. package/src/converter/execution-graph/fusion.js +343 -0
  235. package/src/converter/execution-graph/kv-storage.js +14 -0
  236. package/src/converter/execution-graph/validation.js +431 -0
  237. package/src/converter/execution-graph-transforms.js +927 -0
  238. package/src/converter/forge-candidate-evaluation.js +1 -1
  239. package/src/converter/forge-qualification.js +103 -31
  240. package/src/converter/forge-stages.js +113 -106
  241. package/src/converter/fp8-source.js +99 -0
  242. package/src/converter/linear-norm-gate.js +115 -0
  243. package/src/converter/manifest-builder.js +20 -6
  244. package/src/converter/parsers/gguf.js +21 -2
  245. package/src/converter/quantization-info.js +56 -5
  246. package/src/converter/quantizer.js +4 -145
  247. package/src/converter/qwen4-exp-source-defaults.json +35 -0
  248. package/src/converter/qwen4-exp-source.js +293 -0
  249. package/src/converter/resident-qualification.js +58 -0
  250. package/src/converter/retained-source-shards.js +97 -0
  251. package/src/converter/rope-config.js +1 -0
  252. package/src/converter/source-rotary-frequencies.d.ts +12 -0
  253. package/src/converter/source-rotary-frequencies.js +34 -0
  254. package/src/converter/source-tensor-rules.d.ts +25 -1
  255. package/src/converter/source-tensor-rules.js +31 -1
  256. package/src/converter/tensor-transform.js +60 -7
  257. package/src/converter/tokenizer-contract.js +1 -3
  258. package/src/converter/w8a8-quantizer.js +56 -0
  259. package/src/debug/activation-trace.d.ts +34 -0
  260. package/src/debug/activation-trace.js +89 -0
  261. package/src/debug/activity-trace.d.ts +52 -0
  262. package/src/debug/activity-trace.js +127 -0
  263. package/src/debug/capture-policy.d.ts +9 -1
  264. package/src/debug/capture-policy.js +52 -21
  265. package/src/debug/index.d.ts +3 -0
  266. package/src/debug/index.js +12 -6
  267. package/src/debug/log.d.ts +6 -0
  268. package/src/debug/log.js +26 -0
  269. package/src/debug/perf-guards.js +71 -0
  270. package/src/debug/pipeline-config.js +141 -0
  271. package/src/debug/stats.d.ts +1 -1
  272. package/src/debug/stats.js +7 -2
  273. package/src/debug/tensor.d.ts +15 -3
  274. package/src/debug/tensor.js +43 -27
  275. package/src/debug/trace.js +12 -0
  276. package/src/errors/doppler-error.js +6 -2
  277. package/src/experimental/audio/gemma4.js +19 -10
  278. package/src/experimental/bdpa/basis-decomposed-paged.d.ts +1 -1
  279. package/src/experimental/diffusion/pipeline.d.ts +1 -0
  280. package/src/experimental/distribution/shard-delivery/receipt.js +3 -73
  281. package/src/experimental/distribution/shard-delivery/retry.js +6 -112
  282. package/src/experimental/distribution/shard-delivery.js +19 -632
  283. package/src/experimental/energy/pipeline.d.ts +1 -0
  284. package/src/experimental/logits/cpu.js +2 -7
  285. package/src/experimental/training/artifacts.js +1 -4
  286. package/src/experimental/training/attention-forward.js +1 -1
  287. package/src/experimental/training/autograd.d.ts +21 -0
  288. package/src/experimental/training/autograd.js +44 -20
  289. package/src/experimental/training/checkpoint.js +1 -4
  290. package/src/experimental/training/clip.js +1 -1
  291. package/src/experimental/training/distillation/student-fixture/execution.js +9 -12
  292. package/src/experimental/training/distillation/student-fixture/model.js +9 -12
  293. package/src/experimental/training/distillation/student-fixture.js +9 -12
  294. package/src/experimental/training/lora/checkpoint.js +1 -1
  295. package/src/experimental/training/lora/execution.js +1 -1
  296. package/src/experimental/training/lora/plan.js +1 -1
  297. package/src/experimental/training/lora/recovery.js +1 -1
  298. package/src/experimental/training/lora-pipeline.js +9 -83
  299. package/src/experimental/training/lora-training-round.d.ts +39 -0
  300. package/src/experimental/training/lora-training-round.js +90 -0
  301. package/src/experimental/training/lora.js +2 -1
  302. package/src/experimental/training/loss-scaling.js +1 -1
  303. package/src/experimental/training/loss.js +3 -1
  304. package/src/experimental/training/native-qwen-lora.d.ts +25 -6
  305. package/src/experimental/training/native-qwen-lora.js +176 -21
  306. package/src/experimental/training/operator-command.js +1 -49
  307. package/src/experimental/training/parameter-groups.js +39 -0
  308. package/src/experimental/training/report-ranking.js +52 -0
  309. package/src/experimental/training/runner/lifecycle.js +4 -61
  310. package/src/experimental/training/runner.js +2 -5
  311. package/src/experimental/training/suite/execution.js +3 -5
  312. package/src/experimental/training/suite/plan.js +6 -21
  313. package/src/experimental/training/suite.js +5 -34
  314. package/src/experimental/training/trainer.js +2 -36
  315. package/src/experimental/training/workload-capsules/registry.json +473 -0
  316. package/src/experimental/turboquant/codebook.js +0 -29
  317. package/src/formats/contract-validation.js +30 -0
  318. package/src/formats/flatbuffer-tables.js +55 -0
  319. package/src/formats/float16.js +81 -0
  320. package/src/formats/float8.js +19 -0
  321. package/src/formats/gguf/block-storage.js +51 -0
  322. package/src/formats/gguf/quantized-formats.json +10 -0
  323. package/src/formats/gguf/qwen-source.js +88 -0
  324. package/src/formats/gguf/qwen-source.json +8 -0
  325. package/src/formats/gguf/tokenizer-pre.json +4 -0
  326. package/src/formats/gguf/tokenizer.js +50 -0
  327. package/src/formats/litert/types.js +8 -180
  328. package/src/formats/paged-source-reader.js +158 -0
  329. package/src/formats/q4k-dequant.js +95 -0
  330. package/src/formats/rdrr/classification.js +4 -0
  331. package/src/formats/rdrr/distributed/validation.js +1 -4
  332. package/src/formats/rdrr/fp8-contract.js +38 -0
  333. package/src/formats/rdrr/fp8-storage.js +83 -0
  334. package/src/formats/rdrr/functional-descriptor.js +1 -4
  335. package/src/formats/rdrr/parsing.js +1 -1
  336. package/src/formats/rdrr/q4_0-storage.js +24 -0
  337. package/src/formats/rdrr/storage-descriptor.js +7 -1
  338. package/src/formats/rdrr/types.d.ts +7 -1
  339. package/src/formats/rdrr/validation.js +37 -6
  340. package/src/formats/rdrr/w8a8-storage.js +64 -0
  341. package/src/formats/safetensors/types.js +4 -0
  342. package/src/formats/sha256.js +104 -103
  343. package/src/formats/sorted-json.js +9 -0
  344. package/src/formats/source-runtime.d.ts +52 -0
  345. package/src/formats/tflite/types.js +7 -161
  346. package/src/generation/index.d.ts +7 -1
  347. package/src/generation/index.js +7 -1
  348. package/src/gpu/buffer-identity.js +4 -0
  349. package/src/gpu/command-recorder.d.ts +66 -29
  350. package/src/gpu/command-recorder.js +157 -161
  351. package/src/gpu/device-bindings.js +98 -0
  352. package/src/gpu/device-state.js +0 -4
  353. package/src/gpu/device.d.ts +9 -0
  354. package/src/gpu/device.js +105 -137
  355. package/src/gpu/kernel-selector.js +73 -12
  356. package/src/gpu/kernels/attention/executors-components.js +235 -0
  357. package/src/gpu/kernels/attention/executors.js +296 -510
  358. package/src/gpu/kernels/attention/plan.js +65 -18
  359. package/src/gpu/kernels/attention/query-splitk.js +80 -0
  360. package/src/gpu/kernels/attention_decode_gqa_splitk.wgsl +197 -0
  361. package/src/gpu/kernels/attention_decode_online.wgsl +348 -0
  362. package/src/gpu/kernels/attention_decode_online_f16kv.wgsl +126 -22
  363. package/src/gpu/kernels/attention_decode_subgroup.wgsl +5 -6
  364. package/src/gpu/kernels/attention_head256_f16kv.wgsl +56 -9
  365. package/src/gpu/kernels/attention_indexed.wgsl +179 -0
  366. package/src/gpu/kernels/attention_indexed_f16kv.wgsl +180 -0
  367. package/src/gpu/kernels/attention_paired.wgsl +361 -0
  368. package/src/gpu/kernels/attention_paired_tiled.wgsl +383 -0
  369. package/src/gpu/kernels/attention_prefill_partitioned_head256_f16kv.wgsl +247 -0
  370. package/src/gpu/kernels/attention_prefill_query_splitk_f32.wgsl +234 -0
  371. package/src/gpu/kernels/attention_prefill_query_splitk_reduce_f32.wgsl +103 -0
  372. package/src/gpu/kernels/attention_prefill_query_tile_f16kv.wgsl +225 -0
  373. package/src/gpu/kernels/attention_prefill_query_tile_f32.wgsl +222 -0
  374. package/src/gpu/kernels/backward/adam.js +11 -3
  375. package/src/gpu/kernels/backward/gated_delta_recurrent_backward.js +51 -15
  376. package/src/gpu/kernels/backward/gated_delta_recurrent_backward.wgsl +9 -8
  377. package/src/gpu/kernels/backward/gated_delta_recurrent_checkpoint_forward.js +149 -0
  378. package/src/gpu/kernels/backward/gated_delta_recurrent_checkpoint_forward.wgsl +109 -0
  379. package/src/gpu/kernels/backward/gated_delta_recurrent_checkpointed_backward.js +120 -0
  380. package/src/gpu/kernels/backward/gelu_backward.js +8 -12
  381. package/src/gpu/kernels/backward/index.js +6 -0
  382. package/src/gpu/kernels/backward/qwen_attention_split_q_gate_backward.js +80 -0
  383. package/src/gpu/kernels/backward/qwen_attention_split_q_gate_backward.wgsl +26 -0
  384. package/src/gpu/kernels/backward/qwen_gqa_attention_backward.js +157 -0
  385. package/src/gpu/kernels/backward/qwen_gqa_attention_backward.wgsl +82 -0
  386. package/src/gpu/kernels/backward/qwen_gqa_softmax_backward_scores.wgsl +73 -0
  387. package/src/gpu/kernels/backward/qwen_gqa_softmax_recompute.wgsl +97 -0
  388. package/src/gpu/kernels/backward/qwen_linear_attention_prepare_backward.js +221 -0
  389. package/src/gpu/kernels/backward/qwen_linear_attention_prepare_backward.wgsl +136 -0
  390. package/src/gpu/kernels/backward/rmsnorm_backward.js +98 -80
  391. package/src/gpu/kernels/backward/rope_backward.js +47 -10
  392. package/src/gpu/kernels/backward/rope_backward.wgsl +46 -22
  393. package/src/gpu/kernels/backward/sigmoid_gated_backward.js +83 -0
  394. package/src/gpu/kernels/backward/sigmoid_gated_backward.wgsl +49 -0
  395. package/src/gpu/kernels/backward/silu_backward.js +8 -12
  396. package/src/gpu/kernels/backward/softmax_backward.js +8 -12
  397. package/src/gpu/kernels/cast_f32_to_two_f32.wgsl +12 -0
  398. package/src/gpu/kernels/cast_two_f32_to_f16.wgsl +49 -0
  399. package/src/gpu/kernels/causal_conv1d_silu.js +80 -0
  400. package/src/gpu/kernels/causal_conv1d_silu.wgsl +44 -0
  401. package/src/gpu/kernels/check-stop.js +1 -1
  402. package/src/gpu/kernels/check_finiteness_f32.wgsl +33 -0
  403. package/src/gpu/kernels/conv2d.js +30 -42
  404. package/src/gpu/kernels/dequant.js +1 -1
  405. package/src/gpu/kernels/dequant_mxfp4.wgsl +6 -4
  406. package/src/gpu/kernels/diffusion-gemma-sampling.js +26 -7
  407. package/src/gpu/kernels/diffusion_gemma_sampling.wgsl +66 -2
  408. package/src/gpu/kernels/dispatch.js +36 -1
  409. package/src/gpu/kernels/embedding-pool.js +15 -13
  410. package/src/gpu/kernels/feature-check.js +7 -2
  411. package/src/gpu/kernels/fp8.js +70 -0
  412. package/src/gpu/kernels/fused_ffn.js +83 -154
  413. package/src/gpu/kernels/fused_ffn_q4k.wgsl +43 -1
  414. package/src/gpu/kernels/fused_ffn_q4k_subgroup8.wgsl +228 -0
  415. package/src/gpu/kernels/fused_matmul_q4_batched_f16acc_f16a.wgsl +2 -2
  416. package/src/gpu/kernels/fused_matmul_q4_subgroup.wgsl +146 -0
  417. package/src/gpu/kernels/fused_matmul_q4_widetile.wgsl +14 -4
  418. package/src/gpu/kernels/fused_matmul_q4_widetile_direct.wgsl +204 -0
  419. package/src/gpu/kernels/fused_matmul_residual.js +19 -72
  420. package/src/gpu/kernels/fused_matmul_rmsnorm.js +34 -127
  421. package/src/gpu/kernels/gated-delta-norm-gate.js +45 -0
  422. package/src/gpu/kernels/gated_delta_conv.wgsl +57 -6
  423. package/src/gpu/kernels/gated_delta_conv_f16.wgsl +57 -6
  424. package/src/gpu/kernels/gated_delta_conv_paired.wgsl +282 -0
  425. package/src/gpu/kernels/gated_delta_conv_prefill.wgsl +144 -0
  426. package/src/gpu/kernels/gated_delta_fused_decode.wgsl +375 -40
  427. package/src/gpu/kernels/gated_delta_fused_decode_f16.wgsl +375 -40
  428. package/src/gpu/kernels/gated_delta_fused_decode_paired.wgsl +511 -0
  429. package/src/gpu/kernels/gated_delta_fused_decode_paired_f16.wgsl +513 -0
  430. package/src/gpu/kernels/gated_delta_fused_decode_paired_sigmoid_gate.wgsl +514 -0
  431. package/src/gpu/kernels/gated_delta_fused_decode_paired_sigmoid_gate_f16.wgsl +516 -0
  432. package/src/gpu/kernels/gated_delta_fused_decode_register.wgsl +750 -0
  433. package/src/gpu/kernels/gated_delta_fused_decode_sigmoid_gate.wgsl +511 -0
  434. package/src/gpu/kernels/gated_delta_fused_decode_sigmoid_gate_f16.wgsl +513 -0
  435. package/src/gpu/kernels/gated_delta_gate_paired.wgsl +271 -0
  436. package/src/gpu/kernels/gated_delta_gate_sigmoid_paired.wgsl +273 -0
  437. package/src/gpu/kernels/gated_delta_norm_paired.wgsl +288 -0
  438. package/src/gpu/kernels/gated_delta_prefill_norm_gate.wgsl +227 -0
  439. package/src/gpu/kernels/gated_delta_qk_paired.wgsl +297 -0
  440. package/src/gpu/kernels/gated_delta_qk_paired_parallel.wgsl +299 -0
  441. package/src/gpu/kernels/gated_delta_recurrent.wgsl +362 -32
  442. package/src/gpu/kernels/gated_delta_recurrent_f16.wgsl +362 -32
  443. package/src/gpu/kernels/gated_delta_recurrent_gguf.wgsl +496 -0
  444. package/src/gpu/kernels/gated_delta_recurrent_gguf_register_prefill.wgsl +727 -0
  445. package/src/gpu/kernels/gated_delta_recurrent_paired.wgsl +337 -0
  446. package/src/gpu/kernels/gated_delta_recurrent_register_prefill.wgsl +546 -0
  447. package/src/gpu/kernels/gated_delta_recurrent_sigmoid_gate.wgsl +498 -0
  448. package/src/gpu/kernels/gated_delta_recurrent_sigmoid_gate_f16.wgsl +500 -0
  449. package/src/gpu/kernels/gated_delta_state_paired.wgsl +310 -0
  450. package/src/gpu/kernels/gated_delta_state_paired_sliced.wgsl +348 -0
  451. package/src/gpu/kernels/gated_delta_state_paired_sliced_rolled.wgsl +353 -0
  452. package/src/gpu/kernels/gated_rmsnorm.js +74 -0
  453. package/src/gpu/kernels/gated_rmsnorm.wgsl +62 -0
  454. package/src/gpu/kernels/gather.js +81 -46
  455. package/src/gpu/kernels/gather.wgsl +3 -2
  456. package/src/gpu/kernels/gather_bf16.wgsl +3 -2
  457. package/src/gpu/kernels/gather_f16.wgsl +3 -2
  458. package/src/gpu/kernels/gather_f16_f16_out.wgsl +3 -2
  459. package/src/gpu/kernels/gather_f16_out.wgsl +3 -2
  460. package/src/gpu/kernels/gather_f16_vec4.wgsl +3 -2
  461. package/src/gpu/kernels/gather_f16_vec4_f16_out.wgsl +3 -2
  462. package/src/gpu/kernels/gather_litert_int4_vec4_f16_out.wgsl +3 -2
  463. package/src/gpu/kernels/gather_litert_int4_vec4_f32_out.wgsl +3 -2
  464. package/src/gpu/kernels/gather_q4_0.wgsl +57 -0
  465. package/src/gpu/kernels/gather_split4_f16_vec4_f16_out.wgsl +3 -2
  466. package/src/gpu/kernels/gather_split4_f16_vec4_f32_out.wgsl +104 -0
  467. package/src/gpu/kernels/gather_split8_f16_vec4_f16_out.wgsl +3 -2
  468. package/src/gpu/kernels/gather_split8_f16_vec4_f32_out.wgsl +3 -2
  469. package/src/gpu/kernels/gather_vec4.wgsl +3 -2
  470. package/src/gpu/kernels/gather_vec4_f16_out.wgsl +3 -2
  471. package/src/gpu/kernels/gelu.js +16 -13
  472. package/src/gpu/kernels/gelu.wgsl +16 -0
  473. package/src/gpu/kernels/gelu_f16.wgsl +16 -0
  474. package/src/gpu/kernels/gemma4-route-expert.js +2 -5
  475. package/src/gpu/kernels/generated/uniform-writers-0.js +600 -0
  476. package/src/gpu/kernels/generated/uniform-writers-1.js +602 -0
  477. package/src/gpu/kernels/generated/uniform-writers-2.js +516 -0
  478. package/src/gpu/kernels/generated/uniform-writers.js +557 -0
  479. package/src/gpu/kernels/hyper-connection.js +240 -0
  480. package/src/gpu/kernels/hyper_connection_activation.wgsl +110 -0
  481. package/src/gpu/kernels/hyper_connection_branch.wgsl +60 -0
  482. package/src/gpu/kernels/hyper_connection_inject.wgsl +49 -0
  483. package/src/gpu/kernels/hyper_connection_norm.wgsl +72 -0
  484. package/src/gpu/kernels/kernel-bindings.js +37 -0
  485. package/src/gpu/kernels/kernel-configs.d.ts +12 -2
  486. package/src/gpu/kernels/kernel-configs.js +40 -23
  487. package/src/gpu/kernels/kernel-execution.js +87 -26
  488. package/src/gpu/kernels/kernel-geometry.js +43 -0
  489. package/src/gpu/kernels/kernel-prewarm.js +18 -15
  490. package/src/gpu/kernels/kv-cache-write.js +4 -6
  491. package/src/gpu/kernels/layernorm.js +7 -45
  492. package/src/gpu/kernels/linear-attention-core.js +247 -119
  493. package/src/gpu/kernels/linear-attention-recovery.js +90 -0
  494. package/src/gpu/kernels/linear-norm-ab.js +80 -0
  495. package/src/gpu/kernels/linear_norm_ab_f32.wgsl +243 -0
  496. package/src/gpu/kernels/logit-finalize.js +9 -3
  497. package/src/gpu/kernels/logit-scatter.js +9 -3
  498. package/src/gpu/kernels/logit-suppress.js +24 -0
  499. package/src/gpu/kernels/logit_suppress.wgsl +19 -0
  500. package/src/gpu/kernels/matmul-dispatch.js +70 -146
  501. package/src/gpu/kernels/matmul-selection.js +75 -18
  502. package/src/gpu/kernels/matmul-workgroup-capacity.js +37 -0
  503. package/src/gpu/kernels/matmul.js +81 -108
  504. package/src/gpu/kernels/matmul_compensated_f32.wgsl +215 -0
  505. package/src/gpu/kernels/matmul_f16w_f32a_tiled.wgsl +59 -46
  506. package/src/gpu/kernels/matmul_f32.wgsl +23 -17
  507. package/src/gpu/kernels/matmul_f32_row_subgroup.wgsl +88 -0
  508. package/src/gpu/kernels/matmul_fp8.wgsl +60 -0
  509. package/src/gpu/kernels/matmul_gemv_compensated_f32.wgsl +211 -0
  510. package/src/gpu/kernels/matmul_gemv_f32.wgsl +63 -0
  511. package/src/gpu/kernels/matmul_gemv_f32_subgroup.wgsl +84 -0
  512. package/src/gpu/kernels/matmul_gguf_columns_hoisted_f32.wgsl +342 -0
  513. package/src/gpu/kernels/matmul_gguf_pair_columns_f32.wgsl +279 -0
  514. package/src/gpu/kernels/matmul_gguf_pair_f32.wgsl +197 -0
  515. package/src/gpu/kernels/matmul_paired.wgsl +315 -0
  516. package/src/gpu/kernels/matmul_paired_compensated.wgsl +334 -0
  517. package/src/gpu/kernels/matmul_q4_0.wgsl +234 -0
  518. package/src/gpu/kernels/matmul_q4_0_tile128.wgsl +477 -0
  519. package/src/gpu/kernels/matmul_q4_0_tile128_bounded.wgsl +483 -0
  520. package/src/gpu/kernels/matmul_q4_0_tile64.wgsl +282 -0
  521. package/src/gpu/kernels/matmul_q4_0_tile64_bounded.wgsl +288 -0
  522. package/src/gpu/kernels/matmul_q4_0_tile64x128.wgsl +364 -0
  523. package/src/gpu/kernels/matmul_q4_0_tile64x128_bounded.wgsl +370 -0
  524. package/src/gpu/kernels/matmul_q4_1_columns_f32.wgsl +132 -0
  525. package/src/gpu/kernels/matmul_q5k.wgsl +181 -0
  526. package/src/gpu/kernels/matmul_q5k_columns.wgsl +194 -0
  527. package/src/gpu/kernels/matmul_q5k_cooperative.wgsl +129 -0
  528. package/src/gpu/kernels/matmul_q5k_tile64.wgsl +309 -0
  529. package/src/gpu/kernels/matmul_w8a8.wgsl +55 -0
  530. package/src/gpu/kernels/matmul_w8a8_packed.wgsl +54 -0
  531. package/src/gpu/kernels/matmul_w8a8_packed_cooperative.wgsl +77 -0
  532. package/src/gpu/kernels/moe-grouped.js +132 -0
  533. package/src/gpu/kernels/moe-norm-router.js +91 -0
  534. package/src/gpu/kernels/moe-route.js +135 -0
  535. package/src/gpu/kernels/moe-shared-slot.js +219 -0
  536. package/src/gpu/kernels/moe_grouped_matmul_f32.wgsl +216 -0
  537. package/src/gpu/kernels/moe_grouped_matmul_ordered_f32.wgsl +158 -0
  538. package/src/gpu/kernels/moe_grouped_sort.wgsl +101 -0
  539. package/src/gpu/kernels/moe_norm_router_f32.wgsl +254 -0
  540. package/src/gpu/kernels/moe_route_gguf_split_f32.wgsl +117 -0
  541. package/src/gpu/kernels/moe_route_q4_0_f32.wgsl +81 -0
  542. package/src/gpu/kernels/moe_route_q4_f32.wgsl +250 -0
  543. package/src/gpu/kernels/moe_shared_slot_combine_f32.wgsl +91 -0
  544. package/src/gpu/kernels/moe_shared_slot_down_f32.wgsl +264 -0
  545. package/src/gpu/kernels/moe_shared_slot_down_pair_combine_f32.wgsl +254 -0
  546. package/src/gpu/kernels/moe_shared_slot_down_pair_combine_residual_f32.wgsl +262 -0
  547. package/src/gpu/kernels/moe_shared_slot_down_pair_f32.wgsl +187 -0
  548. package/src/gpu/kernels/moe_shared_slot_gu_f32.wgsl +264 -0
  549. package/src/gpu/kernels/moe_shared_slot_gu_pair_f32.wgsl +267 -0
  550. package/src/gpu/kernels/paired-activation.js +86 -0
  551. package/src/gpu/kernels/paired-attention.js +85 -0
  552. package/src/gpu/kernels/paired-cast.js +82 -0
  553. package/src/gpu/kernels/paired-linear-attention.js +180 -0
  554. package/src/gpu/kernels/paired-matmul.js +86 -0
  555. package/src/gpu/kernels/paired-rmsnorm.js +127 -0
  556. package/src/gpu/kernels/paired-rope.js +44 -0
  557. package/src/gpu/kernels/paired-split.js +74 -0
  558. package/src/gpu/kernels/paired_add.wgsl +261 -0
  559. package/src/gpu/kernels/paired_multiply.wgsl +261 -0
  560. package/src/gpu/kernels/paired_scale.wgsl +260 -0
  561. package/src/gpu/kernels/paired_scale_inplace.wgsl +259 -0
  562. package/src/gpu/kernels/paired_sigmoid.wgsl +266 -0
  563. package/src/gpu/kernels/paired_silu.wgsl +266 -0
  564. package/src/gpu/kernels/paired_silu_unary.wgsl +260 -0
  565. package/src/gpu/kernels/pipeline-cache.d.ts +37 -4
  566. package/src/gpu/kernels/pipeline-cache.js +185 -88
  567. package/src/gpu/kernels/ple.js +145 -0
  568. package/src/gpu/kernels/ple_conv.wgsl +104 -0
  569. package/src/gpu/kernels/ple_gate.wgsl +131 -0
  570. package/src/gpu/kernels/q4_0.js +200 -0
  571. package/src/gpu/kernels/qsa-indexer.d.ts +105 -0
  572. package/src/gpu/kernels/qsa-indexer.js +304 -0
  573. package/src/gpu/kernels/qsa_block_keys.wgsl +110 -0
  574. package/src/gpu/kernels/qsa_block_scores.wgsl +73 -0
  575. package/src/gpu/kernels/qsa_prepare.wgsl +116 -0
  576. package/src/gpu/kernels/qsa_select.wgsl +172 -0
  577. package/src/gpu/kernels/quantize_w8a8.wgsl +81 -0
  578. package/src/gpu/kernels/qwen_attention_split_q_gate.js +71 -0
  579. package/src/gpu/kernels/qwen_attention_split_q_gate.wgsl +26 -0
  580. package/src/gpu/kernels/qwen_linear_attention_decay_paired.wgsl +266 -0
  581. package/src/gpu/kernels/qwen_linear_attention_log_decay_paired.wgsl +273 -0
  582. package/src/gpu/kernels/qwen_linear_attention_prepare.js +153 -0
  583. package/src/gpu/kernels/qwen_linear_attention_prepare.wgsl +120 -0
  584. package/src/gpu/kernels/qwen_linear_attention_prepare_paired.wgsl +267 -0
  585. package/src/gpu/kernels/qwen_linear_attention_scale_paired.wgsl +276 -0
  586. package/src/gpu/kernels/relu.js +5 -12
  587. package/src/gpu/kernels/rep-penalty.js +30 -5
  588. package/src/gpu/kernels/rep_penalty.wgsl +25 -30
  589. package/src/gpu/kernels/rep_penalty_f16.wgsl +24 -25
  590. package/src/gpu/kernels/repeat_channels.js +22 -9
  591. package/src/gpu/kernels/repeat_channels.wgsl +12 -5
  592. package/src/gpu/kernels/repeat_channels_f16.wgsl +12 -5
  593. package/src/gpu/kernels/rescale_w8a8.wgsl +74 -0
  594. package/src/gpu/kernels/residual.js +5 -0
  595. package/src/gpu/kernels/rmsnorm-pair.js +2 -2
  596. package/src/gpu/kernels/rmsnorm-qk.js +27 -5
  597. package/src/gpu/kernels/rmsnorm-stats.js +62 -78
  598. package/src/gpu/kernels/rmsnorm.js +74 -96
  599. package/src/gpu/kernels/rmsnorm.wgsl +9 -3
  600. package/src/gpu/kernels/rmsnorm_f16.wgsl +2 -0
  601. package/src/gpu/kernels/rmsnorm_paired.wgsl +321 -0
  602. package/src/gpu/kernels/rmsnorm_paired_sliced.wgsl +326 -0
  603. package/src/gpu/kernels/rmsnorm_qk.wgsl +32 -8
  604. package/src/gpu/kernels/rmsnorm_stats_subgroups.wgsl +7 -7
  605. package/src/gpu/kernels/rope-dispatch.js +26 -0
  606. package/src/gpu/kernels/rope-precompute.js +29 -28
  607. package/src/gpu/kernels/rope-qk.js +35 -24
  608. package/src/gpu/kernels/rope.js +5 -2
  609. package/src/gpu/kernels/rope.wgsl +2 -2
  610. package/src/gpu/kernels/rope_precompute.wgsl +150 -6
  611. package/src/gpu/kernels/rope_precompute_paired.wgsl +285 -0
  612. package/src/gpu/kernels/rope_qk.wgsl +3 -2
  613. package/src/gpu/kernels/rope_qk_paired.wgsl +341 -0
  614. package/src/gpu/kernels/sample.js +135 -249
  615. package/src/gpu/kernels/sample.wgsl +138 -168
  616. package/src/gpu/kernels/sample_f16.wgsl +192 -171
  617. package/src/gpu/kernels/scale.js +6 -1
  618. package/src/gpu/kernels/scatter_add_routes_f32.wgsl +43 -0
  619. package/src/gpu/kernels/shader-cache.d.ts +7 -1
  620. package/src/gpu/kernels/shader-cache.js +61 -20
  621. package/src/gpu/kernels/shader-source-scope.d.ts +14 -0
  622. package/src/gpu/kernels/shader-source-scope.js +127 -12
  623. package/src/gpu/kernels/sigmoid-gated-add.js +68 -0
  624. package/src/gpu/kernels/sigmoid_gated_add_f32.wgsl +76 -0
  625. package/src/gpu/kernels/silu.js +56 -136
  626. package/src/gpu/kernels/silu.wgsl +54 -3
  627. package/src/gpu/kernels/silu_f16.wgsl +3 -2
  628. package/src/gpu/kernels/softmax.js +57 -19
  629. package/src/gpu/kernels/softmax_topk_logit_rank.wgsl +137 -0
  630. package/src/gpu/kernels/softmax_topk_ranked.wgsl +132 -0
  631. package/src/gpu/kernels/softmax_topk_strided.wgsl +80 -0
  632. package/src/gpu/kernels/speculative-accept.js +97 -0
  633. package/src/gpu/kernels/speculative_accept.wgsl +38 -0
  634. package/src/gpu/kernels/speculative_accept_gpu_limit.wgsl +42 -0
  635. package/src/gpu/kernels/split-dispatch.js +18 -0
  636. package/src/gpu/kernels/split-qkv-rmsnorm-qk.js +3 -6
  637. package/src/gpu/kernels/split-qkv-rmsnorm-rope-qk.js +4 -11
  638. package/src/gpu/kernels/split_qg.js +6 -2
  639. package/src/gpu/kernels/split_qg.wgsl +3 -2
  640. package/src/gpu/kernels/split_qg_f16.wgsl +3 -2
  641. package/src/gpu/kernels/split_qg_paired.wgsl +59 -0
  642. package/src/gpu/kernels/split_qkv.js +7 -16
  643. package/src/gpu/kernels/split_qkv_paired.wgsl +75 -0
  644. package/src/gpu/kernels/subgroup-partition.js +11 -0
  645. package/src/gpu/kernels/uniform-encoding.js +20 -0
  646. package/src/gpu/kernels/uniform-utils.js +44 -49
  647. package/src/gpu/kernels/vision-average-pool.js +2 -5
  648. package/src/gpu/kernels/vision-patch-embed.js +2 -5
  649. package/src/gpu/kernels/vision-position-embedding.js +2 -5
  650. package/src/gpu/kernels/vision-rope-2d.js +2 -5
  651. package/src/gpu/kernels/vision-spatial-merge.js +2 -5
  652. package/src/gpu/kernels/w8a8.js +166 -0
  653. package/src/gpu/prepared-decode-workspace.d.ts +11 -0
  654. package/src/gpu/prepared-decode-workspace.js +104 -0
  655. package/src/gpu/recorder-timestamps.js +63 -0
  656. package/src/gpu/step-contract.d.ts +27 -0
  657. package/src/gpu/step-contract.js +26 -0
  658. package/src/gpu/submit-tracker.js +1 -17
  659. package/src/gpu/tensor.d.ts +13 -4
  660. package/src/gpu/tensor.js +38 -19
  661. package/src/gpu/uniform-cache.d.ts +8 -4
  662. package/src/gpu/uniform-cache.js +41 -25
  663. package/src/gpu/weight-buffer.d.ts +10 -1
  664. package/src/gpu/weight-buffer.js +2 -1
  665. package/src/index.d.ts +3 -0
  666. package/src/index.js +2 -0
  667. package/src/inference/choice-scoring.js +70 -0
  668. package/src/inference/decode-buffers.d.ts +11 -3
  669. package/src/inference/decode-buffers.js +93 -63
  670. package/src/inference/generation-output.js +128 -0
  671. package/src/inference/generation-step.d.ts +14 -0
  672. package/src/inference/generation-step.js +26 -0
  673. package/src/inference/kv-cache/base.d.ts +7 -2
  674. package/src/inference/kv-cache/base.js +10 -8
  675. package/src/inference/kv-cache/copy-state.js +39 -0
  676. package/src/inference/kv-cache/layer-range.js +76 -0
  677. package/src/inference/kv-cache/mixed-geometry.d.ts +3 -2
  678. package/src/inference/kv-cache/mixed-geometry.js +25 -1
  679. package/src/inference/kv-cache/quantized.d.ts +1 -1
  680. package/src/inference/kv-cache/quantized.js +1 -1
  681. package/src/inference/kv-cache/sliding-window.d.ts +2 -2
  682. package/src/inference/kv-cache/sliding-window.js +58 -183
  683. package/src/inference/kv-cache/tiered.d.ts +1 -1
  684. package/src/inference/kv-cache/tiered.js +1 -1
  685. package/src/inference/kv-cache/types.js +2 -28
  686. package/src/inference/kv-cache/update.js +104 -157
  687. package/src/inference/moe-router.d.ts +5 -0
  688. package/src/inference/moe-router.js +42 -31
  689. package/src/inference/pipelines/audio/index.js +5 -2
  690. package/src/inference/pipelines/audio/mel.js +116 -81
  691. package/src/inference/pipelines/context.js +110 -76
  692. package/src/inference/pipelines/factory.js +27 -5
  693. package/src/inference/pipelines/registry.js +9 -3
  694. package/src/inference/pipelines/shader-scoped-pipeline.d.ts +24 -0
  695. package/src/inference/pipelines/shader-scoped-pipeline.js +243 -11
  696. package/src/inference/pipelines/shared/clipped-linear.js +1 -1
  697. package/src/inference/pipelines/structured/json-grammar-mask.d.ts +2 -0
  698. package/src/inference/pipelines/structured/json-grammar-mask.js +115 -118
  699. package/src/inference/pipelines/structured/json-head-pipeline.js +1 -1
  700. package/src/inference/pipelines/text/activity-weights.js +110 -0
  701. package/src/inference/pipelines/text/attention/cache-cast.js +15 -0
  702. package/src/inference/pipelines/text/attention/dispatch-params.js +2 -1
  703. package/src/inference/pipelines/text/attention/interpreter/immediate.js +16 -19
  704. package/src/inference/pipelines/text/attention/interpreter/recorded.js +20 -21
  705. package/src/inference/pipelines/text/attention/interpreter.js +34 -38
  706. package/src/inference/pipelines/text/attention/paired-contract.js +29 -0
  707. package/src/inference/pipelines/text/attention/plan.d.ts +2 -0
  708. package/src/inference/pipelines/text/attention/plan.js +11 -4
  709. package/src/inference/pipelines/text/attention/projection-executor.js +10 -27
  710. package/src/inference/pipelines/text/attention/projection-plan.js +24 -31
  711. package/src/inference/pipelines/text/attention/projections.js +10 -27
  712. package/src/inference/pipelines/text/attention/query-transform.js +2 -2
  713. package/src/inference/pipelines/text/attention/recorded-health.js +2 -1
  714. package/src/inference/pipelines/text/attention/rope-observation.js +26 -3
  715. package/src/inference/pipelines/text/chat-format.js +2 -1
  716. package/src/inference/pipelines/text/config/normalization.js +115 -226
  717. package/src/inference/pipelines/text/config/vision-normalizers.js +240 -0
  718. package/src/inference/pipelines/text/config-components.js +49 -0
  719. package/src/inference/pipelines/text/config.d.ts +45 -1
  720. package/src/inference/pipelines/text/config.js +26 -38
  721. package/src/inference/pipelines/text/debug-utils/config.js +13 -156
  722. package/src/inference/pipelines/text/debug-utils/health-metrics.js +8 -23
  723. package/src/inference/pipelines/text/debug-utils/readback-decoding.js +5 -1
  724. package/src/inference/pipelines/text/embed.js +38 -4
  725. package/src/inference/pipelines/text/embedding-batch.js +23 -0
  726. package/src/inference/pipelines/text/embedding-extraction.js +7 -2
  727. package/src/inference/pipelines/text/embedding-normalization.js +2 -1
  728. package/src/inference/pipelines/text/execution-plan.d.ts +16 -0
  729. package/src/inference/pipelines/text/execution-plan.js +49 -2
  730. package/src/inference/pipelines/text/execution-runtime-builders.js +31 -0
  731. package/src/inference/pipelines/text/execution-v1/validation.js +3 -3
  732. package/src/inference/pipelines/text/execution-v1.js +14 -14
  733. package/src/inference/pipelines/text/execution.js +78 -128
  734. package/src/inference/pipelines/text/ffn/activation-observation.js +45 -0
  735. package/src/inference/pipelines/text/ffn/decode-intermediate.js +10 -0
  736. package/src/inference/pipelines/text/ffn/dense-executor.js +60 -50
  737. package/src/inference/pipelines/text/ffn/dense-plan.js +28 -27
  738. package/src/inference/pipelines/text/ffn/dense.js +30 -50
  739. package/src/inference/pipelines/text/ffn/moe.js +67 -3
  740. package/src/inference/pipelines/text/ffn/paired.js +144 -0
  741. package/src/inference/pipelines/text/ffn/qwen-shared-expert.js +212 -0
  742. package/src/inference/pipelines/text/ffn/sandwich.js +8 -3
  743. package/src/inference/pipelines/text/ffn/standard.js +67 -16
  744. package/src/inference/pipelines/text/finiteness-guard-status.js +9 -0
  745. package/src/inference/pipelines/text/generation-request.d.ts +36 -0
  746. package/src/inference/pipelines/text/generation-request.js +73 -0
  747. package/src/inference/pipelines/text/generator/activation-storage.js +15 -0
  748. package/src/inference/pipelines/text/generator/batch-retry-policy.js +20 -0
  749. package/src/inference/pipelines/text/generator/capsule-generation.js +37 -0
  750. package/src/inference/pipelines/text/generator/compiled-greedy-window.js +154 -0
  751. package/src/inference/pipelines/text/generator/decode-components.js +24 -0
  752. package/src/inference/pipelines/text/generator/decode-readback.js +73 -0
  753. package/src/inference/pipelines/text/generator/decode-runtime.js +401 -403
  754. package/src/inference/pipelines/text/generator/decode.js +594 -626
  755. package/src/inference/pipelines/text/generator/diagnostic-sequence.d.ts +63 -0
  756. package/src/inference/pipelines/text/generator/diagnostic-sequence.js +106 -0
  757. package/src/inference/pipelines/text/generator/diffusion.js +24 -12
  758. package/src/inference/pipelines/text/generator/greedy-head-policy.js +15 -0
  759. package/src/inference/pipelines/text/generator/logits-config.js +11 -4
  760. package/src/inference/pipelines/text/generator/per-layer-buffer.js +21 -0
  761. package/src/inference/pipelines/text/generator/prefill-observation.js +25 -1
  762. package/src/inference/pipelines/text/generator/prefill-policy.js +30 -18
  763. package/src/inference/pipelines/text/generator/prefill-runtime.js +511 -511
  764. package/src/inference/pipelines/text/generator/recorded-step-executor.js +70 -0
  765. package/src/inference/pipelines/text/generator/recorder-stats.js +17 -0
  766. package/src/inference/pipelines/text/generator/recovery.js +6 -0
  767. package/src/inference/pipelines/text/generator/session-context.js +19 -7
  768. package/src/inference/pipelines/text/generator/speculative-runtime.js +82 -0
  769. package/src/inference/pipelines/text/generator/text.js +17 -149
  770. package/src/inference/pipelines/text/generator/token-selection.d.ts +7 -0
  771. package/src/inference/pipelines/text/generator/token-selection.js +59 -0
  772. package/src/inference/pipelines/text/generator/training.js +42 -60
  773. package/src/inference/pipelines/text/generator/whole-token-lane.js +371 -0
  774. package/src/inference/pipelines/text/generator/whole-token-observation.d.ts +72 -0
  775. package/src/inference/pipelines/text/generator/whole-token-observation.js +502 -0
  776. package/src/inference/pipelines/text/generator/whole-token-program.d.ts +93 -0
  777. package/src/inference/pipelines/text/generator/whole-token-program.js +731 -0
  778. package/src/inference/pipelines/text/generator/whole-token-template.js +437 -0
  779. package/src/inference/pipelines/text/generator-logits-observation.js +5 -2
  780. package/src/inference/pipelines/text/generator-runtime.d.ts +107 -0
  781. package/src/inference/pipelines/text/generator-runtime.js +38 -79
  782. package/src/inference/pipelines/text/generator-steps.js +62 -55
  783. package/src/inference/pipelines/text/generator.d.ts +10 -1
  784. package/src/inference/pipelines/text/generator.js +111 -175
  785. package/src/inference/pipelines/text/hyper-connection/decoder-layer.d.ts +75 -0
  786. package/src/inference/pipelines/text/hyper-connection/decoder-layer.js +132 -0
  787. package/src/inference/pipelines/text/hyper-connection/layer-executor.js +104 -0
  788. package/src/inference/pipelines/text/hyper-connection/logits-input.js +20 -0
  789. package/src/inference/pipelines/text/hyper-connection/projection.js +21 -0
  790. package/src/inference/pipelines/text/hyper-connection/sequence-transaction.js +145 -0
  791. package/src/inference/pipelines/text/hyper-connection/session.d.ts +39 -0
  792. package/src/inference/pipelines/text/hyper-connection/session.js +236 -0
  793. package/src/inference/pipelines/text/image-transcription.js +2 -3
  794. package/src/inference/pipelines/text/indexed-attention/attention-runner.js +49 -0
  795. package/src/inference/pipelines/text/indexed-attention/qsa-cache.d.ts +54 -0
  796. package/src/inference/pipelines/text/indexed-attention/qsa-cache.js +256 -0
  797. package/src/inference/pipelines/text/init-qkv-fusion.js +121 -104
  798. package/src/inference/pipelines/text/init-rope.d.ts +26 -0
  799. package/src/inference/pipelines/text/init-rope.js +109 -14
  800. package/src/inference/pipelines/text/init-tokenizer.js +29 -0
  801. package/src/inference/pipelines/text/init.d.ts +28 -10
  802. package/src/inference/pipelines/text/init.js +65 -74
  803. package/src/inference/pipelines/text/kernel-trace.js +33 -11
  804. package/src/inference/pipelines/text/layer-execution-contract.js +1 -1
  805. package/src/inference/pipelines/text/layer-input-execution.js +10 -9
  806. package/src/inference/pipelines/text/layer-partition-contract.d.ts +47 -0
  807. package/src/inference/pipelines/text/layer-partition-contract.js +220 -0
  808. package/src/inference/pipelines/text/layer-plan-gpu.js +153 -80
  809. package/src/inference/pipelines/text/layer-plan.js +9 -2
  810. package/src/inference/pipelines/text/layer.js +34 -47
  811. package/src/inference/pipelines/text/lifecycle.js +79 -178
  812. package/src/inference/pipelines/text/linear-attention/activity.js +29 -0
  813. package/src/inference/pipelines/text/linear-attention/norm-ab.js +59 -0
  814. package/src/inference/pipelines/text/linear-attention/plan.js +35 -34
  815. package/src/inference/pipelines/text/linear-attention/state-checkpoint.js +83 -0
  816. package/src/inference/pipelines/text/linear-attention/state-clone.js +109 -0
  817. package/src/inference/pipelines/text/linear-attention/state-layout.js +45 -0
  818. package/src/inference/pipelines/text/linear-attention-ab-fusion.js +48 -45
  819. package/src/inference/pipelines/text/linear-attention.d.ts +20 -0
  820. package/src/inference/pipelines/text/linear-attention.js +150 -131
  821. package/src/inference/pipelines/text/load-errors.js +2 -19
  822. package/src/inference/pipelines/text/load-policy.js +55 -0
  823. package/src/inference/pipelines/text/logits/gpu-executor.js +130 -103
  824. package/src/inference/pipelines/text/logits/gpu.js +93 -70
  825. package/src/inference/pipelines/text/logits/index.d.ts +14 -2
  826. package/src/inference/pipelines/text/logits/index.js +420 -352
  827. package/src/inference/pipelines/text/logits/output-transform.js +37 -25
  828. package/src/inference/pipelines/text/logits/precision-policy.js +1 -1
  829. package/src/inference/pipelines/text/logits/types.d.ts +8 -1
  830. package/src/inference/pipelines/text/lora-apply.js +1 -1
  831. package/src/inference/pipelines/text/model-load.js +71 -117
  832. package/src/inference/pipelines/text/moe/gpu-executor.js +39 -17
  833. package/src/inference/pipelines/text/moe/grouped-prefill.js +67 -0
  834. package/src/inference/pipelines/text/moe/qwen-route-executor.d.ts +41 -0
  835. package/src/inference/pipelines/text/moe/qwen-route-executor.js +125 -0
  836. package/src/inference/pipelines/text/moe/routed-expert-chunks.js +95 -0
  837. package/src/inference/pipelines/text/moe-gpu.js +132 -50
  838. package/src/inference/pipelines/text/moe-impl.d.ts +23 -3
  839. package/src/inference/pipelines/text/moe-shape-validator.js +12 -0
  840. package/src/inference/pipelines/text/ngram/ngram-addresses.d.ts +30 -0
  841. package/src/inference/pipelines/text/ngram/ngram-addresses.js +134 -0
  842. package/src/inference/pipelines/text/ngram/ngram-table.d.ts +89 -0
  843. package/src/inference/pipelines/text/ngram/ngram-table.js +233 -0
  844. package/src/inference/pipelines/text/ngram/ple-layer.d.ts +54 -0
  845. package/src/inference/pipelines/text/ngram/ple-layer.js +115 -0
  846. package/src/inference/pipelines/text/operator-events.d.ts +129 -0
  847. package/src/inference/pipelines/text/operator-events.js +19 -2
  848. package/src/inference/pipelines/text/ops.js +40 -30
  849. package/src/inference/pipelines/text/paired-execution.js +140 -0
  850. package/src/inference/pipelines/text/partition-attempt.js +105 -0
  851. package/src/inference/pipelines/text/partition-execution.js +347 -0
  852. package/src/inference/pipelines/text/per-layer/materialize.js +3 -10
  853. package/src/inference/pipelines/text/per-layer/plan.js +3 -10
  854. package/src/inference/pipelines/text/per-layer-inputs.js +3 -10
  855. package/src/inference/pipelines/text/pipeline-load-timing.js +2 -1
  856. package/src/inference/pipelines/text/pipeline.d.ts +227 -0
  857. package/src/inference/pipelines/text/pipeline.js +629 -0
  858. package/src/inference/pipelines/text/precomputed-input-norm.js +29 -0
  859. package/src/inference/pipelines/text/probes.js +65 -23
  860. package/src/inference/pipelines/text/resident-partition-contract.d.ts +179 -0
  861. package/src/inference/pipelines/text/resident-partition-contract.js +98 -0
  862. package/src/inference/pipelines/text/resident-partition.js +403 -0
  863. package/src/inference/pipelines/text/resident-pipeline-preparation.js +341 -0
  864. package/src/inference/pipelines/text/sampling-config.d.ts +16 -0
  865. package/src/inference/pipelines/text/sampling-config.js +25 -113
  866. package/src/inference/pipelines/text/sampling.d.ts +9 -1
  867. package/src/inference/pipelines/text/sampling.js +18 -375
  868. package/src/inference/pipelines/text/sequence-state.d.ts +68 -0
  869. package/src/inference/pipelines/text/sequence-state.js +514 -0
  870. package/src/inference/pipelines/text/stage-names.d.ts +88 -0
  871. package/src/inference/pipelines/text/state.d.ts +17 -8
  872. package/src/inference/pipelines/text/state.js +10 -0
  873. package/src/inference/pipelines/text/stopping.js +17 -0
  874. package/src/inference/pipelines/text/tsir-fixture-writer.d.ts +77 -0
  875. package/src/inference/pipelines/text/tsir-fixture-writer.js +3 -12
  876. package/src/inference/pipelines/text/types.d.ts +68 -114
  877. package/src/inference/pipelines/text/warm-generation.d.ts +27 -0
  878. package/src/inference/pipelines/text/warm-generation.js +34 -0
  879. package/src/inference/pipelines/text/weight-loading-config.js +16 -10
  880. package/src/inference/pipelines/text/weights.d.ts +103 -1
  881. package/src/inference/pipelines/text/weights.js +0 -17
  882. package/src/inference/pipelines/text.d.ts +3 -211
  883. package/src/inference/pipelines/text.js +16 -578
  884. package/src/inference/pipelines/video/feature-concat.js +30 -0
  885. package/src/inference/pipelines/video/frame-sampler.js +4 -0
  886. package/src/inference/pipelines/video/index.js +33 -44
  887. package/src/inference/pipelines/vision/encoder.js +1 -1
  888. package/src/inference/pipelines/vision/gemma4.js +6 -7
  889. package/src/inference/pipelines/vision/glmocr.js +11 -13
  890. package/src/inference/pipelines/vision/index.js +14 -3
  891. package/src/inference/pipelines/vision/support.js +93 -0
  892. package/src/inference/pipelines/vision/weight-loading.js +111 -0
  893. package/src/inference/rerank.d.ts +44 -0
  894. package/src/inference/resident-block-contract.d.ts +35 -0
  895. package/src/inference/resident-block-contract.js +105 -0
  896. package/src/inference/resident-output-state.d.ts +14 -0
  897. package/src/inference/resident-output-state.js +89 -0
  898. package/src/inference/resident-publication-contract.d.ts +32 -0
  899. package/src/inference/resident-publication-contract.js +104 -0
  900. package/src/inference/resident-state-contract.d.ts +26 -0
  901. package/src/inference/resident-state-contract.js +135 -0
  902. package/src/inference/resident-target-state.d.ts +32 -0
  903. package/src/inference/resident-target-state.js +152 -0
  904. package/src/inference/sampling-rng.js +35 -0
  905. package/src/inference/token-sampling.js +395 -0
  906. package/src/inference/tokenizer.d.ts +2 -0
  907. package/src/inference/tokenizer.js +16 -0
  908. package/src/inference/tokenizers/bundled/incremental-decoder.d.ts +16 -0
  909. package/src/inference/tokenizers/bundled/incremental-decoder.js +100 -0
  910. package/src/inference/tokenizers/bundled/normalizer.js +44 -0
  911. package/src/inference/tokenizers/bundled.js +25 -42
  912. package/src/inference/tokenizers/sentencepiece.js +4 -26
  913. package/src/loader/doppler-loader.d.ts +13 -0
  914. package/src/loader/doppler-loader.js +34 -62
  915. package/src/loader/dtype-utils.js +1 -19
  916. package/src/loader/embedding-limit-preflight.js +77 -8
  917. package/src/loader/embedding-loader.js +43 -114
  918. package/src/loader/experts/expert-cache.js +1 -4
  919. package/src/loader/experts/expert-loader.d.ts +6 -1
  920. package/src/loader/experts/expert-loader.js +90 -29
  921. package/src/loader/experts/expert-preparation.d.ts +16 -0
  922. package/src/loader/experts/expert-preparation.js +57 -0
  923. package/src/loader/experts/loader-bindings.js +53 -0
  924. package/src/loader/experts/qwen-paging.d.ts +19 -0
  925. package/src/loader/experts/qwen-paging.js +70 -0
  926. package/src/loader/experts/routed-expert-cache.d.ts +56 -0
  927. package/src/loader/experts/routed-expert-cache.js +372 -0
  928. package/src/loader/experts/routed-expert-plan.d.ts +20 -0
  929. package/src/loader/experts/routed-expert-plan.js +46 -0
  930. package/src/loader/final-weights-loader.d.ts +7 -1
  931. package/src/loader/final-weights-loader.js +17 -40
  932. package/src/loader/hyper-connection-loader.d.ts +25 -0
  933. package/src/loader/hyper-connection-loader.js +150 -0
  934. package/src/loader/layer-loader.d.ts +8 -1
  935. package/src/loader/layer-loader.js +67 -97
  936. package/src/loader/layer-tensor-aliases.js +77 -11
  937. package/src/loader/layer-weight-shape.js +13 -0
  938. package/src/loader/load-timing.js +2 -0
  939. package/src/loader/loader-types.d.ts +24 -1
  940. package/src/loader/model-executor.js +27 -365
  941. package/src/loader/model-load.d.ts +18 -0
  942. package/src/loader/model-load.js +432 -0
  943. package/src/loader/ngram-table-bindings.d.ts +11 -0
  944. package/src/loader/ngram-table-bindings.js +61 -0
  945. package/src/loader/per-layer-input-loader.js +5 -83
  946. package/src/loader/q4k-reference-weight.js +84 -0
  947. package/src/loader/shard-cache.js +3 -0
  948. package/src/loader/tensor-load-error.js +20 -1
  949. package/src/loader/tensors/bf16-loader.js +3 -29
  950. package/src/loader/tensors/buffer-write.js +26 -0
  951. package/src/loader/tensors/fp8-loader.js +28 -0
  952. package/src/loader/tensors/load-executor.js +124 -117
  953. package/src/loader/tensors/q4_0-loader.js +32 -0
  954. package/src/loader/tensors/range-backed-weights.js +34 -0
  955. package/src/loader/tensors/source-transform.js +1 -1
  956. package/src/loader/tensors/tensor-loader.js +22 -6
  957. package/src/loader/tensors/w8a8-loader.js +36 -0
  958. package/src/loader/weight-downcast.js +9 -13
  959. package/src/loader/weight-representation-plan.d.ts +28 -0
  960. package/src/loader/weight-representation-plan.js +146 -0
  961. package/src/loader/weights.d.ts +1 -1
  962. package/src/memory/buffer-pool.d.ts +24 -4
  963. package/src/memory/buffer-pool.js +124 -128
  964. package/src/memory/device-budget.d.ts +10 -0
  965. package/src/memory/device-budget.js +89 -0
  966. package/src/memory/device-residency.js +60 -0
  967. package/src/partitions.d.ts +21 -0
  968. package/src/partitions.js +10 -0
  969. package/src/rules/execution-rules-contract-check.js +73 -570
  970. package/src/rules/generated/rule-bundle.json +1 -4305
  971. package/src/rules/greedy-sampling.js +16 -0
  972. package/src/rules/inference/capability-transforms.rules.json +11 -1
  973. package/src/rules/layer-pattern-contract-check.js +49 -222
  974. package/src/rules/rule-matcher.d.ts +62 -0
  975. package/src/rules/rule-matcher.js +132 -1
  976. package/src/rules/rule-registry.d.ts +75 -0
  977. package/src/rules/rule-registry.js +64 -24
  978. package/src/storage/artifact-storage-context.d.ts +99 -0
  979. package/src/storage/artifact-storage-context.js +71 -114
  980. package/src/storage/backend-selection.js +3 -0
  981. package/src/storage/backends/idb-store.d.ts +54 -0
  982. package/src/storage/backends/idb-store.js +12 -0
  983. package/src/storage/backends/memory-store.d.ts +38 -0
  984. package/src/storage/backends/memory-store.js +15 -6
  985. package/src/storage/backends/opfs-store.d.ts +43 -0
  986. package/src/storage/backends/opfs-store.js +6 -0
  987. package/src/storage/blake3.d.ts +17 -0
  988. package/src/storage/blake3.js +153 -68
  989. package/src/storage/distribution-transport.js +626 -3
  990. package/src/storage/download/http-contract.js +199 -0
  991. package/src/storage/download/http-transport.js +824 -0
  992. package/src/storage/download/integrity.d.ts +10 -2
  993. package/src/storage/download/integrity.js +39 -2
  994. package/src/storage/download/transport.js +2 -2
  995. package/src/storage/downloader.js +404 -388
  996. package/src/storage/export.d.ts +1 -0
  997. package/src/storage/export.js +22 -70
  998. package/src/storage/model-cache.d.ts +4 -1
  999. package/src/storage/model-cache.js +131 -52
  1000. package/src/storage/model-read-session.d.ts +13 -0
  1001. package/src/storage/model-read-session.js +76 -0
  1002. package/src/storage/node-file-access.js +108 -0
  1003. package/src/storage/reports.js +1 -4
  1004. package/src/storage/runtime-env.js +6 -0
  1005. package/src/storage/shard-manager.d.ts +10 -0
  1006. package/src/storage/shard-manager.js +644 -579
  1007. package/src/storage/shards/index.js +16 -0
  1008. package/src/storage/shards/integrity.js +35 -49
  1009. package/src/storage/source-artifact-store.d.ts +59 -0
  1010. package/src/storage/source-artifact-store.js +24 -37
  1011. package/src/storage/source-storage-context.d.ts +53 -0
  1012. package/src/storage/source-storage-context.js +298 -0
  1013. package/src/storage/verified-piece-reader.d.ts +23 -0
  1014. package/src/storage/verified-piece-reader.js +134 -0
  1015. package/src/storage/verified-piece-storage.d.ts +7 -0
  1016. package/src/storage/verified-piece-storage.js +16 -0
  1017. package/src/tooling/boundary-evidence.js +1 -4
  1018. package/src/tooling/browser-command-runner.d.ts +1 -1
  1019. package/src/tooling/browser-command-runner.js +2 -2
  1020. package/src/tooling/browser-harness/benchmark-comparison.js +105 -0
  1021. package/src/tooling/browser-harness/benchmark-execution.js +865 -0
  1022. package/src/tooling/browser-harness/decode-diagnostics.js +201 -0
  1023. package/src/tooling/browser-harness/inference-execution.js +543 -0
  1024. package/src/tooling/browser-harness/model-initialization.js +230 -0
  1025. package/src/tooling/browser-harness/model-resolution.js +134 -0
  1026. package/src/tooling/browser-harness/report.js +338 -0
  1027. package/src/tooling/browser-harness/request-timing.js +50 -0
  1028. package/src/tooling/browser-harness/request.js +264 -0
  1029. package/src/tooling/browser-harness/runtime-config.d.ts +26 -0
  1030. package/src/tooling/browser-harness/runtime-config.js +256 -0
  1031. package/src/tooling/browser-harness/text-evidence.d.ts +81 -0
  1032. package/src/tooling/browser-harness/text-evidence.js +695 -0
  1033. package/src/tooling/browser-harness/text-execution.d.ts +37 -0
  1034. package/src/tooling/browser-harness/text-execution.js +721 -0
  1035. package/src/tooling/browser-harness/text-input.d.ts +45 -0
  1036. package/src/tooling/browser-harness/text-input.js +722 -0
  1037. package/src/tooling/browser-harness/timing-diagnostics.js +416 -0
  1038. package/src/tooling/browser-harness-text-helpers.d.ts +31 -0
  1039. package/src/tooling/browser-harness-text-helpers.js +31 -0
  1040. package/src/tooling/browser-harness.d.ts +245 -0
  1041. package/src/tooling/browser-harness.js +337 -0
  1042. package/src/tooling/command-api.d.ts +1 -0
  1043. package/src/tooling/diagnose-runner.js +2 -2
  1044. package/src/tooling/distribution-shard-transport.d.ts +6 -0
  1045. package/src/tooling/execution-cost-ledger.d.ts +2 -1
  1046. package/src/tooling/execution-cost-ledger.js +10 -7
  1047. package/src/tooling/hf-registry/catalog-io.js +7 -5
  1048. package/src/tooling/litert-package-runtime.js +1 -98
  1049. package/src/tooling/model-capsule-pieces.js +47 -0
  1050. package/src/tooling/model-capsule-rig.js +528 -0
  1051. package/src/tooling/node-browser/execution.d.ts +1 -1
  1052. package/src/tooling/node-browser/static-server.js +26 -2
  1053. package/src/tooling/node-browser/transport.js +0 -43
  1054. package/src/tooling/node-capsule-artifact-store.js +24 -0
  1055. package/src/tooling/node-command-execution.js +2 -2
  1056. package/src/tooling/node-command-runner.d.ts +1 -1
  1057. package/src/tooling/node-converter/input.js +36 -5
  1058. package/src/tooling/node-converter/output.js +75 -1
  1059. package/src/tooling/node-converter.js +33 -34
  1060. package/src/tooling/node-source-runtime.js +5 -5
  1061. package/src/tooling/portable-source-path.js +26 -0
  1062. package/src/tooling/production-release.js +3 -6
  1063. package/src/tooling/program-bundle/choice-scoring-reference.js +22 -0
  1064. package/src/tooling/program-bundle/materialize.js +4 -0
  1065. package/src/tooling/program-bundle/wgsl-closure.js +3 -9
  1066. package/src/tooling/program-bundle-host.js +26 -0
  1067. package/src/tooling/program-bundle.js +11 -6
  1068. package/src/tooling/reference-verify.js +5 -17
  1069. package/src/tooling/registered-variant-calibration-job.js +1 -4
  1070. package/src/tooling/registered-variant-calibration.js +1 -4
  1071. package/src/tooling/source-artifact-adapter.d.ts +1 -0
  1072. package/src/tooling/source-artifact-adapter.js +33 -1
  1073. package/src/tooling/source-intake.js +1 -4
  1074. package/src/tooling/source-runtime-bundle.d.ts +4 -85
  1075. package/src/tooling/source-runtime-bundle.js +3 -3
  1076. package/src/tooling/source-runtime-converter-config.js +41 -8
  1077. package/src/tooling/test-harness.d.ts +173 -0
  1078. package/src/tooling/test-harness.js +476 -0
  1079. package/src/tooling-exports/device.d.ts +1 -0
  1080. package/src/tooling-exports/device.js +1 -0
  1081. package/src/tooling-exports/evidence.d.ts +3 -0
  1082. package/src/tooling-exports/manifest.d.ts +1 -1
  1083. package/src/tooling-exports/manifest.js +1 -1
  1084. package/src/tooling-exports/runtime.d.ts +6 -1
  1085. package/src/tooling-exports/runtime.js +6 -1
  1086. package/src/tooling-exports/storage.d.ts +10 -0
  1087. package/src/tooling-exports/storage.js +9 -0
  1088. package/src/tooling-exports/structured.d.ts +2 -1
  1089. package/src/tooling-exports/structured.js +2 -1
  1090. package/src/tooling-exports.shared.d.ts +12 -9
  1091. package/src/tooling-exports.shared.js +6 -12
  1092. package/src/training-browser.d.ts +5 -0
  1093. package/src/training.d.ts +7 -0
  1094. package/src/training.js +1 -0
  1095. package/src/version.js +1 -1
  1096. package/tests/fixtures/linear-core-activation-accuracy.json +12 -0
  1097. package/tests/fixtures/linear-core-refined-accuracy.json +128 -0
  1098. package/tests/fixtures/q4k-ordered-accumulation.json +87 -0
  1099. package/tests/fixtures/rmsnorm-inverse-root.json +18 -0
  1100. package/tests/kernels/browser/kernel-suite.js +230 -0
  1101. package/tests/kernels/browser/test-page.js +5 -6
  1102. package/tests/kernels/harness/benchmark.js +11 -3
  1103. package/tests/kernels/reference/dequant.js +23 -3
  1104. package/tests/kernels/reference/index.js +1 -0
  1105. package/tools/convert-safetensors-node.js +7 -1
  1106. package/src/capsule.d.ts +0 -8
  1107. package/src/capsule.js +0 -4
  1108. package/src/cli/serve/capsule-handler.d.ts +0 -33
  1109. package/src/cli/serve/capsule-handler.js +0 -105
  1110. package/src/cli/serve/capsule-http.js +0 -102
  1111. package/src/client/runtime/index.js +0 -1
  1112. package/src/client/runtime/source-runtime.js +0 -910
  1113. package/src/client/runtime/target-selector.js +0 -2
  1114. package/src/config/backward-registry-loader.d.ts +0 -3
  1115. package/src/config/capsule-serve.d.ts +0 -9
  1116. package/src/config/capsule-serve.js +0 -28
  1117. package/src/config/capsule-serve.schema.json +0 -14
  1118. package/src/config/index.d.ts +0 -52
  1119. package/src/config/index.js +0 -22
  1120. package/src/config/kernels/kernel-ref-digests.js +0 -348
  1121. package/src/config/runtime/diagnostics/debug-logits.json +0 -54
  1122. package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +0 -58
  1123. package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +0 -58
  1124. package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +0 -57
  1125. package/src/config/runtime/experiments/bench/gemma4-bench-q4k.json +0 -33
  1126. package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +0 -58
  1127. package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +0 -58
  1128. package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +0 -81
  1129. package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +0 -213
  1130. package/src/config/runtime/experiments/debug/gemma4-e2b-browser-diagnose-q4k.json +0 -85
  1131. package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +0 -81
  1132. package/src/config/runtime/experiments/verify/gemma3-verify.json +0 -37
  1133. package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +0 -36
  1134. package/src/config/runtime/experiments/verify/lfm2-verify.json +0 -44
  1135. package/src/config/runtime/experiments/verify/translategemma-verify.json +0 -37
  1136. package/src/config/runtime/model/gemma2-debug.json +0 -78
  1137. package/src/config/runtime/model/gemma2-pipeline-debug.json +0 -67
  1138. package/src/config/runtime/model/gemma2-pipeline.json +0 -76
  1139. package/src/config/runtime/model/gemma3-layer-probe.json +0 -86
  1140. package/src/config/runtime/model/qwen3-5-layer-probe.json +0 -53
  1141. package/src/config/runtime/model/qwen3-5-layer3-boundary-probe.json +0 -109
  1142. package/src/config/runtime/model/qwen3-5-linear-attn-debug.json +0 -91
  1143. package/src/config/runtime/optimization-candidates/registry.json +0 -5
  1144. package/src/config/runtime/profiles/diffusiongemma-26b-a4b-throughput.json +0 -27
  1145. package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-overlapped-probe.json +0 -43
  1146. package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-probe.json +0 -40
  1147. package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-b4.json +0 -46
  1148. package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-single.json +0 -44
  1149. package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +0 -61
  1150. package/src/config/runtime/profiles/gemma4-e2b-baseline-probe.json +0 -39
  1151. package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-probe.json +0 -42
  1152. package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-test.json +0 -20
  1153. package/src/config/runtime/profiles/gemma4-e2b-int4ple-baseline-probe.json +0 -27
  1154. package/src/config/runtime/profiles/gemma4-e2b-int4ple-f16a-probe.json +0 -30
  1155. package/src/config/runtime/profiles/gemma4-e2b-int4ple-reference-export.json +0 -62
  1156. package/src/config/runtime/profiles/gemma4-e2b-int4ple-retain-q4k-probe.json +0 -43
  1157. package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +0 -64
  1158. package/src/config/runtime/profiles/gemma4-e2b-prefill-profile.json +0 -33
  1159. package/src/config/runtime/profiles/gemma4-e2b-throughput-probe.json +0 -17
  1160. package/src/config/runtime/profiles/muse-glimmer-30b-source-parity-f32kv.json +0 -30
  1161. package/src/config/runtime/profiles/muse-glimmer-30b-source-parity.json +0 -110
  1162. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-attn128-candidate.json +0 -21
  1163. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-maxbatch64-candidate.json +0 -53
  1164. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-normed-ffn-candidate.json +0 -19
  1165. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-overlap-ringtokens1-candidate.json +0 -53
  1166. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-sequential-candidate.json +0 -53
  1167. package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-throughput.json +0 -86
  1168. package/src/config/runtime/profiles/qwen-3-5-0-8b-prefill-profile.json +0 -33
  1169. package/src/config/runtime/profiles/qwen-3-5-0-8b-throughput-probe.json +0 -17
  1170. package/src/config/runtime/profiles/qwen-3-5-2b-f16-primary-throughput.json +0 -19
  1171. package/src/config/runtime/profiles/qwen-3-5-9b-metal-correctness.json +0 -47
  1172. package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +0 -58
  1173. package/src/config/runtime/profiles/qwen3-8-27b-source-parity.json +0 -87
  1174. package/src/config/runtime/profiles/simulation.json +0 -29
  1175. package/src/config/runtime/profiles/trace-layers.json +0 -125
  1176. package/src/config/runtime/profiles/translategemma-1b-nativekd2-q4k-rdna3-throughput-probe.json +0 -23
  1177. package/src/config/runtime/profiles/turboquant-contiguous-prod.json +0 -30
  1178. package/src/config/runtime/profiles/turboquant-contiguous.json +0 -30
  1179. package/src/config/runtime/profiles/turboquant.json +0 -37
  1180. package/src/config/runtime/profiles/verbose-trace.json +0 -37
  1181. package/src/config/runtime/tiers/gemma4-128gb.json +0 -80
  1182. package/src/config/runtime/tiers/gemma4-16gb.json +0 -83
  1183. package/src/config/runtime/tiers/gemma4-24gb.json +0 -80
  1184. package/src/config/runtime/tiers/gemma4-32gb.json +0 -80
  1185. package/src/config/transforms/capability-transform-resolver.js +0 -4
  1186. package/src/config/transforms/execution-graph/fusion.js +0 -436
  1187. package/src/config/transforms/execution-graph/validation.js +0 -414
  1188. package/src/config/transforms/execution-graph-transforms.js +0 -987
  1189. package/src/converter/shard-packer.d.ts +0 -138
  1190. package/src/converter/shard-packer.js +0 -425
  1191. package/src/experimental/adapters/adapter-manager.d.ts +0 -200
  1192. package/src/experimental/adapters/adapter-manager.js +0 -511
  1193. package/src/experimental/adapters/adapter-registry.d.ts +0 -192
  1194. package/src/experimental/adapters/adapter-registry.js +0 -477
  1195. package/src/experimental/adapters/artifact-contract.d.ts +0 -83
  1196. package/src/experimental/adapters/artifact-contract.js +0 -257
  1197. package/src/experimental/adapters/index.d.ts +0 -114
  1198. package/src/experimental/adapters/index.js +0 -54
  1199. package/src/experimental/bridge/trainer-artifact-bridge.d.ts +0 -162
  1200. package/src/experimental/bridge/trainer-artifact-bridge.js +0 -595
  1201. package/src/experimental/browser/browser-converter.d.ts +0 -71
  1202. package/src/experimental/browser/browser-converter.js +0 -978
  1203. package/src/experimental/browser/file-picker.d.ts +0 -63
  1204. package/src/experimental/browser/file-picker.js +0 -281
  1205. package/src/experimental/browser/gguf-parser-browser.js +0 -17
  1206. package/src/experimental/browser/quantization.js +0 -328
  1207. package/src/experimental/browser/safetensors-parser-browser.js +0 -347
  1208. package/src/experimental/browser/tensor-source-download.js +0 -245
  1209. package/src/experimental/browser/tensor-source-file.d.ts +0 -26
  1210. package/src/experimental/browser/tensor-source-file.js +0 -53
  1211. package/src/experimental/browser/tensor-source-http.d.ts +0 -29
  1212. package/src/experimental/browser/tensor-source-http.js +0 -130
  1213. package/src/experimental/diffusion/image-regression.d.ts +0 -31
  1214. package/src/experimental/diffusion/image-regression.js +0 -107
  1215. package/src/experimental/diffusion/index.d.ts +0 -32
  1216. package/src/experimental/diffusion/index.js +0 -18
  1217. package/src/experimental/diffusion/pipeline.js +0 -727
  1218. package/src/experimental/diffusion/scheduler.js +0 -153
  1219. package/src/experimental/diffusion/text-encoder-gpu.js +0 -947
  1220. package/src/experimental/diffusion/vae.js +0 -596
  1221. package/src/experimental/distribution/descriptor-transport.d.ts +0 -117
  1222. package/src/experimental/distribution/descriptor-transport.js +0 -342
  1223. package/src/experimental/distribution/p2p-control-plane.d.ts +0 -52
  1224. package/src/experimental/distribution/p2p-observability.d.ts +0 -116
  1225. package/src/experimental/distribution/p2p-observability.js +0 -303
  1226. package/src/experimental/distribution/p2p-webrtc-browser.d.ts +0 -37
  1227. package/src/experimental/distribution/shard-delivery/transport.js +0 -831
  1228. package/src/experimental/distribution/shard-delivery.d.ts +0 -251
  1229. package/src/experimental/energy/index.d.ts +0 -2
  1230. package/src/experimental/energy/index.js +0 -2
  1231. package/src/experimental/energy/pipeline.js +0 -697
  1232. package/src/experimental/energy/quintel.d.ts +0 -107
  1233. package/src/experimental/energy/quintel.js +0 -218
  1234. package/src/experimental/orchestration/energy-row-head-pipeline.js +0 -491
  1235. package/src/experimental/orchestration/index.d.ts +0 -21
  1236. package/src/experimental/orchestration/index.js +0 -12
  1237. package/src/formats/quantization-constants.d.ts +0 -11
  1238. package/src/formats/quantization-constants.js +0 -11
  1239. package/src/formats/tokenizer/types.js +0 -22
  1240. package/src/gpu/kernel-selector.d.ts +0 -11
  1241. package/src/gpu/kernels/activation-static-qdq.d.ts +0 -22
  1242. package/src/gpu/kernels/attention.d.ts +0 -253
  1243. package/src/gpu/kernels/backward/adam.d.ts +0 -29
  1244. package/src/gpu/kernels/backward/attention_backward.d.ts +0 -35
  1245. package/src/gpu/kernels/backward/bias_add_backward.d.ts +0 -17
  1246. package/src/gpu/kernels/backward/causal_conv1d_silu_backward.d.ts +0 -24
  1247. package/src/gpu/kernels/backward/conv2d_backward.d.ts +0 -31
  1248. package/src/gpu/kernels/backward/cross_entropy_backward.d.ts +0 -23
  1249. package/src/gpu/kernels/backward/embed_backward.d.ts +0 -29
  1250. package/src/gpu/kernels/backward/executor.d.ts +0 -34
  1251. package/src/gpu/kernels/backward/gated_delta_recurrent_backward.d.ts +0 -39
  1252. package/src/gpu/kernels/backward/gated_rmsnorm_backward.d.ts +0 -32
  1253. package/src/gpu/kernels/backward/gelu_backward.d.ts +0 -16
  1254. package/src/gpu/kernels/backward/groupnorm_backward.d.ts +0 -24
  1255. package/src/gpu/kernels/backward/index.d.ts +0 -26
  1256. package/src/gpu/kernels/backward/layernorm_backward.d.ts +0 -22
  1257. package/src/gpu/kernels/backward/matmul_backward.d.ts +0 -31
  1258. package/src/gpu/kernels/backward/pixel_shuffle_backward.d.ts +0 -22
  1259. package/src/gpu/kernels/backward/rmsnorm_backward.d.ts +0 -24
  1260. package/src/gpu/kernels/backward/rope_backward.d.ts +0 -25
  1261. package/src/gpu/kernels/backward/scale_backward.d.ts +0 -16
  1262. package/src/gpu/kernels/backward/silu_backward.d.ts +0 -16
  1263. package/src/gpu/kernels/backward/softmax_backward.d.ts +0 -16
  1264. package/src/gpu/kernels/backward/upsample2d_backward.d.ts +0 -21
  1265. package/src/gpu/kernels/backward/utils.js +0 -2
  1266. package/src/gpu/kernels/cast.d.ts +0 -67
  1267. package/src/gpu/kernels/clamp.d.ts +0 -22
  1268. package/src/gpu/kernels/conv2d.d.ts +0 -30
  1269. package/src/gpu/kernels/cross_entropy_loss.d.ts +0 -21
  1270. package/src/gpu/kernels/depthwise_conv1d.d.ts +0 -23
  1271. package/src/gpu/kernels/depthwise_conv2d.d.ts +0 -29
  1272. package/src/gpu/kernels/dequant.d.ts +0 -92
  1273. package/src/gpu/kernels/diffusion-gemma-sampling.d.ts +0 -19
  1274. package/src/gpu/kernels/energy.d.ts +0 -113
  1275. package/src/gpu/kernels/feature-check.d.ts +0 -42
  1276. package/src/gpu/kernels/fused_ffn.d.ts +0 -97
  1277. package/src/gpu/kernels/fused_matmul_residual.d.ts +0 -46
  1278. package/src/gpu/kernels/fused_matmul_rmsnorm.d.ts +0 -64
  1279. package/src/gpu/kernels/gather.d.ts +0 -144
  1280. package/src/gpu/kernels/gelu.d.ts +0 -33
  1281. package/src/gpu/kernels/gemma4-route-expert.d.ts +0 -35
  1282. package/src/gpu/kernels/grouped_pointwise_conv2d.d.ts +0 -27
  1283. package/src/gpu/kernels/groupnorm.d.ts +0 -27
  1284. package/src/gpu/kernels/index.d.ts +0 -517
  1285. package/src/gpu/kernels/index.js +0 -408
  1286. package/src/gpu/kernels/kernel-cache-lifecycle.d.ts +0 -9
  1287. package/src/gpu/kernels/kernel-prewarm.d.ts +0 -3
  1288. package/src/gpu/kernels/kv-cache-write.d.ts +0 -22
  1289. package/src/gpu/kernels/kv-quantize.d.ts +0 -37
  1290. package/src/gpu/kernels/layernorm.d.ts +0 -33
  1291. package/src/gpu/kernels/linear_attention.d.ts +0 -27
  1292. package/src/gpu/kernels/lm-head-argmax.d.ts +0 -28
  1293. package/src/gpu/kernels/lm-head-select-logits.d.ts +0 -23
  1294. package/src/gpu/kernels/logit-merge.d.ts +0 -86
  1295. package/src/gpu/kernels/logit-merge.js +0 -266
  1296. package/src/gpu/kernels/matmul.d.ts +0 -89
  1297. package/src/gpu/kernels/modulate.d.ts +0 -29
  1298. package/src/gpu/kernels/moe.d.ts +0 -113
  1299. package/src/gpu/kernels/pixel_shuffle.d.ts +0 -27
  1300. package/src/gpu/kernels/relu.d.ts +0 -18
  1301. package/src/gpu/kernels/repeat_channels.d.ts +0 -21
  1302. package/src/gpu/kernels/residual.d.ts +0 -65
  1303. package/src/gpu/kernels/rmsnorm-pair.d.ts +0 -72
  1304. package/src/gpu/kernels/rmsnorm-qk.d.ts +0 -41
  1305. package/src/gpu/kernels/rmsnorm-stats.d.ts +0 -29
  1306. package/src/gpu/kernels/rmsnorm.d.ts +0 -76
  1307. package/src/gpu/kernels/rope-qk.d.ts +0 -41
  1308. package/src/gpu/kernels/rope.d.ts +0 -48
  1309. package/src/gpu/kernels/sample.d.ts +0 -70
  1310. package/src/gpu/kernels/scale.d.ts +0 -40
  1311. package/src/gpu/kernels/silu.d.ts +0 -77
  1312. package/src/gpu/kernels/soft-embedding.d.ts +0 -28
  1313. package/src/gpu/kernels/softmax.d.ts +0 -57
  1314. package/src/gpu/kernels/split-qkv-rmsnorm-qk.d.ts +0 -44
  1315. package/src/gpu/kernels/split-qkv-rmsnorm-rope-qk.d.ts +0 -59
  1316. package/src/gpu/kernels/split_qg.d.ts +0 -50
  1317. package/src/gpu/kernels/split_qkv.d.ts +0 -53
  1318. package/src/gpu/kernels/transpose.d.ts +0 -21
  1319. package/src/gpu/kernels/types.d.ts +0 -21
  1320. package/src/gpu/kernels/upsample2d.d.ts +0 -21
  1321. package/src/gpu/kernels/utils.js +0 -9
  1322. package/src/gpu/kernels/vision-average-pool.d.ts +0 -13
  1323. package/src/gpu/kernels/vision-patch-embed.d.ts +0 -17
  1324. package/src/gpu/kernels/vision-position-embedding.d.ts +0 -13
  1325. package/src/gpu/kernels/vision-rope-2d.d.ts +0 -16
  1326. package/src/gpu/kernels/vision-spatial-merge.d.ts +0 -19
  1327. package/src/gpu/multi-model-recorder.d.ts +0 -21
  1328. package/src/gpu/multi-model-recorder.js +0 -31
  1329. package/src/gpu/partitioned-buffer-pool.d.ts +0 -28
  1330. package/src/gpu/partitioned-buffer-pool.js +0 -57
  1331. package/src/gpu/perf-guards.js +0 -71
  1332. package/src/inference/browser-harness/benchmark-execution.js +0 -872
  1333. package/src/inference/browser-harness/decode-diagnostics.js +0 -241
  1334. package/src/inference/browser-harness/inference-execution.js +0 -543
  1335. package/src/inference/browser-harness/model-initialization.js +0 -225
  1336. package/src/inference/browser-harness/model-resolution.js +0 -137
  1337. package/src/inference/browser-harness/report.js +0 -338
  1338. package/src/inference/browser-harness/request.js +0 -263
  1339. package/src/inference/browser-harness/runtime-config.d.ts +0 -25
  1340. package/src/inference/browser-harness/runtime-config.js +0 -255
  1341. package/src/inference/browser-harness/runtime-isolation.d.ts +0 -13
  1342. package/src/inference/browser-harness/runtime-report.d.ts +0 -26
  1343. package/src/inference/browser-harness/text-evidence.js +0 -694
  1344. package/src/inference/browser-harness/text-execution.js +0 -757
  1345. package/src/inference/browser-harness/text-input.js +0 -725
  1346. package/src/inference/browser-harness/timing-diagnostics.js +0 -414
  1347. package/src/inference/browser-harness-runtime-helpers.d.ts +0 -3
  1348. package/src/inference/browser-harness-runtime-helpers.js +0 -3
  1349. package/src/inference/browser-harness-text-helpers.js +0 -31
  1350. package/src/inference/browser-harness.d.ts +0 -245
  1351. package/src/inference/browser-harness.js +0 -337
  1352. package/src/inference/expert-router.d.ts +0 -27
  1353. package/src/inference/expert-router.js +0 -55
  1354. package/src/inference/kv-cache/index.d.ts +0 -38
  1355. package/src/inference/kv-cache/index.js +0 -22
  1356. package/src/inference/kv-cache.d.ts +0 -39
  1357. package/src/inference/kv-cache.js +0 -20
  1358. package/src/inference/multi-model-network.d.ts +0 -139
  1359. package/src/inference/multi-model-network.js +0 -435
  1360. package/src/inference/multi-pipeline-pool.d.ts +0 -62
  1361. package/src/inference/multi-pipeline-pool.js +0 -161
  1362. package/src/inference/network-evolution.d.ts +0 -43
  1363. package/src/inference/pipelines/diffusion/init.d.ts +0 -24
  1364. package/src/inference/pipelines/diffusion/init.js +0 -138
  1365. package/src/inference/pipelines/diffusion/profile-timing.js +0 -10
  1366. package/src/inference/pipelines/diffusion/runtime-resources.js +0 -54
  1367. package/src/inference/pipelines/diffusion/sd3/execution.js +0 -805
  1368. package/src/inference/pipelines/diffusion/sd3/plan.js +0 -125
  1369. package/src/inference/pipelines/diffusion/sd3-transformer.js +0 -343
  1370. package/src/inference/pipelines/diffusion/sd3-weights.js +0 -287
  1371. package/src/inference/pipelines/diffusion/text-encoder.js +0 -195
  1372. package/src/inference/pipelines/diffusion/vae/execution.js +0 -803
  1373. package/src/inference/pipelines/diffusion/weight-contract.js +0 -53
  1374. package/src/inference/pipelines/diffusion/weights.js +0 -155
  1375. package/src/inference/pipelines/diffusion-gemma/config.d.ts +0 -27
  1376. package/src/inference/pipelines/diffusion-gemma/config.js +0 -149
  1377. package/src/inference/pipelines/diffusion-gemma/index.d.ts +0 -31
  1378. package/src/inference/pipelines/diffusion-gemma/index.js +0 -12
  1379. package/src/inference/pipelines/diffusion-gemma/pipeline.d.ts +0 -69
  1380. package/src/inference/pipelines/diffusion-gemma/pipeline.js +0 -380
  1381. package/src/inference/pipelines/diffusion-gemma/sampling.d.ts +0 -128
  1382. package/src/inference/pipelines/diffusion-gemma/sampling.js +0 -395
  1383. package/src/inference/pipelines/rng.js +0 -17
  1384. package/src/inference/pipelines/structured/index.d.ts +0 -10
  1385. package/src/inference/pipelines/structured/index.js +0 -10
  1386. package/src/inference/pipelines/text/attention/heterogeneous-contract.js +0 -8
  1387. package/src/inference/pipelines/text/attention/index.js +0 -24
  1388. package/src/inference/pipelines/text/attention/record.js +0 -2
  1389. package/src/inference/pipelines/text/attention/run.js +0 -2
  1390. package/src/inference/pipelines/text/config/validation.js +0 -9
  1391. package/src/inference/pipelines/text/debug-utils/index.js +0 -39
  1392. package/src/inference/pipelines/text/debug-utils/profiles.js +0 -8
  1393. package/src/inference/pipelines/text/debug-utils.js +0 -34
  1394. package/src/inference/pipelines/text/ffn/index.js +0 -16
  1395. package/src/inference/pipelines/text/model-load.d.ts +0 -59
  1396. package/src/inference/test-harness.d.ts +0 -172
  1397. package/src/inference/test-harness.js +0 -470
  1398. package/src/loader/dtype-utils.d.ts +0 -40
  1399. package/src/loader/embedding-loader.d.ts +0 -66
  1400. package/src/loader/index.d.ts +0 -152
  1401. package/src/loader/index.js +0 -126
  1402. package/src/loader/loader-state.d.ts +0 -51
  1403. package/src/loader/loader-state.js +0 -142
  1404. package/src/loader/manifest-config.d.ts +0 -118
  1405. package/src/loader/multi-model-loader.d.ts +0 -59
  1406. package/src/loader/multi-model-loader.js +0 -141
  1407. package/src/loader/quantization-constants.d.ts +0 -11
  1408. package/src/loader/quantization-constants.js +0 -13
  1409. package/src/loader/shard-resolver.d.ts +0 -13
  1410. package/src/loader/tensors/tensor-loader.d.ts +0 -197
  1411. package/src/loader/tensors/tensor-reader.d.ts +0 -33
  1412. package/src/loader/tensors/tensor-role.d.ts +0 -7
  1413. package/src/loader/weight-downcast.d.ts +0 -62
  1414. package/src/loader/weights.js +0 -4
  1415. package/src/loaders/index.d.ts +0 -4
  1416. package/src/loaders/index.js +0 -4
  1417. package/src/models/diffusiongemma.d.ts +0 -7
  1418. package/src/models/diffusiongemma.js +0 -25
  1419. package/src/models/embeddinggemma.d.ts +0 -7
  1420. package/src/models/embeddinggemma.js +0 -24
  1421. package/src/models/family.d.ts +0 -24
  1422. package/src/models/family.js +0 -25
  1423. package/src/models/gemma3.d.ts +0 -7
  1424. package/src/models/gemma3.js +0 -33
  1425. package/src/models/gemma4.d.ts +0 -7
  1426. package/src/models/gemma4.js +0 -65
  1427. package/src/models/qwen3.d.ts +0 -7
  1428. package/src/models/qwen3.js +0 -36
  1429. package/src/rules/capability-transform-resolver.js +0 -80
  1430. package/src/tooling/capsule-v2.d.ts +0 -11
  1431. package/src/tooling/model-capsule-forge.js +0 -478
  1432. package/src/tooling/source-runtime/bundle-materialize.js +0 -298
  1433. package/src/tooling-experimental-exports.browser.js +0 -2
  1434. package/src/tooling-experimental-exports.d.ts +0 -7
  1435. package/src/tooling-experimental-exports.js +0 -2
  1436. package/src/tooling-experimental-exports.shared.d.ts +0 -61
  1437. package/src/tooling-experimental-exports.shared.js +0 -57
  1438. /package/src/{config/transforms → converter}/execution-graph/dtype.js +0 -0
  1439. /package/src/{tooling/source-runtime/bundle-plan.js → formats/source-runtime.js} +0 -0
  1440. /package/src/{inference → tooling}/browser-harness/benchmark-rerank.js +0 -0
  1441. /package/src/{inference → tooling}/browser-harness/diffusion-performance.js +0 -0
  1442. /package/src/{inference → tooling}/browser-harness/runtime-isolation.js +0 -0
  1443. /package/src/{inference → tooling}/browser-harness/runtime-report.js +0 -0
  1444. /package/src/{inference → tooling}/browser-harness/suite-summary.js +0 -0
  1445. /package/src/{inference → tooling}/browser-harness-contract-helpers.js +0 -0
  1446. /package/src/{inference → tooling}/browser-harness-diffusion-energy-suites.js +0 -0
  1447. /package/src/{inference → tooling}/browser-harness-report-helpers.js +0 -0
@@ -1,6 +1,13 @@
1
+ import { prepareActivityRecording } from '../activity-weights.js';
2
+ import { beginGenerationContext, finishGenerationContext, generationContextInput } from '../sequence-state.js';
3
+ import { assertHyperConnectionOperation } from '../hyper-connection/sequence-transaction.js';
4
+ import { lookupDraft, verifySpeculativeTokens } from './speculative-runtime.js';
5
+ import { markDiagnosticSequenceStep } from './diagnostic-sequence.js';
1
6
  import { isGPUSamplingAvailable } from '../../../../gpu/kernels/sample.js';
7
+ import { samplingSeedForToken } from '../../../token-sampling.js';
8
+ import { matchesStopSequence } from '../stopping.js';
2
9
  import { markWarmed as markKernelCacheWarmed } from '../../../../gpu/kernel-selection-cache.js';
3
- import { log, trace, isTraceEnabled } from '../../../../debug/index.js';
10
+ import { log, trace } from '../../../../debug/index.js';
4
11
  import {
5
12
  CAPTURE_LEVELS,
6
13
  createDefaultCaptureConfig,
@@ -8,174 +15,189 @@ import {
8
15
  } from '../../../../debug/index.js';
9
16
  import { validateCallTimeOptions } from '../../../../config/param-validator.js';
10
17
  import { selectRuleValue } from '../../../../rules/rule-registry.js';
11
- import { sample, applyRepetitionPenalty, logitsSanity, getTopK } from '../sampling.js';
12
- import { createKVCache, isStopToken } from '../init.js';
18
+ import { getTopK } from '../sampling.js';
19
+ import { isStopToken } from '../init.js';
13
20
  import { OperatorEventEmitter } from '../operator-events.js';
14
- import { isWeightBuffer, isCpuWeightBuffer, isGpuBufferInstance, isSplitWeightBuffer, getWeightDtype, getWeightMetadata, getLayout } from '../../../../gpu/weight-buffer.js';
15
- import {
16
- decodeStep,
17
- decodeStepLogits as runDecodeStepLogits,
18
- advanceWithToken as runAdvanceWithToken,
19
- generateNTokensGPU,
20
- shouldUseBatchDecode,
21
- sumProfileTimings,
22
- FinitenessError,
23
- advanceWithTokenAndEmbedding as runAdvanceWithTokenAndEmbedding,
24
- } from '../generator-steps.js';
25
- import {
26
- buildLayerContext,
27
- debugCheckBuffer as debugCheckBufferHelper,
28
- resolvePerLayerInputsSession,
29
- } from './session-context.js';
30
- import {
31
- assertTokenIdsInRange,
32
- assertTokenIdInRange,
33
- resolveStepOptions,
34
- resolveGenerateOptions,
35
- resolvePrefillOptions,
36
- resolvePrefillEmbeddingOptions,
37
- resolveAdvanceEmbeddingMode,
38
- getFinalNormWeights,
39
- extractEmbeddingFromHidden,
40
- extractTokenEmbeddingsFromHidden,
41
- } from '../generator-runtime.js';
42
- import { resolveSamplingConfig } from '../sampling-config.js';
43
- import {
44
- advanceDecodeStepCount,
45
- createTsirFixtureState,
46
- drainPendingTsirReads,
47
- } from '../tsir-fixture-writer.js';
48
- import {
49
- activateFallbackExecutionPlan,
50
- hasFallbackExecutionPlan,
51
- rebaseExecutionSessionPlan,
52
- resetActiveExecutionPlan,
53
- resolveMaxBatchDecodeTokens,
54
- resolvePrefillRecorderChunkLayers,
55
- resolveActiveExecutionPlan,
56
- setActiveExecutionPlan,
57
- } from '../execution-plan.js';
58
- import {
59
- cloneLinearAttentionRuntime,
60
- hasLinearAttentionLayers,
61
- resetLinearAttentionRuntime,
62
- restoreLinearAttentionRuntime,
63
- } from '../linear-attention.js';
64
- import {
65
- preparePerLayerInputs,
66
- createPleBufferCache,
67
- prefetchPerLayerRow,
68
- getPleHotVocabularyRuntime,
69
- hasGpuSplitPerLayerInputEmbeddings,
70
- hasRangeBackedPerLayerInputEmbeddings,
71
- } from '../per-layer-inputs.js';
72
- import {
73
- shouldDisableBatchDecodeAfterShortBatch,
74
- resolveHotVocabularyBatchDecodeAvailability,
75
- primePleDecodeRuntimeCache,
76
- recordPrefillProfileStep,
77
- resolveTokenText,
78
- usesReplayPrefillDecode,
79
- assertIncrementalDecodeSupport,
80
- summarizeExecutionPlan,
81
- shouldRetryWithFinitenessFallback,
82
- createUnhandledFinitenessPolicyError,
83
- resolveTargetPlanKVDtype,
84
- resolveCurrentKVCacheDtype,
85
- cloneRuntimeInferenceWithKVDtype,
86
- } from '../generator-decode-policy.js';
87
- import { FINITENESS_RESET_WORDS, borrowLinearWeight, borrowNormWeight, canUseChunkedSoftEmbeddingLogits, getExperimentalIntentBundleModule, normalizeCanvasTokenIds, normalizeSelectedLogitTokenIds, normalizeSelfConditioningLogits, normalizeSelfConditioningLogitsState, normalizeSelfConditioningSoftEmbeddingState, recordPrefillRecorderStats, releaseBorrowedWeight, resolveDiffusionGemmaSoftEmbeddingChunkRows, resolvePrefillChunkSubmitMode, resolveSuppressedSamplingTokenIds, traceActivationHealth } from './text.js';
21
+ import { isCpuWeightBuffer } from '../../../../gpu/weight-buffer.js';
22
+ import { decodeStep, advanceWithToken as runAdvanceWithToken, generateNTokensGPU, shouldUseBatchDecode, advanceWithTokenAndEmbedding as runAdvanceWithTokenAndEmbedding } from '../generator-steps.js';
23
+ import { debugCheckBuffer as debugCheckBufferHelper, resolvePerLayerInputsSession } from './session-context.js';
24
+ import { resolveGenerateOptions, resolveAdvanceEmbeddingMode, settleGenerationStats } from '../generator-runtime.js';
25
+ import { createTsirFixtureState } from '../tsir-fixture-writer.js';
26
+ import { resetActiveExecutionPlan, resolveMaxBatchDecodeTokens, resolveActiveExecutionPlan } from '../execution-plan.js';
27
+ import { hasLinearAttentionLayers } from '../linear-attention.js';
28
+ import { createPleBufferCache, prefetchPerLayerRow, getPleHotVocabularyRuntime, hasGpuSplitPerLayerInputEmbeddings, hasRangeBackedPerLayerInputEmbeddings } from '../per-layer-inputs.js';
29
+ import { shouldDisableBatchDecodeAfterShortBatch, resolveHotVocabularyBatchDecodeAvailability, primePleDecodeRuntimeCache, resolveTokenText, usesReplayPrefillDecode, assertIncrementalDecodeSupport, summarizeExecutionPlan } from '../generator-decode-policy.js';
30
+ import { getExperimentalIntentBundleModule, resolveSuppressedSamplingTokenIds } from './text.js';
31
+ import { assertBatchRetryInPlaceAllowed } from './batch-retry-policy.js';
32
+ import { verifyDecodeStepAhead } from './decode.js';
33
+ import { wholeTokenProgramRequested, prepareWholeTokenBatch } from './whole-token-lane.js';
34
+
35
+ function prepareGenerationRuntime(generator, opts, options) {
36
+ assertHyperConnectionOperation(generator._state, opts);
37
+ generator._resetReplayPrefillRuntimeState();
38
+ generator._state.isGenerating = true;
39
+ generator._resetDecodeRuntimeState();
40
+ delete generator._state.stats.outputUsage;
41
+ generator._state.stats.speculationAttempts = 0;
42
+ generator._state.stats.speculationAccepted = 0;
43
+ generator._state.stats.gpuTimePrefillMs = undefined;
44
+ generator._state.stats.gpuTimeDecodeMs = undefined;
45
+ generator._state.stats.decodeRecordMs = 0;
46
+ generator._state.stats.decodeRecordOps = 0;
47
+ generator._state.stats.decodeRecordPasses = 0;
48
+ generator._state.stats.decodeRecordOpLabels = {};
49
+ generator._state.stats.decodeSubmitWaitMs = 0;
50
+ generator._state.stats.decodeReadbackWaitMs = 0;
51
+ generator._state.stats.decodeReadbackMapWaitMs = 0;
52
+ generator._state.stats.decodeReadbackCleanupMs = 0;
53
+ generator._state.stats.decodeReadbackCopyMs = 0;
54
+ generator._state.stats.prefillRecordMs = 0;
55
+ generator._state.stats.prefillRecordOps = 0;
56
+ generator._state.stats.prefillRecordPasses = 0;
57
+ generator._state.stats.prefillRecordOpLabels = {};
58
+ generator._state.stats.prefillSubmitWaitMs = 0;
59
+ generator._state.stats.singleTokenSubmitWaitMs = 0;
60
+ generator._state.stats.singleTokenReadbackWaitMs = 0;
61
+ generator._state.stats.singleTokenReadbackMapWaitMs = 0;
62
+ generator._state.stats.singleTokenReadbackCleanupMs = 0;
63
+ generator._state.stats.singleTokenReadbackCopyMs = 0;
64
+ generator._state.stats.singleTokenOrchestrationMs = 0;
65
+ generator._state.stats.pleHotVocabularyHits = 0;
66
+ generator._state.stats.pleHotVocabularyMisses = 0;
67
+ generator._state.stats.plePreparedTokenCacheHits = 0;
68
+ generator._state.stats.plePreparedTokenCacheMisses = 0;
69
+ generator._state.stats.plePreparedTokenCacheEntries = 0;
70
+ generator._state.stats.plePreparedTokenCacheBytes = 0;
71
+ generator._state.stats.decodeMode = null;
72
+ generator._state.stats.batchGuardReason = null;
73
+ generator._state.stats.stopReason = null;
74
+ generator._state.stats.stopTokenId = null;
75
+ generator._state.stats.ttftMs = 0;
76
+ generator._state.stats.prefillTimeMs = 0;
77
+ generator._state.stats.decodeTimeMs = 0;
78
+ generator._state.stats.prefillTokens = 0;
79
+ generator._state.stats.reusedPrefixTokens = 0;
80
+ generator._state.stats.prefillComputedTokens = 0;
81
+ generator._state.stats.tokensGenerated = 0;
82
+ generator._state.stats.decodeTokens = 0;
83
+ generator._state.stats.totalTimeMs = 0;
84
+ const startTime = performance.now();
85
+
86
+ opts.onLogits = typeof options.onLogits === 'function' ? options.onLogits : null;
87
+ // Validate and normalize sampling parameters through single source of truth
88
+ const samplingConfig = opts;
89
+ opts.suppressTokenIds = resolveSuppressedSamplingTokenIds(generator._state, samplingConfig);
90
+ const diagnosticsEnabled = options?.diagnostics?.enabled === true
91
+ || generator._state.runtimeConfig?.shared?.harness?.mode === 'diagnose';
92
+ const tsirFixtureCfg = generator._state.runtimeConfig?.shared?.harness?.tsirFixture ?? null;
93
+ if (diagnosticsEnabled || tsirFixtureCfg) {
94
+ const captureConfig = {
95
+ ...createDefaultCaptureConfig(),
96
+ enabled: true,
97
+ defaultLevel: CAPTURE_LEVELS.SLICE,
98
+ ...(options?.diagnostics?.captureConfig ?? {}),
99
+ };
100
+ validateCaptureConfig(captureConfig);
101
+ generator._state.operatorDiagnostics = {
102
+ enabled: diagnosticsEnabled === true,
103
+ captureConfig,
104
+ emitter: diagnosticsEnabled ? new OperatorEventEmitter({
105
+ modelHash: generator._state.manifest?.modelId ?? null,
106
+ runtimeConfigHash: generator._state.resolvedKernelPath?.id ?? null,
107
+ executionPlanHash: opts.executionPlan?.id ?? null,
108
+ }) : null,
109
+ tsirFixture: createTsirFixtureState(tsirFixtureCfg),
110
+ };
111
+ }
112
+ if (opts.__activationTrace?.activity) {
113
+ generator._state.operatorDiagnostics ??= { enabled: false };
114
+ generator._state.operatorDiagnostics.activity = opts.__activationTrace.activity;
115
+ }
116
+ const activePlan = resolveActiveExecutionPlan(generator._state);
117
+ generator._state.stats.executionPlan = {
118
+ primary: summarizeExecutionPlan(generator._state.executionPlanState?.primaryPlan ?? null),
119
+ fallback: summarizeExecutionPlan(generator._state.executionPlanState?.fallbackPlan ?? null),
120
+ activePlanIdAtStart: activePlan?.id ?? null,
121
+ finalActivePlanId: activePlan?.id ?? null,
122
+ transitions: [],
123
+ };
124
+ generator._state.stats.kernelPathId = activePlan?.kernelPathId ?? generator._state.resolvedKernelPath?.id ?? null;
125
+ generator._state.stats.kernelPathSource = activePlan?.kernelPathSource ?? generator._state.kernelPathSource ?? 'none';
126
+ return startTime;
127
+ }
128
+
129
+ // With a kept whole-token program, verify it on decode step 1 while the prefill's last
130
+ // commands run, so step 1 replays it. A failure there invalidates the program; step 1 then
131
+ // observes as it would without this.
132
+ function wholeTokenAheadVerification(generator, opts) {
133
+ const state = generator._state;
134
+ if (!state.wholeTokenProgram?.program.ready || !wholeTokenProgramRequested(state, opts)) return undefined;
135
+ let used = false;
136
+ return async (position, placeholderToken) => {
137
+ if (used) return;
138
+ used = true;
139
+ try {
140
+ await verifyDecodeStepAhead(state, position, placeholderToken, opts, generator._getDecodeHelpers(undefined));
141
+ } catch (error) {
142
+ const message = error instanceof Error ? error.message : String(error);
143
+ state.wholeTokenProgram?.program.invalidate(`verification ahead of decode step 1 failed: ${message}`);
144
+ log.warn('Decode', `Whole-token verification ahead of step 1 failed (${message}); step 1 observes the program again.`);
145
+ }
146
+ };
147
+ }
148
+
149
+ async function samplePrefillToken(generator, prefillLogits, generatedIds, inputIds, opts, prefillStartSeqLen, warn) {
150
+ try {
151
+ return generator._sampleNextTokenFromLogits(prefillLogits, generatedIds, opts);
152
+ } catch (error) {
153
+ if (!generator._shouldUseFinitenessFallback(error, 'prefill-sample')) {
154
+ throw error;
155
+ }
156
+ await finishGenerationContext(generator._state, [], false);
157
+ generationContextInput(generator._state, inputIds);
158
+ if (warn) log.warn('Pipeline', 'FinitenessGuard caught non-finite prefill logits at sampling. Retrying with F32 precision.');
159
+ prefillLogits = await generator._retryWithPersistentFinitenessFallback(
160
+ opts,
161
+ 'prefill-sample',
162
+ opts.maxTokens,
163
+ () => generator._prefill(inputIds, opts),
164
+ opts.generationContext ? 0 : prefillStartSeqLen
165
+ );
166
+ return generator._sampleNextTokenFromLogits(prefillLogits, generatedIds, opts);
167
+ }
168
+ }
169
+
170
+ function finishGenerationRuntime(generator, options, startTime, generatedIds, promptTokenCount) {
171
+ settleGenerationStats(generator._state.stats, startTime,
172
+ Math.max(0, generatedIds.length - promptTokenCount), options.signal?.aborted === true);
173
+ generator._state.stats.batching = { ...generator._state.batchingStats };
174
+ if (generator._state.stats.executionPlan) {
175
+ generator._state.stats.executionPlan.finalActivePlanId = generator._state.executionPlanState?.activePlanId ?? null;
176
+ }
177
+ resetActiveExecutionPlan(generator._state);
178
+ generator._state.stats.operatorDiagnostics = generator._state.operatorDiagnostics?.emitter
179
+ ? {
180
+ enabled: true,
181
+ timeline: generator._state.operatorDiagnostics.emitter.getTimeline(),
182
+ recordCount: generator._state.operatorDiagnostics.emitter.length,
183
+ }
184
+ : null;
185
+ generator._state.operatorDiagnostics = null;
186
+ generator._state.isGenerating = false;
187
+ }
88
188
 
89
189
  export async function* _generateTokensInternal(prompt, options = {}, mode = 'text') {
90
190
  if (!this._state.isLoaded) throw new Error('Model not loaded');
91
191
  if (this._state.isGenerating) throw new Error('Generation already in progress');
92
-
93
192
  validateCallTimeOptions(options);
94
-
95
- this._state.isGenerating = true;
96
- this._resetDecodeRuntimeState();
97
- this._state.stats.gpuTimePrefillMs = undefined;
98
- this._state.stats.gpuTimeDecodeMs = undefined;
99
- this._state.stats.decodeRecordMs = 0;
100
- this._state.stats.decodeRecordOps = 0;
101
- this._state.stats.decodeRecordPasses = 0;
102
- this._state.stats.decodeRecordOpLabels = {};
103
- this._state.stats.decodeSubmitWaitMs = 0;
104
- this._state.stats.decodeReadbackWaitMs = 0;
105
- this._state.stats.decodeReadbackMapWaitMs = 0;
106
- this._state.stats.decodeReadbackCleanupMs = 0;
107
- this._state.stats.decodeReadbackCopyMs = 0;
108
- this._state.stats.prefillRecordMs = 0;
109
- this._state.stats.prefillRecordOps = 0;
110
- this._state.stats.prefillRecordPasses = 0;
111
- this._state.stats.prefillRecordOpLabels = {};
112
- this._state.stats.prefillSubmitWaitMs = 0;
113
- this._state.stats.singleTokenSubmitWaitMs = 0;
114
- this._state.stats.singleTokenReadbackWaitMs = 0;
115
- this._state.stats.singleTokenReadbackMapWaitMs = 0;
116
- this._state.stats.singleTokenReadbackCleanupMs = 0;
117
- this._state.stats.singleTokenReadbackCopyMs = 0;
118
- this._state.stats.singleTokenOrchestrationMs = 0;
119
- this._state.stats.pleHotVocabularyHits = 0;
120
- this._state.stats.pleHotVocabularyMisses = 0;
121
- this._state.stats.plePreparedTokenCacheHits = 0;
122
- this._state.stats.plePreparedTokenCacheMisses = 0;
123
- this._state.stats.plePreparedTokenCacheEntries = 0;
124
- this._state.stats.plePreparedTokenCacheBytes = 0;
125
- this._state.stats.decodeMode = null;
126
- this._state.stats.batchGuardReason = null;
127
- this._state.stats.stopReason = null;
128
- this._state.stats.stopTokenId = null;
129
- this._state.stats.ttftMs = 0;
130
- const startTime = performance.now();
131
-
132
193
  const opts = resolveGenerateOptions(this._state, options);
133
- opts.onLogits = typeof options.onLogits === 'function' ? options.onLogits : null;
134
- opts.onLogits = typeof options.onLogits === 'function' ? options.onLogits : null;
135
- // Validate and normalize sampling parameters through single source of truth
136
- const samplingConfig = resolveSamplingConfig(options, this._state.runtimeConfig);
137
- opts.temperature = samplingConfig.temperature;
138
- opts.topP = samplingConfig.topP;
139
- opts.topK = samplingConfig.topK;
140
- opts.repetitionPenalty = samplingConfig.repetitionPenalty;
141
- opts.suppressTokenIds = resolveSuppressedSamplingTokenIds(this._state, samplingConfig);
142
- const diagnosticsEnabled = options?.diagnostics?.enabled === true
143
- || this._state.runtimeConfig?.shared?.harness?.mode === 'diagnose';
144
- const tsirFixtureCfg = this._state.runtimeConfig?.shared?.harness?.tsirFixture ?? null;
145
- if (diagnosticsEnabled || tsirFixtureCfg) {
146
- const captureConfig = {
147
- ...createDefaultCaptureConfig(),
148
- enabled: true,
149
- defaultLevel: CAPTURE_LEVELS.SLICE,
150
- ...(options?.diagnostics?.captureConfig ?? {}),
151
- };
152
- validateCaptureConfig(captureConfig);
153
- this._state.operatorDiagnostics = {
154
- enabled: diagnosticsEnabled === true,
155
- captureConfig,
156
- emitter: diagnosticsEnabled ? new OperatorEventEmitter({
157
- modelHash: this._state.manifest?.modelId ?? null,
158
- runtimeConfigHash: this._state.resolvedKernelPath?.id ?? null,
159
- executionPlanHash: opts.executionPlan?.id ?? null,
160
- }) : null,
161
- tsirFixture: createTsirFixtureState(tsirFixtureCfg),
162
- };
163
- }
164
- const activePlan = opts.executionPlan ?? resolveActiveExecutionPlan(this._state);
165
- this._state.stats.executionPlan = {
166
- primary: summarizeExecutionPlan(this._state.executionPlanState?.primaryPlan ?? null),
167
- fallback: summarizeExecutionPlan(this._state.executionPlanState?.fallbackPlan ?? null),
168
- activePlanIdAtStart: activePlan?.id ?? null,
169
- finalActivePlanId: activePlan?.id ?? null,
170
- transitions: [],
171
- };
172
- this._state.stats.kernelPathId = activePlan?.kernelPathId ?? this._state.resolvedKernelPath?.id ?? null;
173
- this._state.stats.kernelPathSource = activePlan?.kernelPathSource ?? this._state.kernelPathSource ?? 'none';
174
-
194
+ const startTime = prepareGenerationRuntime(this, opts, options);
195
+ let generatedIds = [];
196
+ let promptTokenCount = 0;
197
+ let completed = false;
175
198
  if (opts.debug) {
176
199
  log.debug('Pipeline', `ChatTemplate: options=${options.useChatTemplate}, final=${opts.useChatTemplate}`);
177
200
  }
178
-
179
201
  const emitToken = async function* (generator, tokenId, textDecoder) {
180
202
  if (mode === 'token') {
181
203
  yield tokenId;
@@ -186,28 +208,29 @@ export async function* _generateTokensInternal(prompt, options = {}, mode = 'tex
186
208
  yield tokenText;
187
209
  if (options.onToken) options.onToken(tokenId, tokenText);
188
210
  };
189
-
190
211
  try {
212
+ beginGenerationContext(this._state, options.generationContext, opts);
213
+ await prepareActivityRecording(this._state, opts);
191
214
  const prefillStartSeqLen = this._state.currentSeqLen;
192
215
  const prefillStart = performance.now();
216
+ opts._whileFinalPrefillRuns = wholeTokenAheadVerification(this, opts);
193
217
  const { inputIds, logits: initialPrefillLogits } = await this._prefillPromptToLogits(prompt, opts, 'generate');
194
- let prefillLogits = initialPrefillLogits;
218
+ opts._whileFinalPrefillRuns = undefined;
219
+ const prefillLogits = initialPrefillLogits;
195
220
  this._state.stats.prefillTimeMs = performance.now() - prefillStart;
196
221
  this._assertTokenIdsInRange(inputIds, 'generate.prefillTokens');
197
- const generatedIds = [...inputIds];
198
- this._state.stats.prefillTokens = inputIds.length;
199
-
222
+ generatedIds = [...inputIds];
223
+ promptTokenCount = inputIds.length;
224
+ this._state.stats.prefillTokens = opts.promptTokenCount = inputIds.length;
200
225
  if (opts.debug) {
201
226
  log.debug('Pipeline', `Input: ${inputIds.length} tokens`);
202
227
  }
203
-
204
228
  const intentBundleConfig = this._state.runtimeConfig.shared.intentBundle;
205
229
  const intentBundle = intentBundleConfig?.bundle;
206
230
  const expectedTopK = intentBundle?.payload?.expectedTopK
207
231
  ?? intentBundle?.payload?.expected_top_k;
208
232
  const maxDriftThreshold = intentBundle?.constraints?.maxDriftThreshold
209
233
  ?? intentBundle?.constraints?.max_drift_threshold;
210
-
211
234
  if (intentBundleConfig?.enabled && Array.isArray(expectedTopK) && expectedTopK.length > 0) {
212
235
  const { enforceLogitDrift } = await getExperimentalIntentBundleModule();
213
236
  const actualTopK = getTopK(
@@ -220,7 +243,6 @@ export async function* _generateTokensInternal(prompt, options = {}, mode = 'tex
220
243
  throw new Error(`Intent bundle drift check failed: ${driftResult.reason}`);
221
244
  }
222
245
  }
223
-
224
246
  if (opts.debug) {
225
247
  const topAfterPenalty = getTopK(
226
248
  Float32Array.from(prefillLogits),
@@ -230,23 +252,7 @@ export async function* _generateTokensInternal(prompt, options = {}, mode = 'tex
230
252
  log.debug('Pipeline', `After rep penalty top-5: ${topAfterPenalty.map(t => `"${t.text}"(${(t.prob * 100).toFixed(1)}%)`).join(', ')}`);
231
253
  }
232
254
 
233
- let firstToken;
234
- try {
235
- firstToken = this._sampleNextTokenFromLogits(prefillLogits, generatedIds, opts);
236
- } catch (error) {
237
- if (!this._shouldUseFinitenessFallback(error, 'prefill-sample')) {
238
- throw error;
239
- }
240
- log.warn('Pipeline', 'FinitenessGuard caught non-finite prefill logits at sampling. Retrying with F32 precision.');
241
- prefillLogits = await this._retryWithPersistentFinitenessFallback(
242
- opts,
243
- 'prefill-sample',
244
- opts.maxTokens,
245
- () => this._prefill(inputIds, opts),
246
- prefillStartSeqLen
247
- );
248
- firstToken = this._sampleNextTokenFromLogits(prefillLogits, generatedIds, opts);
249
- }
255
+ const firstToken = await samplePrefillToken(this, prefillLogits, generatedIds, inputIds, opts, prefillStartSeqLen, true);
250
256
 
251
257
  if (opts.debug) {
252
258
  const firstTokenText = resolveTokenText(this._state.tokenizer, [firstToken], `[${firstToken}]`, (tokens) => this._state.tokenizer?.decode?.(tokens, true, false));
@@ -277,15 +283,17 @@ export async function* _generateTokensInternal(prompt, options = {}, mode = 'tex
277
283
 
278
284
  yield* emitToken(this, firstToken, decodeToken);
279
285
 
280
- if (this._shouldStopAfterAppendedToken(generatedIds, firstToken, opts, decodeRuntime)) {
281
- this._recordStopReason('stop-token-or-sequence', firstToken);
286
+ if (options.signal?.aborted || this._shouldStopAfterAppendedToken(generatedIds, firstToken, opts, decodeRuntime)) {
287
+ this._recordStopReason(options.signal?.aborted ? 'aborted'
288
+ : isStopToken(firstToken, decodeRuntime.stopTokenIds, decodeRuntime.eosToken) ? 'stop-token' : 'stop-sequence',
289
+ options.signal?.aborted ? null : firstToken);
282
290
  this._state.stats.decodeTimeMs = 0;
283
291
  this._state.stats.tokensGenerated = 1;
284
- this._state.stats.decodeTokens = 1;
292
+ this._state.stats.decodeTokens = 0;
285
293
  } else {
286
294
  yield* this._runDecodeLoop(generatedIds, opts, options, decodeRuntime);
287
295
  }
288
- const tokensGenerated = this._state.stats.decodeTokens ?? 1;
296
+ const tokensGenerated = this._state.stats.tokensGenerated ?? 1;
289
297
  this._state.stats.totalTimeMs = performance.now() - startTime;
290
298
 
291
299
  if (opts.debug) {
@@ -310,18 +318,16 @@ export async function* _generateTokensInternal(prompt, options = {}, mode = 'tex
310
318
  decodeSpeed,
311
319
  totalMs: this._state.stats.totalTimeMs,
312
320
  });
321
+ completed = !options.signal?.aborted && !this._finitenessFallbackWindow;
313
322
  } finally {
314
- this._closeFinitenessFallbackWindow(opts);
315
- resetActiveExecutionPlan(this._state);
316
- this._state.stats.operatorDiagnostics = this._state.operatorDiagnostics?.emitter
317
- ? {
318
- enabled: true,
319
- timeline: this._state.operatorDiagnostics.emitter.getTimeline(),
320
- recordCount: this._state.operatorDiagnostics.emitter.length,
323
+ try { await opts.__activationTrace?.drain(); }
324
+ finally {
325
+ try { this._closeFinitenessFallbackWindow(opts); }
326
+ finally {
327
+ try { await finishGenerationContext(this._state, generatedIds, completed); }
328
+ finally { finishGenerationRuntime(this, options, startTime, generatedIds, promptTokenCount); }
321
329
  }
322
- : null;
323
- this._state.operatorDiagnostics = null;
324
- this._state.isGenerating = false;
330
+ }
325
331
  }
326
332
  }
327
333
 
@@ -330,101 +336,26 @@ export async function generateTokenIds(prompt, options = {}) {
330
336
  if (this._state.isGenerating) throw new Error('Generation already in progress');
331
337
 
332
338
  validateCallTimeOptions(options);
333
-
334
- this._state.isGenerating = true;
335
- this._resetDecodeRuntimeState();
336
- this._state.stats.gpuTimePrefillMs = undefined;
337
- this._state.stats.gpuTimeDecodeMs = undefined;
338
- this._state.stats.decodeRecordMs = 0;
339
- this._state.stats.decodeRecordOps = 0;
340
- this._state.stats.decodeRecordPasses = 0;
341
- this._state.stats.decodeRecordOpLabels = {};
342
- this._state.stats.decodeSubmitWaitMs = 0;
343
- this._state.stats.decodeReadbackWaitMs = 0;
344
- this._state.stats.decodeReadbackMapWaitMs = 0;
345
- this._state.stats.decodeReadbackCleanupMs = 0;
346
- this._state.stats.decodeReadbackCopyMs = 0;
347
- this._state.stats.prefillRecordMs = 0;
348
- this._state.stats.prefillRecordOps = 0;
349
- this._state.stats.prefillRecordPasses = 0;
350
- this._state.stats.prefillRecordOpLabels = {};
351
- this._state.stats.prefillSubmitWaitMs = 0;
352
- this._state.stats.singleTokenSubmitWaitMs = 0;
353
- this._state.stats.singleTokenReadbackWaitMs = 0;
354
- this._state.stats.singleTokenReadbackMapWaitMs = 0;
355
- this._state.stats.singleTokenReadbackCleanupMs = 0;
356
- this._state.stats.singleTokenReadbackCopyMs = 0;
357
- this._state.stats.singleTokenOrchestrationMs = 0;
358
- this._state.stats.pleHotVocabularyHits = 0;
359
- this._state.stats.pleHotVocabularyMisses = 0;
360
- this._state.stats.plePreparedTokenCacheHits = 0;
361
- this._state.stats.plePreparedTokenCacheMisses = 0;
362
- this._state.stats.plePreparedTokenCacheEntries = 0;
363
- this._state.stats.plePreparedTokenCacheBytes = 0;
364
- this._state.stats.decodeMode = null;
365
- this._state.stats.batchGuardReason = null;
366
- this._state.stats.stopReason = null;
367
- this._state.stats.stopTokenId = null;
368
- this._state.stats.ttftMs = 0;
369
- const startTime = performance.now();
370
339
  const opts = resolveGenerateOptions(this._state, options);
371
- opts.onLogits = typeof options.onLogits === 'function' ? options.onLogits : null;
372
- // Validate and normalize sampling parameters through single source of truth
373
- const samplingConfig = resolveSamplingConfig(options, this._state.runtimeConfig);
374
- opts.temperature = samplingConfig.temperature;
375
- opts.topP = samplingConfig.topP;
376
- opts.topK = samplingConfig.topK;
377
- opts.repetitionPenalty = samplingConfig.repetitionPenalty;
378
- opts.suppressTokenIds = resolveSuppressedSamplingTokenIds(this._state, samplingConfig);
379
- const diagnosticsEnabled = options?.diagnostics?.enabled === true
380
- || this._state.runtimeConfig?.shared?.harness?.mode === 'diagnose';
381
- const tsirFixtureCfg = this._state.runtimeConfig?.shared?.harness?.tsirFixture ?? null;
382
- if (diagnosticsEnabled || tsirFixtureCfg) {
383
- const captureConfig = {
384
- ...createDefaultCaptureConfig(),
385
- enabled: true,
386
- defaultLevel: CAPTURE_LEVELS.SLICE,
387
- ...(options?.diagnostics?.captureConfig ?? {}),
388
- };
389
- validateCaptureConfig(captureConfig);
390
- this._state.operatorDiagnostics = {
391
- enabled: diagnosticsEnabled === true,
392
- captureConfig,
393
- emitter: diagnosticsEnabled ? new OperatorEventEmitter({
394
- modelHash: this._state.manifest?.modelId ?? null,
395
- runtimeConfigHash: this._state.resolvedKernelPath?.id ?? null,
396
- executionPlanHash: opts.executionPlan?.id ?? null,
397
- }) : null,
398
- tsirFixture: createTsirFixtureState(tsirFixtureCfg),
399
- };
400
- }
340
+ const startTime = prepareGenerationRuntime(this, opts, options);
341
+ let generatedIds = [];
342
+ let promptTokenCount = 0;
343
+ let completed = false;
401
344
 
402
345
  try {
346
+ beginGenerationContext(this._state, options.generationContext, opts);
347
+ await prepareActivityRecording(this._state, opts);
403
348
  const prefillStartSeqLen = this._state.currentSeqLen;
404
349
  const prefillStart = performance.now();
405
350
  const { inputIds, logits: initialPrefillLogits } = await this._prefillPromptToLogits(prompt, opts, 'generateTokenIds');
406
- let prefillLogits = initialPrefillLogits;
351
+ const prefillLogits = initialPrefillLogits;
407
352
  this._state.stats.prefillTimeMs = performance.now() - prefillStart;
408
353
  this._assertTokenIdsInRange(inputIds, 'generateTokenIds.prefillTokens');
409
- const generatedIds = [...inputIds];
410
- this._state.stats.prefillTokens = inputIds.length;
411
-
412
- let firstToken;
413
- try {
414
- firstToken = this._sampleNextTokenFromLogits(prefillLogits, generatedIds, opts);
415
- } catch (error) {
416
- if (!this._shouldUseFinitenessFallback(error, 'prefill-sample')) {
417
- throw error;
418
- }
419
- prefillLogits = await this._retryWithPersistentFinitenessFallback(
420
- opts,
421
- 'prefill-sample',
422
- opts.maxTokens,
423
- () => this._prefill(inputIds, opts),
424
- prefillStartSeqLen
425
- );
426
- firstToken = this._sampleNextTokenFromLogits(prefillLogits, generatedIds, opts);
427
- }
354
+ generatedIds = [...inputIds];
355
+ promptTokenCount = inputIds.length;
356
+ this._state.stats.prefillTokens = opts.promptTokenCount = inputIds.length;
357
+
358
+ const firstToken = await samplePrefillToken(this, prefillLogits, generatedIds, inputIds, opts, prefillStartSeqLen, false);
428
359
 
429
360
  const stopTokenIds = this._state.modelConfig.stopTokenIds;
430
361
  const eosToken = this._state.tokenizer.getSpecialTokens?.()?.eos;
@@ -433,6 +364,7 @@ export async function generateTokenIds(prompt, options = {}) {
433
364
  const tokenIds = [firstToken];
434
365
  this._state.stats.ttftMs = performance.now() - startTime;
435
366
  markKernelCacheWarmed();
367
+ if (options.onToken) options.onToken(firstToken, '');
436
368
 
437
369
  const decodeRuntime = {
438
370
  stopTokenIds,
@@ -442,38 +374,38 @@ export async function generateTokenIds(prompt, options = {}) {
442
374
  emitMode: 'token',
443
375
  };
444
376
 
445
- if (!this._shouldStopAfterAppendedToken(generatedIds, firstToken, opts, decodeRuntime)) {
377
+ if (!options.signal?.aborted && !this._shouldStopAfterAppendedToken(generatedIds, firstToken, opts, decodeRuntime)) {
446
378
  for await (const tokenId of this._runDecodeLoop(generatedIds, opts, options, decodeRuntime)) {
447
379
  tokenIds.push(tokenId);
448
380
  }
449
381
  } else {
450
- this._recordStopReason('stop-token-or-sequence', firstToken);
382
+ this._recordStopReason(options.signal?.aborted ? 'aborted'
383
+ : isStopToken(firstToken, decodeRuntime.stopTokenIds, decodeRuntime.eosToken) ? 'stop-token' : 'stop-sequence',
384
+ options.signal?.aborted ? null : firstToken);
451
385
  this._state.stats.decodeTimeMs = 0;
452
386
  this._state.stats.tokensGenerated = 1;
453
- this._state.stats.decodeTokens = 1;
387
+ this._state.stats.decodeTokens = 0;
454
388
  }
455
389
 
456
390
  this._state.stats.totalTimeMs = performance.now() - startTime;
457
391
 
392
+ completed = !options.signal?.aborted && !this._finitenessFallbackWindow;
458
393
  return {
459
394
  tokenIds,
395
+ // Exact prefilled IDs, so callers can replay a prefix without
396
+ // re-tokenizing displayed text.
397
+ inputTokenIds: [...inputIds],
460
398
  stats: this._state.stats,
461
399
  };
462
400
  } finally {
463
- this._closeFinitenessFallbackWindow(opts);
464
- if (this._state.stats.executionPlan) {
465
- this._state.stats.executionPlan.finalActivePlanId = this._state.executionPlanState?.activePlanId ?? null;
466
- }
467
- resetActiveExecutionPlan(this._state);
468
- this._state.stats.operatorDiagnostics = this._state.operatorDiagnostics?.emitter
469
- ? {
470
- enabled: true,
471
- timeline: this._state.operatorDiagnostics.emitter.getTimeline(),
472
- recordCount: this._state.operatorDiagnostics.emitter.length,
401
+ try { await opts.__activationTrace?.drain(); }
402
+ finally {
403
+ try { this._closeFinitenessFallbackWindow(opts); }
404
+ finally {
405
+ try { await finishGenerationContext(this._state, generatedIds, completed); }
406
+ finally { finishGenerationRuntime(this, options, startTime, generatedIds, promptTokenCount); }
473
407
  }
474
- : null;
475
- this._state.operatorDiagnostics = null;
476
- this._state.isGenerating = false;
408
+ }
477
409
  }
478
410
  }
479
411
 
@@ -536,13 +468,14 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
536
468
  });
537
469
  const initialHotVocabularyBatchDecodeAvailable = resolveCurrentHotVocabularyBatchDecodeAvailable();
538
470
  const executionPlan = opts.executionPlan;
539
- let useBatchPath = replayPrefillDecode
471
+ const wholeTokenReplay = wholeTokenProgramRequested(this._state, opts);
472
+ let useBatchPath = replayPrefillDecode || wholeTokenReplay
540
473
  ? false
541
474
  : shouldUseBatchDecode({
542
475
  batchSize: executionPlan.batchSize,
543
476
  useGPU: this._state.useGPU,
544
477
  gpuSamplingAvailable,
545
- disableMultiTokenDecode: executionPlan.disableMultiTokenDecode || hasSuppressedSamplingTokens,
478
+ disableMultiTokenDecode: executionPlan.disableMultiTokenDecode || hasSuppressedSamplingTokens || typeof opts.logitMaskFn === 'function',
546
479
  disableCommandBatching: executionPlan.disableCommandBatching,
547
480
  isBdpaPagedLayout: this._state.kvCache?.layout === 'bdpa_paged',
548
481
  finitenessFallbackWindowOpen: this._hasFinitenessFallbackWindow(),
@@ -550,6 +483,8 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
550
483
  selfSpeculationEnabled: opts.speculation?.mode === 'self' && !initialHotVocabularyBatchDecodeAvailable,
551
484
  hasRangeBackedPerLayerInputs,
552
485
  });
486
+ const ordinaryBatchPath = useBatchPath;
487
+ if (opts.speculation?.mode === 'lookup') useBatchPath = false;
553
488
  if (!useBatchPath) {
554
489
  let reason = null;
555
490
  if (replayPrefillDecode) reason = 'replay_prefill_decode';
@@ -558,6 +493,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
558
493
  else if (!gpuSamplingAvailable) reason = 'no_gpu_sampling';
559
494
  else if (executionPlan.disableCommandBatching) reason = 'command_batching_disabled';
560
495
  else if (hasSuppressedSamplingTokens) reason = 'sampling_suppression_requires_cpu_logits';
496
+ else if (typeof opts.logitMaskFn === 'function') reason = 'token_constraint_requires_per_token_logits';
561
497
  else if (executionPlan.disableMultiTokenDecode) reason = 'multi_token_decode_disabled';
562
498
  else if (executionPlan.batchSize <= 1) reason = 'batch_size_1';
563
499
  else if (this._state.kvCache?.layout === 'bdpa_paged') reason = 'bdpa_paged_layout';
@@ -576,9 +512,13 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
576
512
 
577
513
  const readbackInterval = executionPlan.readbackInterval;
578
514
  const intervalBatches = readbackInterval == null ? 1 : readbackInterval;
579
- const padTokenId = this._state.tokenizer?.getSpecialTokens?.()?.pad;
580
515
 
581
516
  const decodeSingleTokenViaLogits = async () => this._decodeNextTokenViaLogits(generatedIds, opts);
517
+ const stopIfAborted = () => {
518
+ if (!options.signal?.aborted) return false;
519
+ this._recordStopReason('aborted');
520
+ return true;
521
+ };
582
522
 
583
523
  if (logBatchPath && useBatchPath) {
584
524
  log.debug(
@@ -587,19 +527,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
587
527
  );
588
528
  }
589
529
 
590
- while (tokensGenerated < opts.maxTokens) {
591
- if (options.signal?.aborted) {
592
- this._recordStopReason('aborted');
593
- break;
594
- }
595
- if (this._hasFinitenessFallbackWindow() && useBatchPath) {
596
- useBatchPath = false;
597
- }
598
- const hotVocabularyBatchDecodeAvailable = resolveCurrentHotVocabularyBatchDecodeAvailable();
599
-
600
- if (useBatchPath) {
601
- const remaining = opts.maxTokens - tokensGenerated;
602
- const maxBatchDecodeTokens = resolveMaxBatchDecodeTokens({
530
+ const batchTokenLimit = (hotVocabularyBatchDecodeAvailable) => resolveMaxBatchDecodeTokens({
603
531
  hasHotVocabularyBatchDecode: hotVocabularyBatchDecodeAvailable,
604
532
  hasGpuSplitPerLayerInputs,
605
533
  hasLinearAttentionLayers: hasLinearLayers,
@@ -610,7 +538,77 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
610
538
  numLayers: this._state.modelConfig.numLayers,
611
539
  hiddenSize: this._state.modelConfig.hiddenSize,
612
540
  configuredMaxBatchDecodeTokens: executionPlan.maxBatchDecodeTokens,
613
- });
541
+ });
542
+
543
+ let rejectedDraftBlocks = 0;
544
+ while (tokensGenerated < opts.maxTokens) {
545
+ if (stopIfAborted()) break;
546
+ if (this._hasFinitenessFallbackWindow() && useBatchPath) {
547
+ useBatchPath = false;
548
+ }
549
+ const hotVocabularyBatchDecodeAvailable = resolveCurrentHotVocabularyBatchDecodeAvailable();
550
+
551
+ if (opts.speculation?.mode === 'lookup' && rejectedDraftBlocks < opts.speculation.maxRejectedBlocks) {
552
+ const remaining = opts.maxTokens - tokensGenerated;
553
+ const proposal = remaining > 1 ? lookupDraft(generatedIds, Math.min(opts.speculation.tokens, remaining - 1), opts.speculation.maxMatchTokens, opts.speculation.minMatchTokens) : [];
554
+ if (proposal.length) {
555
+ const stop = (context, token) => isStopToken(token, stopTokenIds, eosToken)
556
+ || matchesStopSequence(this._state.tokenizer, context, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput);
557
+ const result = await verifySpeculativeTokens(this, generatedIds, proposal, opts, options.signal, stop);
558
+ if (result.accepted < proposal.length) rejectedDraftBlocks++;
559
+ if (rejectedDraftBlocks >= opts.speculation.maxRejectedBlocks) useBatchPath = ordinaryBatchPath;
560
+ this._state.stats.decodeMode = 'target_verified_lookup';
561
+ this._state.stats.speculationAttempts += proposal.length;
562
+ this._state.stats.speculationAccepted += result.accepted;
563
+ for (const token of result.tokens) {
564
+ if (stopIfAborted()) break;
565
+ generatedIds.push(token); tokensGenerated++;
566
+ const text = emitMode === 'token' ? '' : decodeToken(token);
567
+ yield emitMode === 'token' ? token : text;
568
+ options.onToken?.(token, text);
569
+ }
570
+ const last = generatedIds[generatedIds.length - 1];
571
+ if (isStopToken(last, stopTokenIds, eosToken)) { this._recordStopReason('stop-token', last); break; }
572
+ if (matchesStopSequence(this._state.tokenizer, generatedIds, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput)) {
573
+ this._recordStopReason('stop-sequence', last); break;
574
+ }
575
+ continue;
576
+ }
577
+ }
578
+
579
+ if (wholeTokenReplay && executionPlan.batchSize > 1 && executionPlan.stopCheckMode === 'batch' && !executionPlan.disableMultiTokenDecode) {
580
+ const requested = Math.min(executionPlan.batchSize, opts.maxTokens - tokensGenerated);
581
+ const maximum = batchTokenLimit(hotVocabularyBatchDecodeAvailable);
582
+ const bounded = maximum == null ? requested : Math.min(requested, maximum);
583
+ if (maximum != null) this._state.batchingStats.maxBatchTokenCap = Math.max(this._state.batchingStats.maxBatchTokenCap ?? 0, maximum);
584
+ if (bounded < executionPlan.batchSize) this._state.batchingStats.batchClampCount = (this._state.batchingStats.batchClampCount ?? 0) + 1;
585
+ const batch = await prepareWholeTokenBatch(this._state, generatedIds, bounded);
586
+ if (batch) {
587
+ let stopped = false;
588
+ const delivered = [];
589
+ try {
590
+ for await (const token of batch.tokens) {
591
+ if (stopIfAborted()) { stopped = true; break; }
592
+ batch.publish(); generatedIds.push(token); tokensGenerated++;
593
+ const text = emitMode === 'token' ? '' : decodeToken(token);
594
+ delivered.push({ id: token, text });
595
+ yield emitMode === 'token' ? token : text;
596
+ options.onToken?.(token, text);
597
+ if (isStopToken(token, stopTokenIds, eosToken)) { this._recordStopReason('stop-token', token); stopped = true; break; }
598
+ if (matchesStopSequence(this._state.tokenizer, generatedIds, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput)) {
599
+ this._recordStopReason('stop-sequence', token); stopped = true; break;
600
+ }
601
+ }
602
+ if (delivered.length) options.onBatch?.(delivered);
603
+ } finally { await batch.settle(); }
604
+ if (stopped) break;
605
+ continue;
606
+ }
607
+ }
608
+
609
+ if (useBatchPath) {
610
+ const remaining = opts.maxTokens - tokensGenerated;
611
+ const maxBatchDecodeTokens = batchTokenLimit(hotVocabularyBatchDecodeAvailable);
614
612
  const requestedBatchTokens = executionPlan.batchSize * intervalBatches;
615
613
  const boundedBatchTokens = maxBatchDecodeTokens == null
616
614
  ? requestedBatchTokens
@@ -647,55 +645,12 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
647
645
  ? opts
648
646
  : { ...opts, executionPlan: boundedExecutionPlan };
649
647
 
648
+ let batchResult;
650
649
  try {
651
- const batchResult = await this._generateNTokensGPU(lastToken, thisBatchSize, generatedIds, batchOpts);
652
- let batchTokens = [];
653
- let hitStop = false;
654
- let stopTokenId = null;
655
- for (const tokenId of batchResult.tokens) {
656
- generatedIds.push(tokenId);
657
- tokensGenerated++;
658
- if (emitMode === 'token') {
659
- yield tokenId;
660
- if (options.onToken) options.onToken(tokenId, '');
661
- batchTokens.push({ id: tokenId, text: '' });
662
- } else {
663
- const tokenText = decodeToken(tokenId);
664
- yield tokenText;
665
- if (options.onToken) options.onToken(tokenId, tokenText);
666
- batchTokens.push({ id: tokenId, text: tokenText });
667
- }
668
- if (batchTokens.length === executionPlan.batchSize) {
669
- if (options.onBatch) options.onBatch(batchTokens);
670
- batchTokens = [];
671
- }
672
- if (isStopToken(tokenId, stopTokenIds, eosToken)) {
673
- hitStop = true;
674
- stopTokenId = tokenId;
675
- break;
676
- }
677
- }
678
- if (batchTokens.length > 0 && options.onBatch) options.onBatch(batchTokens);
679
- if (opts.stopSequences.length > 0) {
680
- const fullText = this._state.tokenizer.decode(generatedIds.slice(stopSequenceStart), false);
681
- if (opts.stopSequences.some((seq) => fullText.endsWith(seq))) {
682
- this._recordStopReason('stop-sequence', generatedIds[generatedIds.length - 1] ?? null);
683
- break;
684
- }
685
- }
686
- if (hitStop) {
687
- this._recordStopReason('stop-token', stopTokenId);
688
- break;
689
- }
690
- if (shouldDisableBatchDecodeAfterShortBatch({
691
- hitStop,
692
- actualCount: batchResult.actualCount,
693
- requestedCount: thisBatchSize,
694
- })) {
695
- useBatchPath = false;
696
- continue;
697
- }
650
+ batchResult = await this._generateNTokensGPU(lastToken, thisBatchSize, generatedIds, batchOpts);
698
651
  } catch (error) {
652
+ if (stopIfAborted()) break;
653
+ assertBatchRetryInPlaceAllowed(this._state, error);
699
654
  log.warn('Pipeline', `Batch decode failed, falling back to single-token: ${error}`);
700
655
  useBatchPath = false;
701
656
  let nextToken;
@@ -713,6 +668,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
713
668
  throw singleTokenError;
714
669
  }
715
670
  }
671
+ if (stopIfAborted()) break;
716
672
  generatedIds.push(nextToken);
717
673
  tokensGenerated++;
718
674
  if (emitMode === 'token') {
@@ -728,6 +684,52 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
728
684
  this._recordStopReason('stop-token', nextToken);
729
685
  break;
730
686
  }
687
+ continue;
688
+ }
689
+ let batchTokens = [];
690
+ let hitStop = false;
691
+ let stopTokenId = null;
692
+ for (const tokenId of batchResult.tokens) {
693
+ if (options.signal?.aborted) break;
694
+ generatedIds.push(tokenId);
695
+ tokensGenerated++;
696
+ if (emitMode === 'token') {
697
+ yield tokenId;
698
+ if (options.onToken) options.onToken(tokenId, '');
699
+ batchTokens.push({ id: tokenId, text: '' });
700
+ } else {
701
+ const tokenText = decodeToken(tokenId);
702
+ yield tokenText;
703
+ if (options.onToken) options.onToken(tokenId, tokenText);
704
+ batchTokens.push({ id: tokenId, text: tokenText });
705
+ }
706
+ if (batchTokens.length === executionPlan.batchSize) {
707
+ if (options.onBatch) options.onBatch(batchTokens);
708
+ batchTokens = [];
709
+ }
710
+ if (isStopToken(tokenId, stopTokenIds, eosToken)) {
711
+ hitStop = true;
712
+ stopTokenId = tokenId;
713
+ break;
714
+ }
715
+ }
716
+ if (batchTokens.length > 0 && options.onBatch) options.onBatch(batchTokens);
717
+ if (stopIfAborted()) break;
718
+ if (matchesStopSequence(this._state.tokenizer, generatedIds, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput)) {
719
+ this._recordStopReason('stop-sequence', generatedIds[generatedIds.length - 1] ?? null);
720
+ break;
721
+ }
722
+ if (hitStop) {
723
+ this._recordStopReason('stop-token', stopTokenId);
724
+ break;
725
+ }
726
+ if (shouldDisableBatchDecodeAfterShortBatch({
727
+ hitStop,
728
+ actualCount: batchResult.actualCount,
729
+ requestedCount: thisBatchSize,
730
+ })) {
731
+ useBatchPath = false;
732
+ continue;
731
733
  }
732
734
  } else if (opts.speculation?.mode === 'self') {
733
735
  // Self-speculation: decode one base token plus a configurable burst of
@@ -756,6 +758,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
756
758
  throw error;
757
759
  }
758
760
  }
761
+ if (stopIfAborted()) break;
759
762
  generatedIds.push(baseToken);
760
763
  tokensGenerated++;
761
764
  if (emitMode === 'token') {
@@ -773,15 +776,13 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
773
776
  break;
774
777
  }
775
778
  if (tokensGenerated >= opts.maxTokens) break;
776
- if (opts.stopSequences.length > 0) {
777
- const fullText = this._state.tokenizer.decode(generatedIds.slice(stopSequenceStart), false);
778
- if (opts.stopSequences.some((seq) => fullText.endsWith(seq))) {
779
- this._recordStopReason('stop-sequence', baseToken);
780
- break;
781
- }
779
+ if (matchesStopSequence(this._state.tokenizer, generatedIds, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput)) {
780
+ this._recordStopReason('stop-sequence', baseToken);
781
+ break;
782
782
  }
783
783
 
784
784
  for (let specIndex = 0; specIndex < speculativeBurstTokens; specIndex += 1) {
785
+ if (stopIfAborted()) break;
785
786
  if (tokensGenerated >= opts.maxTokens) {
786
787
  break;
787
788
  }
@@ -796,6 +797,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
796
797
  throw error;
797
798
  }
798
799
  }
800
+ if (stopIfAborted()) break;
799
801
  generatedIds.push(specToken);
800
802
  tokensGenerated++;
801
803
  this._state.stats.speculationAttempts = (this._state.stats.speculationAttempts ?? 0) + 1;
@@ -812,7 +814,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
812
814
 
813
815
  if (opts.debug || opts.benchmark) {
814
816
  const elapsedMs = performance.now() - decodeStart;
815
- const tokPerSec = (tokensGenerated / elapsedMs) * 1000;
817
+ const tokPerSec = (Math.max(0, tokensGenerated - 1) / elapsedMs) * 1000;
816
818
  log.debug('Decode', `#${tokensGenerated} speculation:self (${tokPerSec.toFixed(2)} tok/s avg)`);
817
819
  }
818
820
 
@@ -820,24 +822,18 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
820
822
  this._recordStopReason('stop-token', specToken);
821
823
  break;
822
824
  }
823
- if (opts.stopSequences.length > 0) {
824
- const fullText = this._state.tokenizer.decode(generatedIds.slice(stopSequenceStart), false);
825
- if (opts.stopSequences.some((seq) => fullText.endsWith(seq))) {
826
- this._recordStopReason('stop-sequence', specToken);
827
- break;
828
- }
825
+ if (matchesStopSequence(this._state.tokenizer, generatedIds, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput)) {
826
+ this._recordStopReason('stop-sequence', specToken);
827
+ break;
829
828
  }
830
829
  }
831
830
  if (isStopToken(generatedIds[generatedIds.length - 1], stopTokenIds, eosToken)) {
832
831
  this._recordStopReason('stop-token', generatedIds[generatedIds.length - 1]);
833
832
  break;
834
833
  }
835
- if (opts.stopSequences.length > 0) {
836
- const fullText = this._state.tokenizer.decode(generatedIds.slice(stopSequenceStart), false);
837
- if (opts.stopSequences.some((seq) => fullText.endsWith(seq))) {
838
- this._recordStopReason('stop-sequence', generatedIds[generatedIds.length - 1] ?? null);
839
- break;
840
- }
834
+ if (matchesStopSequence(this._state.tokenizer, generatedIds, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput)) {
835
+ this._recordStopReason('stop-sequence', generatedIds[generatedIds.length - 1] ?? null);
836
+ break;
841
837
  }
842
838
  } else {
843
839
  const tokenStart = performance.now();
@@ -859,6 +855,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
859
855
  }
860
856
  }
861
857
  const tokenTime = performance.now() - tokenStart;
858
+ if (stopIfAborted()) break;
862
859
  generatedIds.push(nextToken);
863
860
  tokensGenerated++;
864
861
 
@@ -887,7 +884,7 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
887
884
 
888
885
  if (opts.debug || opts.benchmark) {
889
886
  const elapsedMs = performance.now() - decodeStart;
890
- const tokPerSec = (tokensGenerated / elapsedMs) * 1000;
887
+ const tokPerSec = (Math.max(0, tokensGenerated - 1) / elapsedMs) * 1000;
891
888
  log.debug('Decode', `#${tokensGenerated} "${tokenText}" ${tokenTime.toFixed(0)}ms (${tokPerSec.toFixed(2)} tok/s avg)`);
892
889
  }
893
890
 
@@ -895,12 +892,9 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
895
892
  this._recordStopReason('stop-token', nextToken);
896
893
  break;
897
894
  }
898
- if (opts.stopSequences.length > 0) {
899
- const fullText = this._state.tokenizer.decode(generatedIds.slice(stopSequenceStart), false);
900
- if (opts.stopSequences.some((seq) => fullText.endsWith(seq))) {
901
- this._recordStopReason('stop-sequence', nextToken);
902
- break;
903
- }
895
+ if (matchesStopSequence(this._state.tokenizer, generatedIds, stopSequenceStart, opts.stopSequences, this._state.modelConfig?.reasoningOutput)) {
896
+ this._recordStopReason('stop-sequence', nextToken);
897
+ break;
904
898
  }
905
899
  }
906
900
  }
@@ -910,20 +904,23 @@ export async function* _runDecodeLoop(generatedIds, opts, options, runtime) {
910
904
  }
911
905
  this._state.stats.decodeTimeMs = performance.now() - decodeStart;
912
906
  this._state.stats.tokensGenerated = tokensGenerated;
913
- this._state.stats.decodeTokens = tokensGenerated;
907
+ // Prefill produces the first token; decode timing covers only later tokens.
908
+ this._state.stats.decodeTokens = Math.max(0, tokensGenerated - 1);
914
909
  this._state.stats.batching = { ...this._state.batchingStats };
915
910
  }
916
911
 
917
912
  export async function _decodeStep(currentIds, opts) {
918
913
  if (usesReplayPrefillDecode(this._state)) {
919
- const stepResult = await this._decodeStepToLogits(currentIds, opts);
920
- return this._sampleNextTokenFromLogits(stepResult.logits, currentIds, opts);
914
+ return this._decodeNextTokenViaLogits(currentIds, opts);
921
915
  }
922
916
  const debugCheckBuffer = this._state.debug
923
- ? (buffer, label, numTokens, expectedDim) =>
924
- debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim)
917
+ ? (buffer, label, numTokens, expectedDim, representation) =>
918
+ debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim, representation)
925
919
  : undefined;
926
- return decodeStep(this._state, currentIds, opts, this._getDecodeHelpers(debugCheckBuffer));
920
+ const sampling = opts.temperature === 0 ? opts : {
921
+ ...opts, seed: samplingSeedForToken(opts.seed, currentIds.length - opts.promptTokenCount),
922
+ };
923
+ return decodeStep(this._state, currentIds, sampling, this._getDecodeHelpers(debugCheckBuffer));
927
924
  }
928
925
 
929
926
  export async function decodeStepLogits(currentIds, options = {}) {
@@ -936,6 +933,7 @@ export async function decodeStepLogits(currentIds, options = {}) {
936
933
  validateCallTimeOptions(options);
937
934
 
938
935
  const opts = this._resolveStepOptions(options);
936
+ markDiagnosticSequenceStep(this._state, 'decode', options);
939
937
  return this._decodeStepToLogits(currentIds, opts);
940
938
  }
941
939
 
@@ -949,8 +947,8 @@ export async function advanceWithToken(tokenId, options = {}) {
949
947
 
950
948
  const opts = this._resolveStepOptions(options);
951
949
  const debugCheckBuffer = this._state.debug
952
- ? (buffer, label, numTokens, expectedDim) =>
953
- debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim)
950
+ ? (buffer, label, numTokens, expectedDim, representation) =>
951
+ debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim, representation)
954
952
  : undefined;
955
953
 
956
954
  this._assertTokenIdInRange(tokenId, 'advanceWithToken');
@@ -968,8 +966,8 @@ export async function advanceWithTokenAndEmbedding(tokenId, options = {}) {
968
966
  const opts = this._resolveStepOptions(options);
969
967
  const embeddingMode = resolveAdvanceEmbeddingMode(this._state, options);
970
968
  const debugCheckBuffer = this._state.debug
971
- ? (buffer, label, numTokens, expectedDim) =>
972
- debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim)
969
+ ? (buffer, label, numTokens, expectedDim, representation) =>
970
+ debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim, representation)
973
971
  : undefined;
974
972
 
975
973
  this._assertTokenIdInRange(tokenId, 'advanceWithTokenAndEmbedding');
@@ -984,8 +982,8 @@ export async function advanceWithTokenAndEmbedding(tokenId, options = {}) {
984
982
 
985
983
  export async function _generateNTokensGPU(startToken, N, currentIds, opts) {
986
984
  const debugCheckBuffer = this._state.debug
987
- ? (buffer, label, numTokens, expectedDim) =>
988
- debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim)
985
+ ? (buffer, label, numTokens, expectedDim, representation) =>
986
+ debugCheckBufferHelper(this._state, buffer, label, numTokens, expectedDim, representation)
989
987
  : undefined;
990
988
  return generateNTokensGPU(this._state, startToken, N, currentIds, opts, this._getDecodeHelpers(debugCheckBuffer));
991
989
  }