doppler-gpu 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/README.md +97 -29
- package/package.json +40 -27
- package/src/cli/config/doppler-quickstart.json +10 -0
- package/src/cli/doppler-cli.js +66 -22
- package/src/cli/doppler-quickstart.d.ts +61 -0
- package/src/cli/doppler-quickstart.js +299 -0
- package/src/cli/doppler-serve.js +395 -0
- package/src/client/doppler-api.browser.js +13 -377
- package/src/client/doppler-api.d.ts +35 -56
- package/src/client/doppler-api.js +12 -363
- package/src/client/doppler-registry.json +55 -2
- package/src/client/runtime/index.d.ts +63 -0
- package/src/client/runtime/index.js +173 -0
- package/src/client/runtime/lora.d.ts +36 -0
- package/src/client/runtime/lora.js +165 -0
- package/src/client/{doppler-provider → runtime}/model-manager.d.ts +1 -1
- package/src/client/{doppler-provider → runtime}/model-manager.js +56 -30
- package/src/client/runtime/model-session.d.ts +72 -0
- package/src/client/runtime/model-session.js +122 -0
- package/src/client/runtime/model-source.d.ts +43 -0
- package/src/client/runtime/model-source.js +101 -0
- package/src/client/{doppler-provider → runtime}/source-runtime.d.ts +8 -5
- package/src/client/runtime/source-runtime.js +919 -0
- package/src/client/runtime/storage.d.ts +5 -0
- package/src/client/runtime/storage.js +51 -0
- package/src/client/{doppler-provider → runtime}/types.d.ts +14 -2
- package/src/config/README.md +2 -0
- package/src/config/conversion/README.md +47 -7
- package/src/config/conversion/embeddinggemma/google-embeddinggemma-300m-q4k-ehf16-af32.json +67 -5
- package/src/config/conversion/gemma3/gemma-3-1b-it-f16-af32.json +62 -11
- package/src/config/conversion/gemma3/gemma-3-1b-it-q4k-ehf16-af32.json +79 -18
- package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af32.json +61 -13
- package/src/config/conversion/gemma3/translategemma-4b-1b-enes-q4k-ehf16-af32.json +53 -10
- package/src/config/conversion/gemma3/translategemma-4b-it-q4k-ehf16-af32.json +66 -18
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32.json +256 -0
- package/src/config/conversion/gemma4/gemma-4-moe-q4k-ehf16-af32.json +49 -8
- package/src/config/conversion/gpt-oss-20b-f16-xmxfp4.json +45 -6
- package/src/config/conversion/janus/janus-pro-1b-text-q4k-ehaf16.json +45 -6
- package/src/config/conversion/lfm2/lfm2.5-1.2b-instruct-q4k-ehf16-af32.json +57 -9
- package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +105 -26
- package/src/config/conversion/qwen3/qwen-3-5-2b-q4k-ehaf16.json +83 -33
- package/src/config/conversion/sana/sana-sprint-0.6b-f16.json +33 -5
- package/src/config/execution-contract-check.d.ts +2 -1
- package/src/config/execution-contract-check.js +187 -53
- package/src/config/kernel-path-loader.d.ts +36 -0
- package/src/config/kernel-path-loader.js +97 -10
- package/src/config/kernels/kernel-ref-digests.js +40 -24
- package/src/config/kernels/registry.js +0 -1
- package/src/config/kernels/registry.json +772 -66
- package/src/config/merge-contract-check.js +3 -0
- package/src/config/merge.d.ts +18 -1
- package/src/config/merge.js +56 -0
- package/src/config/param-categories.js +5 -0
- package/src/config/param-validator.js +42 -26
- package/src/config/platforms/apple-m3.json +1 -1
- package/src/config/platforms/loader.js +21 -16
- package/src/config/required-inference-fields-contract-check.js +16 -0
- package/src/config/runtime/compute/f16-batched.json +2 -0
- package/src/config/runtime/default.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +57 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +57 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +2 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +57 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +57 -0
- package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +81 -0
- package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +5 -0
- package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +81 -0
- package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +38 -0
- package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +63 -0
- package/src/config/runtime/profiles/gemma4-e2b-throughput.json +39 -0
- package/src/config/runtime/profiles/low-memory.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous-prod.json +29 -0
- package/src/config/runtime/profiles/turboquant-contiguous.json +29 -0
- package/src/config/runtime/profiles/turboquant.json +36 -0
- package/src/config/runtime/profiles/vector-stability.json +1 -0
- package/src/config/runtime/tiers/gemma4-128gb.json +79 -0
- package/src/config/runtime/tiers/gemma4-16gb.json +15 -2
- package/src/config/runtime/tiers/gemma4-24gb.json +15 -2
- package/src/config/runtime/tiers/gemma4-32gb.json +15 -2
- package/src/config/runtime.js +11 -4
- package/src/config/schema/converter.schema.d.ts +4 -2
- package/src/config/schema/converter.schema.js +7 -5
- package/src/config/schema/doppler.schema.d.ts +26 -2
- package/src/config/schema/doppler.schema.js +77 -28
- package/src/config/schema/execution-v1.schema.d.ts +78 -5
- package/src/config/schema/execution-v1.schema.js +62 -1
- package/src/config/schema/index.d.ts +22 -29
- package/src/config/schema/index.js +15 -17
- package/src/config/schema/inference.schema.d.ts +26 -4
- package/src/config/schema/kernel-path.schema.d.ts +30 -3
- package/src/config/schema/kernel-registry.schema.d.ts +1 -1
- package/src/config/schema/kernel-registry.schema.js +1 -0
- package/src/config/schema/kvcache.schema.js +7 -0
- package/src/config/schema/loading.schema.d.ts +28 -0
- package/src/config/schema/loading.schema.js +9 -0
- package/src/config/schema/manifest.schema.d.ts +79 -5
- package/src/config/schema/manifest.schema.js +7 -1
- package/src/config/schema/platform.schema.d.ts +10 -8
- package/src/config/schema/speculation-self.schema.js +0 -5
- package/src/config/schema/support-tiers.schema.d.ts +53 -0
- package/src/config/schema/support-tiers.schema.js +128 -0
- package/src/config/source-packages/litert/gemma-4-e2b-it.json +622 -0
- package/src/config/source-packages/registry.json +15 -0
- package/src/config/support-tiers/subsystems.json +502 -0
- package/src/config/transforms/capability-transform-resolver.d.ts +16 -5
- package/src/config/transforms/capability-transform-resolver.js +44 -9
- package/src/config/transforms/execution-graph-transforms.d.ts +113 -2
- package/src/config/transforms/execution-graph-transforms.js +1220 -8
- package/src/converter/conversion-plan.js +20 -8
- package/src/converter/core.d.ts +48 -1
- package/src/converter/core.js +249 -62
- package/src/converter/parsers/gguf.d.ts +10 -1
- package/src/converter/rope-config.d.ts +1 -0
- package/src/converter/rope-config.js +75 -5
- package/src/converter/shard-packer.js +2 -2
- package/src/debug/tensor.js +13 -1
- package/src/{adapters → experimental/adapters}/adapter-manager.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/adapter-manager.js +2 -2
- package/src/{adapters → experimental/adapters}/adapter-manifest.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/adapter-manifest.js +1 -1
- package/src/{adapters → experimental/adapters}/adapter-registry.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/adapter-registry.js +1 -1
- package/src/{adapters → experimental/adapters}/lora-loader.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/lora-loader.js +2 -2
- package/src/{bridge → experimental/bridge}/extension-client.js +2 -2
- package/src/{bridge → experimental/bridge}/node-bridge.js +2 -4
- package/src/{bridge → experimental/bridge}/protocol.js +1 -1
- package/src/{browser → experimental/browser}/browser-converter.d.ts +4 -4
- package/src/{browser → experimental/browser}/browser-converter.js +12 -12
- package/src/{browser → experimental/browser}/gguf-importer.d.ts +1 -1
- package/src/{browser → experimental/browser}/gguf-importer.js +8 -8
- package/src/{browser → experimental/browser}/gguf-parser-browser.d.ts +2 -2
- package/src/{browser → experimental/browser}/gguf-parser-browser.js +3 -3
- package/src/{browser → experimental/browser}/quantization.d.ts +3 -3
- package/src/{browser → experimental/browser}/quantization.js +4 -4
- package/src/{browser → experimental/browser}/safetensors-parser-browser.d.ts +3 -3
- package/src/{browser → experimental/browser}/safetensors-parser-browser.js +3 -3
- package/src/{browser → experimental/browser}/shard-io-browser.d.ts +1 -1
- package/src/{browser → experimental/browser}/shard-io-browser.js +2 -2
- package/src/{browser → experimental/browser}/tensor-source-download.js +3 -3
- package/src/experimental/diffusion/index.d.ts +8 -0
- package/src/experimental/diffusion/index.js +8 -0
- package/src/{distribution → experimental/distribution}/p2p-transport-contract.js +1 -1
- package/src/{distribution → experimental/distribution}/p2p-transport.js +1 -1
- package/src/{distribution → experimental/distribution}/shard-delivery.js +5 -5
- package/src/experimental/energy/index.d.ts +2 -0
- package/src/experimental/energy/index.js +2 -0
- package/src/{hotswap → experimental/hotswap}/intent-bundle.d.ts +1 -1
- package/src/{hotswap → experimental/hotswap}/intent-bundle.js +2 -2
- package/src/{hotswap → experimental/hotswap}/manifest.d.ts +2 -2
- package/src/{hotswap → experimental/hotswap}/manifest.js +1 -1
- package/src/{hotswap → experimental/hotswap}/model-swap.js +1 -1
- package/src/{hotswap → experimental/hotswap}/runtime.d.ts +1 -1
- package/src/experimental/orchestration/index.d.ts +12 -0
- package/src/experimental/orchestration/index.js +12 -0
- package/src/{training → experimental/training}/README.md +1 -1
- package/src/{training → experimental/training}/artifacts.d.ts +3 -3
- package/src/{training → experimental/training}/artifacts.js +3 -3
- package/src/{training → experimental/training}/attention-backward.d.ts +1 -1
- package/src/{training → experimental/training}/attention-backward.js +3 -3
- package/src/{training → experimental/training}/attention-forward.d.ts +2 -2
- package/src/{training → experimental/training}/attention-forward.js +1 -1
- package/src/{training → experimental/training}/autograd.d.ts +2 -2
- package/src/{training → experimental/training}/autograd.js +7 -7
- package/src/{training → experimental/training}/backward-kernels.js +1 -1
- package/src/{training → experimental/training}/checkpoint.js +1 -1
- package/src/{training → experimental/training}/clip.d.ts +2 -2
- package/src/{training → experimental/training}/clip.js +3 -3
- package/src/{training → experimental/training}/export.d.ts +2 -2
- package/src/{training → experimental/training}/export.js +2 -2
- package/src/{training → experimental/training}/lora-pipeline.js +4 -4
- package/src/{training → experimental/training}/lora.d.ts +1 -1
- package/src/{training → experimental/training}/lora.js +4 -4
- package/src/{training → experimental/training}/loss-scaling.d.ts +2 -2
- package/src/{training → experimental/training}/loss-scaling.js +3 -3
- package/src/{training → experimental/training}/loss.d.ts +2 -2
- package/src/{training → experimental/training}/loss.js +1 -1
- package/src/{training → experimental/training}/operator-artifacts.js +1 -1
- package/src/{training → experimental/training}/optimizer.d.ts +2 -2
- package/src/{training → experimental/training}/optimizer.js +3 -3
- package/src/{training → experimental/training}/runner.d.ts +2 -2
- package/src/{training → experimental/training}/runner.js +5 -5
- package/src/{training → experimental/training}/suite.js +16 -16
- package/src/{training → experimental/training}/tensor-factory.d.ts +1 -1
- package/src/{training → experimental/training}/tensor-factory.js +2 -2
- package/src/{training → experimental/training}/trainer.d.ts +3 -3
- package/src/{training → experimental/training}/trainer.js +3 -3
- package/src/{training → experimental/training}/ul_dataset.d.ts +2 -2
- package/src/{training → experimental/training}/ul_dataset.js +1 -1
- package/src/{training → experimental/training}/ul_schedule.d.ts +1 -1
- package/src/{training → experimental/training}/workloads.js +4 -4
- package/src/formats/index.d.ts +24 -0
- package/src/formats/index.js +6 -0
- package/src/formats/litert/index.d.ts +1 -0
- package/src/formats/litert/index.js +1 -0
- package/src/formats/litert/types.d.ts +87 -0
- package/src/formats/litert/types.js +568 -0
- package/src/formats/rdrr/classification.js +16 -8
- package/src/formats/rdrr/parsing.d.ts +3 -2
- package/src/formats/rdrr/types.d.ts +33 -0
- package/src/formats/rdrr/validation.js +16 -5
- package/src/formats/tflite/index.d.ts +1 -0
- package/src/formats/tflite/index.js +1 -0
- package/src/formats/tflite/types.d.ts +84 -0
- package/src/formats/tflite/types.js +633 -0
- package/src/generation/index.d.ts +16 -14
- package/src/generation/index.js +1 -32
- package/src/gpu/command-recorder.d.ts +17 -1
- package/src/gpu/command-recorder.js +47 -10
- package/src/gpu/device.d.ts +3 -1
- package/src/gpu/device.js +17 -11
- package/src/gpu/kernel-selector.js +3 -1
- package/src/gpu/kernels/attention.d.ts +2 -0
- package/src/gpu/kernels/attention.js +359 -14
- package/src/gpu/kernels/attention.wgsl +20 -1
- package/src/gpu/kernels/attention_decode_contiguous_turboquant_f16kv.wgsl +180 -0
- package/src/gpu/kernels/attention_decode_contiguous_turboquant_prod_f16kv.wgsl +192 -0
- package/src/gpu/kernels/attention_decode_online_f16.wgsl +36 -18
- package/src/gpu/kernels/attention_decode_online_f16kv.wgsl +36 -18
- package/src/gpu/kernels/attention_decode_tiered_turboquant_f16kv.wgsl +269 -0
- package/src/gpu/kernels/attention_decode_tiered_turboquant_prod_f16kv.wgsl +281 -0
- package/src/gpu/kernels/attention_head256_f16kv.wgsl +269 -0
- package/src/gpu/kernels/attention_streaming.wgsl +22 -3
- package/src/gpu/kernels/attention_streaming_f16.wgsl +1 -1
- package/src/gpu/kernels/attention_streaming_f16kv.wgsl +1 -1
- package/src/gpu/kernels/backward/attention_backward.d.ts +14 -1
- package/src/gpu/kernels/check-hot-vocab-stop.d.ts +18 -0
- package/src/gpu/kernels/check-hot-vocab-stop.js +108 -0
- package/src/gpu/kernels/codegen/patches/attention_streaming_f16.from.attention_streaming.diff +1 -1
- package/src/gpu/kernels/codegen/patches/attention_streaming_f16kv.from.attention_streaming.diff +1 -1
- package/src/gpu/kernels/codegen/patches/rope_f16.from.rope.diff +126 -194
- package/src/gpu/kernels/codegen/wgsl-variants.js +24 -6
- package/src/gpu/kernels/depthwise_conv1d.d.ts +23 -0
- package/src/gpu/kernels/depthwise_conv1d.js +51 -0
- package/src/gpu/kernels/depthwise_conv1d.wgsl +46 -0
- package/src/gpu/kernels/feature-check.js +0 -1
- package/src/gpu/kernels/fused_ffn.js +67 -22
- package/src/gpu/kernels/fused_ffn_q4k.wgsl +48 -43
- package/src/gpu/kernels/fused_ffn_q4k_f16.wgsl +329 -0
- package/src/gpu/kernels/fused_matmul_q4.wgsl +417 -0
- package/src/gpu/kernels/fused_matmul_q4_batched_multicol_shared.wgsl +174 -0
- package/src/gpu/kernels/gather.d.ts +4 -0
- package/src/gpu/kernels/gather.js +13 -2
- package/src/gpu/kernels/gather.wgsl +5 -3
- package/src/gpu/kernels/gather_f16.wgsl +5 -3
- package/src/gpu/kernels/index.d.ts +7 -0
- package/src/gpu/kernels/index.js +6 -0
- package/src/gpu/kernels/kernel-configs.js +1 -0
- package/src/gpu/kernels/kv-quantize.js +87 -55
- package/src/gpu/kernels/kv_quantize_turboquant.wgsl +153 -0
- package/src/gpu/kernels/kv_quantize_turboquant_prod.wgsl +230 -0
- package/src/gpu/kernels/linear-attention-core.d.ts +3 -0
- package/src/gpu/kernels/linear-attention-core.js +145 -56
- package/src/gpu/kernels/matmul-dispatch.js +3 -0
- package/src/gpu/kernels/matmul-selection.js +31 -42
- package/src/gpu/kernels/matmul.d.ts +3 -0
- package/src/gpu/kernels/matmul.js +72 -34
- package/src/gpu/kernels/residual.d.ts +2 -0
- package/src/gpu/kernels/residual.js +43 -4
- package/src/gpu/kernels/rope.d.ts +2 -0
- package/src/gpu/kernels/rope.js +19 -6
- package/src/gpu/kernels/rope.wgsl +24 -12
- package/src/gpu/kernels/rope_f16.wgsl +97 -38
- package/src/gpu/kernels/scale.d.ts +5 -0
- package/src/gpu/kernels/scale.js +6 -1
- package/src/gpu/kernels/scale.wgsl +3 -1
- package/src/gpu/kernels/scale_f16.wgsl +32 -0
- package/src/gpu/kernels/turboquant-codebook.js +564 -0
- package/src/gpu/kernels/uniform-utils.js +26 -0
- package/src/gpu/kernels/utils.js +6 -1
- package/src/gpu/submit-probe.d.ts +12 -0
- package/src/gpu/submit-probe.js +77 -0
- package/src/gpu/weight-buffer.d.ts +26 -3
- package/src/gpu/weight-buffer.js +62 -2
- package/src/index-browser.d.ts +1 -91
- package/src/index-browser.js +0 -66
- package/src/index.d.ts +1 -102
- package/src/index.js +0 -74
- package/src/inference/browser-harness-model-helpers.d.ts +3 -0
- package/src/inference/browser-harness-model-helpers.js +134 -11
- package/src/inference/browser-harness-runtime-helpers.js +1 -9
- package/src/inference/browser-harness-text-helpers.js +441 -70
- package/src/inference/browser-harness.js +61 -4
- package/src/inference/decode-ring.d.ts +2 -0
- package/src/inference/decode-ring.js +20 -0
- package/src/inference/kv-cache/index.d.ts +3 -0
- package/src/inference/kv-cache/index.js +2 -0
- package/src/inference/kv-cache/mixed-geometry.d.ts +84 -0
- package/src/inference/kv-cache/mixed-geometry.js +422 -0
- package/src/inference/kv-cache/quantized.d.ts +56 -0
- package/src/inference/kv-cache/quantized.js +383 -0
- package/src/inference/kv-cache/tiered.d.ts +20 -3
- package/src/inference/kv-cache/tiered.js +203 -65
- package/src/inference/kv-cache/types.d.ts +49 -6
- package/src/inference/kv-cache.d.ts +3 -0
- package/src/inference/kv-cache.js +2 -0
- package/src/inference/multi-model-network.js +2 -1
- package/src/inference/pipelines/audio/gemma4.js +655 -0
- package/src/inference/pipelines/audio/index.js +39 -0
- package/src/inference/pipelines/audio/mel.js +171 -0
- package/src/inference/pipelines/context.js +9 -1
- package/src/inference/pipelines/diffusion/text-encoder-gpu.js +2 -0
- package/src/inference/pipelines/shared/clipped-linear.js +46 -0
- package/src/inference/pipelines/text/attention/dispatch-params.d.ts +2 -1
- package/src/inference/pipelines/text/attention/dispatch-params.js +52 -8
- package/src/inference/pipelines/text/attention/output-projection.js +3 -3
- package/src/inference/pipelines/text/attention/precision-contract.d.ts +36 -0
- package/src/inference/pipelines/text/attention/precision-contract.js +115 -0
- package/src/inference/pipelines/text/attention/projections.d.ts +23 -0
- package/src/inference/pipelines/text/attention/projections.js +182 -15
- package/src/inference/pipelines/text/attention/quant-options.js +54 -0
- package/src/inference/pipelines/text/attention/record.js +257 -69
- package/src/inference/pipelines/text/attention/run.js +306 -94
- package/src/inference/pipelines/text/attention/types.d.ts +11 -0
- package/src/inference/pipelines/text/chat-format.d.ts +8 -1
- package/src/inference/pipelines/text/chat-format.js +89 -5
- package/src/inference/pipelines/text/config.d.ts +78 -26
- package/src/inference/pipelines/text/config.js +722 -28
- package/src/inference/pipelines/text/dtype-contract.d.ts +15 -0
- package/src/inference/pipelines/text/dtype-contract.js +38 -0
- package/src/inference/pipelines/text/embed.d.ts +4 -0
- package/src/inference/pipelines/text/embed.js +165 -172
- package/src/inference/pipelines/text/execution-plan.d.ts +19 -0
- package/src/inference/pipelines/text/execution-plan.js +112 -20
- package/src/inference/pipelines/text/execution-runtime-builders.d.ts +8 -4
- package/src/inference/pipelines/text/execution-runtime-builders.js +90 -49
- package/src/inference/pipelines/text/execution-v1.d.ts +23 -4
- package/src/inference/pipelines/text/execution-v1.js +411 -33
- package/src/inference/pipelines/text/ffn/dense.d.ts +59 -0
- package/src/inference/pipelines/text/ffn/dense.js +575 -63
- package/src/inference/pipelines/text/ffn/moe.js +1 -0
- package/src/inference/pipelines/text/ffn/sandwich.js +20 -4
- package/src/inference/pipelines/text/ffn/standard.js +28 -4
- package/src/inference/pipelines/text/finiteness-policy.d.ts +4 -0
- package/src/inference/pipelines/text/finiteness-policy.js +14 -11
- package/src/inference/pipelines/text/generator-helpers.d.ts +7 -0
- package/src/inference/pipelines/text/generator-helpers.js +39 -4
- package/src/inference/pipelines/text/generator-runtime.js +45 -8
- package/src/inference/pipelines/text/generator-steps.js +407 -75
- package/src/inference/pipelines/text/generator.d.ts +6 -0
- package/src/inference/pipelines/text/generator.js +1179 -305
- package/src/inference/pipelines/text/init.d.ts +39 -7
- package/src/inference/pipelines/text/init.js +525 -110
- package/src/inference/pipelines/text/layer-plan.d.ts +1 -0
- package/src/inference/pipelines/text/layer-plan.js +2 -0
- package/src/inference/pipelines/text/layer.js +402 -19
- package/src/inference/pipelines/text/linear-attention.d.ts +4 -0
- package/src/inference/pipelines/text/linear-attention.js +112 -41
- package/src/inference/pipelines/text/logits/gpu.d.ts +2 -1
- package/src/inference/pipelines/text/logits/gpu.js +334 -15
- package/src/inference/pipelines/text/logits/index.d.ts +11 -0
- package/src/inference/pipelines/text/logits/index.js +227 -29
- package/src/inference/pipelines/text/logits/types.d.ts +3 -0
- package/src/inference/pipelines/text/logits/utils.js +3 -1
- package/src/inference/pipelines/text/lora-apply.js +3 -3
- package/src/inference/pipelines/text/model-load.d.ts +2 -1
- package/src/inference/pipelines/text/model-load.js +205 -178
- package/src/inference/pipelines/text/moe-gpu.js +8 -0
- package/src/inference/pipelines/text/moe-impl.d.ts +2 -0
- package/src/inference/pipelines/text/ops.d.ts +16 -2
- package/src/inference/pipelines/text/ops.js +11 -2
- package/src/inference/pipelines/text/per-layer-inputs.d.ts +107 -0
- package/src/inference/pipelines/text/per-layer-inputs.js +1581 -0
- package/src/inference/pipelines/text/probes.js +6 -0
- package/src/inference/pipelines/text/sampling-config.js +9 -1
- package/src/inference/pipelines/text/stage-names.js +3 -0
- package/src/inference/pipelines/text/state.d.ts +12 -3
- package/src/inference/pipelines/text/state.js +19 -0
- package/src/inference/pipelines/text/types.d.ts +79 -7
- package/src/inference/pipelines/text/weights.d.ts +2 -2
- package/src/inference/pipelines/text/weights.js +4 -0
- package/src/inference/pipelines/text.d.ts +6 -0
- package/src/inference/pipelines/text.js +860 -11
- package/src/inference/pipelines/video/frame-sampler.js +36 -0
- package/src/inference/pipelines/video/index.js +87 -0
- package/src/inference/pipelines/vision/encoder.js +27 -6
- package/src/inference/pipelines/vision/gemma4.js +731 -0
- package/src/inference/pipelines/vision/image-preprocess.js +22 -7
- package/src/inference/pipelines/vision/index.js +35 -10
- package/src/inference/pipelines/vision/ops.js +31 -26
- package/src/inference/pipelines/vision/patch-embed.js +22 -10
- package/src/inference/runtime-model.d.ts +89 -0
- package/src/inference/runtime-model.js +152 -0
- package/src/inference/test-harness.d.ts +8 -1
- package/src/inference/test-harness.js +54 -20
- package/src/inference/tokenizer.d.ts +5 -0
- package/src/inference/tokenizer.js +43 -0
- package/src/inference/tokenizers/base.d.ts +5 -0
- package/src/inference/tokenizers/base.js +5 -0
- package/src/inference/tokenizers/behavior-flags.d.ts +9 -0
- package/src/inference/tokenizers/behavior-flags.js +100 -0
- package/src/inference/tokenizers/bundled.d.ts +4 -0
- package/src/inference/tokenizers/bundled.js +110 -0
- package/src/inference/tokenizers/sentencepiece.d.ts +2 -0
- package/src/inference/tokenizers/sentencepiece.js +16 -0
- package/src/inference/tokenizers/types.d.ts +2 -0
- package/src/loader/doppler-loader.d.ts +10 -3
- package/src/loader/doppler-loader.js +103 -5
- package/src/loader/embedding-loader.d.ts +5 -1
- package/src/loader/embedding-loader.js +57 -6
- package/src/loader/final-weights-loader.js +44 -5
- package/src/loader/layer-loader.js +210 -8
- package/src/loader/loader-state.js +2 -2
- package/src/loader/loader-types.d.ts +17 -1
- package/src/loader/memory-monitor.d.ts +8 -0
- package/src/loader/memory-monitor.js +21 -0
- package/src/loader/multi-model-loader.d.ts +9 -1
- package/src/loader/multi-model-loader.js +9 -1
- package/src/loader/per-layer-input-loader.d.ts +30 -0
- package/src/loader/per-layer-input-loader.js +478 -0
- package/src/loader/shard-cache.d.ts +4 -3
- package/src/loader/shard-resolver.js +2 -0
- package/src/loader/tensors/source-transform.d.ts +50 -0
- package/src/loader/tensors/source-transform.js +776 -0
- package/src/loader/tensors/tensor-loader.d.ts +12 -0
- package/src/loader/tensors/tensor-loader.js +208 -123
- package/src/loader/tensors/tensor-reader.d.ts +8 -0
- package/src/loader/tensors/tensor-reader.js +283 -15
- package/src/loaders/index.d.ts +4 -0
- package/src/loaders/index.js +4 -0
- package/src/memory/buffer-pool.d.ts +4 -0
- package/src/memory/buffer-pool.js +36 -0
- package/src/rules/execution-rules-contract-check.d.ts +4 -0
- package/src/rules/execution-rules-contract-check.js +150 -24
- package/src/rules/inference/attention.rules.json +15 -0
- package/src/rules/inference/capability-transforms.rules.json +30 -0
- package/src/rules/inference/execution.rules.json +54 -2
- package/src/rules/inference/ffn.rules.json +33 -0
- package/src/rules/kernels/attention.rules.json +7 -0
- package/src/rules/kernels/fused-ffn.rules.json +4 -2
- package/src/rules/kernels/kv_quantize.rules.json +2 -0
- package/src/rules/kernels/matmul.rules.json +14 -0
- package/src/rules/kernels/scale.rules.json +2 -0
- package/src/rules/loader/tensor-loader.rules.json +1 -0
- package/src/storage/artifact-storage-context.d.ts +53 -0
- package/src/storage/artifact-storage-context.js +560 -0
- package/src/storage/downloader.js +7 -1
- package/src/storage/index.d.ts +18 -0
- package/src/storage/index.js +13 -0
- package/src/storage/preflight.js +22 -0
- package/src/storage/quickstart-downloader.js +35 -2
- package/src/storage/registry.d.ts +1 -0
- package/src/storage/registry.js +26 -4
- package/src/storage/shard-manager.d.ts +4 -0
- package/src/storage/shard-manager.js +25 -6
- package/src/storage/source-artifact-store.d.ts +9 -0
- package/src/storage/source-artifact-store.js +134 -0
- package/src/tooling/browser-command-runner.js +12 -5
- package/src/tooling/command-api-family-normalizers.js +144 -0
- package/src/tooling/command-api-helpers.js +1 -0
- package/src/tooling/command-api.d.ts +32 -9
- package/src/tooling/command-api.js +0 -25
- package/src/tooling/command-runner-shared.js +1 -2
- package/src/tooling/command-runner.html +5 -2
- package/src/tooling/diagnose-runner.js +1 -1
- package/src/tooling/kernel-path-builder/index.js +48 -32
- package/src/tooling/lean-execution-contract.d.ts +1 -1
- package/src/tooling/lean-execution-contract.js +2 -149
- package/src/tooling/litert-package-runtime.d.ts +46 -0
- package/src/tooling/litert-package-runtime.js +950 -0
- package/src/tooling/node-browser-command-runner.d.ts +13 -0
- package/src/tooling/node-browser-command-runner.js +163 -3
- package/src/tooling/node-command-runner.js +14 -5
- package/src/tooling/node-converter.js +226 -63
- package/src/tooling/node-source-runtime.d.ts +8 -3
- package/src/tooling/node-source-runtime.js +561 -236
- package/src/tooling/node-webgpu.js +7 -30
- package/src/tooling/opfs-cache.d.ts +18 -1
- package/src/tooling/opfs-cache.js +126 -9
- package/src/tooling/runtime-input-composition.d.ts +0 -1
- package/src/tooling/runtime-input-composition.js +0 -5
- package/src/tooling/source-artifact-adapter.d.ts +134 -0
- package/src/tooling/source-artifact-adapter.js +366 -0
- package/src/tooling/source-package-profiles.d.ts +33 -0
- package/src/tooling/source-package-profiles.js +57 -0
- package/src/tooling/source-runtime-bundle.d.ts +46 -6
- package/src/tooling/source-runtime-bundle.js +371 -60
- package/src/tooling/source-runtime-converter-config.d.ts +24 -0
- package/src/tooling/source-runtime-converter-config.js +297 -0
- package/src/tooling-experimental-exports.browser.js +2 -0
- package/src/tooling-experimental-exports.d.ts +7 -0
- package/src/tooling-experimental-exports.js +7 -0
- package/src/tooling-experimental-exports.shared.d.ts +26 -0
- package/src/tooling-experimental-exports.shared.js +29 -0
- package/src/tooling-exports.shared.d.ts +0 -23
- package/src/tooling-exports.shared.js +6 -28
- package/src/version.js +1 -1
- package/src/client/doppler-provider/generation.d.ts +0 -25
- package/src/client/doppler-provider/generation.js +0 -126
- package/src/client/doppler-provider/index.d.ts +0 -2
- package/src/client/doppler-provider/index.js +0 -3
- package/src/client/doppler-provider/provider.d.ts +0 -5
- package/src/client/doppler-provider/provider.js +0 -102
- package/src/client/doppler-provider/source-runtime.js +0 -677
- package/src/client/doppler-provider.d.ts +0 -46
- package/src/client/doppler-provider.js +0 -36
- package/src/config/schema/inference-defaults.schema.d.ts +0 -276
- package/src/config/schema/inference-defaults.schema.js +0 -189
- package/src/diffusion/index.d.ts +0 -8
- package/src/diffusion/index.js +0 -8
- package/src/energy/index.d.ts +0 -2
- package/src/energy/index.js +0 -2
- package/src/index-internal.d.ts +0 -2
- package/src/index-internal.js +0 -2
- /package/src/client/{doppler-provider → runtime}/types.js +0 -0
- /package/src/{adapters → experimental/adapters}/index.d.ts +0 -0
- /package/src/{adapters → experimental/adapters}/index.js +0 -0
- /package/src/{bridge → experimental/bridge}/extension/background.d.ts +0 -0
- /package/src/{bridge → experimental/bridge}/extension/background.js +0 -0
- /package/src/{bridge → experimental/bridge}/extension/manifest.json +0 -0
- /package/src/{bridge → experimental/bridge}/extension-client.d.ts +0 -0
- /package/src/{bridge → experimental/bridge}/index.d.ts +0 -0
- /package/src/{bridge → experimental/bridge}/index.js +0 -0
- /package/src/{bridge → experimental/bridge}/protocol.d.ts +0 -0
- /package/src/{browser → experimental/browser}/file-picker.d.ts +0 -0
- /package/src/{browser → experimental/browser}/file-picker.js +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-download.d.ts +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-file.d.ts +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-file.js +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-http.d.ts +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-http.js +0 -0
- /package/src/{diffusion → experimental/diffusion}/config/expansion-lanes.json +0 -0
- /package/src/{diffusion → experimental/diffusion}/image-regression.d.ts +0 -0
- /package/src/{diffusion → experimental/diffusion}/image-regression.js +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-control-plane.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-control-plane.js +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-observability.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-observability.js +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-transport-contract.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-webrtc-browser.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-webrtc-browser.js +0 -0
- /package/src/{distribution → experimental/distribution}/shard-delivery.d.ts +0 -0
- /package/src/{hotswap → experimental/hotswap}/runtime.js +0 -0
- /package/src/{training → experimental/training}/checkpoint-watch.d.ts +0 -0
- /package/src/{training → experimental/training}/checkpoint-watch.js +0 -0
- /package/src/{training → experimental/training}/checkpoint.d.ts +0 -0
- /package/src/{training → experimental/training}/dataloader.d.ts +0 -0
- /package/src/{training → experimental/training}/dataloader.js +0 -0
- /package/src/{training → experimental/training}/datasets/index.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/index.js +0 -0
- /package/src/{training → experimental/training}/datasets/jsonl.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/jsonl.js +0 -0
- /package/src/{training → experimental/training}/datasets/reploid.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/reploid.js +0 -0
- /package/src/{training → experimental/training}/datasets/text-pairs.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/text-pairs.js +0 -0
- /package/src/{training → experimental/training}/datasets/token-batch.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/token-batch.js +0 -0
- /package/src/{training → experimental/training}/datasets/translation-pairs.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/translation-pairs.js +0 -0
- /package/src/{training → experimental/training}/distillation/artifacts.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/artifacts.js +0 -0
- /package/src/{training → experimental/training}/distillation/checkpoint-watch.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/checkpoint-watch.js +0 -0
- /package/src/{training → experimental/training}/distillation/dataset.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/dataset.js +0 -0
- /package/src/{training → experimental/training}/distillation/eval.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/eval.js +0 -0
- /package/src/{training → experimental/training}/distillation/index.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/index.js +0 -0
- /package/src/{training → experimental/training}/distillation/runtime.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/runtime.js +0 -0
- /package/src/{training → experimental/training}/distillation/scoreboard.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/scoreboard.js +0 -0
- /package/src/{training → experimental/training}/distillation/stage-a.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/stage-a.js +0 -0
- /package/src/{training → experimental/training}/distillation/stage-b.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/stage-b.js +0 -0
- /package/src/{training → experimental/training}/distillation/student-fixture.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/student-fixture.js +0 -0
- /package/src/{training → experimental/training}/distillation/suite-data.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/suite-data.js +0 -0
- /package/src/{training → experimental/training}/index.d.ts +0 -0
- /package/src/{training → experimental/training}/index.js +0 -0
- /package/src/{training → experimental/training}/lora-pipeline.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/base.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/base.js +0 -0
- /package/src/{training → experimental/training}/objectives/cross_entropy.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/cross_entropy.js +0 -0
- /package/src/{training → experimental/training}/objectives/distill_kd.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/distill_kd.js +0 -0
- /package/src/{training → experimental/training}/objectives/distill_triplet.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/distill_triplet.js +0 -0
- /package/src/{training → experimental/training}/objectives/index.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/index.js +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage1_joint.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage1_joint.js +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage2_base.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage2_base.js +0 -0
- /package/src/{training → experimental/training}/operator-artifacts.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-command.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-command.js +0 -0
- /package/src/{training → experimental/training}/operator-eval.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-eval.js +0 -0
- /package/src/{training → experimental/training}/operator-scoreboard.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-scoreboard.js +0 -0
- /package/src/{training → experimental/training}/suite.d.ts +0 -0
- /package/src/{training → experimental/training}/ul_schedule.js +0 -0
- /package/src/{training → experimental/training}/workload-packs/distill-translategemma-medium.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/distill-translategemma-tiny.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/lora-toy-medium.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/lora-toy-tiny.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/registry.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/ul-training-medium.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/ul-training-tiny.json +0 -0
- /package/src/{training → experimental/training}/workloads.d.ts +0 -0
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { getDevice, getKernelCapabilities } from '../device.js';
|
|
2
2
|
import { createTensor } from '../tensor.js';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getBuffer,
|
|
5
|
+
getLayout,
|
|
6
|
+
getWeightDtype,
|
|
7
|
+
isWeightBuffer,
|
|
8
|
+
resolveWeightBufferMaterialization,
|
|
9
|
+
} from '../weight-buffer.js';
|
|
4
10
|
import { log, trace, isTraceEnabled } from '../../debug/index.js';
|
|
5
|
-
import { releaseBuffer
|
|
11
|
+
import { releaseBuffer } from '../../memory/buffer-pool.js';
|
|
6
12
|
import { releaseUniformBuffer } from '../uniform-cache.js';
|
|
7
13
|
import { castF16ToF32, recordCastF16ToF32 } from './cast.js';
|
|
14
|
+
import { getKernelPathMatmulVariant } from '../../config/kernel-path-loader.js';
|
|
15
|
+
import { assertImplicitDtypeTransitionAllowed } from '../../inference/pipelines/text/dtype-contract.js';
|
|
8
16
|
import {
|
|
9
17
|
resolveMatmulPhase,
|
|
10
18
|
resolveMatmulConstants,
|
|
@@ -20,6 +28,7 @@ import {
|
|
|
20
28
|
resolveMatmulOutput,
|
|
21
29
|
selectMatmulKernel,
|
|
22
30
|
} from './matmul-selection.js';
|
|
31
|
+
import { selectRuleValue as selectKernelRuleValue } from './rule-registry.js';
|
|
23
32
|
import {
|
|
24
33
|
MatmulKernel,
|
|
25
34
|
calculateMatmulDispatch,
|
|
@@ -123,6 +132,29 @@ function createMatmulBindGroupEntries(variant, uniformBuffer, matmulInput, bBuff
|
|
|
123
132
|
return entries;
|
|
124
133
|
}
|
|
125
134
|
|
|
135
|
+
function resolvePreferredWeightDtype(variant, hasQ4KMaterialization) {
|
|
136
|
+
if (typeof variant !== 'string' || variant.length === 0) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let config;
|
|
141
|
+
try {
|
|
142
|
+
config = getMatmulConfig(variant, null);
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const variantWeightDtype = config?.weightDtype ?? null;
|
|
148
|
+
if (!variantWeightDtype) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return selectKernelRuleValue('matmul', 'preferredWeightDtype', {
|
|
153
|
+
variantWeightDtype,
|
|
154
|
+
hasQ4KMaterialization,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
126
158
|
async function executeMatmul(recorder, A, B, M, N, K, options = {}) {
|
|
127
159
|
const isRecord = Boolean(recorder);
|
|
128
160
|
const mode = isRecord ? 'record' : 'run';
|
|
@@ -139,11 +171,16 @@ async function executeMatmul(recorder, A, B, M, N, K, options = {}) {
|
|
|
139
171
|
cOffset = 0,
|
|
140
172
|
} = options;
|
|
141
173
|
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
174
|
+
const phase = resolveMatmulPhase(M, options.phaseOverride ?? null);
|
|
175
|
+
const pathVariant = getKernelPathMatmulVariant(options.role, phase, options.layerIdx, options.kernelPath);
|
|
176
|
+
const hasQ4KMat = isWeightBuffer(B) && B.materializations?.q4k?.buffer != null;
|
|
177
|
+
const preferredWeightDtype = resolvePreferredWeightDtype(pathVariant, hasQ4KMat);
|
|
178
|
+
const resolvedWeight = resolveWeightBufferMaterialization(B, preferredWeightDtype);
|
|
179
|
+
const bBuffer = getBuffer(resolvedWeight);
|
|
180
|
+
const weightDtype = getWeightDtype(resolvedWeight);
|
|
181
|
+
const weightLabel = (resolvedWeight && typeof resolvedWeight === 'object' ? resolvedWeight.label : null) ?? bBuffer?.label ?? null;
|
|
182
|
+
const weightLayout = getLayout(resolvedWeight);
|
|
183
|
+
const weightShape = resolvedWeight?.shape ? `[${resolvedWeight.shape.join(', ')}]` : null;
|
|
147
184
|
const matmulDebug = normalizeMatmulDebugConfig(options.matmulDebug);
|
|
148
185
|
const debugAttention = matmulDebug?.enabled === true;
|
|
149
186
|
const isAttnProj = isAttentionProjectionRole(options.role ?? '');
|
|
@@ -157,7 +194,7 @@ async function executeMatmul(recorder, A, B, M, N, K, options = {}) {
|
|
|
157
194
|
trace.kernels(`${modeLabel}: M=${M}, N=${N}, K=${K}, transposeBOption=${transposeBOption}, weightLayout=${weightLayout}, weightDtype=${weightDtype}`);
|
|
158
195
|
}
|
|
159
196
|
|
|
160
|
-
const transposeB = resolveTransposeB(
|
|
197
|
+
const transposeB = resolveTransposeB(resolvedWeight, transposeBOption);
|
|
161
198
|
validateMatmulDimensions(opLabel, M, N, K);
|
|
162
199
|
|
|
163
200
|
const aDtype = toMatmulDtype(A.dtype);
|
|
@@ -189,13 +226,19 @@ async function executeMatmul(recorder, A, B, M, N, K, options = {}) {
|
|
|
189
226
|
options
|
|
190
227
|
);
|
|
191
228
|
|
|
192
|
-
const phase = resolveMatmulPhase(M, options.phaseOverride ?? null);
|
|
193
229
|
const constants = resolveMatmulConstants(options, phase);
|
|
194
230
|
|
|
195
231
|
let matmulInput = A;
|
|
196
232
|
let matmulADtype = aDtype;
|
|
197
233
|
let castedInput = null;
|
|
198
234
|
if (matmulADtype === 'f16' && requiresF32Input(variant)) {
|
|
235
|
+
assertImplicitDtypeTransitionAllowed({
|
|
236
|
+
executionPolicies: options.executionPolicies ?? null,
|
|
237
|
+
fromDtype: 'f16',
|
|
238
|
+
toDtype: 'f32',
|
|
239
|
+
op: options.role ? `matmul(${options.role})` : 'matmul',
|
|
240
|
+
detail: `Variant "${variant}" would widen activations internally.`,
|
|
241
|
+
});
|
|
199
242
|
if (isTraceEnabled('kernels')) {
|
|
200
243
|
trace.kernels(`Matmul: casting f16 activations to f32 for variant=${variant}`);
|
|
201
244
|
}
|
|
@@ -225,35 +268,37 @@ async function executeMatmul(recorder, A, B, M, N, K, options = {}) {
|
|
|
225
268
|
bOffset
|
|
226
269
|
);
|
|
227
270
|
} catch (err) {
|
|
271
|
+
const detailParts = [];
|
|
272
|
+
if (options.role) detailParts.push(`role=${options.role}`);
|
|
273
|
+
if (Number.isFinite(options.layerIdx)) detailParts.push(`layer=${options.layerIdx}`);
|
|
274
|
+
if (weightLabel) detailParts.push(`label=${weightLabel}`);
|
|
275
|
+
if (weightDtype) detailParts.push(`weightDtype=${weightDtype}`);
|
|
276
|
+
if (weightLayout) detailParts.push(`layout=${weightLayout}`);
|
|
277
|
+
if (weightShape) detailParts.push(`shape=${weightShape}`);
|
|
278
|
+
if (Number.isFinite(bBuffer?.size)) detailParts.push(`bSize=${bBuffer.size}`);
|
|
279
|
+
if (Number.isFinite(bOffset) && bOffset > 0) detailParts.push(`bOffset=${bOffset}`);
|
|
280
|
+
const detail = detailParts.length ? ` (${detailParts.join(', ')})` : '';
|
|
228
281
|
if (shouldValidateAttentionWeightBuffer && isAttnProj && err instanceof Error && err.message.includes('B buffer too small')) {
|
|
229
|
-
const
|
|
282
|
+
const probeDetail = [
|
|
230
283
|
`role=${options.role ?? ''}`,
|
|
231
284
|
`layer=${Number.isFinite(options.layerIdx) ? options.layerIdx : '?'}`,
|
|
232
285
|
`M=${M}`,
|
|
233
286
|
`N=${N}`,
|
|
234
287
|
`K=${K}`,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const detail = detailParts.join(' ');
|
|
288
|
+
...(weightDtype ? [`weightDtype=${weightDtype}`] : []),
|
|
289
|
+
...(weightLayout ? [`weightLayout=${weightLayout}`] : []),
|
|
290
|
+
...(weightShape ? [`shape=${weightShape}`] : []),
|
|
291
|
+
...(weightLabel ? [`label=${weightLabel}`] : []),
|
|
292
|
+
...(Number.isFinite(bBuffer?.size) ? [`bSize=${bBuffer.size}`] : []),
|
|
293
|
+
].join(' ');
|
|
242
294
|
if (shouldLogAttentionWeightBuffer) {
|
|
243
|
-
log.warn('MatmulQKVProbe', `${err.message} | ${
|
|
295
|
+
log.warn('MatmulQKVProbe', `${err.message} | ${probeDetail}`);
|
|
244
296
|
}
|
|
245
297
|
if (shouldFailOnSmallAttentionWeightBuffer) {
|
|
246
|
-
throw new Error(`${err.message}${detail
|
|
298
|
+
throw new Error(`${err.message}${detail}`);
|
|
247
299
|
}
|
|
248
300
|
}
|
|
249
|
-
if (
|
|
250
|
-
const detailParts = [];
|
|
251
|
-
if (weightLabel) detailParts.push(`label=${weightLabel}`);
|
|
252
|
-
if (weightDtype) detailParts.push(`weightDtype=${weightDtype}`);
|
|
253
|
-
if (weightLayout) detailParts.push(`layout=${weightLayout}`);
|
|
254
|
-
if (weightShape) detailParts.push(`shape=${weightShape}`);
|
|
255
|
-
if (Number.isFinite(bBuffer?.size)) detailParts.push(`bSize=${bBuffer.size}`);
|
|
256
|
-
const detail = detailParts.length ? ` (${detailParts.join(', ')})` : '';
|
|
301
|
+
if (err instanceof Error && err.message.includes('B buffer too small')) {
|
|
257
302
|
throw new Error(`${err.message}${detail}`);
|
|
258
303
|
}
|
|
259
304
|
throw err;
|
|
@@ -352,13 +397,6 @@ async function executeMatmul(recorder, A, B, M, N, K, options = {}) {
|
|
|
352
397
|
kernel.dispatch(pipeline, bindGroup, dispatchPlan.workgroups);
|
|
353
398
|
}
|
|
354
399
|
completed = true;
|
|
355
|
-
if (!isRecord && matmulDebug?.logProjectionValues && isAttnProj && M === 1 && options.layerIdx === 0) {
|
|
356
|
-
await device.queue.onSubmittedWorkDone();
|
|
357
|
-
const raw = await readBuffer(C);
|
|
358
|
-
const numVals = Math.min(8, Math.floor(raw.byteLength / 4));
|
|
359
|
-
const vals = numVals > 0 ? new Float32Array(raw, 0, numVals) : [];
|
|
360
|
-
log.warn('ProjectionProbe', `role=${options.role ?? ''} L0 M1 first8_f32: ${Array.from(vals).map(v => v.toFixed(5)).join(' ')}`);
|
|
361
|
-
}
|
|
362
400
|
return createTensor(C, actualOutputDtype, [M, N], 'matmul_output');
|
|
363
401
|
} finally {
|
|
364
402
|
if (!isRecord && uniformBuffer) {
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
import type { Tensor } from '../tensor.js';
|
|
10
10
|
import type { CommandRecorder } from '../command-recorder.js';
|
|
11
11
|
import type { OutputBufferOptions } from './types.js';
|
|
12
|
+
import type { ExecutionV1PoliciesSchema } from '../../config/schema/execution-v1.schema.js';
|
|
12
13
|
|
|
13
14
|
/** Residual kernel options */
|
|
14
15
|
export interface ResidualOptions extends OutputBufferOptions {
|
|
15
16
|
useVec4?: boolean;
|
|
16
17
|
dataOffset?: number;
|
|
17
18
|
biasOffset?: number;
|
|
19
|
+
executionPolicies?: ExecutionV1PoliciesSchema | null;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/** Context for residual variant selection rules. */
|
|
@@ -5,6 +5,7 @@ import { WORKGROUP_SIZES, VEC4_ELEMENTS_PER_WG } from './constants.js';
|
|
|
5
5
|
import { unifiedKernelWrapper } from './utils.js';
|
|
6
6
|
import { castF16ToF32, castF32ToF16, recordCastF16ToF32, recordCastF32ToF16 } from './cast.js';
|
|
7
7
|
import { selectRuleValue } from './rule-registry.js';
|
|
8
|
+
import { assertImplicitDtypeTransitionAllowed } from '../../inference/pipelines/text/dtype-contract.js';
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
function selectResidualVariant(outputDtype, useVec4) {
|
|
@@ -23,30 +24,58 @@ function selectBiasAddVariant(dataDtype, biasDtype) {
|
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
async function alignResidualInputs(a, b, recorder) {
|
|
27
|
+
async function alignResidualInputs(a, b, recorder, executionPolicies = null) {
|
|
27
28
|
if (a.dtype === b.dtype) {
|
|
28
29
|
return { a, b, temps: [] };
|
|
29
30
|
}
|
|
30
31
|
if (a.dtype === 'f16' && b.dtype === 'f32') {
|
|
32
|
+
assertImplicitDtypeTransitionAllowed({
|
|
33
|
+
executionPolicies,
|
|
34
|
+
fromDtype: a.dtype,
|
|
35
|
+
toDtype: 'f32',
|
|
36
|
+
op: 'residual_add',
|
|
37
|
+
detail: 'Residual add would widen one input implicitly.',
|
|
38
|
+
});
|
|
31
39
|
const casted = recorder ? await recordCastF16ToF32(recorder, a) : await castF16ToF32(a);
|
|
32
40
|
return { a: casted, b, temps: [casted.buffer] };
|
|
33
41
|
}
|
|
34
42
|
if (a.dtype === 'f32' && b.dtype === 'f16') {
|
|
43
|
+
assertImplicitDtypeTransitionAllowed({
|
|
44
|
+
executionPolicies,
|
|
45
|
+
fromDtype: b.dtype,
|
|
46
|
+
toDtype: 'f32',
|
|
47
|
+
op: 'residual_add',
|
|
48
|
+
detail: 'Residual add would widen one input implicitly.',
|
|
49
|
+
});
|
|
35
50
|
const casted = recorder ? await recordCastF16ToF32(recorder, b) : await castF16ToF32(b);
|
|
36
51
|
return { a, b: casted, temps: [casted.buffer] };
|
|
37
52
|
}
|
|
38
53
|
return { a, b, temps: [] };
|
|
39
54
|
}
|
|
40
55
|
|
|
41
|
-
async function alignBiasTensor(data, bias, recorder) {
|
|
56
|
+
async function alignBiasTensor(data, bias, recorder, executionPolicies = null) {
|
|
42
57
|
if (data.dtype === bias.dtype) {
|
|
43
58
|
return { bias, temps: [] };
|
|
44
59
|
}
|
|
45
60
|
if (data.dtype === 'f16' && bias.dtype === 'f32') {
|
|
61
|
+
assertImplicitDtypeTransitionAllowed({
|
|
62
|
+
executionPolicies,
|
|
63
|
+
fromDtype: bias.dtype,
|
|
64
|
+
toDtype: 'f16',
|
|
65
|
+
op: 'bias_add',
|
|
66
|
+
detail: 'Bias add would narrow the bias tensor implicitly.',
|
|
67
|
+
});
|
|
46
68
|
const casted = recorder ? await recordCastF32ToF16(recorder, bias) : await castF32ToF16(bias);
|
|
47
69
|
return { bias: casted, temps: [casted.buffer] };
|
|
48
70
|
}
|
|
49
71
|
if (data.dtype === 'f32' && bias.dtype === 'f16') {
|
|
72
|
+
assertImplicitDtypeTransitionAllowed({
|
|
73
|
+
executionPolicies,
|
|
74
|
+
fromDtype: bias.dtype,
|
|
75
|
+
toDtype: 'f32',
|
|
76
|
+
op: 'bias_add',
|
|
77
|
+
detail: 'Bias add would widen the bias tensor implicitly.',
|
|
78
|
+
});
|
|
50
79
|
const casted = recorder ? await recordCastF16ToF32(recorder, bias) : await castF16ToF32(bias);
|
|
51
80
|
return { bias: casted, temps: [casted.buffer] };
|
|
52
81
|
}
|
|
@@ -84,7 +113,12 @@ async function _residualAdd(target, a, b, size, options = {}) {
|
|
|
84
113
|
const { useVec4 = true, outputBuffer = null } = options;
|
|
85
114
|
const ownsOutput = outputBuffer == null;
|
|
86
115
|
|
|
87
|
-
const { a: aAligned, b: bAligned, temps } = await alignResidualInputs(
|
|
116
|
+
const { a: aAligned, b: bAligned, temps } = await alignResidualInputs(
|
|
117
|
+
a,
|
|
118
|
+
b,
|
|
119
|
+
recorder,
|
|
120
|
+
options.executionPolicies ?? null
|
|
121
|
+
);
|
|
88
122
|
const outputDtype = inferOutputDtype(aAligned, bAligned);
|
|
89
123
|
const bytesPerElement = dtypeBytes(outputDtype);
|
|
90
124
|
|
|
@@ -120,7 +154,12 @@ async function _biasAdd(target, data, bias, numTokens, dim, options = {}) {
|
|
|
120
154
|
const recorder = target && typeof target.beginComputePass === 'function' ? target : null;
|
|
121
155
|
const { dataOffset = 0, biasOffset = 0 } = options;
|
|
122
156
|
|
|
123
|
-
const { bias: biasAligned, temps } = await alignBiasTensor(
|
|
157
|
+
const { bias: biasAligned, temps } = await alignBiasTensor(
|
|
158
|
+
data,
|
|
159
|
+
bias,
|
|
160
|
+
recorder,
|
|
161
|
+
options.executionPolicies ?? null
|
|
162
|
+
);
|
|
124
163
|
const variant = selectBiasAddVariant(data.dtype, biasAligned.dtype);
|
|
125
164
|
const device = target?.device;
|
|
126
165
|
const maxPerDim = Number.isFinite(device?.limits?.maxComputeWorkgroupsPerDimension)
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import type { Tensor } from '../tensor.js';
|
|
11
11
|
import type { CommandRecorder } from '../command-recorder.js';
|
|
12
12
|
import type { OutputBufferOptions } from './types.js';
|
|
13
|
+
import type { ExecutionV1PoliciesSchema } from '../../config/schema/execution-v1.schema.js';
|
|
13
14
|
|
|
14
15
|
/** RoPE kernel options */
|
|
15
16
|
export interface RoPEOptions extends OutputBufferOptions {
|
|
@@ -19,6 +20,7 @@ export interface RoPEOptions extends OutputBufferOptions {
|
|
|
19
20
|
interleaved?: boolean;
|
|
20
21
|
ropeTheta?: number;
|
|
21
22
|
startPos?: number;
|
|
23
|
+
executionPolicies?: ExecutionV1PoliciesSchema | null;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/** Context for RoPE variant selection rules. */
|
package/src/gpu/kernels/rope.js
CHANGED
|
@@ -7,6 +7,7 @@ import { getKernelThresholds } from '../../config/schema/index.js';
|
|
|
7
7
|
import { selectRuleValue } from './rule-registry.js';
|
|
8
8
|
import { castF16ToF32, castF32ToF16, recordCastF16ToF32, recordCastF32ToF16 } from './cast.js';
|
|
9
9
|
import { releaseBuffer } from '../../memory/buffer-pool.js';
|
|
10
|
+
import { assertImplicitDtypeTransitionAllowed } from '../../inference/pipelines/text/dtype-contract.js';
|
|
10
11
|
|
|
11
12
|
const getRopeDefaults = () => getKernelThresholds().rope;
|
|
12
13
|
|
|
@@ -30,22 +31,27 @@ async function _rope(target, input, freqsCos, freqsSin, seqLen, options = {}) {
|
|
|
30
31
|
throw new Error(`RoPE rotaryDim must be in (0, headDim]; got ${rotaryDim} for headDim ${headDim}`);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const needsF32Cast = input.dtype === 'f16' && (rotaryDim !== headDim || interleaved);
|
|
34
|
+
const caps = getKernelCapabilities();
|
|
35
|
+
const needsF32Cast = input.dtype === 'f16'
|
|
36
|
+
&& caps.hasF16 !== true
|
|
37
|
+
&& (rotaryDim !== headDim || interleaved);
|
|
38
38
|
let ropeInput = input;
|
|
39
39
|
let f32TempBuffer = null;
|
|
40
40
|
|
|
41
41
|
if (needsF32Cast) {
|
|
42
|
+
assertImplicitDtypeTransitionAllowed({
|
|
43
|
+
executionPolicies: options.executionPolicies ?? null,
|
|
44
|
+
fromDtype: input.dtype,
|
|
45
|
+
toDtype: 'f32',
|
|
46
|
+
op: 'rope',
|
|
47
|
+
detail: 'RoPE would widen activations implicitly for interleaved or partial rotary mode.',
|
|
48
|
+
});
|
|
42
49
|
ropeInput = target
|
|
43
50
|
? await recordCastF16ToF32(target, input)
|
|
44
51
|
: await castF16ToF32(input);
|
|
45
52
|
f32TempBuffer = ropeInput.buffer;
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
const caps = getKernelCapabilities();
|
|
49
55
|
const useF16 = ropeInput.dtype === 'f16' && caps.hasF16;
|
|
50
56
|
const variant = selectRuleValue('rope', 'variant', { useF16 });
|
|
51
57
|
|
|
@@ -69,6 +75,13 @@ async function _rope(target, input, freqsCos, freqsSin, seqLen, options = {}) {
|
|
|
69
75
|
);
|
|
70
76
|
|
|
71
77
|
if (needsF32Cast) {
|
|
78
|
+
assertImplicitDtypeTransitionAllowed({
|
|
79
|
+
executionPolicies: options.executionPolicies ?? null,
|
|
80
|
+
fromDtype: ropeInput.dtype,
|
|
81
|
+
toDtype: 'f16',
|
|
82
|
+
op: 'rope',
|
|
83
|
+
detail: 'RoPE would narrow activations implicitly when restoring the original buffer dtype.',
|
|
84
|
+
});
|
|
72
85
|
target
|
|
73
86
|
? await recordCastF32ToF16(target, ropeInput, { outputBuffer: input.buffer })
|
|
74
87
|
: await castF32ToF16(ropeInput, { outputBuffer: input.buffer });
|
|
@@ -35,6 +35,20 @@ struct Uniforms {
|
|
|
35
35
|
@group(0) @binding(2) var<storage, read_write> freqs_cos: array<f32>; // Precomputed cos [max_seq_len, head_dim/2]
|
|
36
36
|
@group(0) @binding(3) var<storage, read_write> freqs_sin: array<f32>; // Precomputed sin [max_seq_len, head_dim/2]
|
|
37
37
|
|
|
38
|
+
fn get_first_rotary_idx(pair_idx: u32) -> u32 {
|
|
39
|
+
if (u.interleaved == 1u) {
|
|
40
|
+
return pair_idx * 2u;
|
|
41
|
+
}
|
|
42
|
+
return pair_idx;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fn get_second_rotary_idx(pair_idx: u32, head_dim: u32) -> u32 {
|
|
46
|
+
if (u.interleaved == 1u) {
|
|
47
|
+
return pair_idx * 2u + 1u;
|
|
48
|
+
}
|
|
49
|
+
return pair_idx + (head_dim / 2u);
|
|
50
|
+
}
|
|
51
|
+
|
|
38
52
|
// Apply RoPE using precomputed frequencies
|
|
39
53
|
@compute @workgroup_size(WORKGROUP_SIZE, 1, 1)
|
|
40
54
|
fn main(
|
|
@@ -67,10 +81,9 @@ fn main(
|
|
|
67
81
|
let cos_val = freqs_cos[freq_idx];
|
|
68
82
|
let sin_val = freqs_sin[freq_idx];
|
|
69
83
|
|
|
70
|
-
// Apply "rotate-half" layout: pair (x[i], x[i + half_dim])
|
|
71
84
|
let base_idx = pos * num_heads * head_dim + head_idx * head_dim;
|
|
72
|
-
let first_idx =
|
|
73
|
-
let second_idx =
|
|
85
|
+
let first_idx = get_first_rotary_idx(pair_idx);
|
|
86
|
+
let second_idx = get_second_rotary_idx(pair_idx, head_dim);
|
|
74
87
|
let x0 = input[base_idx + first_idx];
|
|
75
88
|
let x1 = input[base_idx + second_idx];
|
|
76
89
|
|
|
@@ -120,10 +133,9 @@ fn rope_compute_freqs(
|
|
|
120
133
|
let cos_val = cos(theta);
|
|
121
134
|
let sin_val = sin(theta);
|
|
122
135
|
|
|
123
|
-
// Apply "rotate-half" layout: pair (x[i], x[i + half_dim])
|
|
124
136
|
let base_idx = pos * num_heads * head_dim + head_idx * head_dim;
|
|
125
|
-
let first_idx =
|
|
126
|
-
let second_idx =
|
|
137
|
+
let first_idx = get_first_rotary_idx(pair_idx);
|
|
138
|
+
let second_idx = get_second_rotary_idx(pair_idx, head_dim);
|
|
127
139
|
let x0 = input[base_idx + first_idx];
|
|
128
140
|
let x1 = input[base_idx + second_idx];
|
|
129
141
|
|
|
@@ -175,8 +187,8 @@ fn rope_qk(
|
|
|
175
187
|
let k_base_idx = q_base_idx + head_dim; // K starts after Q
|
|
176
188
|
|
|
177
189
|
// Process Q
|
|
178
|
-
let first_idx =
|
|
179
|
-
let second_idx =
|
|
190
|
+
let first_idx = get_first_rotary_idx(pair_idx);
|
|
191
|
+
let second_idx = get_second_rotary_idx(pair_idx, head_dim);
|
|
180
192
|
let q0 = input[q_base_idx + first_idx];
|
|
181
193
|
let q1 = input[q_base_idx + second_idx];
|
|
182
194
|
input[q_base_idx + first_idx] = q0 * cos_val - q1 * sin_val;
|
|
@@ -262,8 +274,8 @@ fn rope_ntk_scaled(
|
|
|
262
274
|
let sin_val = sin(theta);
|
|
263
275
|
|
|
264
276
|
let base_idx = pos * num_heads * head_dim + head_idx * head_dim;
|
|
265
|
-
let first_idx =
|
|
266
|
-
let second_idx =
|
|
277
|
+
let first_idx = get_first_rotary_idx(pair_idx);
|
|
278
|
+
let second_idx = get_second_rotary_idx(pair_idx, head_dim);
|
|
267
279
|
let x0 = input[base_idx + first_idx];
|
|
268
280
|
let x1 = input[base_idx + second_idx];
|
|
269
281
|
|
|
@@ -334,8 +346,8 @@ fn rope_yarn(
|
|
|
334
346
|
let sin_val = sin(theta);
|
|
335
347
|
|
|
336
348
|
let base_idx = pos * num_heads * head_dim + head_idx * head_dim;
|
|
337
|
-
let first_idx =
|
|
338
|
-
let second_idx =
|
|
349
|
+
let first_idx = get_first_rotary_idx(pair_idx);
|
|
350
|
+
let second_idx = get_second_rotary_idx(pair_idx, head_dim);
|
|
339
351
|
let x0 = input[base_idx + first_idx];
|
|
340
352
|
let x1 = input[base_idx + second_idx];
|
|
341
353
|
|