doppler-gpu 0.6.1 → 0.7.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 +141 -38
- package/README.md +47 -195
- package/models/catalog.json +108 -51
- package/package.json +92 -122
- package/src/capsule-runtime.d.ts +15 -8
- package/src/capsule-runtime.js +7 -3
- package/src/cli/cli-output.js +85 -9
- package/src/cli/doppler-cli.js +23 -21
- package/src/client/capsule-host.browser.js +6 -0
- package/src/client/capsule-host.d.ts +11 -0
- package/src/client/capsule-host.js +6 -0
- package/src/client/doppler-api.browser.js +1 -1
- package/src/client/doppler-api.d.ts +1 -0
- package/src/client/doppler-api.js +1 -1
- package/src/client/doppler-registry.js +6 -0
- package/src/client/inspection.d.ts +10 -1
- package/src/client/inspection.js +24 -12
- package/src/client/model-host/index.d.ts +3 -0
- package/src/client/model-host/index.js +73 -18
- package/src/client/model-host/model-session.d.ts +47 -17
- package/src/client/model-host/model-session.js +285 -154
- package/src/client/model-host/source-loading.js +910 -0
- package/src/client/provider.js +6 -6
- package/src/client/resident-partitions.d.ts +30 -0
- package/src/client/resident-partitions.js +114 -0
- package/src/client/runtime/capsule-acquisition.d.ts +17 -2
- package/src/client/runtime/capsule-artifact-source.js +23 -1
- package/src/client/runtime/capsule-operation-adapters.d.ts +3 -2
- package/src/client/runtime/capsule-operation-adapters.js +44 -8
- package/src/client/runtime/capsule-operation-deltas.js +44 -0
- package/src/client/runtime/capsule-operation-executor.d.ts +2 -2
- package/src/client/runtime/capsule-operation-executor.js +11 -5
- package/src/client/runtime/capsule-operation-stream.d.ts +10 -0
- package/src/client/runtime/capsule-operation-stream.js +81 -0
- package/src/client/runtime/capsule-piece-reader.js +88 -0
- package/src/client/runtime/capsule-program-adapter.js +51 -21
- package/src/client/runtime/command-executor.d.ts +13 -0
- package/src/client/runtime/command-executor.js +54 -11
- package/src/client/runtime/composition-root.d.ts +35 -12
- package/src/client/runtime/composition-root.js +186 -57
- package/src/client/runtime/fetch-capsule-artifact-store.d.ts +3 -2
- package/src/client/runtime/fetch-capsule-artifact-store.js +56 -1
- package/src/client/runtime/lora.d.ts +22 -0
- package/src/client/runtime/lora.js +86 -26
- package/src/client/runtime/model-manager.js +10 -75
- package/src/client/runtime/model-source.d.ts +1 -0
- package/src/client/runtime/model-source.js +1 -1
- package/src/client/runtime/node-quickstart-cache.js +7 -2
- package/src/client/runtime/resource-binder.d.ts +1 -0
- package/src/client/runtime/resource-binder.js +20 -14
- package/src/client/runtime/scoped-session.d.ts +10 -0
- package/src/client/runtime/scoped-session.js +41 -3
- package/src/client/runtime/session-controller.d.ts +15 -1
- package/src/client/runtime/session-controller.js +102 -30
- package/src/client/runtime/verified-capsule-artifact-store.d.ts +27 -0
- package/src/client/runtime/verified-capsule-artifact-store.js +255 -58
- package/src/client/wrap-pipeline-handle.js +23 -17
- package/src/config/canonical-contract-codec.d.ts +10 -0
- package/src/config/canonical-contract-codec.js +144 -0
- package/src/config/canonical-generation-policy.d.ts +7 -0
- package/src/config/canonical-generation-policy.js +66 -0
- package/src/config/capsule-loading.d.ts +5 -1
- package/src/config/capsule-loading.js +1 -1
- package/src/config/capsule-loading.schema.json +63 -4
- package/src/config/capsule-operation.d.ts +10 -3
- package/src/config/capsule-operation.js +6 -1
- package/src/config/capsule-operations.json +26 -1
- package/src/config/capsule-release-contract.js +2 -29
- package/src/config/capsule-token-selection.d.ts +15 -0
- package/src/config/capsule-token-selection.js +39 -0
- package/src/config/capsule-token-selection.json +11 -0
- package/src/config/capsule-v2.d.ts +1 -0
- package/src/config/capsule-v2.js +14 -21
- package/src/config/choice-scoring-reference.js +66 -0
- package/src/config/choice-scoring.d.ts +21 -0
- package/src/config/choice-scoring.js +66 -0
- package/src/config/choice-scoring.json +8 -0
- package/src/config/conversion/amplify/amplify-120m-f16-af32.json +4 -4
- package/src/config/conversion/diffusiongemma/diffusiongemma-26b-a4b-it-q4k-ehf16-af16.json +7 -7
- package/src/config/conversion/embeddinggemma/google-embeddinggemma-300m-q4k-ehf16-af32.json +3 -3
- package/src/config/conversion/esm/esm2-t12-35m-ur50d-f32-af32.json +12 -8
- package/src/config/conversion/esmc/esmc-300m-f32-af32.json +260 -55
- package/src/config/conversion/gemma3/gemma-3-1b-it-f16-af32.json +16 -10
- package/src/config/conversion/gemma3/gemma-3-1b-it-q4k-ehf16-af32.json +9 -8
- package/src/config/conversion/gemma3/gemma-3-270m-it-f16-af32.json +6 -6
- package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af16.json +9 -9
- package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af32.json +8 -7
- package/src/config/conversion/gemma3/gemma-3-270m-it-w8a8-ehf16-af32.json +491 -0
- package/src/config/conversion/gemma3/translategemma-4b-1b-enes-q4k-ehf16-af32.json +5 -5
- package/src/config/conversion/gemma3/translategemma-4b-it-q4k-ehf16-af32.json +9 -8
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af16.json +24 -8
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af32.json +24 -8
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-hq4k-af16.json +25 -9
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-w4a16-ct-ehf16-af16.json +21 -5
- package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af16.json +26 -9
- package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af32.json +26 -9
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af16-int4ple.json +26 -9
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32-int4ple.json +25 -8
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32.json +25 -8
- package/src/config/conversion/gemma4/gemma-4-moe-q4k-ehf16-af32.json +7 -6
- package/src/config/conversion/glmocr/glm-ocr-f16-af32.json +7 -7
- package/src/config/conversion/gpt-oss-20b-f16-xmxfp4.json +7 -6
- package/src/config/conversion/janus/janus-pro-1b-text-q4k-ehaf16.json +7 -6
- package/src/config/conversion/lfm2/lfm2.5-1.2b-instruct-q4k-ehf16-af32.json +20 -12
- package/src/config/conversion/minicpm/minicpm4-0-5b-f16-af32.json +7 -9
- package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-bf16-af32.json +7 -7
- package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-f16-af32.json +7 -7
- package/src/config/conversion/nucleotide-transformer/nucleotide-transformer-v2-50m-f32-af32.json +252 -53
- package/src/config/conversion/qwen3/qwen-3-4b-instruct-2507-q4k-ehf16-af32.json +501 -0
- package/src/config/conversion/qwen3/qwen-3-5-0-8b-canonical-f32.json +461 -0
- package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +8 -8
- package/src/config/conversion/qwen3/qwen-3-5-2b-q4k-ehaf16.json +8 -8
- package/src/config/conversion/qwen3/qwen-3-5-9b-f16-af32.json +7 -7
- package/src/config/conversion/qwen3/qwen-3-5-9b-q4k-ehaf16.json +8 -8
- package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-eaf16.json +8 -8
- package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-ehaf16.json +8 -8
- package/src/config/conversion/qwen3/qwen-3-6-35b-a3b-q4_0-passthrough.json +1218 -0
- package/src/config/conversion/qwen3/qwen-3-6-35b-a3b-text-q4k-ehf16-af32.json +581 -0
- package/src/config/conversion/qwen3/qwen-3-8-flash-next-text-q4k-ehf16-af32.json +1063 -0
- package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-f16-af32.json +11 -11
- package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-q4k-ehf16-af32.json +6 -6
- package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-af32.json +18 -10
- package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-true-logit-af32.json +10 -10
- package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-q4k-ehf16-af32.json +18 -18
- package/src/config/conversion/qwen3/qwen3.8-27b-q4_0-passthrough.json +823 -0
- package/src/config/conversion/qwen3/qwen3.8-27b-text-f16-af32.json +11 -11
- package/src/config/conversion/qwen3/qwen3.8-27b-text-q4k-ehaf16.json +11 -11
- package/src/config/embedding-contract.d.ts +17 -0
- package/src/config/embedding-contract.js +12 -0
- package/src/config/embedding-reference.js +32 -0
- package/src/config/execution-registry-contract.d.ts +41 -0
- package/src/config/execution-registry-contract.js +171 -0
- package/src/config/generation-contract.d.ts +28 -1
- package/src/config/generation-contract.json +119 -0
- package/src/config/initial-execution-identity.d.ts +1 -1
- package/src/config/initial-execution-identity.js +9 -9
- package/src/config/inspection/activity-stages.json +42 -0
- package/src/config/inspection/observation-policies.json +135 -0
- package/src/config/kernel-path-loader.d.ts +30 -0
- package/src/config/kernel-path-loader.js +69 -13
- package/src/config/kernel-registry-contract.d.ts +78 -13
- package/src/config/kernel-registry-contract.js +110 -38
- package/src/config/kernels/backward-registry.json +1 -1
- package/src/config/kernels/registry.js +3 -47
- package/src/config/kernels/registry.json +31747 -7849
- package/src/config/layer-partition-plan.d.ts +93 -0
- package/src/config/layer-partition-plan.js +305 -0
- package/src/config/manifest-inference-validation.js +10 -0
- package/src/config/merge/execution-patches.js +14 -0
- package/src/config/merge.d.ts +4 -0
- package/src/config/merge.js +50 -0
- package/src/config/model-ir-v2.d.ts +1 -0
- package/src/config/model-ir-v2.js +5 -16
- package/src/config/model-ir.js +9 -14
- package/src/config/ordered-resident-qualification.d.ts +16 -0
- package/src/config/ordered-resident-qualification.js +62 -0
- package/src/config/param-categories.js +4 -0
- package/src/config/param-validator.js +64 -29
- package/src/config/production-release-evidence.js +2 -27
- package/src/config/production-release.js +2 -29
- package/src/config/quickstart-registry.json +57 -8
- package/src/config/reasoning-output.d.ts +6 -0
- package/src/config/reasoning-output.js +26 -0
- package/src/config/revocation-policy.js +1 -4
- package/src/config/rope-frequencies.js +9 -0
- package/src/config/runtime/profiles/demo-f16-comparison.json +20 -0
- package/src/config/runtime/profiles/flash-next-node-host-cache-qualification.json +21 -0
- package/src/config/runtime/profiles/flash-next-paged-qualification.json +23 -0
- package/src/config/runtime/profiles/flash-next-routed-f32kv-qualification.json +72 -0
- package/src/config/runtime/profiles/flash-next-routed-qualification.json +27 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-parity.json +51 -2
- package/src/config/runtime/profiles/qwen-3-5-0-8b-vulkan-parity.json +88 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-vulkan-subgroup8.json +173 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-vulkan-throughput.json +33 -0
- package/src/config/runtime/profiles/qwen-3-5-2b-metal-throughput.json +51 -2
- package/src/config/runtime/profiles/qwen-3-5-2b-vulkan-parity.json +15 -0
- package/src/config/runtime/profiles/qwen3-6-35b-a3b-q4_0-candidate.json +4491 -0
- package/src/config/runtime/profiles/qwen3-6-35b-a3b-q4_0-pooled-q8-common-diagnostic.json +4407 -0
- package/src/config/runtime/profiles/qwen3-6-35b-a3b-route-f32-candidate.json +17 -0
- package/src/config/runtime/profiles/qwen3-6-35b-a3b-route-f32-workspace-candidate.json +13 -0
- package/src/config/runtime.d.ts +6 -0
- package/src/config/runtime.js +51 -21
- package/src/config/schema/benchmark.schema.d.ts +1 -0
- package/src/config/schema/benchmark.schema.js +2 -0
- package/src/config/schema/conversion.schema.d.ts +5 -0
- package/src/config/schema/converter.schema.d.ts +10 -0
- package/src/config/schema/converter.schema.js +10 -0
- package/src/config/schema/debug.schema.d.ts +1 -0
- package/src/config/schema/doppler.schema.js +16 -9
- package/src/config/schema/emulation.schema.js +0 -77
- package/src/config/schema/execution-v1.schema.d.ts +32 -2
- package/src/config/schema/execution-v1.schema.js +8 -0
- package/src/config/schema/fp8.schema.d.ts +17 -0
- package/src/config/schema/fp8.schema.js +27 -0
- package/src/config/schema/hyper-connection-decoder.schema.d.ts +98 -0
- package/src/config/schema/hyper-connection-decoder.schema.js +213 -0
- package/src/config/schema/index.d.ts +2 -2
- package/src/config/schema/index.js +3 -0
- package/src/config/schema/inference.schema.d.ts +8 -2
- package/src/config/schema/kernel-registry.schema.d.ts +22 -7
- package/src/config/schema/kernel-registry.schema.js +13 -2
- package/src/config/schema/kernel-thresholds.schema.d.ts +3 -0
- package/src/config/schema/kernel-thresholds.schema.js +14 -3
- package/src/config/schema/kernel-warmup.schema.d.ts +15 -0
- package/src/config/schema/kernel-warmup.schema.js +3 -0
- package/src/config/schema/loading.schema.d.ts +41 -0
- package/src/config/schema/loading.schema.js +67 -0
- package/src/config/schema/manifest-rope.schema.d.ts +55 -0
- package/src/config/schema/manifest.schema.d.ts +47 -57
- package/src/config/schema/manifest.schema.js +41 -2
- package/src/config/schema/ngram-embedding.schema.d.ts +116 -0
- package/src/config/schema/ngram-embedding.schema.js +312 -0
- package/src/config/schema/program-bundle.schema.d.ts +1 -0
- package/src/config/schema/program-bundle.schema.js +8 -3
- package/src/config/schema/quantization-defaults.schema.d.ts +1 -1
- package/src/config/schema/quantization.schema.d.ts +2 -0
- package/src/config/schema/quantization.schema.js +2 -0
- package/src/config/schema/speculation-self.schema.d.ts +6 -1
- package/src/config/schema/speculation-self.schema.js +29 -2
- package/src/config/schema/w8a8.schema.d.ts +24 -0
- package/src/config/schema/w8a8.schema.js +38 -0
- package/src/config/source-packages/litert/gemma-4-e2b-it.json +6 -6
- package/src/config/supported-operations.json +105 -0
- package/src/config/target-plan.d.ts +16 -2
- package/src/config/target-plan.js +63 -16
- package/src/config/wgsl-language-contract.js +47 -0
- package/src/converter/artifact-identity.js +27 -47
- package/src/converter/capability-transform-resolver.js +80 -0
- package/src/converter/conversion-plan.js +14 -14
- package/src/converter/core.d.ts +2 -0
- package/src/converter/core.js +15 -16
- package/src/converter/execution-graph/fusion.js +343 -0
- package/src/converter/execution-graph/kv-storage.js +14 -0
- package/src/converter/execution-graph/validation.js +431 -0
- package/src/converter/execution-graph-transforms.js +927 -0
- package/src/converter/forge-candidate-evaluation.js +1 -1
- package/src/converter/forge-qualification.js +101 -30
- package/src/converter/forge-stages.js +107 -102
- package/src/converter/fp8-source.js +99 -0
- package/src/converter/linear-norm-gate.js +115 -0
- package/src/converter/manifest-builder.js +20 -6
- package/src/converter/parsers/gguf.js +21 -2
- package/src/converter/quantization-info.js +56 -5
- package/src/converter/quantizer.js +4 -159
- package/src/converter/qwen4-exp-source-defaults.json +35 -0
- package/src/converter/qwen4-exp-source.js +293 -0
- package/src/converter/resident-qualification.js +58 -0
- package/src/converter/retained-source-shards.js +97 -0
- package/src/converter/rope-config.js +1 -0
- package/src/converter/source-rotary-frequencies.d.ts +12 -0
- package/src/converter/source-rotary-frequencies.js +34 -0
- package/src/converter/source-tensor-rules.d.ts +25 -1
- package/src/converter/source-tensor-rules.js +31 -1
- package/src/converter/tensor-transform.js +60 -7
- package/src/converter/tokenizer-contract.js +1 -3
- package/src/converter/w8a8-quantizer.js +56 -0
- package/src/debug/activation-trace.d.ts +35 -0
- package/src/debug/activation-trace.js +89 -0
- package/src/debug/activity-trace.d.ts +76 -0
- package/src/debug/activity-trace.js +232 -0
- package/src/debug/capture-policy.d.ts +9 -1
- package/src/debug/capture-policy.js +52 -21
- package/src/debug/index.d.ts +3 -0
- package/src/debug/index.js +12 -6
- package/src/debug/log.d.ts +6 -0
- package/src/debug/log.js +26 -0
- package/src/debug/perf-guards.js +71 -0
- package/src/debug/pipeline-config.js +141 -0
- package/src/debug/stats.d.ts +1 -1
- package/src/debug/stats.js +7 -2
- package/src/debug/tensor.d.ts +15 -3
- package/src/debug/tensor.js +43 -27
- package/src/debug/trace.js +12 -0
- package/src/errors/doppler-error.js +6 -2
- package/src/experimental/audio/gemma4.js +19 -10
- package/src/experimental/bdpa/basis-decomposed-paged.d.ts +1 -1
- package/src/experimental/diffusion/pipeline.d.ts +1 -0
- package/src/experimental/distribution/shard-delivery/receipt.js +3 -73
- package/src/experimental/distribution/shard-delivery/retry.js +6 -112
- package/src/experimental/distribution/shard-delivery.js +19 -632
- package/src/experimental/energy/pipeline.d.ts +1 -0
- package/src/experimental/logits/cpu.js +2 -7
- package/src/experimental/training/artifacts.js +1 -4
- package/src/experimental/training/attention-forward.js +1 -1
- package/src/experimental/training/autograd.d.ts +21 -0
- package/src/experimental/training/autograd.js +44 -20
- package/src/experimental/training/checkpoint.js +1 -4
- package/src/experimental/training/clip.js +1 -1
- package/src/experimental/training/distillation/student-fixture/execution.js +9 -12
- package/src/experimental/training/distillation/student-fixture/model.js +9 -12
- package/src/experimental/training/distillation/student-fixture.js +9 -12
- package/src/experimental/training/lora/checkpoint.js +1 -1
- package/src/experimental/training/lora/execution.js +1 -1
- package/src/experimental/training/lora/plan.js +1 -1
- package/src/experimental/training/lora/recovery.js +1 -1
- package/src/experimental/training/lora-pipeline.js +9 -83
- package/src/experimental/training/lora-training-round.d.ts +39 -0
- package/src/experimental/training/lora-training-round.js +90 -0
- package/src/experimental/training/lora.js +2 -1
- package/src/experimental/training/loss-scaling.js +1 -1
- package/src/experimental/training/loss.js +3 -1
- package/src/experimental/training/native-qwen-lora.d.ts +25 -6
- package/src/experimental/training/native-qwen-lora.js +176 -21
- package/src/experimental/training/operator-command.js +1 -49
- package/src/experimental/training/parameter-groups.js +39 -0
- package/src/experimental/training/report-ranking.js +52 -0
- package/src/experimental/training/runner/lifecycle.js +4 -61
- package/src/experimental/training/runner.js +2 -5
- package/src/experimental/training/suite/execution.js +3 -5
- package/src/experimental/training/suite/plan.js +6 -21
- package/src/experimental/training/suite.js +5 -34
- package/src/experimental/training/trainer.js +2 -36
- package/src/experimental/training/workload-capsules/registry.json +473 -0
- package/src/experimental/turboquant/codebook.js +0 -29
- package/src/formats/contract-validation.js +30 -0
- package/src/formats/flatbuffer-tables.js +55 -0
- package/src/formats/float16.js +81 -0
- package/src/formats/float8.js +19 -0
- package/src/formats/gguf/block-storage.js +51 -0
- package/src/formats/gguf/quantized-formats.json +10 -0
- package/src/formats/gguf/qwen-source.js +88 -0
- package/src/formats/gguf/qwen-source.json +8 -0
- package/src/formats/gguf/tokenizer-pre.json +4 -0
- package/src/formats/gguf/tokenizer.js +50 -0
- package/src/formats/litert/types.js +8 -180
- package/src/formats/paged-source-reader.js +158 -0
- package/src/formats/q4k-dequant.js +95 -0
- package/src/formats/rdrr/classification.js +4 -0
- package/src/formats/rdrr/distributed/validation.js +1 -4
- package/src/formats/rdrr/fp8-contract.js +38 -0
- package/src/formats/rdrr/fp8-storage.js +83 -0
- package/src/formats/rdrr/functional-descriptor.js +1 -4
- package/src/formats/rdrr/parsing.js +1 -1
- package/src/formats/rdrr/q4_0-storage.js +24 -0
- package/src/formats/rdrr/storage-descriptor.js +7 -1
- package/src/formats/rdrr/types.d.ts +7 -1
- package/src/formats/rdrr/validation.js +37 -6
- package/src/formats/rdrr/w8a8-storage.js +64 -0
- package/src/formats/safetensors/types.js +4 -0
- package/src/formats/sha256.js +104 -103
- package/src/formats/sorted-json.js +9 -0
- package/src/formats/source-runtime.d.ts +52 -0
- package/src/formats/tflite/types.js +7 -161
- package/src/generation/index.d.ts +7 -1
- package/src/generation/index.js +7 -1
- package/src/gpu/buffer-identity.js +4 -0
- package/src/gpu/command-recorder.d.ts +66 -29
- package/src/gpu/command-recorder.js +157 -161
- package/src/gpu/device-bindings.js +98 -0
- package/src/gpu/device-state.js +0 -12
- package/src/gpu/device.d.ts +9 -0
- package/src/gpu/device.js +104 -141
- package/src/gpu/kernel-selector.js +73 -12
- package/src/gpu/kernels/attention/executors-components.js +235 -0
- package/src/gpu/kernels/attention/executors.js +296 -510
- package/src/gpu/kernels/attention/plan.js +65 -18
- package/src/gpu/kernels/attention/query-splitk.js +80 -0
- package/src/gpu/kernels/attention_decode_gqa_splitk.wgsl +197 -0
- package/src/gpu/kernels/attention_decode_online.wgsl +348 -0
- package/src/gpu/kernels/attention_decode_online_f16kv.wgsl +126 -22
- package/src/gpu/kernels/attention_decode_subgroup.wgsl +5 -6
- package/src/gpu/kernels/attention_head256_f16kv.wgsl +56 -9
- package/src/gpu/kernels/attention_indexed.wgsl +179 -0
- package/src/gpu/kernels/attention_indexed_f16kv.wgsl +180 -0
- package/src/gpu/kernels/attention_paired.wgsl +361 -0
- package/src/gpu/kernels/attention_paired_tiled.wgsl +383 -0
- package/src/gpu/kernels/attention_prefill_partitioned_head256_f16kv.wgsl +247 -0
- package/src/gpu/kernels/attention_prefill_query_splitk_f32.wgsl +234 -0
- package/src/gpu/kernels/attention_prefill_query_splitk_reduce_f32.wgsl +103 -0
- package/src/gpu/kernels/attention_prefill_query_tile_f16kv.wgsl +225 -0
- package/src/gpu/kernels/attention_prefill_query_tile_f32.wgsl +222 -0
- package/src/gpu/kernels/backward/adam.js +11 -3
- package/src/gpu/kernels/backward/gated_delta_recurrent_backward.js +51 -15
- package/src/gpu/kernels/backward/gated_delta_recurrent_backward.wgsl +9 -8
- package/src/gpu/kernels/backward/gated_delta_recurrent_checkpoint_forward.js +149 -0
- package/src/gpu/kernels/backward/gated_delta_recurrent_checkpoint_forward.wgsl +109 -0
- package/src/gpu/kernels/backward/gated_delta_recurrent_checkpointed_backward.js +120 -0
- package/src/gpu/kernels/backward/gelu_backward.js +8 -12
- package/src/gpu/kernels/backward/index.js +6 -0
- package/src/gpu/kernels/backward/qwen_attention_split_q_gate_backward.js +80 -0
- package/src/gpu/kernels/backward/qwen_attention_split_q_gate_backward.wgsl +26 -0
- package/src/gpu/kernels/backward/qwen_gqa_attention_backward.js +157 -0
- package/src/gpu/kernels/backward/qwen_gqa_attention_backward.wgsl +82 -0
- package/src/gpu/kernels/backward/qwen_gqa_softmax_backward_scores.wgsl +73 -0
- package/src/gpu/kernels/backward/qwen_gqa_softmax_recompute.wgsl +97 -0
- package/src/gpu/kernels/backward/qwen_linear_attention_prepare_backward.js +221 -0
- package/src/gpu/kernels/backward/qwen_linear_attention_prepare_backward.wgsl +136 -0
- package/src/gpu/kernels/backward/rmsnorm_backward.js +98 -80
- package/src/gpu/kernels/backward/rope_backward.js +47 -10
- package/src/gpu/kernels/backward/rope_backward.wgsl +46 -22
- package/src/gpu/kernels/backward/sigmoid_gated_backward.js +83 -0
- package/src/gpu/kernels/backward/sigmoid_gated_backward.wgsl +49 -0
- package/src/gpu/kernels/backward/silu_backward.js +8 -12
- package/src/gpu/kernels/backward/softmax_backward.js +8 -12
- package/src/gpu/kernels/cast_f32_to_two_f32.wgsl +12 -0
- package/src/gpu/kernels/cast_two_f32_to_f16.wgsl +49 -0
- package/src/gpu/kernels/causal_conv1d_silu.js +80 -0
- package/src/gpu/kernels/causal_conv1d_silu.wgsl +44 -0
- package/src/gpu/kernels/check-stop.js +1 -1
- package/src/gpu/kernels/check_finiteness_f32.wgsl +33 -0
- package/src/gpu/kernels/conv2d.js +30 -42
- package/src/gpu/kernels/dequant.js +1 -1
- package/src/gpu/kernels/dequant_mxfp4.wgsl +6 -4
- package/src/gpu/kernels/diffusion-gemma-sampling.js +26 -7
- package/src/gpu/kernels/diffusion_gemma_sampling.wgsl +66 -2
- package/src/gpu/kernels/dispatch.js +36 -1
- package/src/gpu/kernels/embedding-pool.js +15 -13
- package/src/gpu/kernels/feature-check.js +7 -2
- package/src/gpu/kernels/fp8.js +70 -0
- package/src/gpu/kernels/fused_ffn.js +83 -154
- package/src/gpu/kernels/fused_ffn_q4k.wgsl +43 -1
- package/src/gpu/kernels/fused_ffn_q4k_subgroup8.wgsl +228 -0
- package/src/gpu/kernels/fused_matmul_q4_batched_f16acc_f16a.wgsl +2 -2
- package/src/gpu/kernels/fused_matmul_q4_subgroup.wgsl +146 -0
- package/src/gpu/kernels/fused_matmul_q4_widetile.wgsl +14 -4
- package/src/gpu/kernels/fused_matmul_q4_widetile_direct.wgsl +204 -0
- package/src/gpu/kernels/fused_matmul_residual.js +19 -72
- package/src/gpu/kernels/fused_matmul_rmsnorm.js +34 -127
- package/src/gpu/kernels/gated-delta-norm-gate.js +45 -0
- package/src/gpu/kernels/gated_delta_conv.wgsl +57 -6
- package/src/gpu/kernels/gated_delta_conv_f16.wgsl +57 -6
- package/src/gpu/kernels/gated_delta_conv_paired.wgsl +282 -0
- package/src/gpu/kernels/gated_delta_conv_prefill.wgsl +144 -0
- package/src/gpu/kernels/gated_delta_fused_decode.wgsl +375 -40
- package/src/gpu/kernels/gated_delta_fused_decode_f16.wgsl +375 -40
- package/src/gpu/kernels/gated_delta_fused_decode_paired.wgsl +511 -0
- package/src/gpu/kernels/gated_delta_fused_decode_paired_f16.wgsl +513 -0
- package/src/gpu/kernels/gated_delta_fused_decode_paired_sigmoid_gate.wgsl +514 -0
- package/src/gpu/kernels/gated_delta_fused_decode_paired_sigmoid_gate_f16.wgsl +516 -0
- package/src/gpu/kernels/gated_delta_fused_decode_register.wgsl +750 -0
- package/src/gpu/kernels/gated_delta_fused_decode_sigmoid_gate.wgsl +511 -0
- package/src/gpu/kernels/gated_delta_fused_decode_sigmoid_gate_f16.wgsl +513 -0
- package/src/gpu/kernels/gated_delta_gate_paired.wgsl +271 -0
- package/src/gpu/kernels/gated_delta_gate_sigmoid_paired.wgsl +273 -0
- package/src/gpu/kernels/gated_delta_norm_paired.wgsl +288 -0
- package/src/gpu/kernels/gated_delta_prefill_norm_gate.wgsl +227 -0
- package/src/gpu/kernels/gated_delta_qk_paired.wgsl +297 -0
- package/src/gpu/kernels/gated_delta_qk_paired_parallel.wgsl +299 -0
- package/src/gpu/kernels/gated_delta_recurrent.wgsl +362 -32
- package/src/gpu/kernels/gated_delta_recurrent_f16.wgsl +362 -32
- package/src/gpu/kernels/gated_delta_recurrent_gguf.wgsl +496 -0
- package/src/gpu/kernels/gated_delta_recurrent_gguf_register_prefill.wgsl +727 -0
- package/src/gpu/kernels/gated_delta_recurrent_paired.wgsl +337 -0
- package/src/gpu/kernels/gated_delta_recurrent_register_prefill.wgsl +546 -0
- package/src/gpu/kernels/gated_delta_recurrent_sigmoid_gate.wgsl +498 -0
- package/src/gpu/kernels/gated_delta_recurrent_sigmoid_gate_f16.wgsl +500 -0
- package/src/gpu/kernels/gated_delta_state_paired.wgsl +310 -0
- package/src/gpu/kernels/gated_delta_state_paired_sliced.wgsl +348 -0
- package/src/gpu/kernels/gated_delta_state_paired_sliced_rolled.wgsl +353 -0
- package/src/gpu/kernels/gated_rmsnorm.js +74 -0
- package/src/gpu/kernels/gated_rmsnorm.wgsl +62 -0
- package/src/gpu/kernels/gather.js +81 -46
- package/src/gpu/kernels/gather.wgsl +3 -2
- package/src/gpu/kernels/gather_bf16.wgsl +3 -2
- package/src/gpu/kernels/gather_f16.wgsl +3 -2
- package/src/gpu/kernels/gather_f16_f16_out.wgsl +3 -2
- package/src/gpu/kernels/gather_f16_out.wgsl +3 -2
- package/src/gpu/kernels/gather_f16_vec4.wgsl +3 -2
- package/src/gpu/kernels/gather_f16_vec4_f16_out.wgsl +3 -2
- package/src/gpu/kernels/gather_litert_int4_vec4_f16_out.wgsl +3 -2
- package/src/gpu/kernels/gather_litert_int4_vec4_f32_out.wgsl +3 -2
- package/src/gpu/kernels/gather_q4_0.wgsl +57 -0
- package/src/gpu/kernels/gather_split4_f16_vec4_f16_out.wgsl +3 -2
- package/src/gpu/kernels/gather_split4_f16_vec4_f32_out.wgsl +104 -0
- package/src/gpu/kernels/gather_split8_f16_vec4_f16_out.wgsl +3 -2
- package/src/gpu/kernels/gather_split8_f16_vec4_f32_out.wgsl +3 -2
- package/src/gpu/kernels/gather_vec4.wgsl +3 -2
- package/src/gpu/kernels/gather_vec4_f16_out.wgsl +3 -2
- package/src/gpu/kernels/gelu.js +5 -12
- package/src/gpu/kernels/gemma4-route-expert.js +2 -5
- package/src/gpu/kernels/generated/uniform-writers-0.js +600 -0
- package/src/gpu/kernels/generated/uniform-writers-1.js +602 -0
- package/src/gpu/kernels/generated/uniform-writers-2.js +516 -0
- package/src/gpu/kernels/generated/uniform-writers.js +557 -0
- package/src/gpu/kernels/hyper-connection.js +240 -0
- package/src/gpu/kernels/hyper_connection_activation.wgsl +110 -0
- package/src/gpu/kernels/hyper_connection_branch.wgsl +60 -0
- package/src/gpu/kernels/hyper_connection_inject.wgsl +49 -0
- package/src/gpu/kernels/hyper_connection_norm.wgsl +72 -0
- package/src/gpu/kernels/kernel-bindings.js +37 -0
- package/src/gpu/kernels/kernel-configs.d.ts +12 -2
- package/src/gpu/kernels/kernel-configs.js +40 -23
- package/src/gpu/kernels/kernel-execution.js +87 -26
- package/src/gpu/kernels/kernel-geometry.js +43 -0
- package/src/gpu/kernels/kernel-prewarm.js +18 -15
- package/src/gpu/kernels/kv-cache-write.js +4 -6
- package/src/gpu/kernels/layernorm.js +7 -45
- package/src/gpu/kernels/linear-attention-core.js +247 -119
- package/src/gpu/kernels/linear-attention-recovery.js +90 -0
- package/src/gpu/kernels/linear-norm-ab.js +80 -0
- package/src/gpu/kernels/linear_norm_ab_f32.wgsl +243 -0
- package/src/gpu/kernels/logit-finalize.js +9 -3
- package/src/gpu/kernels/logit-scatter.js +9 -3
- package/src/gpu/kernels/logit-suppress.js +24 -0
- package/src/gpu/kernels/logit_suppress.wgsl +19 -0
- package/src/gpu/kernels/matmul-dispatch.js +70 -146
- package/src/gpu/kernels/matmul-selection.js +75 -18
- package/src/gpu/kernels/matmul-workgroup-capacity.js +37 -0
- package/src/gpu/kernels/matmul.js +81 -108
- package/src/gpu/kernels/matmul_compensated_f32.wgsl +215 -0
- package/src/gpu/kernels/matmul_f16w_f32a_tiled.wgsl +59 -46
- package/src/gpu/kernels/matmul_f32.wgsl +23 -17
- package/src/gpu/kernels/matmul_f32_row_subgroup.wgsl +88 -0
- package/src/gpu/kernels/matmul_fp8.wgsl +60 -0
- package/src/gpu/kernels/matmul_gemv_compensated_f32.wgsl +211 -0
- package/src/gpu/kernels/matmul_gemv_f32.wgsl +63 -0
- package/src/gpu/kernels/matmul_gemv_f32_subgroup.wgsl +84 -0
- package/src/gpu/kernels/matmul_gguf_columns_hoisted_f32.wgsl +342 -0
- package/src/gpu/kernels/matmul_gguf_pair_columns_f32.wgsl +279 -0
- package/src/gpu/kernels/matmul_gguf_pair_f32.wgsl +197 -0
- package/src/gpu/kernels/matmul_paired.wgsl +315 -0
- package/src/gpu/kernels/matmul_paired_compensated.wgsl +334 -0
- package/src/gpu/kernels/matmul_q4_0.wgsl +234 -0
- package/src/gpu/kernels/matmul_q4_0_tile128.wgsl +477 -0
- package/src/gpu/kernels/matmul_q4_0_tile128_bounded.wgsl +483 -0
- package/src/gpu/kernels/matmul_q4_0_tile64.wgsl +282 -0
- package/src/gpu/kernels/matmul_q4_0_tile64_bounded.wgsl +288 -0
- package/src/gpu/kernels/matmul_q4_0_tile64x128.wgsl +364 -0
- package/src/gpu/kernels/matmul_q4_0_tile64x128_bounded.wgsl +370 -0
- package/src/gpu/kernels/matmul_q4_1_columns_f32.wgsl +132 -0
- package/src/gpu/kernels/matmul_q5k.wgsl +181 -0
- package/src/gpu/kernels/matmul_q5k_columns.wgsl +194 -0
- package/src/gpu/kernels/matmul_q5k_cooperative.wgsl +129 -0
- package/src/gpu/kernels/matmul_q5k_tile64.wgsl +309 -0
- package/src/gpu/kernels/matmul_w8a8.wgsl +55 -0
- package/src/gpu/kernels/matmul_w8a8_packed.wgsl +54 -0
- package/src/gpu/kernels/matmul_w8a8_packed_cooperative.wgsl +77 -0
- package/src/gpu/kernels/moe-grouped.js +132 -0
- package/src/gpu/kernels/moe-norm-router.js +91 -0
- package/src/gpu/kernels/moe-route.js +135 -0
- package/src/gpu/kernels/moe-shared-slot.js +219 -0
- package/src/gpu/kernels/moe_grouped_matmul_f32.wgsl +216 -0
- package/src/gpu/kernels/moe_grouped_matmul_ordered_f32.wgsl +158 -0
- package/src/gpu/kernels/moe_grouped_sort.wgsl +101 -0
- package/src/gpu/kernels/moe_norm_router_f32.wgsl +254 -0
- package/src/gpu/kernels/moe_route_gguf_split_f32.wgsl +117 -0
- package/src/gpu/kernels/moe_route_q4_0_f32.wgsl +81 -0
- package/src/gpu/kernels/moe_route_q4_f32.wgsl +250 -0
- package/src/gpu/kernels/moe_shared_slot_combine_f32.wgsl +91 -0
- package/src/gpu/kernels/moe_shared_slot_down_f32.wgsl +264 -0
- package/src/gpu/kernels/moe_shared_slot_down_pair_combine_f32.wgsl +254 -0
- package/src/gpu/kernels/moe_shared_slot_down_pair_combine_residual_f32.wgsl +262 -0
- package/src/gpu/kernels/moe_shared_slot_down_pair_f32.wgsl +187 -0
- package/src/gpu/kernels/moe_shared_slot_gu_f32.wgsl +264 -0
- package/src/gpu/kernels/moe_shared_slot_gu_pair_f32.wgsl +267 -0
- package/src/gpu/kernels/paired-activation.js +86 -0
- package/src/gpu/kernels/paired-attention.js +85 -0
- package/src/gpu/kernels/paired-cast.js +82 -0
- package/src/gpu/kernels/paired-linear-attention.js +180 -0
- package/src/gpu/kernels/paired-matmul.js +86 -0
- package/src/gpu/kernels/paired-rmsnorm.js +127 -0
- package/src/gpu/kernels/paired-rope.js +44 -0
- package/src/gpu/kernels/paired-split.js +74 -0
- package/src/gpu/kernels/paired_add.wgsl +261 -0
- package/src/gpu/kernels/paired_multiply.wgsl +261 -0
- package/src/gpu/kernels/paired_scale.wgsl +260 -0
- package/src/gpu/kernels/paired_scale_inplace.wgsl +259 -0
- package/src/gpu/kernels/paired_sigmoid.wgsl +266 -0
- package/src/gpu/kernels/paired_silu.wgsl +266 -0
- package/src/gpu/kernels/paired_silu_unary.wgsl +260 -0
- package/src/gpu/kernels/pipeline-cache.d.ts +37 -4
- package/src/gpu/kernels/pipeline-cache.js +185 -88
- package/src/gpu/kernels/ple.js +145 -0
- package/src/gpu/kernels/ple_conv.wgsl +104 -0
- package/src/gpu/kernels/ple_gate.wgsl +131 -0
- package/src/gpu/kernels/q4_0.js +200 -0
- package/src/gpu/kernels/qsa-indexer.d.ts +105 -0
- package/src/gpu/kernels/qsa-indexer.js +304 -0
- package/src/gpu/kernels/qsa_block_keys.wgsl +110 -0
- package/src/gpu/kernels/qsa_block_scores.wgsl +73 -0
- package/src/gpu/kernels/qsa_prepare.wgsl +116 -0
- package/src/gpu/kernels/qsa_select.wgsl +172 -0
- package/src/gpu/kernels/quantize_w8a8.wgsl +81 -0
- package/src/gpu/kernels/qwen_attention_split_q_gate.js +71 -0
- package/src/gpu/kernels/qwen_attention_split_q_gate.wgsl +26 -0
- package/src/gpu/kernels/qwen_linear_attention_decay_paired.wgsl +266 -0
- package/src/gpu/kernels/qwen_linear_attention_log_decay_paired.wgsl +273 -0
- package/src/gpu/kernels/qwen_linear_attention_prepare.js +153 -0
- package/src/gpu/kernels/qwen_linear_attention_prepare.wgsl +120 -0
- package/src/gpu/kernels/qwen_linear_attention_prepare_paired.wgsl +267 -0
- package/src/gpu/kernels/qwen_linear_attention_scale_paired.wgsl +276 -0
- package/src/gpu/kernels/relu.js +5 -12
- package/src/gpu/kernels/repeat_channels.js +22 -9
- package/src/gpu/kernels/repeat_channels.wgsl +12 -5
- package/src/gpu/kernels/repeat_channels_f16.wgsl +12 -5
- package/src/gpu/kernels/rescale_w8a8.wgsl +74 -0
- package/src/gpu/kernels/residual.js +5 -0
- package/src/gpu/kernels/rmsnorm-pair.js +2 -2
- package/src/gpu/kernels/rmsnorm-qk.js +27 -5
- package/src/gpu/kernels/rmsnorm-stats.js +62 -78
- package/src/gpu/kernels/rmsnorm.js +74 -96
- package/src/gpu/kernels/rmsnorm.wgsl +9 -3
- package/src/gpu/kernels/rmsnorm_f16.wgsl +2 -0
- package/src/gpu/kernels/rmsnorm_paired.wgsl +321 -0
- package/src/gpu/kernels/rmsnorm_paired_sliced.wgsl +326 -0
- package/src/gpu/kernels/rmsnorm_qk.wgsl +32 -8
- package/src/gpu/kernels/rmsnorm_stats_subgroups.wgsl +7 -7
- package/src/gpu/kernels/rope-dispatch.js +26 -0
- package/src/gpu/kernels/rope-precompute.js +29 -28
- package/src/gpu/kernels/rope-qk.js +35 -24
- package/src/gpu/kernels/rope.js +5 -2
- package/src/gpu/kernels/rope.wgsl +2 -2
- package/src/gpu/kernels/rope_precompute.wgsl +150 -6
- package/src/gpu/kernels/rope_precompute_paired.wgsl +285 -0
- package/src/gpu/kernels/rope_qk.wgsl +3 -2
- package/src/gpu/kernels/rope_qk_paired.wgsl +341 -0
- package/src/gpu/kernels/sample.js +115 -244
- package/src/gpu/kernels/sample.wgsl +53 -38
- package/src/gpu/kernels/sample_f16.wgsl +53 -38
- package/src/gpu/kernels/scale.js +6 -1
- package/src/gpu/kernels/scatter_add_routes_f32.wgsl +43 -0
- package/src/gpu/kernels/shader-cache.d.ts +7 -1
- package/src/gpu/kernels/shader-cache.js +61 -20
- package/src/gpu/kernels/shader-source-scope.d.ts +14 -0
- package/src/gpu/kernels/shader-source-scope.js +127 -12
- package/src/gpu/kernels/sigmoid-gated-add.js +68 -0
- package/src/gpu/kernels/sigmoid_gated_add_f32.wgsl +76 -0
- package/src/gpu/kernels/silu.js +56 -136
- package/src/gpu/kernels/silu.wgsl +54 -3
- package/src/gpu/kernels/silu_f16.wgsl +3 -2
- package/src/gpu/kernels/softmax.js +57 -19
- package/src/gpu/kernels/softmax_topk_logit_rank.wgsl +137 -0
- package/src/gpu/kernels/softmax_topk_ranked.wgsl +132 -0
- package/src/gpu/kernels/softmax_topk_strided.wgsl +80 -0
- package/src/gpu/kernels/speculative-accept.js +97 -0
- package/src/gpu/kernels/speculative_accept.wgsl +38 -0
- package/src/gpu/kernels/speculative_accept_gpu_limit.wgsl +42 -0
- package/src/gpu/kernels/split-dispatch.js +18 -0
- package/src/gpu/kernels/split-qkv-rmsnorm-qk.js +3 -6
- package/src/gpu/kernels/split-qkv-rmsnorm-rope-qk.js +4 -11
- package/src/gpu/kernels/split_qg.js +6 -2
- package/src/gpu/kernels/split_qg.wgsl +3 -2
- package/src/gpu/kernels/split_qg_f16.wgsl +3 -2
- package/src/gpu/kernels/split_qg_paired.wgsl +59 -0
- package/src/gpu/kernels/split_qkv.js +7 -16
- package/src/gpu/kernels/split_qkv_paired.wgsl +75 -0
- package/src/gpu/kernels/subgroup-partition.js +11 -0
- package/src/gpu/kernels/uniform-encoding.js +20 -0
- package/src/gpu/kernels/uniform-utils.js +44 -49
- package/src/gpu/kernels/vision-average-pool.js +2 -5
- package/src/gpu/kernels/vision-patch-embed.js +2 -5
- package/src/gpu/kernels/vision-position-embedding.js +2 -5
- package/src/gpu/kernels/vision-rope-2d.js +2 -5
- package/src/gpu/kernels/vision-spatial-merge.js +2 -5
- package/src/gpu/kernels/w8a8.js +166 -0
- package/src/gpu/prepared-decode-workspace.d.ts +11 -0
- package/src/gpu/prepared-decode-workspace.js +104 -0
- package/src/gpu/recorder-timestamps.js +63 -0
- package/src/gpu/step-contract.d.ts +27 -0
- package/src/gpu/step-contract.js +26 -0
- package/src/gpu/submit-tracker.js +1 -17
- package/src/gpu/tensor.d.ts +13 -4
- package/src/gpu/tensor.js +38 -19
- package/src/gpu/uniform-cache.d.ts +8 -4
- package/src/gpu/uniform-cache.js +41 -25
- package/src/gpu/weight-buffer.d.ts +10 -1
- package/src/gpu/weight-buffer.js +2 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/inference/choice-scoring.js +70 -0
- package/src/inference/decode-buffers.d.ts +11 -3
- package/src/inference/decode-buffers.js +93 -63
- package/src/inference/generation-output.js +128 -0
- package/src/inference/generation-step.d.ts +14 -0
- package/src/inference/generation-step.js +26 -0
- package/src/inference/kv-cache/base.d.ts +7 -2
- package/src/inference/kv-cache/base.js +10 -8
- package/src/inference/kv-cache/copy-state.js +39 -0
- package/src/inference/kv-cache/layer-range.js +76 -0
- package/src/inference/kv-cache/mixed-geometry.d.ts +3 -2
- package/src/inference/kv-cache/mixed-geometry.js +25 -1
- package/src/inference/kv-cache/quantized.d.ts +1 -1
- package/src/inference/kv-cache/quantized.js +1 -1
- package/src/inference/kv-cache/sliding-window.d.ts +2 -2
- package/src/inference/kv-cache/sliding-window.js +58 -183
- package/src/inference/kv-cache/tiered.d.ts +1 -1
- package/src/inference/kv-cache/tiered.js +1 -1
- package/src/inference/kv-cache/types.js +2 -28
- package/src/inference/kv-cache/update.js +104 -157
- package/src/inference/moe-router.d.ts +5 -0
- package/src/inference/moe-router.js +42 -31
- package/src/inference/pipelines/audio/index.js +5 -2
- package/src/inference/pipelines/audio/mel.js +116 -81
- package/src/inference/pipelines/context.js +109 -79
- package/src/inference/pipelines/factory.js +27 -5
- package/src/inference/pipelines/registry.js +9 -3
- package/src/inference/pipelines/shader-scoped-pipeline.d.ts +24 -0
- package/src/inference/pipelines/shader-scoped-pipeline.js +243 -11
- package/src/inference/pipelines/shared/clipped-linear.js +1 -1
- package/src/inference/pipelines/structured/json-head-pipeline.js +1 -1
- package/src/inference/pipelines/text/activity-weights.js +110 -0
- package/src/inference/pipelines/text/attention/cache-cast.js +15 -0
- package/src/inference/pipelines/text/attention/dispatch-params.js +2 -1
- package/src/inference/pipelines/text/attention/interpreter/immediate.js +16 -19
- package/src/inference/pipelines/text/attention/interpreter/recorded.js +20 -21
- package/src/inference/pipelines/text/attention/interpreter.js +34 -38
- package/src/inference/pipelines/text/attention/paired-contract.js +29 -0
- package/src/inference/pipelines/text/attention/plan.d.ts +2 -0
- package/src/inference/pipelines/text/attention/plan.js +11 -4
- package/src/inference/pipelines/text/attention/projection-executor.js +10 -27
- package/src/inference/pipelines/text/attention/projection-plan.js +24 -31
- package/src/inference/pipelines/text/attention/projections.js +10 -27
- package/src/inference/pipelines/text/attention/query-transform.js +2 -2
- package/src/inference/pipelines/text/attention/recorded-health.js +2 -1
- package/src/inference/pipelines/text/attention/rope-observation.js +26 -3
- package/src/inference/pipelines/text/chat-format.js +2 -1
- package/src/inference/pipelines/text/config/normalization.js +115 -226
- package/src/inference/pipelines/text/config/vision-normalizers.js +240 -0
- package/src/inference/pipelines/text/config-components.js +49 -0
- package/src/inference/pipelines/text/config.d.ts +45 -1
- package/src/inference/pipelines/text/config.js +26 -38
- package/src/inference/pipelines/text/debug-utils/config.js +13 -156
- package/src/inference/pipelines/text/debug-utils/health-metrics.js +8 -23
- package/src/inference/pipelines/text/debug-utils/readback-decoding.js +5 -1
- package/src/inference/pipelines/text/embed.js +38 -4
- package/src/inference/pipelines/text/embedding-batch.js +23 -0
- package/src/inference/pipelines/text/embedding-extraction.js +7 -2
- package/src/inference/pipelines/text/embedding-normalization.js +2 -1
- package/src/inference/pipelines/text/execution-plan.d.ts +16 -0
- package/src/inference/pipelines/text/execution-plan.js +49 -2
- package/src/inference/pipelines/text/execution-runtime-builders.js +31 -0
- package/src/inference/pipelines/text/execution-v1/validation.js +3 -3
- package/src/inference/pipelines/text/execution-v1.js +14 -14
- package/src/inference/pipelines/text/execution.js +78 -128
- package/src/inference/pipelines/text/ffn/activation-observation.js +45 -0
- package/src/inference/pipelines/text/ffn/decode-intermediate.js +10 -0
- package/src/inference/pipelines/text/ffn/dense-executor.js +55 -50
- package/src/inference/pipelines/text/ffn/dense-plan.js +28 -27
- package/src/inference/pipelines/text/ffn/dense.js +28 -48
- package/src/inference/pipelines/text/ffn/moe.js +67 -3
- package/src/inference/pipelines/text/ffn/paired.js +144 -0
- package/src/inference/pipelines/text/ffn/qwen-shared-expert.js +212 -0
- package/src/inference/pipelines/text/ffn/sandwich.js +8 -3
- package/src/inference/pipelines/text/ffn/standard.js +67 -16
- package/src/inference/pipelines/text/finiteness-guard-status.js +9 -0
- package/src/inference/pipelines/text/generation-request.d.ts +36 -0
- package/src/inference/pipelines/text/generation-request.js +73 -0
- package/src/inference/pipelines/text/generator/activation-storage.js +15 -0
- package/src/inference/pipelines/text/generator/batch-retry-policy.js +20 -0
- package/src/inference/pipelines/text/generator/capsule-generation.js +37 -0
- package/src/inference/pipelines/text/generator/compiled-greedy-window.js +154 -0
- package/src/inference/pipelines/text/generator/decode-components.js +24 -0
- package/src/inference/pipelines/text/generator/decode-readback.js +73 -0
- package/src/inference/pipelines/text/generator/decode-runtime.js +398 -392
- package/src/inference/pipelines/text/generator/decode.js +593 -637
- package/src/inference/pipelines/text/generator/diagnostic-sequence.d.ts +63 -0
- package/src/inference/pipelines/text/generator/diagnostic-sequence.js +106 -0
- package/src/inference/pipelines/text/generator/diffusion.js +24 -12
- package/src/inference/pipelines/text/generator/greedy-head-policy.js +15 -0
- package/src/inference/pipelines/text/generator/logits-config.js +11 -4
- package/src/inference/pipelines/text/generator/per-layer-buffer.js +21 -0
- package/src/inference/pipelines/text/generator/prefill-observation.js +25 -1
- package/src/inference/pipelines/text/generator/prefill-policy.js +30 -18
- package/src/inference/pipelines/text/generator/prefill-runtime.js +511 -511
- package/src/inference/pipelines/text/generator/recorded-step-executor.js +70 -0
- package/src/inference/pipelines/text/generator/recorder-stats.js +17 -0
- package/src/inference/pipelines/text/generator/recovery.js +6 -0
- package/src/inference/pipelines/text/generator/session-context.js +19 -7
- package/src/inference/pipelines/text/generator/speculative-runtime.js +82 -0
- package/src/inference/pipelines/text/generator/text.js +17 -149
- package/src/inference/pipelines/text/generator/token-selection.d.ts +7 -0
- package/src/inference/pipelines/text/generator/token-selection.js +59 -0
- package/src/inference/pipelines/text/generator/training.js +39 -58
- package/src/inference/pipelines/text/generator/whole-token-lane.js +371 -0
- package/src/inference/pipelines/text/generator/whole-token-observation.d.ts +72 -0
- package/src/inference/pipelines/text/generator/whole-token-observation.js +502 -0
- package/src/inference/pipelines/text/generator/whole-token-program.d.ts +93 -0
- package/src/inference/pipelines/text/generator/whole-token-program.js +731 -0
- package/src/inference/pipelines/text/generator/whole-token-template.js +437 -0
- package/src/inference/pipelines/text/generator-runtime.d.ts +107 -0
- package/src/inference/pipelines/text/generator-runtime.js +24 -64
- package/src/inference/pipelines/text/generator-steps.js +49 -49
- package/src/inference/pipelines/text/generator.d.ts +10 -1
- package/src/inference/pipelines/text/generator.js +96 -166
- package/src/inference/pipelines/text/hyper-connection/decoder-layer.d.ts +75 -0
- package/src/inference/pipelines/text/hyper-connection/decoder-layer.js +132 -0
- package/src/inference/pipelines/text/hyper-connection/layer-executor.js +104 -0
- package/src/inference/pipelines/text/hyper-connection/logits-input.js +20 -0
- package/src/inference/pipelines/text/hyper-connection/projection.js +21 -0
- package/src/inference/pipelines/text/hyper-connection/sequence-transaction.js +145 -0
- package/src/inference/pipelines/text/hyper-connection/session.d.ts +39 -0
- package/src/inference/pipelines/text/hyper-connection/session.js +236 -0
- package/src/inference/pipelines/text/image-transcription.js +2 -3
- package/src/inference/pipelines/text/indexed-attention/attention-runner.js +49 -0
- package/src/inference/pipelines/text/indexed-attention/qsa-cache.d.ts +54 -0
- package/src/inference/pipelines/text/indexed-attention/qsa-cache.js +256 -0
- package/src/inference/pipelines/text/init-qkv-fusion.js +121 -104
- package/src/inference/pipelines/text/init-rope.d.ts +26 -0
- package/src/inference/pipelines/text/init-rope.js +109 -14
- package/src/inference/pipelines/text/init-tokenizer.js +29 -0
- package/src/inference/pipelines/text/init.d.ts +28 -10
- package/src/inference/pipelines/text/init.js +65 -74
- package/src/inference/pipelines/text/kernel-trace.js +33 -11
- package/src/inference/pipelines/text/layer-execution-contract.js +1 -1
- package/src/inference/pipelines/text/layer-input-execution.js +10 -9
- package/src/inference/pipelines/text/layer-partition-contract.d.ts +47 -0
- package/src/inference/pipelines/text/layer-partition-contract.js +220 -0
- package/src/inference/pipelines/text/layer-plan-gpu.js +153 -80
- package/src/inference/pipelines/text/layer-plan.js +9 -2
- package/src/inference/pipelines/text/layer.js +34 -47
- package/src/inference/pipelines/text/lifecycle.js +79 -178
- package/src/inference/pipelines/text/linear-attention/activity.js +29 -0
- package/src/inference/pipelines/text/linear-attention/norm-ab.js +59 -0
- package/src/inference/pipelines/text/linear-attention/plan.js +35 -34
- package/src/inference/pipelines/text/linear-attention/state-checkpoint.js +83 -0
- package/src/inference/pipelines/text/linear-attention/state-clone.js +109 -0
- package/src/inference/pipelines/text/linear-attention/state-layout.js +45 -0
- package/src/inference/pipelines/text/linear-attention-ab-fusion.js +48 -45
- package/src/inference/pipelines/text/linear-attention.d.ts +20 -0
- package/src/inference/pipelines/text/linear-attention.js +130 -135
- package/src/inference/pipelines/text/load-errors.js +2 -19
- package/src/inference/pipelines/text/load-policy.js +55 -0
- package/src/inference/pipelines/text/logits/gpu-executor.js +130 -103
- package/src/inference/pipelines/text/logits/gpu.js +93 -70
- package/src/inference/pipelines/text/logits/index.d.ts +14 -2
- package/src/inference/pipelines/text/logits/index.js +420 -352
- package/src/inference/pipelines/text/logits/output-transform.js +28 -23
- package/src/inference/pipelines/text/logits/precision-policy.js +1 -1
- package/src/inference/pipelines/text/logits/types.d.ts +8 -1
- package/src/inference/pipelines/text/lora-apply.js +1 -1
- package/src/inference/pipelines/text/model-load.js +71 -117
- package/src/inference/pipelines/text/moe/gpu-executor.js +39 -17
- package/src/inference/pipelines/text/moe/grouped-prefill.js +67 -0
- package/src/inference/pipelines/text/moe/qwen-route-executor.d.ts +41 -0
- package/src/inference/pipelines/text/moe/qwen-route-executor.js +125 -0
- package/src/inference/pipelines/text/moe/routed-expert-chunks.js +95 -0
- package/src/inference/pipelines/text/moe-gpu.js +132 -50
- package/src/inference/pipelines/text/moe-impl.d.ts +23 -3
- package/src/inference/pipelines/text/moe-shape-validator.js +12 -0
- package/src/inference/pipelines/text/ngram/ngram-addresses.d.ts +30 -0
- package/src/inference/pipelines/text/ngram/ngram-addresses.js +134 -0
- package/src/inference/pipelines/text/ngram/ngram-table.d.ts +89 -0
- package/src/inference/pipelines/text/ngram/ngram-table.js +233 -0
- package/src/inference/pipelines/text/ngram/ple-layer.d.ts +54 -0
- package/src/inference/pipelines/text/ngram/ple-layer.js +115 -0
- package/src/inference/pipelines/text/operator-events.d.ts +129 -0
- package/src/inference/pipelines/text/operator-events.js +19 -2
- package/src/inference/pipelines/text/ops.js +40 -30
- package/src/inference/pipelines/text/paired-execution.js +140 -0
- package/src/inference/pipelines/text/partition-attempt.js +105 -0
- package/src/inference/pipelines/text/partition-execution.js +352 -0
- package/src/inference/pipelines/text/per-layer/materialize.js +3 -10
- package/src/inference/pipelines/text/per-layer/plan.js +3 -10
- package/src/inference/pipelines/text/per-layer-inputs.js +3 -10
- package/src/inference/pipelines/text/pipeline-load-timing.js +2 -1
- package/src/inference/pipelines/text/pipeline.d.ts +227 -0
- package/src/inference/pipelines/text/pipeline.js +629 -0
- package/src/inference/pipelines/text/precomputed-input-norm.js +29 -0
- package/src/inference/pipelines/text/probes.js +65 -23
- package/src/inference/pipelines/text/resident-partition-contract.d.ts +179 -0
- package/src/inference/pipelines/text/resident-partition-contract.js +98 -0
- package/src/inference/pipelines/text/resident-partition.js +403 -0
- package/src/inference/pipelines/text/resident-pipeline-preparation.js +341 -0
- package/src/inference/pipelines/text/sampling-config.d.ts +16 -0
- package/src/inference/pipelines/text/sampling-config.js +7 -4
- package/src/inference/pipelines/text/sequence-state.d.ts +70 -0
- package/src/inference/pipelines/text/sequence-state.js +521 -0
- package/src/inference/pipelines/text/stage-names.d.ts +88 -0
- package/src/inference/pipelines/text/state.d.ts +17 -8
- package/src/inference/pipelines/text/state.js +10 -0
- package/src/inference/pipelines/text/stopping.js +17 -0
- package/src/inference/pipelines/text/tsir-fixture-writer.d.ts +77 -0
- package/src/inference/pipelines/text/tsir-fixture-writer.js +3 -12
- package/src/inference/pipelines/text/types.d.ts +65 -111
- package/src/inference/pipelines/text/warm-generation.d.ts +27 -0
- package/src/inference/pipelines/text/warm-generation.js +34 -0
- package/src/inference/pipelines/text/weight-loading-config.js +16 -10
- package/src/inference/pipelines/text/weights.d.ts +103 -1
- package/src/inference/pipelines/text/weights.js +0 -17
- package/src/inference/pipelines/text.d.ts +3 -211
- package/src/inference/pipelines/text.js +16 -578
- package/src/inference/pipelines/video/feature-concat.js +30 -0
- package/src/inference/pipelines/video/frame-sampler.js +4 -0
- package/src/inference/pipelines/video/index.js +33 -44
- package/src/inference/pipelines/vision/encoder.js +1 -1
- package/src/inference/pipelines/vision/gemma4.js +6 -7
- package/src/inference/pipelines/vision/glmocr.js +11 -13
- package/src/inference/pipelines/vision/index.js +14 -3
- package/src/inference/pipelines/vision/support.js +93 -0
- package/src/inference/pipelines/vision/weight-loading.js +111 -0
- package/src/inference/rerank.d.ts +44 -0
- package/src/inference/resident-block-contract.d.ts +35 -0
- package/src/inference/resident-block-contract.js +105 -0
- package/src/inference/resident-output-state.d.ts +14 -0
- package/src/inference/resident-output-state.js +89 -0
- package/src/inference/resident-publication-contract.d.ts +32 -0
- package/src/inference/resident-publication-contract.js +104 -0
- package/src/inference/resident-state-contract.d.ts +26 -0
- package/src/inference/resident-state-contract.js +135 -0
- package/src/inference/resident-target-state.d.ts +32 -0
- package/src/inference/resident-target-state.js +152 -0
- package/src/inference/sampling-rng.js +35 -0
- package/src/inference/token-sampling.js +76 -0
- package/src/inference/tokenizer.d.ts +2 -0
- package/src/inference/tokenizer.js +16 -0
- package/src/inference/tokenizers/bundled/incremental-decoder.d.ts +16 -0
- package/src/inference/tokenizers/bundled/incremental-decoder.js +100 -0
- package/src/inference/tokenizers/bundled/normalizer.js +44 -0
- package/src/inference/tokenizers/bundled.js +25 -42
- package/src/inference/tokenizers/sentencepiece.js +4 -26
- package/src/loader/doppler-loader.d.ts +13 -0
- package/src/loader/doppler-loader.js +34 -62
- package/src/loader/dtype-utils.js +1 -19
- package/src/loader/embedding-limit-preflight.js +77 -8
- package/src/loader/embedding-loader.js +43 -114
- package/src/loader/experts/expert-cache.js +1 -4
- package/src/loader/experts/expert-loader.d.ts +6 -1
- package/src/loader/experts/expert-loader.js +90 -29
- package/src/loader/experts/expert-preparation.d.ts +16 -0
- package/src/loader/experts/expert-preparation.js +57 -0
- package/src/loader/experts/loader-bindings.js +53 -0
- package/src/loader/experts/qwen-paging.d.ts +19 -0
- package/src/loader/experts/qwen-paging.js +70 -0
- package/src/loader/experts/routed-expert-cache.d.ts +56 -0
- package/src/loader/experts/routed-expert-cache.js +372 -0
- package/src/loader/experts/routed-expert-plan.d.ts +20 -0
- package/src/loader/experts/routed-expert-plan.js +46 -0
- package/src/loader/final-weights-loader.d.ts +7 -1
- package/src/loader/final-weights-loader.js +17 -40
- package/src/loader/hyper-connection-loader.d.ts +25 -0
- package/src/loader/hyper-connection-loader.js +150 -0
- package/src/loader/layer-loader.d.ts +8 -1
- package/src/loader/layer-loader.js +67 -97
- package/src/loader/layer-tensor-aliases.js +77 -11
- package/src/loader/layer-weight-shape.js +13 -0
- package/src/loader/load-timing.js +2 -0
- package/src/loader/loader-types.d.ts +24 -1
- package/src/loader/model-executor.js +27 -365
- package/src/loader/model-load.d.ts +18 -0
- package/src/loader/model-load.js +432 -0
- package/src/loader/ngram-table-bindings.d.ts +11 -0
- package/src/loader/ngram-table-bindings.js +61 -0
- package/src/loader/per-layer-input-loader.js +5 -83
- package/src/loader/q4k-reference-weight.js +84 -0
- package/src/loader/shard-cache.js +3 -0
- package/src/loader/tensor-load-error.js +20 -1
- package/src/loader/tensors/bf16-loader.js +3 -29
- package/src/loader/tensors/buffer-write.js +26 -0
- package/src/loader/tensors/fp8-loader.js +28 -0
- package/src/loader/tensors/load-executor.js +124 -117
- package/src/loader/tensors/q4_0-loader.js +32 -0
- package/src/loader/tensors/range-backed-weights.js +34 -0
- package/src/loader/tensors/source-transform.js +1 -1
- package/src/loader/tensors/tensor-loader.js +22 -6
- package/src/loader/tensors/w8a8-loader.js +36 -0
- package/src/loader/weight-downcast.js +9 -13
- package/src/loader/weight-representation-plan.d.ts +28 -0
- package/src/loader/weight-representation-plan.js +146 -0
- package/src/loader/weights.d.ts +1 -1
- package/src/memory/buffer-pool.d.ts +24 -4
- package/src/memory/buffer-pool.js +124 -128
- package/src/memory/device-budget.d.ts +10 -0
- package/src/memory/device-budget.js +89 -0
- package/src/memory/device-residency.js +60 -0
- package/src/memory/sequence-retirement.js +19 -0
- package/src/partitions.d.ts +21 -0
- package/src/partitions.js +10 -0
- package/src/rules/execution-rules-contract-check.js +73 -570
- package/src/rules/generated/rule-bundle.json +1 -4305
- package/src/rules/greedy-sampling.js +16 -0
- package/src/rules/inference/capability-transforms.rules.json +11 -1
- package/src/rules/layer-pattern-contract-check.js +49 -222
- package/src/rules/rule-matcher.d.ts +62 -0
- package/src/rules/rule-matcher.js +132 -1
- package/src/rules/rule-registry.d.ts +75 -0
- package/src/rules/rule-registry.js +64 -24
- package/src/storage/artifact-storage-context.d.ts +99 -0
- package/src/storage/artifact-storage-context.js +71 -114
- package/src/storage/backend-selection.js +3 -0
- package/src/storage/backends/idb-store.d.ts +54 -0
- package/src/storage/backends/idb-store.js +12 -0
- package/src/storage/backends/memory-store.d.ts +38 -0
- package/src/storage/backends/memory-store.js +15 -6
- package/src/storage/backends/opfs-store.d.ts +2 -0
- package/src/storage/backends/opfs-store.js +6 -0
- package/src/storage/blake3.d.ts +17 -0
- package/src/storage/blake3.js +153 -68
- package/src/storage/distribution-transport.js +626 -3
- package/src/storage/download/http-contract.js +199 -0
- package/src/storage/download/http-transport.js +824 -0
- package/src/storage/download/integrity.d.ts +10 -2
- package/src/storage/download/integrity.js +39 -2
- package/src/storage/download/transport.js +2 -2
- package/src/storage/downloader.js +404 -388
- package/src/storage/export.d.ts +1 -0
- package/src/storage/export.js +22 -70
- package/src/storage/model-cache.d.ts +4 -1
- package/src/storage/model-cache.js +131 -52
- package/src/storage/model-read-session.d.ts +13 -0
- package/src/storage/model-read-session.js +76 -0
- package/src/storage/node-file-access.js +108 -0
- package/src/storage/reports.js +1 -4
- package/src/storage/runtime-env.js +6 -0
- package/src/storage/shard-manager.d.ts +10 -0
- package/src/storage/shard-manager.js +644 -579
- package/src/storage/shards/index.js +16 -0
- package/src/storage/shards/integrity.js +35 -49
- package/src/storage/source-artifact-store.d.ts +59 -0
- package/src/storage/source-artifact-store.js +24 -37
- package/src/storage/source-storage-context.d.ts +53 -0
- package/src/storage/source-storage-context.js +298 -0
- package/src/storage/verified-piece-reader.d.ts +23 -0
- package/src/storage/verified-piece-reader.js +134 -0
- package/src/storage/verified-piece-storage.d.ts +7 -0
- package/src/storage/verified-piece-storage.js +16 -0
- package/src/tooling/boundary-evidence.js +1 -4
- package/src/tooling/browser-command-runner.d.ts +1 -1
- package/src/tooling/browser-command-runner.js +2 -2
- package/src/tooling/browser-harness/benchmark-comparison.js +105 -0
- package/src/tooling/browser-harness/benchmark-execution.js +865 -0
- package/src/tooling/browser-harness/decode-diagnostics.js +201 -0
- package/src/tooling/browser-harness/inference-execution.js +543 -0
- package/src/tooling/browser-harness/model-initialization.js +230 -0
- package/src/tooling/browser-harness/model-resolution.js +134 -0
- package/src/tooling/browser-harness/report.js +338 -0
- package/src/tooling/browser-harness/request-timing.js +50 -0
- package/src/tooling/browser-harness/request.js +264 -0
- package/src/tooling/browser-harness/runtime-config.d.ts +26 -0
- package/src/tooling/browser-harness/runtime-config.js +256 -0
- package/src/tooling/browser-harness/text-evidence.d.ts +81 -0
- package/src/tooling/browser-harness/text-evidence.js +695 -0
- package/src/tooling/browser-harness/text-execution.d.ts +37 -0
- package/src/tooling/browser-harness/text-execution.js +721 -0
- package/src/tooling/browser-harness/text-input.d.ts +45 -0
- package/src/tooling/browser-harness/text-input.js +722 -0
- package/src/tooling/browser-harness/timing-diagnostics.js +416 -0
- package/src/tooling/browser-harness-text-helpers.d.ts +31 -0
- package/src/tooling/browser-harness-text-helpers.js +31 -0
- package/src/tooling/browser-harness.d.ts +245 -0
- package/src/tooling/browser-harness.js +337 -0
- package/src/tooling/command-api.d.ts +1 -0
- package/src/tooling/diagnose-runner.js +2 -2
- package/src/tooling/distribution-shard-transport.d.ts +6 -0
- package/src/tooling/execution-cost-ledger.d.ts +2 -1
- package/src/tooling/execution-cost-ledger.js +10 -7
- package/src/tooling/hf-registry/catalog-io.js +7 -5
- package/src/tooling/litert-package-runtime.js +1 -98
- package/src/tooling/model-capsule-pieces.js +47 -0
- package/src/tooling/model-capsule-rig.js +528 -0
- package/src/tooling/node-browser/execution.d.ts +1 -1
- package/src/tooling/node-browser/static-server.js +25 -2
- package/src/tooling/node-browser/transport.js +0 -43
- package/src/tooling/node-capsule-artifact-store.js +24 -0
- package/src/tooling/node-command-execution.js +2 -2
- package/src/tooling/node-command-runner.d.ts +1 -1
- package/src/tooling/node-converter/input.js +36 -5
- package/src/tooling/node-converter/output.js +75 -1
- package/src/tooling/node-converter.js +33 -34
- package/src/tooling/node-source-runtime.js +5 -5
- package/src/tooling/portable-source-path.js +26 -0
- package/src/tooling/production-release.js +3 -6
- package/src/tooling/program-bundle/choice-scoring-reference.js +22 -0
- package/src/tooling/program-bundle/materialize.js +4 -0
- package/src/tooling/program-bundle/wgsl-closure.js +3 -9
- package/src/tooling/program-bundle-host.js +26 -0
- package/src/tooling/program-bundle.js +11 -6
- package/src/tooling/reference-verify.js +5 -17
- package/src/tooling/registered-variant-calibration-job.js +1 -4
- package/src/tooling/registered-variant-calibration.js +1 -4
- package/src/tooling/source-artifact-adapter.d.ts +1 -0
- package/src/tooling/source-artifact-adapter.js +33 -1
- package/src/tooling/source-intake.js +1 -4
- package/src/tooling/source-runtime-bundle.d.ts +4 -85
- package/src/tooling/source-runtime-bundle.js +3 -3
- package/src/tooling/source-runtime-converter-config.js +41 -8
- package/src/tooling/test-harness.d.ts +173 -0
- package/src/tooling/test-harness.js +476 -0
- package/src/tooling-exports/device.d.ts +1 -0
- package/src/tooling-exports/device.js +1 -0
- package/src/tooling-exports/evidence.d.ts +3 -0
- package/src/tooling-exports/manifest.d.ts +1 -1
- package/src/tooling-exports/manifest.js +1 -1
- package/src/tooling-exports/runtime.d.ts +6 -1
- package/src/tooling-exports/runtime.js +6 -1
- package/src/tooling-exports/storage.d.ts +8 -0
- package/src/tooling-exports/storage.js +8 -0
- package/src/tooling-exports/structured.d.ts +2 -1
- package/src/tooling-exports/structured.js +2 -1
- package/src/tooling-exports.shared.d.ts +12 -9
- package/src/tooling-exports.shared.js +6 -12
- package/src/training-browser.d.ts +5 -0
- package/src/training.d.ts +7 -0
- package/src/training.js +1 -0
- package/src/version.js +1 -1
- package/tests/fixtures/linear-core-activation-accuracy.json +12 -0
- package/tests/fixtures/linear-core-refined-accuracy.json +128 -0
- package/tests/fixtures/q4k-ordered-accumulation.json +87 -0
- package/tests/fixtures/rmsnorm-inverse-root.json +18 -0
- package/tests/kernels/browser/kernel-suite.js +230 -0
- package/tests/kernels/browser/test-page.js +4 -6
- package/tests/kernels/harness/benchmark.js +11 -3
- package/tests/kernels/reference/dequant.js +23 -3
- package/tests/kernels/reference/index.js +1 -0
- package/tools/convert-safetensors-node.js +7 -1
- package/src/capsule.d.ts +0 -8
- package/src/capsule.js +0 -4
- package/src/cli/serve/capsule-handler.d.ts +0 -33
- package/src/cli/serve/capsule-handler.js +0 -105
- package/src/cli/serve/capsule-http.js +0 -102
- package/src/client/runtime/index.js +0 -1
- package/src/client/runtime/source-runtime.js +0 -910
- package/src/client/runtime/target-selector.js +0 -2
- package/src/config/backward-registry-loader.d.ts +0 -3
- package/src/config/capsule-serve.d.ts +0 -9
- package/src/config/capsule-serve.js +0 -28
- package/src/config/capsule-serve.schema.json +0 -14
- package/src/config/index.d.ts +0 -52
- package/src/config/index.js +0 -22
- package/src/config/kernels/kernel-ref-digests.js +0 -348
- package/src/config/runtime/diagnostics/debug-logits.json +0 -54
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +0 -58
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +0 -58
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +0 -57
- package/src/config/runtime/experiments/bench/gemma4-bench-q4k.json +0 -33
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +0 -58
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +0 -58
- package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +0 -81
- package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +0 -213
- package/src/config/runtime/experiments/debug/gemma4-e2b-browser-diagnose-q4k.json +0 -85
- package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +0 -81
- package/src/config/runtime/experiments/verify/gemma3-verify.json +0 -37
- package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +0 -36
- package/src/config/runtime/experiments/verify/lfm2-verify.json +0 -44
- package/src/config/runtime/experiments/verify/translategemma-verify.json +0 -37
- package/src/config/runtime/model/gemma2-debug.json +0 -78
- package/src/config/runtime/model/gemma2-pipeline-debug.json +0 -67
- package/src/config/runtime/model/gemma2-pipeline.json +0 -76
- package/src/config/runtime/model/gemma3-layer-probe.json +0 -86
- package/src/config/runtime/model/qwen3-5-layer-probe.json +0 -53
- package/src/config/runtime/model/qwen3-5-layer3-boundary-probe.json +0 -109
- package/src/config/runtime/model/qwen3-5-linear-attn-debug.json +0 -91
- package/src/config/runtime/optimization-candidates/registry.json +0 -5
- package/src/config/runtime/profiles/diffusiongemma-26b-a4b-throughput.json +0 -27
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-overlapped-probe.json +0 -43
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-probe.json +0 -40
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-b4.json +0 -46
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-single.json +0 -44
- package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +0 -61
- package/src/config/runtime/profiles/gemma4-e2b-baseline-probe.json +0 -39
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-probe.json +0 -42
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-test.json +0 -20
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-baseline-probe.json +0 -27
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-f16a-probe.json +0 -30
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-reference-export.json +0 -62
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-retain-q4k-probe.json +0 -43
- package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +0 -64
- package/src/config/runtime/profiles/gemma4-e2b-prefill-profile.json +0 -33
- package/src/config/runtime/profiles/gemma4-e2b-throughput-probe.json +0 -17
- package/src/config/runtime/profiles/muse-glimmer-30b-source-parity-f32kv.json +0 -30
- package/src/config/runtime/profiles/muse-glimmer-30b-source-parity.json +0 -110
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-attn128-candidate.json +0 -21
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-maxbatch64-candidate.json +0 -53
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-normed-ffn-candidate.json +0 -19
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-overlap-ringtokens1-candidate.json +0 -53
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-sequential-candidate.json +0 -53
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-throughput.json +0 -86
- package/src/config/runtime/profiles/qwen-3-5-0-8b-prefill-profile.json +0 -33
- package/src/config/runtime/profiles/qwen-3-5-0-8b-throughput-probe.json +0 -17
- package/src/config/runtime/profiles/qwen-3-5-2b-f16-primary-throughput.json +0 -19
- package/src/config/runtime/profiles/qwen-3-5-9b-metal-correctness.json +0 -47
- package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +0 -58
- package/src/config/runtime/profiles/qwen3-8-27b-source-parity.json +0 -87
- package/src/config/runtime/profiles/simulation.json +0 -29
- package/src/config/runtime/profiles/trace-layers.json +0 -125
- package/src/config/runtime/profiles/translategemma-1b-nativekd2-q4k-rdna3-throughput-probe.json +0 -23
- package/src/config/runtime/profiles/turboquant-contiguous-prod.json +0 -30
- package/src/config/runtime/profiles/turboquant-contiguous.json +0 -30
- package/src/config/runtime/profiles/turboquant.json +0 -37
- package/src/config/runtime/profiles/verbose-trace.json +0 -37
- package/src/config/runtime/tiers/gemma4-128gb.json +0 -80
- package/src/config/runtime/tiers/gemma4-16gb.json +0 -83
- package/src/config/runtime/tiers/gemma4-24gb.json +0 -80
- package/src/config/runtime/tiers/gemma4-32gb.json +0 -80
- package/src/config/transforms/capability-transform-resolver.js +0 -4
- package/src/config/transforms/execution-graph/fusion.js +0 -436
- package/src/config/transforms/execution-graph/validation.js +0 -414
- package/src/config/transforms/execution-graph-transforms.js +0 -987
- package/src/converter/shard-packer.d.ts +0 -138
- package/src/converter/shard-packer.js +0 -425
- package/src/experimental/adapters/adapter-manager.d.ts +0 -200
- package/src/experimental/adapters/adapter-manager.js +0 -511
- package/src/experimental/adapters/adapter-registry.d.ts +0 -192
- package/src/experimental/adapters/adapter-registry.js +0 -477
- package/src/experimental/adapters/artifact-contract.d.ts +0 -83
- package/src/experimental/adapters/artifact-contract.js +0 -257
- package/src/experimental/adapters/index.d.ts +0 -114
- package/src/experimental/adapters/index.js +0 -54
- package/src/experimental/bridge/trainer-artifact-bridge.d.ts +0 -162
- package/src/experimental/bridge/trainer-artifact-bridge.js +0 -595
- package/src/experimental/browser/browser-converter.d.ts +0 -71
- package/src/experimental/browser/browser-converter.js +0 -978
- package/src/experimental/browser/file-picker.d.ts +0 -63
- package/src/experimental/browser/file-picker.js +0 -281
- package/src/experimental/browser/gguf-parser-browser.js +0 -17
- package/src/experimental/browser/quantization.js +0 -328
- package/src/experimental/browser/safetensors-parser-browser.js +0 -347
- package/src/experimental/browser/tensor-source-download.js +0 -245
- package/src/experimental/browser/tensor-source-file.d.ts +0 -26
- package/src/experimental/browser/tensor-source-file.js +0 -53
- package/src/experimental/browser/tensor-source-http.d.ts +0 -29
- package/src/experimental/browser/tensor-source-http.js +0 -130
- package/src/experimental/diffusion/image-regression.d.ts +0 -31
- package/src/experimental/diffusion/image-regression.js +0 -107
- package/src/experimental/diffusion/index.d.ts +0 -32
- package/src/experimental/diffusion/index.js +0 -18
- package/src/experimental/diffusion/pipeline.js +0 -727
- package/src/experimental/diffusion/scheduler.js +0 -153
- package/src/experimental/diffusion/text-encoder-gpu.js +0 -947
- package/src/experimental/diffusion/vae.js +0 -596
- package/src/experimental/distribution/descriptor-transport.d.ts +0 -117
- package/src/experimental/distribution/descriptor-transport.js +0 -342
- package/src/experimental/distribution/p2p-control-plane.d.ts +0 -52
- package/src/experimental/distribution/p2p-observability.d.ts +0 -116
- package/src/experimental/distribution/p2p-observability.js +0 -303
- package/src/experimental/distribution/p2p-webrtc-browser.d.ts +0 -37
- package/src/experimental/distribution/shard-delivery/transport.js +0 -831
- package/src/experimental/distribution/shard-delivery.d.ts +0 -251
- package/src/experimental/energy/index.d.ts +0 -2
- package/src/experimental/energy/index.js +0 -2
- package/src/experimental/energy/pipeline.js +0 -697
- package/src/experimental/energy/quintel.d.ts +0 -107
- package/src/experimental/energy/quintel.js +0 -218
- package/src/experimental/orchestration/energy-row-head-pipeline.js +0 -491
- package/src/experimental/orchestration/index.d.ts +0 -21
- package/src/experimental/orchestration/index.js +0 -12
- package/src/formats/quantization-constants.d.ts +0 -11
- package/src/formats/quantization-constants.js +0 -11
- package/src/formats/tokenizer/types.js +0 -22
- package/src/gpu/kernel-selector.d.ts +0 -11
- package/src/gpu/kernels/activation-static-qdq.d.ts +0 -22
- package/src/gpu/kernels/attention.d.ts +0 -253
- package/src/gpu/kernels/backward/adam.d.ts +0 -29
- package/src/gpu/kernels/backward/attention_backward.d.ts +0 -35
- package/src/gpu/kernels/backward/bias_add_backward.d.ts +0 -17
- package/src/gpu/kernels/backward/causal_conv1d_silu_backward.d.ts +0 -24
- package/src/gpu/kernels/backward/conv2d_backward.d.ts +0 -31
- package/src/gpu/kernels/backward/cross_entropy_backward.d.ts +0 -23
- package/src/gpu/kernels/backward/embed_backward.d.ts +0 -29
- package/src/gpu/kernels/backward/executor.d.ts +0 -34
- package/src/gpu/kernels/backward/gated_delta_recurrent_backward.d.ts +0 -39
- package/src/gpu/kernels/backward/gated_rmsnorm_backward.d.ts +0 -32
- package/src/gpu/kernels/backward/gelu_backward.d.ts +0 -16
- package/src/gpu/kernels/backward/groupnorm_backward.d.ts +0 -24
- package/src/gpu/kernels/backward/index.d.ts +0 -26
- package/src/gpu/kernels/backward/layernorm_backward.d.ts +0 -22
- package/src/gpu/kernels/backward/matmul_backward.d.ts +0 -31
- package/src/gpu/kernels/backward/pixel_shuffle_backward.d.ts +0 -22
- package/src/gpu/kernels/backward/rmsnorm_backward.d.ts +0 -24
- package/src/gpu/kernels/backward/rope_backward.d.ts +0 -25
- package/src/gpu/kernels/backward/scale_backward.d.ts +0 -16
- package/src/gpu/kernels/backward/silu_backward.d.ts +0 -16
- package/src/gpu/kernels/backward/softmax_backward.d.ts +0 -16
- package/src/gpu/kernels/backward/upsample2d_backward.d.ts +0 -21
- package/src/gpu/kernels/backward/utils.js +0 -2
- package/src/gpu/kernels/cast.d.ts +0 -67
- package/src/gpu/kernels/clamp.d.ts +0 -22
- package/src/gpu/kernels/conv2d.d.ts +0 -30
- package/src/gpu/kernels/cross_entropy_loss.d.ts +0 -21
- package/src/gpu/kernels/depthwise_conv1d.d.ts +0 -23
- package/src/gpu/kernels/depthwise_conv2d.d.ts +0 -29
- package/src/gpu/kernels/dequant.d.ts +0 -92
- package/src/gpu/kernels/diffusion-gemma-sampling.d.ts +0 -19
- package/src/gpu/kernels/energy.d.ts +0 -113
- package/src/gpu/kernels/feature-check.d.ts +0 -42
- package/src/gpu/kernels/fused_ffn.d.ts +0 -97
- package/src/gpu/kernels/fused_matmul_residual.d.ts +0 -46
- package/src/gpu/kernels/fused_matmul_rmsnorm.d.ts +0 -64
- package/src/gpu/kernels/gather.d.ts +0 -144
- package/src/gpu/kernels/gelu.d.ts +0 -37
- package/src/gpu/kernels/gemma4-route-expert.d.ts +0 -35
- package/src/gpu/kernels/grouped_pointwise_conv2d.d.ts +0 -27
- package/src/gpu/kernels/groupnorm.d.ts +0 -27
- package/src/gpu/kernels/index.d.ts +0 -517
- package/src/gpu/kernels/index.js +0 -408
- package/src/gpu/kernels/kernel-cache-lifecycle.d.ts +0 -9
- package/src/gpu/kernels/kernel-prewarm.d.ts +0 -3
- package/src/gpu/kernels/kv-cache-write.d.ts +0 -22
- package/src/gpu/kernels/kv-quantize.d.ts +0 -37
- package/src/gpu/kernels/layernorm.d.ts +0 -33
- package/src/gpu/kernels/linear_attention.d.ts +0 -27
- package/src/gpu/kernels/lm-head-argmax.d.ts +0 -28
- package/src/gpu/kernels/lm-head-select-logits.d.ts +0 -23
- package/src/gpu/kernels/logit-merge.d.ts +0 -86
- package/src/gpu/kernels/logit-merge.js +0 -266
- package/src/gpu/kernels/matmul.d.ts +0 -89
- package/src/gpu/kernels/modulate.d.ts +0 -29
- package/src/gpu/kernels/moe.d.ts +0 -113
- package/src/gpu/kernels/pixel_shuffle.d.ts +0 -27
- package/src/gpu/kernels/relu.d.ts +0 -18
- package/src/gpu/kernels/repeat_channels.d.ts +0 -21
- package/src/gpu/kernels/residual.d.ts +0 -65
- package/src/gpu/kernels/rmsnorm-pair.d.ts +0 -72
- package/src/gpu/kernels/rmsnorm-qk.d.ts +0 -41
- package/src/gpu/kernels/rmsnorm-stats.d.ts +0 -29
- package/src/gpu/kernels/rmsnorm.d.ts +0 -76
- package/src/gpu/kernels/rope-qk.d.ts +0 -41
- package/src/gpu/kernels/rope.d.ts +0 -48
- package/src/gpu/kernels/sample.d.ts +0 -71
- package/src/gpu/kernels/scale.d.ts +0 -40
- package/src/gpu/kernels/silu.d.ts +0 -77
- package/src/gpu/kernels/soft-embedding.d.ts +0 -28
- package/src/gpu/kernels/softmax.d.ts +0 -57
- package/src/gpu/kernels/split-qkv-rmsnorm-qk.d.ts +0 -44
- package/src/gpu/kernels/split-qkv-rmsnorm-rope-qk.d.ts +0 -59
- package/src/gpu/kernels/split_qg.d.ts +0 -50
- package/src/gpu/kernels/split_qkv.d.ts +0 -53
- package/src/gpu/kernels/transpose.d.ts +0 -21
- package/src/gpu/kernels/types.d.ts +0 -21
- package/src/gpu/kernels/upsample2d.d.ts +0 -21
- package/src/gpu/kernels/utils.js +0 -9
- package/src/gpu/kernels/vision-average-pool.d.ts +0 -13
- package/src/gpu/kernels/vision-patch-embed.d.ts +0 -17
- package/src/gpu/kernels/vision-position-embedding.d.ts +0 -13
- package/src/gpu/kernels/vision-rope-2d.d.ts +0 -16
- package/src/gpu/kernels/vision-spatial-merge.d.ts +0 -19
- package/src/gpu/multi-model-recorder.d.ts +0 -21
- package/src/gpu/multi-model-recorder.js +0 -31
- package/src/gpu/partitioned-buffer-pool.d.ts +0 -28
- package/src/gpu/partitioned-buffer-pool.js +0 -57
- package/src/gpu/perf-guards.js +0 -71
- package/src/inference/browser-harness/benchmark-execution.js +0 -872
- package/src/inference/browser-harness/decode-diagnostics.js +0 -241
- package/src/inference/browser-harness/inference-execution.js +0 -543
- package/src/inference/browser-harness/model-initialization.js +0 -225
- package/src/inference/browser-harness/model-resolution.js +0 -137
- package/src/inference/browser-harness/report.js +0 -338
- package/src/inference/browser-harness/request.js +0 -263
- package/src/inference/browser-harness/runtime-config.d.ts +0 -25
- package/src/inference/browser-harness/runtime-config.js +0 -255
- package/src/inference/browser-harness/runtime-isolation.d.ts +0 -13
- package/src/inference/browser-harness/runtime-report.d.ts +0 -26
- package/src/inference/browser-harness/text-evidence.js +0 -694
- package/src/inference/browser-harness/text-execution.js +0 -757
- package/src/inference/browser-harness/text-input.js +0 -725
- package/src/inference/browser-harness/timing-diagnostics.js +0 -414
- package/src/inference/browser-harness-runtime-helpers.d.ts +0 -3
- package/src/inference/browser-harness-runtime-helpers.js +0 -3
- package/src/inference/browser-harness-text-helpers.js +0 -31
- package/src/inference/browser-harness.d.ts +0 -245
- package/src/inference/browser-harness.js +0 -337
- package/src/inference/expert-router.d.ts +0 -27
- package/src/inference/expert-router.js +0 -55
- package/src/inference/kv-cache/index.d.ts +0 -38
- package/src/inference/kv-cache/index.js +0 -22
- package/src/inference/kv-cache.d.ts +0 -39
- package/src/inference/kv-cache.js +0 -20
- package/src/inference/multi-model-network.d.ts +0 -139
- package/src/inference/multi-model-network.js +0 -435
- package/src/inference/multi-pipeline-pool.d.ts +0 -62
- package/src/inference/multi-pipeline-pool.js +0 -161
- package/src/inference/network-evolution.d.ts +0 -43
- package/src/inference/pipelines/diffusion/init.d.ts +0 -24
- package/src/inference/pipelines/diffusion/init.js +0 -138
- package/src/inference/pipelines/diffusion/profile-timing.js +0 -10
- package/src/inference/pipelines/diffusion/runtime-resources.js +0 -54
- package/src/inference/pipelines/diffusion/sd3/execution.js +0 -805
- package/src/inference/pipelines/diffusion/sd3/plan.js +0 -125
- package/src/inference/pipelines/diffusion/sd3-transformer.js +0 -343
- package/src/inference/pipelines/diffusion/sd3-weights.js +0 -287
- package/src/inference/pipelines/diffusion/text-encoder.js +0 -195
- package/src/inference/pipelines/diffusion/vae/execution.js +0 -803
- package/src/inference/pipelines/diffusion/weight-contract.js +0 -53
- package/src/inference/pipelines/diffusion/weights.js +0 -155
- package/src/inference/pipelines/diffusion-gemma/config.d.ts +0 -27
- package/src/inference/pipelines/diffusion-gemma/config.js +0 -149
- package/src/inference/pipelines/diffusion-gemma/index.d.ts +0 -31
- package/src/inference/pipelines/diffusion-gemma/index.js +0 -12
- package/src/inference/pipelines/diffusion-gemma/pipeline.d.ts +0 -69
- package/src/inference/pipelines/diffusion-gemma/pipeline.js +0 -380
- package/src/inference/pipelines/diffusion-gemma/sampling.d.ts +0 -128
- package/src/inference/pipelines/diffusion-gemma/sampling.js +0 -395
- package/src/inference/pipelines/rng.js +0 -17
- package/src/inference/pipelines/structured/index.d.ts +0 -10
- package/src/inference/pipelines/structured/index.js +0 -10
- package/src/inference/pipelines/text/attention/heterogeneous-contract.js +0 -8
- package/src/inference/pipelines/text/attention/index.js +0 -24
- package/src/inference/pipelines/text/attention/record.js +0 -2
- package/src/inference/pipelines/text/attention/run.js +0 -2
- package/src/inference/pipelines/text/config/validation.js +0 -9
- package/src/inference/pipelines/text/debug-utils/index.js +0 -39
- package/src/inference/pipelines/text/debug-utils/profiles.js +0 -8
- package/src/inference/pipelines/text/debug-utils.js +0 -34
- package/src/inference/pipelines/text/ffn/index.js +0 -16
- package/src/inference/pipelines/text/model-load.d.ts +0 -59
- package/src/inference/test-harness.d.ts +0 -172
- package/src/inference/test-harness.js +0 -470
- package/src/loader/dtype-utils.d.ts +0 -40
- package/src/loader/embedding-loader.d.ts +0 -66
- package/src/loader/index.d.ts +0 -152
- package/src/loader/index.js +0 -126
- package/src/loader/loader-state.d.ts +0 -51
- package/src/loader/loader-state.js +0 -142
- package/src/loader/manifest-config.d.ts +0 -118
- package/src/loader/multi-model-loader.d.ts +0 -59
- package/src/loader/multi-model-loader.js +0 -141
- package/src/loader/quantization-constants.d.ts +0 -11
- package/src/loader/quantization-constants.js +0 -13
- package/src/loader/shard-resolver.d.ts +0 -13
- package/src/loader/tensors/tensor-loader.d.ts +0 -197
- package/src/loader/tensors/tensor-reader.d.ts +0 -33
- package/src/loader/tensors/tensor-role.d.ts +0 -7
- package/src/loader/weight-downcast.d.ts +0 -62
- package/src/loader/weights.js +0 -4
- package/src/loaders/index.d.ts +0 -4
- package/src/loaders/index.js +0 -4
- package/src/models/diffusiongemma.d.ts +0 -7
- package/src/models/diffusiongemma.js +0 -25
- package/src/models/embeddinggemma.d.ts +0 -7
- package/src/models/embeddinggemma.js +0 -24
- package/src/models/family.d.ts +0 -24
- package/src/models/family.js +0 -25
- package/src/models/gemma3.d.ts +0 -7
- package/src/models/gemma3.js +0 -33
- package/src/models/gemma4.d.ts +0 -7
- package/src/models/gemma4.js +0 -65
- package/src/models/qwen3.d.ts +0 -7
- package/src/models/qwen3.js +0 -36
- package/src/rules/capability-transform-resolver.js +0 -80
- package/src/tooling/capsule-v2.d.ts +0 -11
- package/src/tooling/model-capsule-forge.js +0 -478
- package/src/tooling/source-runtime/bundle-materialize.js +0 -298
- package/src/tooling-experimental-exports.browser.js +0 -2
- package/src/tooling-experimental-exports.d.ts +0 -7
- package/src/tooling-experimental-exports.js +0 -2
- package/src/tooling-experimental-exports.shared.d.ts +0 -61
- package/src/tooling-experimental-exports.shared.js +0 -57
- /package/src/{config/transforms → converter}/execution-graph/dtype.js +0 -0
- /package/src/{tooling/source-runtime/bundle-plan.js → formats/source-runtime.js} +0 -0
- /package/src/{inference → tooling}/browser-harness/benchmark-rerank.js +0 -0
- /package/src/{inference → tooling}/browser-harness/diffusion-performance.js +0 -0
- /package/src/{inference → tooling}/browser-harness/runtime-isolation.js +0 -0
- /package/src/{inference → tooling}/browser-harness/runtime-report.js +0 -0
- /package/src/{inference → tooling}/browser-harness/suite-summary.js +0 -0
- /package/src/{inference → tooling}/browser-harness-contract-helpers.js +0 -0
- /package/src/{inference → tooling}/browser-harness-diffusion-energy-suites.js +0 -0
- /package/src/{inference → tooling}/browser-harness-report-helpers.js +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { getKernelConfig } from './kernel-configs.js';
|
|
2
|
+
import { unifiedKernelWrapper } from './kernel-execution.js';
|
|
3
|
+
import { isGpuBufferInstance, isWeightBuffer, getWeightDtype } from '../weight-buffer.js';
|
|
4
|
+
import { resolveNormWeightDtype } from './rmsnorm.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {GPUBuffer | import('../weight-buffer.js').WeightBuffer} weight
|
|
8
|
+
* @param {number} rows
|
|
9
|
+
* @param {number} columns
|
|
10
|
+
* @param {string} label
|
|
11
|
+
* @returns {GPUBuffer}
|
|
12
|
+
*/
|
|
13
|
+
function f32RowWeight(weight, rows, columns, label) {
|
|
14
|
+
const buffer = isWeightBuffer(weight) ? weight.buffer : weight;
|
|
15
|
+
const dtype = isWeightBuffer(weight) ? getWeightDtype(weight) : 'f32';
|
|
16
|
+
const layout = isWeightBuffer(weight) ? weight.layout : 'row';
|
|
17
|
+
if (!isGpuBufferInstance(buffer) || dtype !== 'f32' || layout !== 'row' || buffer.size < rows * columns * 4) {
|
|
18
|
+
throw new Error(`[MoE norm router] ${label} must be a row-major F32 [${rows}, ${columns}] weight.`);
|
|
19
|
+
}
|
|
20
|
+
return buffer;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {import('../tensor.js').Tensor} tensor
|
|
25
|
+
* @param {number} hiddenSize
|
|
26
|
+
* @param {string} label
|
|
27
|
+
*/
|
|
28
|
+
function f32Row(tensor, hiddenSize, label) {
|
|
29
|
+
if (tensor.dtype !== 'f32' || tensor.precision != null || tensor.buffer.size < hiddenSize * 4) {
|
|
30
|
+
throw new Error(`[MoE norm router] ${label} must be one scalar F32 row of ${hiddenSize} values.`);
|
|
31
|
+
}
|
|
32
|
+
return tensor.buffer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @type {typeof import('./moe-norm-router.js').recordMoENormRouter} */
|
|
36
|
+
export async function recordMoENormRouter(recorder, options) {
|
|
37
|
+
const { hiddenSize, numExperts } = options;
|
|
38
|
+
if (!Number.isSafeInteger(hiddenSize) || hiddenSize < 4 || hiddenSize % 4 !== 0
|
|
39
|
+
|| !Number.isSafeInteger(numExperts) || numExperts < 1 || !(options.eps > 0)) {
|
|
40
|
+
throw new Error('[MoE norm router] Positive hiddenSize (a multiple of 4), numExperts and eps are required.');
|
|
41
|
+
}
|
|
42
|
+
// Both variants reproduce rmsnorm/default's normalized row at its registered thread
|
|
43
|
+
// count; f32 also reproduces matmul/gemv_f32_subgroup's logits at its geometry. A
|
|
44
|
+
// registry change to a reproduced kernel must change these too.
|
|
45
|
+
const variant = options.variant;
|
|
46
|
+
if (variant !== 'f32' && variant !== 'f32_single_pass') {
|
|
47
|
+
throw new Error('[MoE norm router] Explicit registered variant required (f32 or f32_single_pass).');
|
|
48
|
+
}
|
|
49
|
+
const fused = getKernelConfig('moe_norm_router', variant);
|
|
50
|
+
const norm = getKernelConfig('rmsnorm', 'default');
|
|
51
|
+
const gemv = getKernelConfig('matmul', 'gemv_f32_subgroup');
|
|
52
|
+
const { WORKGROUP_SIZE: workgroupSize, COLS_PER_WG: colsPerWorkgroup, NORM_THREADS: normThreads, ROWS: rows } = fused.wgslOverrides ?? {};
|
|
53
|
+
const singlePass = variant === 'f32_single_pass';
|
|
54
|
+
if (typeof normThreads !== 'number' || normThreads !== norm.workgroupSize?.[0] || (singlePass
|
|
55
|
+
? typeof rows !== 'number' || rows < 1 || rows > 4
|
|
56
|
+
: typeof workgroupSize !== 'number' || typeof colsPerWorkgroup !== 'number'
|
|
57
|
+
|| workgroupSize !== gemv.wgslOverrides?.WORKGROUP_SIZE || colsPerWorkgroup !== gemv.wgslOverrides?.COLS_PER_WG)) {
|
|
58
|
+
throw new Error('[MoE norm router] Registered geometry no longer matches the reproduced kernels.');
|
|
59
|
+
}
|
|
60
|
+
const device = recorder.device;
|
|
61
|
+
// The staged row, the norm partial sums and (single pass) four row dots per thread.
|
|
62
|
+
if (hiddenSize * 4 + normThreads * (singlePass ? 20 : 4) > device.limits.maxComputeWorkgroupStorageSize) {
|
|
63
|
+
throw new Error('[MoE norm router] The normalized row exceeds workgroup storage.');
|
|
64
|
+
}
|
|
65
|
+
const outputs = [options.normedOutput, options.prenormOutput, options.logitsOutput, options.sharedGateOutput];
|
|
66
|
+
const sizes = [hiddenSize * 4, hiddenSize * 4, numExperts * 4, 4];
|
|
67
|
+
if (outputs.some((buffer, i) => !buffer || buffer.size < sizes[i]) || new Set(outputs).size !== outputs.length) {
|
|
68
|
+
throw new Error('[MoE norm router] Four distinct outputs of the declared sizes are required.');
|
|
69
|
+
}
|
|
70
|
+
const normWeight = isWeightBuffer(options.normWeight) ? options.normWeight.buffer : options.normWeight;
|
|
71
|
+
const columns = numExperts + 1;
|
|
72
|
+
const workgroupsX = Math.ceil(columns / (singlePass ? /** @type {number} */ (rows) : /** @type {number} */ (colsPerWorkgroup)));
|
|
73
|
+
await unifiedKernelWrapper('moe_norm_router', recorder, variant, [
|
|
74
|
+
f32Row(options.input, hiddenSize, 'input'),
|
|
75
|
+
f32Row(options.residual, hiddenSize, 'residual'),
|
|
76
|
+
normWeight,
|
|
77
|
+
f32RowWeight(options.routerWeight, numExperts, hiddenSize, 'router weight'),
|
|
78
|
+
f32RowWeight(options.sharedRouterWeight, 1, hiddenSize, 'shared router weight'),
|
|
79
|
+
...outputs,
|
|
80
|
+
], { hidden_size: hiddenSize, num_experts: numExperts, eps: options.eps, workgroups_x: workgroupsX },
|
|
81
|
+
[workgroupsX, 1, 1], {
|
|
82
|
+
...(singlePass
|
|
83
|
+
? { ROWS: /** @type {number} */ (rows) }
|
|
84
|
+
: { WORKGROUP_SIZE: /** @type {number} */ (workgroupSize), COLS_PER_WG: /** @type {number} */ (colsPerWorkgroup) }),
|
|
85
|
+
NORM_THREADS: normThreads,
|
|
86
|
+
HIDDEN_SIZE: hiddenSize,
|
|
87
|
+
RMS_NORM_OFFSET: options.rmsNormWeightOffset,
|
|
88
|
+
// The norm weight dtype resolves as rmsnorm.js resolves it.
|
|
89
|
+
WEIGHT_IS_F16: resolveNormWeightDtype(options.normWeight, hiddenSize) === 'f16',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ggufBlockFormat,ggufBlockBytes } from '../../formats/gguf/block-storage.js';
|
|
2
|
+
import { q40Dispatch } from './q4_0.js';
|
|
3
|
+
import { getDevice } from '../device.js';
|
|
4
|
+
import { selectRuleValue } from '../../rules/rule-registry.js';
|
|
5
|
+
import { QK_K, Q4K_BLOCK_BYTES } from '../../config/schema/index.js';
|
|
6
|
+
import { createTensor } from '../tensor.js';
|
|
7
|
+
import { getBuffer, getWeightDtype, isGpuBufferInstance } from '../weight-buffer.js';
|
|
8
|
+
import { getKernelConfig } from './kernel-configs.js';
|
|
9
|
+
import { unifiedKernelWrapper, withKernelOutput } from './kernel-execution.js';
|
|
10
|
+
|
|
11
|
+
/** @param {unknown} value @param {string} label @returns {number} */
|
|
12
|
+
function positive(value, label) {
|
|
13
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1 || value > 0xFFFFFFFF) {
|
|
14
|
+
throw new Error(`[MoE route] ${label} must be a positive u32.`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @param {{size: number} | null | undefined} buffer @param {number} bytes @param {string} label */
|
|
20
|
+
function extent(buffer, bytes, label) {
|
|
21
|
+
positive(bytes, `${label} byte extent`);
|
|
22
|
+
if (!buffer || !Number.isSafeInteger(buffer.size) || buffer.size < bytes) {
|
|
23
|
+
throw new Error(`[MoE route] ${label} buffer is smaller than ${bytes} bytes.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {import('../tensor.js').Tensor} input @param {number} rows @param {number} cols */
|
|
28
|
+
function tensor(input, rows, cols) {
|
|
29
|
+
if (input?.dtype !== 'f32' || input.precision !== undefined || input.components !== undefined
|
|
30
|
+
|| input.elementStrideBytes !== undefined || input.shape.length !== 2
|
|
31
|
+
|| input.shape[0] !== rows || input.shape[1] !== cols) {
|
|
32
|
+
throw new Error('[MoE route] Expected a scalar F32 tensor with explicit row/column geometry.');
|
|
33
|
+
}
|
|
34
|
+
extent(input.buffer, rows * cols * 4, 'input');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {GPUBuffer | null | undefined} output @param {GPUBuffer[]} inputs */
|
|
38
|
+
function outputAlias(output, inputs) {
|
|
39
|
+
if (output && inputs.includes(output)) throw new Error('[MoE route] Output must not alias an input.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {import('../command-recorder.js').CommandRecorder | null} target
|
|
44
|
+
* @param {import('../tensor.js').Tensor} input
|
|
45
|
+
* @param {GPUBuffer} indices
|
|
46
|
+
* @param {import('../weight-buffer.js').WeightBuffer} weights
|
|
47
|
+
* @param {import('./moe-route.js').RouteQ4MatmulOptions} options
|
|
48
|
+
*/
|
|
49
|
+
async function matmul(target, input, indices, weights, options) {
|
|
50
|
+
const { numRoutes, numExperts, topK, N, K, inputMode, alpha, outputBuffer, upWeights } = options;
|
|
51
|
+
for (const [key, value] of Object.entries({ numRoutes, numExperts, topK, N, K })) positive(value, key);
|
|
52
|
+
if (numRoutes % topK || topK > numExperts) throw new Error('[MoE route] Invalid route/topK/expert geometry.');
|
|
53
|
+
if (inputMode !== 'token' && inputMode !== 'route') throw new Error('[MoE route] Explicit token or route inputMode required.');
|
|
54
|
+
if (!Number.isFinite(alpha) || !Number.isFinite(Math.fround(alpha))) throw new Error('[MoE route] Finite F32 alpha required.');
|
|
55
|
+
tensor(input, inputMode === 'token' ? numRoutes / topK : numRoutes, K);
|
|
56
|
+
const bank = getBuffer(weights);
|
|
57
|
+
if (!isGpuBufferInstance(bank)) throw new Error('[MoE route] A resident GPU weight bank is required.');
|
|
58
|
+
const dtype = getWeightDtype(weights);
|
|
59
|
+
const split = upWeights != null;
|
|
60
|
+
if (split && (N%2 || getWeightDtype(upWeights) !== dtype || upWeights.layout !== 'row'
|
|
61
|
+
|| JSON.stringify(upWeights.shape) !== JSON.stringify(weights.shape))) throw new Error('[MoE route] Separate gate/up banks must have identical packed storage geometry.');
|
|
62
|
+
if ((dtype !== 'q4k' && dtype !== 'q4_0' && dtype !== 'q4_1' && dtype !== 'q8_0' && dtype !== 'q6k') || weights.layout !== 'row'
|
|
63
|
+
|| weights.shape?.length !== 3 || weights.shape[0] !== numExperts
|
|
64
|
+
|| weights.shape[1] !== (split ? N/2 : N) || weights.shape[2] !== K) {
|
|
65
|
+
throw new Error('[MoE route] Expected a row-packed Q4_K bank shaped [experts, N, K].');
|
|
66
|
+
}
|
|
67
|
+
const blocks = Math.ceil(K / QK_K);
|
|
68
|
+
const bytes = dtype !== 'q4k' ? ggufBlockBytes(weights.shape,dtype) : numExperts * N * blocks * Q4K_BLOCK_BYTES;
|
|
69
|
+
extent(bank, bytes, 'weight bank');
|
|
70
|
+
const upBank = split ? getBuffer(upWeights) : null;
|
|
71
|
+
if (upBank !== null && !isGpuBufferInstance(upBank)) throw new Error('[MoE route] A resident GPU up weight bank is required.');
|
|
72
|
+
if (upBank) extent(upBank, bytes, 'up weight bank');
|
|
73
|
+
extent(indices, numRoutes * 4, 'routing indices');
|
|
74
|
+
outputAlias(outputBuffer, [input.buffer, indices, bank, ...(upBank ? [upBank] : [])]);
|
|
75
|
+
if (outputBuffer) extent(outputBuffer, numRoutes * N * 4, 'output');
|
|
76
|
+
const variant = selectRuleValue('kernels', 'matmul', 'routeQ4Variant', { weightDtype: dtype, split });
|
|
77
|
+
const config = getKernelConfig('moe_route_matmul', variant);
|
|
78
|
+
if (config.weightDtype !== dtype) throw new Error('[MoE route] Kernel storage disagrees with expert bank.');
|
|
79
|
+
const constants = config.wgslOverrides;
|
|
80
|
+
const columns = positive(constants?.COLS_PER_WG, 'COLS_PER_WG');
|
|
81
|
+
const threads = positive(constants?.THREADS_PER_COL_GEMV, 'THREADS_PER_COL_GEMV');
|
|
82
|
+
const workgroup = positive(constants?.WORKGROUP_SIZE, 'WORKGROUP_SIZE');
|
|
83
|
+
if (workgroup !== columns * threads || workgroup > 256) throw new Error('[MoE route] Invalid registered reduction geometry.');
|
|
84
|
+
if (constants?.USE_FULL_BLOCK_FAST_PATH === true && K % QK_K !== 0) {
|
|
85
|
+
throw new Error('[MoE route] Full-block specialization cannot execute a partial Q4_K row.');
|
|
86
|
+
}
|
|
87
|
+
return withKernelOutput(target, outputBuffer ?? null, numRoutes * N * 4, 'moe_route_matmul', async output => {
|
|
88
|
+
await unifiedKernelWrapper('moe_route_matmul', target, variant,
|
|
89
|
+
[input.buffer, bank, output, indices, ...(upBank ? [upBank] : [])], {
|
|
90
|
+
M: numRoutes, N, K, alpha, num_blocks_per_row: blocks, blocks: dtype !== 'q4k' ? K/ggufBlockFormat(dtype).values : 0,
|
|
91
|
+
num_experts: numExperts, top_k: topK, input_mode: inputMode === 'token' ? 0 : 1,
|
|
92
|
+
}, dtype !== 'q4k' ? q40Dispatch(target?.device ?? getDevice(), Math.ceil(N / columns)*numRoutes) : [Math.ceil(N / columns), numRoutes, 1]);
|
|
93
|
+
return createTensor(output, 'f32', [numRoutes, N], 'moe_route_matmul');
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {import('../command-recorder.js').CommandRecorder | null} target
|
|
99
|
+
* @param {import('../tensor.js').Tensor} input
|
|
100
|
+
* @param {GPUBuffer} weights
|
|
101
|
+
* @param {import('./moe-route.js').RouteScatterOptions} options
|
|
102
|
+
*/
|
|
103
|
+
async function scatter(target, input, weights, options) {
|
|
104
|
+
const { numTokens, hiddenSize, topK, outputBuffer } = options;
|
|
105
|
+
for (const [key, value] of Object.entries({ numTokens, hiddenSize, topK })) positive(value, key);
|
|
106
|
+
tensor(input, numTokens * topK, hiddenSize);
|
|
107
|
+
extent(weights, numTokens * topK * 4, 'routing weights');
|
|
108
|
+
outputAlias(outputBuffer, [input.buffer, weights]);
|
|
109
|
+
if (outputBuffer) extent(outputBuffer, numTokens * hiddenSize * 4, 'output');
|
|
110
|
+
const config = getKernelConfig('scatter_add_routes', 'f32');
|
|
111
|
+
const threads = positive(config.workgroupSize[0], 'scatter workgroup');
|
|
112
|
+
return withKernelOutput(target, outputBuffer ?? null, numTokens * hiddenSize * 4, 'moe_route_scatter', async output => {
|
|
113
|
+
await unifiedKernelWrapper('scatter_add_routes', target, 'f32', [input.buffer, weights, output], {
|
|
114
|
+
num_tokens: numTokens, hidden_size: hiddenSize, top_k: topK,
|
|
115
|
+
}, [Math.ceil(numTokens * hiddenSize / threads), 1, 1]);
|
|
116
|
+
return createTensor(output, 'f32', [numTokens, hiddenSize], 'moe_route_scatter');
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @type {typeof import('./moe-route.js').runRouteQ4Matmul} */
|
|
121
|
+
export function runRouteQ4Matmul(input, indices, weights, options) {
|
|
122
|
+
return matmul(null, input, indices, weights, options);
|
|
123
|
+
}
|
|
124
|
+
/** @type {typeof import('./moe-route.js').recordRouteQ4Matmul} */
|
|
125
|
+
export function recordRouteQ4Matmul(recorder, input, indices, weights, options) {
|
|
126
|
+
return matmul(recorder, input, indices, weights, options);
|
|
127
|
+
}
|
|
128
|
+
/** @type {typeof import('./moe-route.js').runRouteScatter} */
|
|
129
|
+
export function runRouteScatter(input, weights, options) {
|
|
130
|
+
return scatter(null, input, weights, options);
|
|
131
|
+
}
|
|
132
|
+
/** @type {typeof import('./moe-route.js').recordRouteScatter} */
|
|
133
|
+
export function recordRouteScatter(recorder, input, weights, options) {
|
|
134
|
+
return scatter(recorder, input, weights, options);
|
|
135
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { ggufBlockFormat, ggufBlockBytes } from '../../formats/gguf/block-storage.js';
|
|
2
|
+
import { getDevice, getKernelCapabilities } from '../device.js';
|
|
3
|
+
import { createTensor } from '../tensor.js';
|
|
4
|
+
import { getKernelConfig } from './kernel-configs.js';
|
|
5
|
+
import { assertQ40Buffer, q40Dispatch } from './q4_0.js';
|
|
6
|
+
import { unifiedKernelWrapper, withKernelOutput } from './kernel-execution.js';
|
|
7
|
+
import { acquireBuffer, releaseBuffer } from '../../memory/buffer-pool.js';
|
|
8
|
+
|
|
9
|
+
const COMBINE_WORKGROUP = 256;
|
|
10
|
+
|
|
11
|
+
/** @type {typeof import('./moe-shared-slot.js').validateSharedSlotGeometry} */
|
|
12
|
+
export function validateSharedSlotGeometry(options) {
|
|
13
|
+
for (const value of [options.numTokens, options.numExperts, options.topK, options.hiddenSize,
|
|
14
|
+
options.intermediateSize, options.sharedSize]) {
|
|
15
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 0xffffff) {
|
|
16
|
+
throw new Error('[MoE shared slot] Explicit positive bounded geometry is required.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (options.topK > options.numExperts || options.hiddenSize % 32
|
|
20
|
+
|| options.intermediateSize % 32 || options.sharedSize % 32
|
|
21
|
+
|| (options.swigluLimit !== null && (!Number.isFinite(options.swigluLimit) || !Number.isFinite(Math.fround(options.swigluLimit))))) {
|
|
22
|
+
throw new Error('[MoE shared slot] Invalid topK, complete native blocks, or explicit SwiGLU limit.');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @param {GPUDevice} device @param {import('../weight-buffer.js').WeightBuffer} weight
|
|
27
|
+
* @param {number[]} shape */
|
|
28
|
+
function validateWeight(device, weight, shape) {
|
|
29
|
+
if (!weight || weight.layout !== 'row' || !['q4_0', 'q4_1', 'q5_0', 'q8_0'].includes(weight.dtype)
|
|
30
|
+
|| weight.shape.length !== shape.length || weight.shape.some((n, i) => n !== shape[i])) {
|
|
31
|
+
throw new Error('[MoE shared slot] Expected declared native GGUF row-packed weight geometry.');
|
|
32
|
+
}
|
|
33
|
+
assertQ40Buffer(device, weight.buffer, ggufBlockBytes(shape, weight.dtype), GPUBufferUsage.STORAGE, 'shared slot weight');
|
|
34
|
+
return ggufBlockFormat(weight.dtype);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {GPUDevice} device @param {import('../tensor.js').Tensor} input @param {number} rows @param {number} columns */
|
|
38
|
+
function validateInput(device, input, rows, columns) {
|
|
39
|
+
if (input.dtype !== 'f32' || input.precision != null || input.components != null
|
|
40
|
+
|| input.elementStrideBytes != null || input.shape.length !== 2
|
|
41
|
+
|| input.shape[0] !== rows || input.shape[1] !== columns) {
|
|
42
|
+
throw new Error('[MoE shared slot] Explicit scalar F32 input geometry required.');
|
|
43
|
+
}
|
|
44
|
+
assertQ40Buffer(device, input.buffer, rows * columns * 4, GPUBufferUsage.STORAGE, 'shared slot input');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {import('../command-recorder.js').CommandRecorder | null} recorder
|
|
48
|
+
* @param {import('./moe-shared-slot.js').SharedSlotOptions} options
|
|
49
|
+
* @param {string} operation @param {number} storageSlots @param {number} inputWidth */
|
|
50
|
+
function prepare(recorder, options, operation, storageSlots, inputWidth) {
|
|
51
|
+
validateSharedSlotGeometry(options);
|
|
52
|
+
const device = recorder?.device ?? getDevice();
|
|
53
|
+
if (!device) throw new Error('[MoE shared slot] Active device required.');
|
|
54
|
+
const variant = resolveSharedSlotVariant(options.variant);
|
|
55
|
+
const config = getKernelConfig(operation, variant);
|
|
56
|
+
const width = config.wgslOverrides?.WORKGROUP_SIZE;
|
|
57
|
+
if (typeof width !== 'number') throw new Error('[MoE shared slot] Registered workgroup size required.');
|
|
58
|
+
let rowsPerWorkgroup = 0;
|
|
59
|
+
const slotStride = Math.max(options.intermediateSize, options.sharedSize);
|
|
60
|
+
/** @type {Record<string, number>} */
|
|
61
|
+
let constants = { WORKGROUP_SIZE: width };
|
|
62
|
+
if (variant === PAIR_VARIANT || variant === PAIR_COMBINE_VARIANT || variant === PAIR_COMBINE_RESIDUAL_VARIANT) {
|
|
63
|
+
const threadsPerRow = config.wgslOverrides?.THREADS_PER_ROW;
|
|
64
|
+
if (typeof threadsPerRow !== 'number') throw new Error('[MoE shared slot] Registered row group size required.');
|
|
65
|
+
rowsPerWorkgroup = width / threadsPerRow;
|
|
66
|
+
const pairs = inputWidth / 64;
|
|
67
|
+
const minSubgroup = device.features?.has('subgroups') ? getKernelCapabilities()?.adapterInfo?.subgroupMinSize : null;
|
|
68
|
+
if (typeof minSubgroup !== 'number' || typeof threadsPerRow !== 'number'
|
|
69
|
+
|| threadsPerRow < 1 || (threadsPerRow & (threadsPerRow - 1)) || minSubgroup < threadsPerRow
|
|
70
|
+
|| typeof width !== 'number' || width % minSubgroup || width % threadsPerRow
|
|
71
|
+
|| width > device.limits.maxComputeInvocationsPerWorkgroup) {
|
|
72
|
+
throw new Error('[MoE shared slot] Pair geometry requires subgroups no narrower than one row group.');
|
|
73
|
+
}
|
|
74
|
+
if (options.hiddenSize % 64 || options.intermediateSize % 64 || options.sharedSize % 64
|
|
75
|
+
|| pairs * 17 * 16 > device.limits.maxComputeWorkgroupStorageSize
|
|
76
|
+
|| options.numTokens * (options.topK + 1) > device.limits.maxComputeWorkgroupsPerDimension) {
|
|
77
|
+
throw new Error('[MoE shared slot] Pair geometry requires even block counts and bounded staging.');
|
|
78
|
+
}
|
|
79
|
+
constants = variant !== PAIR_VARIANT
|
|
80
|
+
? { WORKGROUP_SIZE: width, THREADS_PER_ROW: threadsPerRow }
|
|
81
|
+
: { WORKGROUP_SIZE: width, THREADS_PER_ROW: threadsPerRow, MAX_INPUT_PAIRS: pairs };
|
|
82
|
+
} else if (typeof width !== 'number' || width < 4 || width % 4 || (width & (width - 1))
|
|
83
|
+
|| width > device.limits.maxComputeInvocationsPerWorkgroup
|
|
84
|
+
|| width * 16 * storageSlots > device.limits.maxComputeWorkgroupStorageSize) {
|
|
85
|
+
throw new Error('[MoE shared slot] Registered reduction exceeds device workgroup limits.');
|
|
86
|
+
}
|
|
87
|
+
const uniforms = { num_tokens: options.numTokens, hidden_size: options.hiddenSize,
|
|
88
|
+
intermediate_size: options.intermediateSize, shared_size: options.sharedSize,
|
|
89
|
+
num_experts: options.numExperts, slot_stride: slotStride, clamp_max: options.swigluLimit ?? 0, _pad: 0 };
|
|
90
|
+
assertQ40Buffer(device, options.indices, options.numTokens * options.topK * 4, GPUBufferUsage.STORAGE, 'route indices');
|
|
91
|
+
return { device, width, slotStride, uniforms, variant, rowsPerWorkgroup, constants };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const PAIR_VARIANT = 'pair_f32';
|
|
95
|
+
// Down only: the pair row geometry with the slot combine in the same dispatch.
|
|
96
|
+
const PAIR_COMBINE_VARIANT = 'pair_combine_f32';
|
|
97
|
+
// Down only: pair_combine_f32 that also adds the layer's outer residual.
|
|
98
|
+
const PAIR_COMBINE_RESIDUAL_VARIANT = 'pair_combine_residual_f32';
|
|
99
|
+
/** @param {string | undefined} variant */
|
|
100
|
+
function resolveSharedSlotVariant(variant) {
|
|
101
|
+
if (variant !== 'native_f32' && variant !== PAIR_VARIANT && variant !== PAIR_COMBINE_VARIANT
|
|
102
|
+
&& variant !== PAIR_COMBINE_RESIDUAL_VARIANT) {
|
|
103
|
+
throw new Error('[MoE shared slot] Explicit registered shared-slot variant required.');
|
|
104
|
+
}
|
|
105
|
+
return variant;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/** @param {GPUDevice} device @param {GPUBuffer | null | undefined} output
|
|
110
|
+
* @param {number} bytes @param {GPUBuffer[]} inputs */
|
|
111
|
+
function validateOutput(device, output, bytes, inputs) {
|
|
112
|
+
if (!Number.isSafeInteger(bytes) || bytes > 0xffffffff || bytes > device.limits.maxStorageBufferBindingSize) {
|
|
113
|
+
throw new Error('[MoE shared slot] Output extent exceeds binding limits.');
|
|
114
|
+
}
|
|
115
|
+
if (!output) return;
|
|
116
|
+
assertQ40Buffer(device, output, bytes, GPUBufferUsage.STORAGE, 'shared slot output');
|
|
117
|
+
if (inputs.includes(output)) throw new Error('[MoE shared slot] Output must not alias inputs.');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @type {typeof import('./moe-shared-slot.js').executeSharedSlotGateUp} */
|
|
121
|
+
export async function executeSharedSlotGateUp(recorder, input, weights, options) {
|
|
122
|
+
const { device, slotStride, uniforms, variant, rowsPerWorkgroup, constants } =
|
|
123
|
+
prepare(recorder, options, 'moe_shared_slot_gu', 2, options.hiddenSize);
|
|
124
|
+
if (variant === PAIR_COMBINE_VARIANT || variant === PAIR_COMBINE_RESIDUAL_VARIANT) {
|
|
125
|
+
throw new Error(`[MoE shared slot] ${variant} is a down-only variant.`);
|
|
126
|
+
}
|
|
127
|
+
const { numTokens, numExperts, topK, hiddenSize, intermediateSize, sharedSize } = options;
|
|
128
|
+
validateInput(device, input, numTokens, hiddenSize);
|
|
129
|
+
const routed = validateWeight(device, weights.gate, [numExperts, intermediateSize, hiddenSize]);
|
|
130
|
+
validateWeight(device, weights.up, [numExperts, intermediateSize, hiddenSize]);
|
|
131
|
+
const shared = validateWeight(device, weights.sharedGate, [sharedSize, hiddenSize]);
|
|
132
|
+
validateWeight(device, weights.sharedUp, [sharedSize, hiddenSize]);
|
|
133
|
+
if (weights.gate.dtype !== weights.up.dtype || weights.sharedGate.dtype !== weights.sharedUp.dtype) {
|
|
134
|
+
throw new Error('[MoE shared slot] Gate/up storage must match within each bank.');
|
|
135
|
+
}
|
|
136
|
+
const buffers = [input.buffer, weights.gate.buffer, weights.up.buffer,
|
|
137
|
+
weights.sharedGate.buffer, weights.sharedUp.buffer, options.indices];
|
|
138
|
+
const rows = numTokens * (topK + 1), bytes = rows * slotStride * 4;
|
|
139
|
+
validateOutput(device, options.outputBuffer, bytes, buffers);
|
|
140
|
+
return withKernelOutput(recorder, options.outputBuffer ?? null, bytes, 'moe_shared_slot_gu', async output => {
|
|
141
|
+
const workgroups = variant === PAIR_VARIANT
|
|
142
|
+
? [Math.ceil(slotStride / rowsPerWorkgroup), rows, 1]
|
|
143
|
+
: q40Dispatch(device, Math.ceil(slotStride / 4) * rows);
|
|
144
|
+
await unifiedKernelWrapper('moe_shared_slot_gu', recorder, variant, [...buffers, output], uniforms,
|
|
145
|
+
workgroups,
|
|
146
|
+
{ ...constants, TOP_K: topK, ROUTED_FORMAT: routed.code, ROUTED_BYTES: routed.bytes,
|
|
147
|
+
SHARED_FORMAT: shared.code, SHARED_BYTES: shared.bytes });
|
|
148
|
+
return createTensor(output, 'f32', [rows, slotStride], 'moe_shared_slot_gu');
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** @type {typeof import('./moe-shared-slot.js').executeSharedSlotDown} */
|
|
153
|
+
export async function executeSharedSlotDown(recorder, input, weights, gate, options) {
|
|
154
|
+
const { device, width, slotStride, uniforms, variant, rowsPerWorkgroup, constants } = prepare(recorder, options,
|
|
155
|
+
'moe_shared_slot_down', options.topK + 1, Math.max(options.intermediateSize, options.sharedSize));
|
|
156
|
+
const { numTokens, numExperts, topK, hiddenSize, intermediateSize, sharedSize } = options;
|
|
157
|
+
validateInput(device, input, numTokens * (topK + 1), slotStride);
|
|
158
|
+
validateInput(device, gate, numTokens, 1);
|
|
159
|
+
const routed = validateWeight(device, weights.down, [numExperts, hiddenSize, intermediateSize]);
|
|
160
|
+
const shared = validateWeight(device, weights.sharedDown, [hiddenSize, sharedSize]);
|
|
161
|
+
assertQ40Buffer(device, options.routeWeights, numTokens * topK * 4, GPUBufferUsage.STORAGE, 'route weights');
|
|
162
|
+
const buffers = [input.buffer, weights.down.buffer, weights.sharedDown.buffer,
|
|
163
|
+
options.indices, options.routeWeights, gate.buffer];
|
|
164
|
+
const bytes = numTokens * hiddenSize * 4;
|
|
165
|
+
// The residual-bearing variant and a residual input come together or not at all:
|
|
166
|
+
// the caller skips its own residual add only when this kernel adds it.
|
|
167
|
+
const residual = options.residual ?? null;
|
|
168
|
+
if ((variant === PAIR_COMBINE_RESIDUAL_VARIANT) !== (residual !== null)) {
|
|
169
|
+
throw new Error(`[MoE shared slot] ${variant} ${residual ? 'does not add' : 'requires'} an outer residual input.`);
|
|
170
|
+
}
|
|
171
|
+
if (residual) validateInput(device, residual, numTokens, hiddenSize);
|
|
172
|
+
validateOutput(device, options.outputBuffer, bytes, residual ? [...buffers, residual.buffer] : buffers);
|
|
173
|
+
const kernelConstants = { ...constants, TOP_K: topK, ROUTED_FORMAT: routed.code, ROUTED_BYTES: routed.bytes,
|
|
174
|
+
SHARED_FORMAT: shared.code, SHARED_BYTES: shared.bytes };
|
|
175
|
+
if (residual) {
|
|
176
|
+
return withKernelOutput(recorder, options.outputBuffer ?? null, bytes, 'moe_shared_slot_down', async output => {
|
|
177
|
+
await unifiedKernelWrapper('moe_shared_slot_down', recorder, variant, [...buffers, output, residual.buffer], uniforms,
|
|
178
|
+
[Math.ceil(hiddenSize / rowsPerWorkgroup), numTokens, 1], kernelConstants);
|
|
179
|
+
return createTensor(output, 'f32', [numTokens, hiddenSize], 'moe_shared_slot_down_residual');
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (variant === PAIR_COMBINE_VARIANT) {
|
|
183
|
+
return withKernelOutput(recorder, options.outputBuffer ?? null, bytes, 'moe_shared_slot_down', async output => {
|
|
184
|
+
await unifiedKernelWrapper('moe_shared_slot_down', recorder, variant, [...buffers, output], uniforms,
|
|
185
|
+
[Math.ceil(hiddenSize / rowsPerWorkgroup), numTokens, 1], kernelConstants);
|
|
186
|
+
return createTensor(output, 'f32', [numTokens, hiddenSize], 'moe_shared_slot_down');
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (variant === PAIR_VARIANT) {
|
|
190
|
+
const slotsBytes = numTokens * (topK + 1) * hiddenSize * 4;
|
|
191
|
+
validateOutput(device, options.slotsBuffer, slotsBytes, buffers);
|
|
192
|
+
const slots = options.slotsBuffer ?? acquireBuffer(slotsBytes, undefined, 'moe_shared_slot_down_slots');
|
|
193
|
+
try {
|
|
194
|
+
return await withKernelOutput(recorder, options.outputBuffer ?? null, bytes, 'moe_shared_slot_down', async output => {
|
|
195
|
+
if (output === slots) throw new Error('[MoE shared slot] Output must not alias per-slot outputs.');
|
|
196
|
+
await unifiedKernelWrapper('moe_shared_slot_down', recorder, variant,
|
|
197
|
+
[input.buffer, weights.down.buffer, weights.sharedDown.buffer, options.indices, slots], uniforms,
|
|
198
|
+
[Math.ceil(hiddenSize / rowsPerWorkgroup), numTokens * (topK + 1), 1], kernelConstants);
|
|
199
|
+
await unifiedKernelWrapper('moe_shared_slot_combine', recorder, 'f32',
|
|
200
|
+
[slots, options.routeWeights, gate.buffer, output], uniforms,
|
|
201
|
+
q40Dispatch(device, Math.ceil(numTokens * hiddenSize / COMBINE_WORKGROUP)),
|
|
202
|
+
{ WORKGROUP_SIZE: COMBINE_WORKGROUP, TOP_K: topK });
|
|
203
|
+
return createTensor(output, 'f32', [numTokens, hiddenSize], 'moe_shared_slot_down');
|
|
204
|
+
});
|
|
205
|
+
} finally {
|
|
206
|
+
if (!options.slotsBuffer) {
|
|
207
|
+
if (recorder) recorder.trackTemporaryBuffer(slots);
|
|
208
|
+
else releaseBuffer(slots);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return withKernelOutput(recorder, options.outputBuffer ?? null, bytes, 'moe_shared_slot_down', async output => {
|
|
213
|
+
await unifiedKernelWrapper('moe_shared_slot_down', recorder, 'native_f32', [...buffers, output], uniforms,
|
|
214
|
+
q40Dispatch(device, Math.ceil(hiddenSize / 4) * numTokens),
|
|
215
|
+
{ WORKGROUP_SIZE: width, TOP_K: topK, ROUTED_FORMAT: routed.code, ROUTED_BYTES: routed.bytes,
|
|
216
|
+
SHARED_FORMAT: shared.code, SHARED_BYTES: shared.bytes });
|
|
217
|
+
return createTensor(output, 'f32', [numTokens, hiddenSize], 'moe_shared_slot_down');
|
|
218
|
+
});
|
|
219
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// Adapted from Pooled engine/wgsl/moe_group.js, revision
|
|
2
|
+
// 6b4a24f73cce7ef9a9e3ab35b9a0d4c09b51dfff: stable counting sort and F32 row tiles.
|
|
3
|
+
// MIT License
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) 2026 Nehanth Narendrula
|
|
6
|
+
//
|
|
7
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
// in the Software without restriction, including without limitation the rights
|
|
10
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
// furnished to do so, subject to the following conditions:
|
|
13
|
+
//
|
|
14
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
// copies or substantial portions of the Software.
|
|
16
|
+
//
|
|
17
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
// SOFTWARE.
|
|
24
|
+
//
|
|
25
|
+
override WORKGROUP_SIZE: u32;
|
|
26
|
+
override GROUP_SIZE: u32;
|
|
27
|
+
override ROWS_PER_THREAD: u32;
|
|
28
|
+
override INPUT_IS_TOKEN: bool;
|
|
29
|
+
override SPLIT_GATE_UP: bool;
|
|
30
|
+
override QUANT_FORMAT: u32;
|
|
31
|
+
override BLOCK_BYTES: u32;
|
|
32
|
+
struct Uniforms {
|
|
33
|
+
num_routes: u32, num_experts: u32, top_k: u32, pair_offset: u32,
|
|
34
|
+
N: u32, K: u32, _pad0: u32, _pad1: u32,
|
|
35
|
+
}
|
|
36
|
+
@group(0) @binding(0) var<uniform> u: Uniforms;
|
|
37
|
+
@group(0) @binding(1) var<storage, read> input: array<f32>;
|
|
38
|
+
@group(0) @binding(2) var<storage, read> weights: array<u32>;
|
|
39
|
+
@group(0) @binding(3) var<storage, read> up_weights: array<u32>;
|
|
40
|
+
@group(0) @binding(4) var<storage, read> groups: array<u32>;
|
|
41
|
+
@group(0) @binding(5) var<storage, read_write> output: array<f32>;
|
|
42
|
+
var<private> use_up: bool;
|
|
43
|
+
fn bank_word(i: u32) -> u32 {
|
|
44
|
+
if (use_up) { return up_weights[i]; }
|
|
45
|
+
return weights[i];
|
|
46
|
+
}
|
|
47
|
+
fn bytes4(word: u32) -> vec4<u32> {
|
|
48
|
+
return (vec4<u32>(word) >> vec4<u32>(0u,8u,16u,24u)) & vec4<u32>(255u);
|
|
49
|
+
}
|
|
50
|
+
fn signed4(word: u32) -> vec4<f32> {
|
|
51
|
+
let v = bitcast<i32>(word);
|
|
52
|
+
return vec4<f32>(f32((v << 24u) >> 24u), f32((v << 16u) >> 24u),
|
|
53
|
+
f32((v << 8u) >> 24u), f32(v >> 24u));
|
|
54
|
+
}
|
|
55
|
+
// Original interleaved GGUF blocks. Named words keep unaligned native loads
|
|
56
|
+
// and unpacking in registers instead of dynamically indexing a private array.
|
|
57
|
+
struct NativeBlock {
|
|
58
|
+
scale: f32, minimum: f32,
|
|
59
|
+
q0: u32, q1: u32, q2: u32, q3: u32,
|
|
60
|
+
q4: u32, q5: u32, q6: u32, q7: u32,
|
|
61
|
+
}
|
|
62
|
+
fn aligned_quants(low: u32, high: u32, unaligned: bool) -> u32 {
|
|
63
|
+
if (unaligned) { return high; }
|
|
64
|
+
return (low >> 16u) | (high << 16u);
|
|
65
|
+
}
|
|
66
|
+
fn load_native_block(base: u32) -> NativeBlock {
|
|
67
|
+
let first = base / 4u;
|
|
68
|
+
let unaligned = (base % 4u) != 0u;
|
|
69
|
+
let b0 = bank_word(first);
|
|
70
|
+
let b1 = bank_word(first + 1u);
|
|
71
|
+
let b2 = bank_word(first + 2u);
|
|
72
|
+
let b3 = bank_word(first + 3u);
|
|
73
|
+
let b4 = bank_word(first + 4u);
|
|
74
|
+
var block: NativeBlock;
|
|
75
|
+
block.scale = unpack2x16float(b0 >> select(0u, 16u, unaligned)).x;
|
|
76
|
+
if (QUANT_FORMAT == 1u) {
|
|
77
|
+
block.minimum = unpack2x16float(b0).y;
|
|
78
|
+
block.q0 = b1; block.q1 = b2; block.q2 = b3; block.q3 = b4;
|
|
79
|
+
} else {
|
|
80
|
+
block.q0 = aligned_quants(b0, b1, unaligned);
|
|
81
|
+
block.q1 = aligned_quants(b1, b2, unaligned);
|
|
82
|
+
block.q2 = aligned_quants(b2, b3, unaligned);
|
|
83
|
+
block.q3 = aligned_quants(b3, b4, unaligned);
|
|
84
|
+
}
|
|
85
|
+
if (QUANT_FORMAT == 2u) {
|
|
86
|
+
let b5 = bank_word(first + 5u);
|
|
87
|
+
let b6 = bank_word(first + 6u);
|
|
88
|
+
let b7 = bank_word(first + 7u);
|
|
89
|
+
let b8 = bank_word(first + 8u);
|
|
90
|
+
block.q4 = aligned_quants(b4, b5, unaligned);
|
|
91
|
+
block.q5 = aligned_quants(b5, b6, unaligned);
|
|
92
|
+
block.q6 = aligned_quants(b6, b7, unaligned);
|
|
93
|
+
block.q7 = aligned_quants(b7, b8, unaligned);
|
|
94
|
+
}
|
|
95
|
+
return block;
|
|
96
|
+
}
|
|
97
|
+
fn weight4(word: u32, high: bool, scale: f32, minimum: f32) -> vec4<f32> {
|
|
98
|
+
if (QUANT_FORMAT == 2u) { return scale * signed4(word); }
|
|
99
|
+
let q = (bytes4(word) >> vec4<u32>(select(0u, 4u, high))) & vec4<u32>(15u);
|
|
100
|
+
if (QUANT_FORMAT == 1u) { return scale * vec4<f32>(q) + vec4<f32>(minimum); }
|
|
101
|
+
return scale * (vec4<f32>(q) - vec4<f32>(8.0));
|
|
102
|
+
}
|
|
103
|
+
// Whole-vector stores only (overlapping component writes are unsafe on Metal). tile
|
|
104
|
+
// holds, per pair, the 8 blocks x 8 four-value groups of the current K tile:
|
|
105
|
+
// tile[pair * 64 + j * 8 + b] = input values 4j .. 4j + 3 of block b, the values
|
|
106
|
+
// weight4(j) multiplies, so lane b reads one vec4 per j, conflict free.
|
|
107
|
+
var<workgroup> tile: array<vec4<f32>, 512>;
|
|
108
|
+
var<workgroup> partial: array<f32, 1024>;
|
|
109
|
+
var<workgroup> route_ids: array<u32, 8>;
|
|
110
|
+
var<workgroup> chunk_count: u32;
|
|
111
|
+
// Keep each pair's dot sequence unchanged while the caller names its accumulator.
|
|
112
|
+
fn pair_dot(w0: vec4<f32>, w1: vec4<f32>, w2: vec4<f32>, w3: vec4<f32>,
|
|
113
|
+
w4: vec4<f32>, w5: vec4<f32>, w6: vec4<f32>, w7: vec4<f32>, p: u32, lane: u32) -> f32 {
|
|
114
|
+
var sum = 0.0;
|
|
115
|
+
sum += dot(w0, tile[p * 64u + 0u + lane]);
|
|
116
|
+
sum += dot(w1, tile[p * 64u + 8u + lane]);
|
|
117
|
+
sum += dot(w2, tile[p * 64u + 16u + lane]);
|
|
118
|
+
sum += dot(w3, tile[p * 64u + 24u + lane]);
|
|
119
|
+
sum += dot(w4, tile[p * 64u + 32u + lane]);
|
|
120
|
+
sum += dot(w5, tile[p * 64u + 40u + lane]);
|
|
121
|
+
sum += dot(w6, tile[p * 64u + 48u + lane]);
|
|
122
|
+
sum += dot(w7, tile[p * 64u + 56u + lane]);
|
|
123
|
+
return sum;
|
|
124
|
+
}
|
|
125
|
+
fn reduce_pair(p: u32, t: u32, row0: u32, acc: vec4<f32>) {
|
|
126
|
+
workgroupBarrier();
|
|
127
|
+
for (var r = 0u; r < ROWS_PER_THREAD; r++) {
|
|
128
|
+
partial[r * WORKGROUP_SIZE + t] = acc[r];
|
|
129
|
+
}
|
|
130
|
+
workgroupBarrier();
|
|
131
|
+
if (t < 32u * ROWS_PER_THREAD && row0 + t < u.N) {
|
|
132
|
+
let r = t / 32u; let row_lane = t % 32u;
|
|
133
|
+
var sum = 0.0;
|
|
134
|
+
for (var l = 0u; l < 8u; l++) { sum += partial[r * WORKGROUP_SIZE + row_lane * 8u + l]; }
|
|
135
|
+
output[route_ids[p] * u.N + row0 + t] = sum;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
@compute @workgroup_size(WORKGROUP_SIZE)
|
|
139
|
+
fn main(@builtin(workgroup_id) wg: vec3<u32>, @builtin(local_invocation_index) t: u32) {
|
|
140
|
+
if (t == 0u) { chunk_count = groups[wg.y * 4u + 1u]; }
|
|
141
|
+
let n = workgroupUniformLoad(&chunk_count);
|
|
142
|
+
let first = groups[wg.y * 4u];
|
|
143
|
+
let expert = groups[wg.y * 4u + 2u];
|
|
144
|
+
if (t < n) { route_ids[t] = groups[u.pair_offset + first + t]; }
|
|
145
|
+
let lane = t & 7u;
|
|
146
|
+
let row0 = wg.x * (32u * ROWS_PER_THREAD);
|
|
147
|
+
let blocks = u.K / 32u;
|
|
148
|
+
// Eight admitted route slots, with scalar-addressable row components.
|
|
149
|
+
var acc0: vec4<f32>;
|
|
150
|
+
var acc1: vec4<f32>;
|
|
151
|
+
var acc2: vec4<f32>;
|
|
152
|
+
var acc3: vec4<f32>;
|
|
153
|
+
var acc4: vec4<f32>;
|
|
154
|
+
var acc5: vec4<f32>;
|
|
155
|
+
var acc6: vec4<f32>;
|
|
156
|
+
var acc7: vec4<f32>;
|
|
157
|
+
for (var kt = 0u; kt < blocks; kt += 8u) {
|
|
158
|
+
workgroupBarrier();
|
|
159
|
+
for (var i = t; i < GROUP_SIZE * 64u; i += WORKGROUP_SIZE) {
|
|
160
|
+
let pair = i / 64u;
|
|
161
|
+
let j = (i / 8u) % 8u;
|
|
162
|
+
let b = i % 8u;
|
|
163
|
+
if (pair < n && kt + b < blocks) {
|
|
164
|
+
var input_row = route_ids[pair];
|
|
165
|
+
if (INPUT_IS_TOKEN) { input_row /= u.top_k; }
|
|
166
|
+
let k = input_row * u.K + (kt + b) * 32u + j * 4u;
|
|
167
|
+
tile[i] = vec4<f32>(input[k], input[k + 1u], input[k + 2u], input[k + 3u]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
workgroupBarrier();
|
|
171
|
+
let block_idx = kt + lane;
|
|
172
|
+
if (block_idx < blocks) {
|
|
173
|
+
for (var r = 0u; r < ROWS_PER_THREAD; r++) {
|
|
174
|
+
let row = row0 + r * 32u + (t >> 3u);
|
|
175
|
+
if (row < u.N) {
|
|
176
|
+
var bank_rows = u.N;
|
|
177
|
+
var bank_row = row;
|
|
178
|
+
use_up = false;
|
|
179
|
+
if (SPLIT_GATE_UP) {
|
|
180
|
+
bank_rows /= 2u;
|
|
181
|
+
use_up = row >= bank_rows;
|
|
182
|
+
bank_row = row % bank_rows;
|
|
183
|
+
}
|
|
184
|
+
// This lane's block of the row, dequantized once and reused by every
|
|
185
|
+
// pair: per (pair, row) the same sum in the same order.
|
|
186
|
+
let base = ((expert * bank_rows + bank_row) * blocks + block_idx) * BLOCK_BYTES;
|
|
187
|
+
let block = load_native_block(base);
|
|
188
|
+
let w0 = weight4(block.q0, false, block.scale, block.minimum);
|
|
189
|
+
let w1 = weight4(block.q1, false, block.scale, block.minimum);
|
|
190
|
+
let w2 = weight4(block.q2, false, block.scale, block.minimum);
|
|
191
|
+
let w3 = weight4(block.q3, false, block.scale, block.minimum);
|
|
192
|
+
let w4 = weight4(select(block.q0, block.q4, QUANT_FORMAT == 2u), true, block.scale, block.minimum);
|
|
193
|
+
let w5 = weight4(select(block.q1, block.q5, QUANT_FORMAT == 2u), true, block.scale, block.minimum);
|
|
194
|
+
let w6 = weight4(select(block.q2, block.q6, QUANT_FORMAT == 2u), true, block.scale, block.minimum);
|
|
195
|
+
let w7 = weight4(select(block.q3, block.q7, QUANT_FORMAT == 2u), true, block.scale, block.minimum);
|
|
196
|
+
if (n > 0u) { acc0[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 0u, lane); }
|
|
197
|
+
if (n > 1u) { acc1[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 1u, lane); }
|
|
198
|
+
if (n > 2u) { acc2[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 2u, lane); }
|
|
199
|
+
if (n > 3u) { acc3[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 3u, lane); }
|
|
200
|
+
if (n > 4u) { acc4[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 4u, lane); }
|
|
201
|
+
if (n > 5u) { acc5[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 5u, lane); }
|
|
202
|
+
if (n > 6u) { acc6[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 6u, lane); }
|
|
203
|
+
if (n > 7u) { acc7[r] += pair_dot(w0, w1, w2, w3, w4, w5, w6, w7, 7u, lane); }
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (n > 0u) { reduce_pair(0u, t, row0, acc0); }
|
|
209
|
+
if (n > 1u) { reduce_pair(1u, t, row0, acc1); }
|
|
210
|
+
if (n > 2u) { reduce_pair(2u, t, row0, acc2); }
|
|
211
|
+
if (n > 3u) { reduce_pair(3u, t, row0, acc3); }
|
|
212
|
+
if (n > 4u) { reduce_pair(4u, t, row0, acc4); }
|
|
213
|
+
if (n > 5u) { reduce_pair(5u, t, row0, acc5); }
|
|
214
|
+
if (n > 6u) { reduce_pair(6u, t, row0, acc6); }
|
|
215
|
+
if (n > 7u) { reduce_pair(7u, t, row0, acc7); }
|
|
216
|
+
}
|