doppler-gpu 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/README.md +97 -29
- package/package.json +40 -27
- package/src/cli/config/doppler-quickstart.json +10 -0
- package/src/cli/doppler-cli.js +66 -22
- package/src/cli/doppler-quickstart.d.ts +61 -0
- package/src/cli/doppler-quickstart.js +299 -0
- package/src/cli/doppler-serve.js +395 -0
- package/src/client/doppler-api.browser.js +13 -377
- package/src/client/doppler-api.d.ts +35 -56
- package/src/client/doppler-api.js +12 -363
- package/src/client/doppler-registry.json +55 -2
- package/src/client/runtime/index.d.ts +63 -0
- package/src/client/runtime/index.js +173 -0
- package/src/client/runtime/lora.d.ts +36 -0
- package/src/client/runtime/lora.js +165 -0
- package/src/client/{doppler-provider → runtime}/model-manager.d.ts +1 -1
- package/src/client/{doppler-provider → runtime}/model-manager.js +56 -30
- package/src/client/runtime/model-session.d.ts +72 -0
- package/src/client/runtime/model-session.js +122 -0
- package/src/client/runtime/model-source.d.ts +43 -0
- package/src/client/runtime/model-source.js +101 -0
- package/src/client/{doppler-provider → runtime}/source-runtime.d.ts +8 -5
- package/src/client/runtime/source-runtime.js +919 -0
- package/src/client/runtime/storage.d.ts +5 -0
- package/src/client/runtime/storage.js +51 -0
- package/src/client/{doppler-provider → runtime}/types.d.ts +14 -2
- package/src/config/README.md +2 -0
- package/src/config/conversion/README.md +47 -7
- package/src/config/conversion/embeddinggemma/google-embeddinggemma-300m-q4k-ehf16-af32.json +67 -5
- package/src/config/conversion/gemma3/gemma-3-1b-it-f16-af32.json +62 -11
- package/src/config/conversion/gemma3/gemma-3-1b-it-q4k-ehf16-af32.json +79 -18
- package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af32.json +61 -13
- package/src/config/conversion/gemma3/translategemma-4b-1b-enes-q4k-ehf16-af32.json +53 -10
- package/src/config/conversion/gemma3/translategemma-4b-it-q4k-ehf16-af32.json +66 -18
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32.json +256 -0
- package/src/config/conversion/gemma4/gemma-4-moe-q4k-ehf16-af32.json +49 -8
- package/src/config/conversion/gpt-oss-20b-f16-xmxfp4.json +45 -6
- package/src/config/conversion/janus/janus-pro-1b-text-q4k-ehaf16.json +45 -6
- package/src/config/conversion/lfm2/lfm2.5-1.2b-instruct-q4k-ehf16-af32.json +57 -9
- package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +105 -26
- package/src/config/conversion/qwen3/qwen-3-5-2b-q4k-ehaf16.json +83 -33
- package/src/config/conversion/sana/sana-sprint-0.6b-f16.json +33 -5
- package/src/config/execution-contract-check.d.ts +2 -1
- package/src/config/execution-contract-check.js +187 -53
- package/src/config/kernel-path-loader.d.ts +36 -0
- package/src/config/kernel-path-loader.js +97 -10
- package/src/config/kernels/kernel-ref-digests.js +40 -24
- package/src/config/kernels/registry.js +0 -1
- package/src/config/kernels/registry.json +772 -66
- package/src/config/merge-contract-check.js +3 -0
- package/src/config/merge.d.ts +18 -1
- package/src/config/merge.js +56 -0
- package/src/config/param-categories.js +5 -0
- package/src/config/param-validator.js +42 -26
- package/src/config/platforms/apple-m3.json +1 -1
- package/src/config/platforms/loader.js +21 -16
- package/src/config/required-inference-fields-contract-check.js +16 -0
- package/src/config/runtime/compute/f16-batched.json +2 -0
- package/src/config/runtime/default.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +57 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +57 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +2 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +57 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +57 -0
- package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +81 -0
- package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +5 -0
- package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +81 -0
- package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +38 -0
- package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +63 -0
- package/src/config/runtime/profiles/gemma4-e2b-throughput.json +39 -0
- package/src/config/runtime/profiles/low-memory.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous-prod.json +29 -0
- package/src/config/runtime/profiles/turboquant-contiguous.json +29 -0
- package/src/config/runtime/profiles/turboquant.json +36 -0
- package/src/config/runtime/profiles/vector-stability.json +1 -0
- package/src/config/runtime/tiers/gemma4-128gb.json +79 -0
- package/src/config/runtime/tiers/gemma4-16gb.json +15 -2
- package/src/config/runtime/tiers/gemma4-24gb.json +15 -2
- package/src/config/runtime/tiers/gemma4-32gb.json +15 -2
- package/src/config/runtime.js +11 -4
- package/src/config/schema/converter.schema.d.ts +4 -2
- package/src/config/schema/converter.schema.js +7 -5
- package/src/config/schema/doppler.schema.d.ts +26 -2
- package/src/config/schema/doppler.schema.js +77 -28
- package/src/config/schema/execution-v1.schema.d.ts +78 -5
- package/src/config/schema/execution-v1.schema.js +62 -1
- package/src/config/schema/index.d.ts +22 -29
- package/src/config/schema/index.js +15 -17
- package/src/config/schema/inference.schema.d.ts +26 -4
- package/src/config/schema/kernel-path.schema.d.ts +30 -3
- package/src/config/schema/kernel-registry.schema.d.ts +1 -1
- package/src/config/schema/kernel-registry.schema.js +1 -0
- package/src/config/schema/kvcache.schema.js +7 -0
- package/src/config/schema/loading.schema.d.ts +28 -0
- package/src/config/schema/loading.schema.js +9 -0
- package/src/config/schema/manifest.schema.d.ts +79 -5
- package/src/config/schema/manifest.schema.js +7 -1
- package/src/config/schema/platform.schema.d.ts +10 -8
- package/src/config/schema/speculation-self.schema.js +0 -5
- package/src/config/schema/support-tiers.schema.d.ts +53 -0
- package/src/config/schema/support-tiers.schema.js +128 -0
- package/src/config/source-packages/litert/gemma-4-e2b-it.json +622 -0
- package/src/config/source-packages/registry.json +15 -0
- package/src/config/support-tiers/subsystems.json +502 -0
- package/src/config/transforms/capability-transform-resolver.d.ts +16 -5
- package/src/config/transforms/capability-transform-resolver.js +44 -9
- package/src/config/transforms/execution-graph-transforms.d.ts +113 -2
- package/src/config/transforms/execution-graph-transforms.js +1220 -8
- package/src/converter/conversion-plan.js +20 -8
- package/src/converter/core.d.ts +48 -1
- package/src/converter/core.js +249 -62
- package/src/converter/parsers/gguf.d.ts +10 -1
- package/src/converter/rope-config.d.ts +1 -0
- package/src/converter/rope-config.js +75 -5
- package/src/converter/shard-packer.js +2 -2
- package/src/debug/tensor.js +13 -1
- package/src/{adapters → experimental/adapters}/adapter-manager.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/adapter-manager.js +2 -2
- package/src/{adapters → experimental/adapters}/adapter-manifest.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/adapter-manifest.js +1 -1
- package/src/{adapters → experimental/adapters}/adapter-registry.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/adapter-registry.js +1 -1
- package/src/{adapters → experimental/adapters}/lora-loader.d.ts +1 -1
- package/src/{adapters → experimental/adapters}/lora-loader.js +2 -2
- package/src/{bridge → experimental/bridge}/extension-client.js +2 -2
- package/src/{bridge → experimental/bridge}/node-bridge.js +2 -4
- package/src/{bridge → experimental/bridge}/protocol.js +1 -1
- package/src/{browser → experimental/browser}/browser-converter.d.ts +4 -4
- package/src/{browser → experimental/browser}/browser-converter.js +12 -12
- package/src/{browser → experimental/browser}/gguf-importer.d.ts +1 -1
- package/src/{browser → experimental/browser}/gguf-importer.js +8 -8
- package/src/{browser → experimental/browser}/gguf-parser-browser.d.ts +2 -2
- package/src/{browser → experimental/browser}/gguf-parser-browser.js +3 -3
- package/src/{browser → experimental/browser}/quantization.d.ts +3 -3
- package/src/{browser → experimental/browser}/quantization.js +4 -4
- package/src/{browser → experimental/browser}/safetensors-parser-browser.d.ts +3 -3
- package/src/{browser → experimental/browser}/safetensors-parser-browser.js +3 -3
- package/src/{browser → experimental/browser}/shard-io-browser.d.ts +1 -1
- package/src/{browser → experimental/browser}/shard-io-browser.js +2 -2
- package/src/{browser → experimental/browser}/tensor-source-download.js +3 -3
- package/src/experimental/diffusion/index.d.ts +8 -0
- package/src/experimental/diffusion/index.js +8 -0
- package/src/{distribution → experimental/distribution}/p2p-transport-contract.js +1 -1
- package/src/{distribution → experimental/distribution}/p2p-transport.js +1 -1
- package/src/{distribution → experimental/distribution}/shard-delivery.js +5 -5
- package/src/experimental/energy/index.d.ts +2 -0
- package/src/experimental/energy/index.js +2 -0
- package/src/{hotswap → experimental/hotswap}/intent-bundle.d.ts +1 -1
- package/src/{hotswap → experimental/hotswap}/intent-bundle.js +2 -2
- package/src/{hotswap → experimental/hotswap}/manifest.d.ts +2 -2
- package/src/{hotswap → experimental/hotswap}/manifest.js +1 -1
- package/src/{hotswap → experimental/hotswap}/model-swap.js +1 -1
- package/src/{hotswap → experimental/hotswap}/runtime.d.ts +1 -1
- package/src/experimental/orchestration/index.d.ts +12 -0
- package/src/experimental/orchestration/index.js +12 -0
- package/src/{training → experimental/training}/README.md +1 -1
- package/src/{training → experimental/training}/artifacts.d.ts +3 -3
- package/src/{training → experimental/training}/artifacts.js +3 -3
- package/src/{training → experimental/training}/attention-backward.d.ts +1 -1
- package/src/{training → experimental/training}/attention-backward.js +3 -3
- package/src/{training → experimental/training}/attention-forward.d.ts +2 -2
- package/src/{training → experimental/training}/attention-forward.js +1 -1
- package/src/{training → experimental/training}/autograd.d.ts +2 -2
- package/src/{training → experimental/training}/autograd.js +7 -7
- package/src/{training → experimental/training}/backward-kernels.js +1 -1
- package/src/{training → experimental/training}/checkpoint.js +1 -1
- package/src/{training → experimental/training}/clip.d.ts +2 -2
- package/src/{training → experimental/training}/clip.js +3 -3
- package/src/{training → experimental/training}/export.d.ts +2 -2
- package/src/{training → experimental/training}/export.js +2 -2
- package/src/{training → experimental/training}/lora-pipeline.js +4 -4
- package/src/{training → experimental/training}/lora.d.ts +1 -1
- package/src/{training → experimental/training}/lora.js +4 -4
- package/src/{training → experimental/training}/loss-scaling.d.ts +2 -2
- package/src/{training → experimental/training}/loss-scaling.js +3 -3
- package/src/{training → experimental/training}/loss.d.ts +2 -2
- package/src/{training → experimental/training}/loss.js +1 -1
- package/src/{training → experimental/training}/operator-artifacts.js +1 -1
- package/src/{training → experimental/training}/optimizer.d.ts +2 -2
- package/src/{training → experimental/training}/optimizer.js +3 -3
- package/src/{training → experimental/training}/runner.d.ts +2 -2
- package/src/{training → experimental/training}/runner.js +5 -5
- package/src/{training → experimental/training}/suite.js +16 -16
- package/src/{training → experimental/training}/tensor-factory.d.ts +1 -1
- package/src/{training → experimental/training}/tensor-factory.js +2 -2
- package/src/{training → experimental/training}/trainer.d.ts +3 -3
- package/src/{training → experimental/training}/trainer.js +3 -3
- package/src/{training → experimental/training}/ul_dataset.d.ts +2 -2
- package/src/{training → experimental/training}/ul_dataset.js +1 -1
- package/src/{training → experimental/training}/ul_schedule.d.ts +1 -1
- package/src/{training → experimental/training}/workloads.js +4 -4
- package/src/formats/index.d.ts +24 -0
- package/src/formats/index.js +6 -0
- package/src/formats/litert/index.d.ts +1 -0
- package/src/formats/litert/index.js +1 -0
- package/src/formats/litert/types.d.ts +87 -0
- package/src/formats/litert/types.js +568 -0
- package/src/formats/rdrr/classification.js +16 -8
- package/src/formats/rdrr/parsing.d.ts +3 -2
- package/src/formats/rdrr/types.d.ts +33 -0
- package/src/formats/rdrr/validation.js +16 -5
- package/src/formats/tflite/index.d.ts +1 -0
- package/src/formats/tflite/index.js +1 -0
- package/src/formats/tflite/types.d.ts +84 -0
- package/src/formats/tflite/types.js +633 -0
- package/src/generation/index.d.ts +16 -14
- package/src/generation/index.js +1 -32
- package/src/gpu/command-recorder.d.ts +17 -1
- package/src/gpu/command-recorder.js +47 -10
- package/src/gpu/device.d.ts +3 -1
- package/src/gpu/device.js +17 -11
- package/src/gpu/kernel-selector.js +3 -1
- package/src/gpu/kernels/attention.d.ts +2 -0
- package/src/gpu/kernels/attention.js +359 -14
- package/src/gpu/kernels/attention.wgsl +20 -1
- package/src/gpu/kernels/attention_decode_contiguous_turboquant_f16kv.wgsl +180 -0
- package/src/gpu/kernels/attention_decode_contiguous_turboquant_prod_f16kv.wgsl +192 -0
- package/src/gpu/kernels/attention_decode_online_f16.wgsl +36 -18
- package/src/gpu/kernels/attention_decode_online_f16kv.wgsl +36 -18
- package/src/gpu/kernels/attention_decode_tiered_turboquant_f16kv.wgsl +269 -0
- package/src/gpu/kernels/attention_decode_tiered_turboquant_prod_f16kv.wgsl +281 -0
- package/src/gpu/kernels/attention_head256_f16kv.wgsl +269 -0
- package/src/gpu/kernels/attention_streaming.wgsl +22 -3
- package/src/gpu/kernels/attention_streaming_f16.wgsl +1 -1
- package/src/gpu/kernels/attention_streaming_f16kv.wgsl +1 -1
- package/src/gpu/kernels/backward/attention_backward.d.ts +14 -1
- package/src/gpu/kernels/check-hot-vocab-stop.d.ts +18 -0
- package/src/gpu/kernels/check-hot-vocab-stop.js +108 -0
- package/src/gpu/kernels/codegen/patches/attention_streaming_f16.from.attention_streaming.diff +1 -1
- package/src/gpu/kernels/codegen/patches/attention_streaming_f16kv.from.attention_streaming.diff +1 -1
- package/src/gpu/kernels/codegen/patches/rope_f16.from.rope.diff +126 -194
- package/src/gpu/kernels/codegen/wgsl-variants.js +24 -6
- package/src/gpu/kernels/depthwise_conv1d.d.ts +23 -0
- package/src/gpu/kernels/depthwise_conv1d.js +51 -0
- package/src/gpu/kernels/depthwise_conv1d.wgsl +46 -0
- package/src/gpu/kernels/feature-check.js +0 -1
- package/src/gpu/kernels/fused_ffn.js +67 -22
- package/src/gpu/kernels/fused_ffn_q4k.wgsl +48 -43
- package/src/gpu/kernels/fused_ffn_q4k_f16.wgsl +329 -0
- package/src/gpu/kernels/fused_matmul_q4.wgsl +417 -0
- package/src/gpu/kernels/fused_matmul_q4_batched_multicol_shared.wgsl +174 -0
- package/src/gpu/kernels/gather.d.ts +4 -0
- package/src/gpu/kernels/gather.js +13 -2
- package/src/gpu/kernels/gather.wgsl +5 -3
- package/src/gpu/kernels/gather_f16.wgsl +5 -3
- package/src/gpu/kernels/index.d.ts +7 -0
- package/src/gpu/kernels/index.js +6 -0
- package/src/gpu/kernels/kernel-configs.js +1 -0
- package/src/gpu/kernels/kv-quantize.js +87 -55
- package/src/gpu/kernels/kv_quantize_turboquant.wgsl +153 -0
- package/src/gpu/kernels/kv_quantize_turboquant_prod.wgsl +230 -0
- package/src/gpu/kernels/linear-attention-core.d.ts +3 -0
- package/src/gpu/kernels/linear-attention-core.js +145 -56
- package/src/gpu/kernels/matmul-dispatch.js +3 -0
- package/src/gpu/kernels/matmul-selection.js +31 -42
- package/src/gpu/kernels/matmul.d.ts +3 -0
- package/src/gpu/kernels/matmul.js +72 -34
- package/src/gpu/kernels/residual.d.ts +2 -0
- package/src/gpu/kernels/residual.js +43 -4
- package/src/gpu/kernels/rope.d.ts +2 -0
- package/src/gpu/kernels/rope.js +19 -6
- package/src/gpu/kernels/rope.wgsl +24 -12
- package/src/gpu/kernels/rope_f16.wgsl +97 -38
- package/src/gpu/kernels/scale.d.ts +5 -0
- package/src/gpu/kernels/scale.js +6 -1
- package/src/gpu/kernels/scale.wgsl +3 -1
- package/src/gpu/kernels/scale_f16.wgsl +32 -0
- package/src/gpu/kernels/turboquant-codebook.js +564 -0
- package/src/gpu/kernels/uniform-utils.js +26 -0
- package/src/gpu/kernels/utils.js +6 -1
- package/src/gpu/submit-probe.d.ts +12 -0
- package/src/gpu/submit-probe.js +77 -0
- package/src/gpu/weight-buffer.d.ts +26 -3
- package/src/gpu/weight-buffer.js +62 -2
- package/src/index-browser.d.ts +1 -91
- package/src/index-browser.js +0 -66
- package/src/index.d.ts +1 -102
- package/src/index.js +0 -74
- package/src/inference/browser-harness-model-helpers.d.ts +3 -0
- package/src/inference/browser-harness-model-helpers.js +134 -11
- package/src/inference/browser-harness-runtime-helpers.js +1 -9
- package/src/inference/browser-harness-text-helpers.js +441 -70
- package/src/inference/browser-harness.js +61 -4
- package/src/inference/decode-ring.d.ts +2 -0
- package/src/inference/decode-ring.js +20 -0
- package/src/inference/kv-cache/index.d.ts +3 -0
- package/src/inference/kv-cache/index.js +2 -0
- package/src/inference/kv-cache/mixed-geometry.d.ts +84 -0
- package/src/inference/kv-cache/mixed-geometry.js +422 -0
- package/src/inference/kv-cache/quantized.d.ts +56 -0
- package/src/inference/kv-cache/quantized.js +383 -0
- package/src/inference/kv-cache/tiered.d.ts +20 -3
- package/src/inference/kv-cache/tiered.js +203 -65
- package/src/inference/kv-cache/types.d.ts +49 -6
- package/src/inference/kv-cache.d.ts +3 -0
- package/src/inference/kv-cache.js +2 -0
- package/src/inference/multi-model-network.js +2 -1
- package/src/inference/pipelines/audio/gemma4.js +655 -0
- package/src/inference/pipelines/audio/index.js +39 -0
- package/src/inference/pipelines/audio/mel.js +171 -0
- package/src/inference/pipelines/context.js +9 -1
- package/src/inference/pipelines/diffusion/text-encoder-gpu.js +2 -0
- package/src/inference/pipelines/shared/clipped-linear.js +46 -0
- package/src/inference/pipelines/text/attention/dispatch-params.d.ts +2 -1
- package/src/inference/pipelines/text/attention/dispatch-params.js +52 -8
- package/src/inference/pipelines/text/attention/output-projection.js +3 -3
- package/src/inference/pipelines/text/attention/precision-contract.d.ts +36 -0
- package/src/inference/pipelines/text/attention/precision-contract.js +115 -0
- package/src/inference/pipelines/text/attention/projections.d.ts +23 -0
- package/src/inference/pipelines/text/attention/projections.js +182 -15
- package/src/inference/pipelines/text/attention/quant-options.js +54 -0
- package/src/inference/pipelines/text/attention/record.js +257 -69
- package/src/inference/pipelines/text/attention/run.js +306 -94
- package/src/inference/pipelines/text/attention/types.d.ts +11 -0
- package/src/inference/pipelines/text/chat-format.d.ts +8 -1
- package/src/inference/pipelines/text/chat-format.js +89 -5
- package/src/inference/pipelines/text/config.d.ts +78 -26
- package/src/inference/pipelines/text/config.js +722 -28
- package/src/inference/pipelines/text/dtype-contract.d.ts +15 -0
- package/src/inference/pipelines/text/dtype-contract.js +38 -0
- package/src/inference/pipelines/text/embed.d.ts +4 -0
- package/src/inference/pipelines/text/embed.js +165 -172
- package/src/inference/pipelines/text/execution-plan.d.ts +19 -0
- package/src/inference/pipelines/text/execution-plan.js +112 -20
- package/src/inference/pipelines/text/execution-runtime-builders.d.ts +8 -4
- package/src/inference/pipelines/text/execution-runtime-builders.js +90 -49
- package/src/inference/pipelines/text/execution-v1.d.ts +23 -4
- package/src/inference/pipelines/text/execution-v1.js +411 -33
- package/src/inference/pipelines/text/ffn/dense.d.ts +59 -0
- package/src/inference/pipelines/text/ffn/dense.js +575 -63
- package/src/inference/pipelines/text/ffn/moe.js +1 -0
- package/src/inference/pipelines/text/ffn/sandwich.js +20 -4
- package/src/inference/pipelines/text/ffn/standard.js +28 -4
- package/src/inference/pipelines/text/finiteness-policy.d.ts +4 -0
- package/src/inference/pipelines/text/finiteness-policy.js +14 -11
- package/src/inference/pipelines/text/generator-helpers.d.ts +7 -0
- package/src/inference/pipelines/text/generator-helpers.js +39 -4
- package/src/inference/pipelines/text/generator-runtime.js +45 -8
- package/src/inference/pipelines/text/generator-steps.js +407 -75
- package/src/inference/pipelines/text/generator.d.ts +6 -0
- package/src/inference/pipelines/text/generator.js +1179 -305
- package/src/inference/pipelines/text/init.d.ts +39 -7
- package/src/inference/pipelines/text/init.js +525 -110
- package/src/inference/pipelines/text/layer-plan.d.ts +1 -0
- package/src/inference/pipelines/text/layer-plan.js +2 -0
- package/src/inference/pipelines/text/layer.js +402 -19
- package/src/inference/pipelines/text/linear-attention.d.ts +4 -0
- package/src/inference/pipelines/text/linear-attention.js +112 -41
- package/src/inference/pipelines/text/logits/gpu.d.ts +2 -1
- package/src/inference/pipelines/text/logits/gpu.js +334 -15
- package/src/inference/pipelines/text/logits/index.d.ts +11 -0
- package/src/inference/pipelines/text/logits/index.js +227 -29
- package/src/inference/pipelines/text/logits/types.d.ts +3 -0
- package/src/inference/pipelines/text/logits/utils.js +3 -1
- package/src/inference/pipelines/text/lora-apply.js +3 -3
- package/src/inference/pipelines/text/model-load.d.ts +2 -1
- package/src/inference/pipelines/text/model-load.js +205 -178
- package/src/inference/pipelines/text/moe-gpu.js +8 -0
- package/src/inference/pipelines/text/moe-impl.d.ts +2 -0
- package/src/inference/pipelines/text/ops.d.ts +16 -2
- package/src/inference/pipelines/text/ops.js +11 -2
- package/src/inference/pipelines/text/per-layer-inputs.d.ts +107 -0
- package/src/inference/pipelines/text/per-layer-inputs.js +1581 -0
- package/src/inference/pipelines/text/probes.js +6 -0
- package/src/inference/pipelines/text/sampling-config.js +9 -1
- package/src/inference/pipelines/text/stage-names.js +3 -0
- package/src/inference/pipelines/text/state.d.ts +12 -3
- package/src/inference/pipelines/text/state.js +19 -0
- package/src/inference/pipelines/text/types.d.ts +79 -7
- package/src/inference/pipelines/text/weights.d.ts +2 -2
- package/src/inference/pipelines/text/weights.js +4 -0
- package/src/inference/pipelines/text.d.ts +6 -0
- package/src/inference/pipelines/text.js +860 -11
- package/src/inference/pipelines/video/frame-sampler.js +36 -0
- package/src/inference/pipelines/video/index.js +87 -0
- package/src/inference/pipelines/vision/encoder.js +27 -6
- package/src/inference/pipelines/vision/gemma4.js +731 -0
- package/src/inference/pipelines/vision/image-preprocess.js +22 -7
- package/src/inference/pipelines/vision/index.js +35 -10
- package/src/inference/pipelines/vision/ops.js +31 -26
- package/src/inference/pipelines/vision/patch-embed.js +22 -10
- package/src/inference/runtime-model.d.ts +89 -0
- package/src/inference/runtime-model.js +152 -0
- package/src/inference/test-harness.d.ts +8 -1
- package/src/inference/test-harness.js +54 -20
- package/src/inference/tokenizer.d.ts +5 -0
- package/src/inference/tokenizer.js +43 -0
- package/src/inference/tokenizers/base.d.ts +5 -0
- package/src/inference/tokenizers/base.js +5 -0
- package/src/inference/tokenizers/behavior-flags.d.ts +9 -0
- package/src/inference/tokenizers/behavior-flags.js +100 -0
- package/src/inference/tokenizers/bundled.d.ts +4 -0
- package/src/inference/tokenizers/bundled.js +110 -0
- package/src/inference/tokenizers/sentencepiece.d.ts +2 -0
- package/src/inference/tokenizers/sentencepiece.js +16 -0
- package/src/inference/tokenizers/types.d.ts +2 -0
- package/src/loader/doppler-loader.d.ts +10 -3
- package/src/loader/doppler-loader.js +103 -5
- package/src/loader/embedding-loader.d.ts +5 -1
- package/src/loader/embedding-loader.js +57 -6
- package/src/loader/final-weights-loader.js +44 -5
- package/src/loader/layer-loader.js +210 -8
- package/src/loader/loader-state.js +2 -2
- package/src/loader/loader-types.d.ts +17 -1
- package/src/loader/memory-monitor.d.ts +8 -0
- package/src/loader/memory-monitor.js +21 -0
- package/src/loader/multi-model-loader.d.ts +9 -1
- package/src/loader/multi-model-loader.js +9 -1
- package/src/loader/per-layer-input-loader.d.ts +30 -0
- package/src/loader/per-layer-input-loader.js +478 -0
- package/src/loader/shard-cache.d.ts +4 -3
- package/src/loader/shard-resolver.js +2 -0
- package/src/loader/tensors/source-transform.d.ts +50 -0
- package/src/loader/tensors/source-transform.js +776 -0
- package/src/loader/tensors/tensor-loader.d.ts +12 -0
- package/src/loader/tensors/tensor-loader.js +208 -123
- package/src/loader/tensors/tensor-reader.d.ts +8 -0
- package/src/loader/tensors/tensor-reader.js +283 -15
- package/src/loaders/index.d.ts +4 -0
- package/src/loaders/index.js +4 -0
- package/src/memory/buffer-pool.d.ts +4 -0
- package/src/memory/buffer-pool.js +36 -0
- package/src/rules/execution-rules-contract-check.d.ts +4 -0
- package/src/rules/execution-rules-contract-check.js +150 -24
- package/src/rules/inference/attention.rules.json +15 -0
- package/src/rules/inference/capability-transforms.rules.json +30 -0
- package/src/rules/inference/execution.rules.json +54 -2
- package/src/rules/inference/ffn.rules.json +33 -0
- package/src/rules/kernels/attention.rules.json +7 -0
- package/src/rules/kernels/fused-ffn.rules.json +4 -2
- package/src/rules/kernels/kv_quantize.rules.json +2 -0
- package/src/rules/kernels/matmul.rules.json +14 -0
- package/src/rules/kernels/scale.rules.json +2 -0
- package/src/rules/loader/tensor-loader.rules.json +1 -0
- package/src/storage/artifact-storage-context.d.ts +53 -0
- package/src/storage/artifact-storage-context.js +560 -0
- package/src/storage/downloader.js +7 -1
- package/src/storage/index.d.ts +18 -0
- package/src/storage/index.js +13 -0
- package/src/storage/preflight.js +22 -0
- package/src/storage/quickstart-downloader.js +35 -2
- package/src/storage/registry.d.ts +1 -0
- package/src/storage/registry.js +26 -4
- package/src/storage/shard-manager.d.ts +4 -0
- package/src/storage/shard-manager.js +25 -6
- package/src/storage/source-artifact-store.d.ts +9 -0
- package/src/storage/source-artifact-store.js +134 -0
- package/src/tooling/browser-command-runner.js +12 -5
- package/src/tooling/command-api-family-normalizers.js +144 -0
- package/src/tooling/command-api-helpers.js +1 -0
- package/src/tooling/command-api.d.ts +32 -9
- package/src/tooling/command-api.js +0 -25
- package/src/tooling/command-runner-shared.js +1 -2
- package/src/tooling/command-runner.html +5 -2
- package/src/tooling/diagnose-runner.js +1 -1
- package/src/tooling/kernel-path-builder/index.js +48 -32
- package/src/tooling/lean-execution-contract.d.ts +1 -1
- package/src/tooling/lean-execution-contract.js +2 -149
- package/src/tooling/litert-package-runtime.d.ts +46 -0
- package/src/tooling/litert-package-runtime.js +950 -0
- package/src/tooling/node-browser-command-runner.d.ts +13 -0
- package/src/tooling/node-browser-command-runner.js +163 -3
- package/src/tooling/node-command-runner.js +14 -5
- package/src/tooling/node-converter.js +226 -63
- package/src/tooling/node-source-runtime.d.ts +8 -3
- package/src/tooling/node-source-runtime.js +561 -236
- package/src/tooling/node-webgpu.js +7 -30
- package/src/tooling/opfs-cache.d.ts +18 -1
- package/src/tooling/opfs-cache.js +126 -9
- package/src/tooling/runtime-input-composition.d.ts +0 -1
- package/src/tooling/runtime-input-composition.js +0 -5
- package/src/tooling/source-artifact-adapter.d.ts +134 -0
- package/src/tooling/source-artifact-adapter.js +366 -0
- package/src/tooling/source-package-profiles.d.ts +33 -0
- package/src/tooling/source-package-profiles.js +57 -0
- package/src/tooling/source-runtime-bundle.d.ts +46 -6
- package/src/tooling/source-runtime-bundle.js +371 -60
- package/src/tooling/source-runtime-converter-config.d.ts +24 -0
- package/src/tooling/source-runtime-converter-config.js +297 -0
- package/src/tooling-experimental-exports.browser.js +2 -0
- package/src/tooling-experimental-exports.d.ts +7 -0
- package/src/tooling-experimental-exports.js +7 -0
- package/src/tooling-experimental-exports.shared.d.ts +26 -0
- package/src/tooling-experimental-exports.shared.js +29 -0
- package/src/tooling-exports.shared.d.ts +0 -23
- package/src/tooling-exports.shared.js +6 -28
- package/src/version.js +1 -1
- package/src/client/doppler-provider/generation.d.ts +0 -25
- package/src/client/doppler-provider/generation.js +0 -126
- package/src/client/doppler-provider/index.d.ts +0 -2
- package/src/client/doppler-provider/index.js +0 -3
- package/src/client/doppler-provider/provider.d.ts +0 -5
- package/src/client/doppler-provider/provider.js +0 -102
- package/src/client/doppler-provider/source-runtime.js +0 -677
- package/src/client/doppler-provider.d.ts +0 -46
- package/src/client/doppler-provider.js +0 -36
- package/src/config/schema/inference-defaults.schema.d.ts +0 -276
- package/src/config/schema/inference-defaults.schema.js +0 -189
- package/src/diffusion/index.d.ts +0 -8
- package/src/diffusion/index.js +0 -8
- package/src/energy/index.d.ts +0 -2
- package/src/energy/index.js +0 -2
- package/src/index-internal.d.ts +0 -2
- package/src/index-internal.js +0 -2
- /package/src/client/{doppler-provider → runtime}/types.js +0 -0
- /package/src/{adapters → experimental/adapters}/index.d.ts +0 -0
- /package/src/{adapters → experimental/adapters}/index.js +0 -0
- /package/src/{bridge → experimental/bridge}/extension/background.d.ts +0 -0
- /package/src/{bridge → experimental/bridge}/extension/background.js +0 -0
- /package/src/{bridge → experimental/bridge}/extension/manifest.json +0 -0
- /package/src/{bridge → experimental/bridge}/extension-client.d.ts +0 -0
- /package/src/{bridge → experimental/bridge}/index.d.ts +0 -0
- /package/src/{bridge → experimental/bridge}/index.js +0 -0
- /package/src/{bridge → experimental/bridge}/protocol.d.ts +0 -0
- /package/src/{browser → experimental/browser}/file-picker.d.ts +0 -0
- /package/src/{browser → experimental/browser}/file-picker.js +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-download.d.ts +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-file.d.ts +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-file.js +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-http.d.ts +0 -0
- /package/src/{browser → experimental/browser}/tensor-source-http.js +0 -0
- /package/src/{diffusion → experimental/diffusion}/config/expansion-lanes.json +0 -0
- /package/src/{diffusion → experimental/diffusion}/image-regression.d.ts +0 -0
- /package/src/{diffusion → experimental/diffusion}/image-regression.js +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-control-plane.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-control-plane.js +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-observability.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-observability.js +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-transport-contract.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-webrtc-browser.d.ts +0 -0
- /package/src/{distribution → experimental/distribution}/p2p-webrtc-browser.js +0 -0
- /package/src/{distribution → experimental/distribution}/shard-delivery.d.ts +0 -0
- /package/src/{hotswap → experimental/hotswap}/runtime.js +0 -0
- /package/src/{training → experimental/training}/checkpoint-watch.d.ts +0 -0
- /package/src/{training → experimental/training}/checkpoint-watch.js +0 -0
- /package/src/{training → experimental/training}/checkpoint.d.ts +0 -0
- /package/src/{training → experimental/training}/dataloader.d.ts +0 -0
- /package/src/{training → experimental/training}/dataloader.js +0 -0
- /package/src/{training → experimental/training}/datasets/index.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/index.js +0 -0
- /package/src/{training → experimental/training}/datasets/jsonl.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/jsonl.js +0 -0
- /package/src/{training → experimental/training}/datasets/reploid.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/reploid.js +0 -0
- /package/src/{training → experimental/training}/datasets/text-pairs.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/text-pairs.js +0 -0
- /package/src/{training → experimental/training}/datasets/token-batch.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/token-batch.js +0 -0
- /package/src/{training → experimental/training}/datasets/translation-pairs.d.ts +0 -0
- /package/src/{training → experimental/training}/datasets/translation-pairs.js +0 -0
- /package/src/{training → experimental/training}/distillation/artifacts.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/artifacts.js +0 -0
- /package/src/{training → experimental/training}/distillation/checkpoint-watch.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/checkpoint-watch.js +0 -0
- /package/src/{training → experimental/training}/distillation/dataset.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/dataset.js +0 -0
- /package/src/{training → experimental/training}/distillation/eval.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/eval.js +0 -0
- /package/src/{training → experimental/training}/distillation/index.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/index.js +0 -0
- /package/src/{training → experimental/training}/distillation/runtime.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/runtime.js +0 -0
- /package/src/{training → experimental/training}/distillation/scoreboard.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/scoreboard.js +0 -0
- /package/src/{training → experimental/training}/distillation/stage-a.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/stage-a.js +0 -0
- /package/src/{training → experimental/training}/distillation/stage-b.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/stage-b.js +0 -0
- /package/src/{training → experimental/training}/distillation/student-fixture.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/student-fixture.js +0 -0
- /package/src/{training → experimental/training}/distillation/suite-data.d.ts +0 -0
- /package/src/{training → experimental/training}/distillation/suite-data.js +0 -0
- /package/src/{training → experimental/training}/index.d.ts +0 -0
- /package/src/{training → experimental/training}/index.js +0 -0
- /package/src/{training → experimental/training}/lora-pipeline.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/base.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/base.js +0 -0
- /package/src/{training → experimental/training}/objectives/cross_entropy.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/cross_entropy.js +0 -0
- /package/src/{training → experimental/training}/objectives/distill_kd.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/distill_kd.js +0 -0
- /package/src/{training → experimental/training}/objectives/distill_triplet.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/distill_triplet.js +0 -0
- /package/src/{training → experimental/training}/objectives/index.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/index.js +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage1_joint.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage1_joint.js +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage2_base.d.ts +0 -0
- /package/src/{training → experimental/training}/objectives/ul_stage2_base.js +0 -0
- /package/src/{training → experimental/training}/operator-artifacts.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-command.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-command.js +0 -0
- /package/src/{training → experimental/training}/operator-eval.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-eval.js +0 -0
- /package/src/{training → experimental/training}/operator-scoreboard.d.ts +0 -0
- /package/src/{training → experimental/training}/operator-scoreboard.js +0 -0
- /package/src/{training → experimental/training}/suite.d.ts +0 -0
- /package/src/{training → experimental/training}/ul_schedule.js +0 -0
- /package/src/{training → experimental/training}/workload-packs/distill-translategemma-medium.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/distill-translategemma-tiny.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/lora-toy-medium.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/lora-toy-tiny.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/registry.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/ul-training-medium.json +0 -0
- /package/src/{training → experimental/training}/workload-packs/ul-training-tiny.json +0 -0
- /package/src/{training → experimental/training}/workloads.d.ts +0 -0
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
import { float32ToFloat16 } from '../../converter/quantizer.js';
|
|
2
|
+
|
|
3
|
+
function computeElementCount(shape, tensorName) {
|
|
4
|
+
if (!Array.isArray(shape)) {
|
|
5
|
+
throw new Error(`[DopplerLoader] Tensor "${tensorName}" shape must be an array.`);
|
|
6
|
+
}
|
|
7
|
+
let total = 1;
|
|
8
|
+
for (let index = 0; index < shape.length; index++) {
|
|
9
|
+
const value = Number(shape[index]);
|
|
10
|
+
if (!Number.isFinite(value) || Math.floor(value) !== value || value < 0) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid shape[${index}] (${shape[index]}).`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
total *= value;
|
|
16
|
+
}
|
|
17
|
+
return total;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function computeSourceByteLength(elementCount, sourceDtype, tensorName) {
|
|
21
|
+
if (sourceDtype === 'INT8' || sourceDtype === 'UINT8') {
|
|
22
|
+
return elementCount;
|
|
23
|
+
}
|
|
24
|
+
if (sourceDtype === 'INT4') {
|
|
25
|
+
return Math.ceil(elementCount / 2);
|
|
26
|
+
}
|
|
27
|
+
if (sourceDtype === 'INT2') {
|
|
28
|
+
return Math.ceil(elementCount / 4);
|
|
29
|
+
}
|
|
30
|
+
throw new Error(
|
|
31
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.sourceDtype "${sourceDtype}".`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getPackedValuesPerByte(sourceDtype, tensorName) {
|
|
36
|
+
if (sourceDtype === 'INT8' || sourceDtype === 'UINT8') {
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
if (sourceDtype === 'INT4') {
|
|
40
|
+
return 2;
|
|
41
|
+
}
|
|
42
|
+
if (sourceDtype === 'INT2') {
|
|
43
|
+
return 4;
|
|
44
|
+
}
|
|
45
|
+
throw new Error(
|
|
46
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.sourceDtype "${sourceDtype}".`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readStoredQuantizedValue(bytes, index, sourceDtype, storageEncoding = 'signed') {
|
|
51
|
+
if (sourceDtype === 'INT8') {
|
|
52
|
+
if (storageEncoding === 'offset_binary') {
|
|
53
|
+
return bytes[index];
|
|
54
|
+
}
|
|
55
|
+
return new Int8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)[index];
|
|
56
|
+
}
|
|
57
|
+
if (sourceDtype === 'UINT8') {
|
|
58
|
+
return bytes[index];
|
|
59
|
+
}
|
|
60
|
+
if (sourceDtype === 'INT2') {
|
|
61
|
+
const packed = bytes[index >> 2];
|
|
62
|
+
const shift = (index & 3) * 2;
|
|
63
|
+
const dibit = (packed >> shift) & 0x03;
|
|
64
|
+
if (storageEncoding === 'offset_binary') {
|
|
65
|
+
return dibit;
|
|
66
|
+
}
|
|
67
|
+
return dibit >= 2 ? dibit - 4 : dibit;
|
|
68
|
+
}
|
|
69
|
+
const packed = bytes[index >> 1];
|
|
70
|
+
const nibble = (index & 1) === 0 ? (packed & 0x0f) : (packed >> 4);
|
|
71
|
+
if (storageEncoding === 'offset_binary') {
|
|
72
|
+
return nibble;
|
|
73
|
+
}
|
|
74
|
+
return nibble >= 8 ? nibble - 16 : nibble;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function readQuantizedValue(bytes, index, sourceDtype, storageEncoding = 'signed') {
|
|
78
|
+
const rawValue = readStoredQuantizedValue(bytes, index, sourceDtype, storageEncoding);
|
|
79
|
+
if (sourceDtype === 'INT8' || sourceDtype === 'UINT8') {
|
|
80
|
+
if (storageEncoding === 'offset_binary') {
|
|
81
|
+
return rawValue - 128;
|
|
82
|
+
}
|
|
83
|
+
return rawValue;
|
|
84
|
+
}
|
|
85
|
+
if (sourceDtype === 'INT2') {
|
|
86
|
+
if (storageEncoding === 'offset_binary') {
|
|
87
|
+
return rawValue - 2;
|
|
88
|
+
}
|
|
89
|
+
return rawValue;
|
|
90
|
+
}
|
|
91
|
+
if (storageEncoding === 'offset_binary') {
|
|
92
|
+
return rawValue - 8;
|
|
93
|
+
}
|
|
94
|
+
return rawValue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function computeStoredQuantizedSum(bytes, sourceDtype, storageEncoding = 'signed') {
|
|
98
|
+
let total = 0;
|
|
99
|
+
if (sourceDtype === 'INT8') {
|
|
100
|
+
if (storageEncoding === 'offset_binary') {
|
|
101
|
+
for (let index = 0; index < bytes.byteLength; index++) {
|
|
102
|
+
total += bytes[index];
|
|
103
|
+
}
|
|
104
|
+
return total;
|
|
105
|
+
}
|
|
106
|
+
const signed = new Int8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
107
|
+
for (let index = 0; index < signed.length; index++) {
|
|
108
|
+
total += signed[index];
|
|
109
|
+
}
|
|
110
|
+
return total;
|
|
111
|
+
}
|
|
112
|
+
if (sourceDtype === 'UINT8') {
|
|
113
|
+
for (let index = 0; index < bytes.byteLength; index++) {
|
|
114
|
+
total += bytes[index];
|
|
115
|
+
}
|
|
116
|
+
return total;
|
|
117
|
+
}
|
|
118
|
+
if (sourceDtype === 'INT2') {
|
|
119
|
+
for (let index = 0; index < bytes.byteLength; index++) {
|
|
120
|
+
const packed = bytes[index];
|
|
121
|
+
const a = packed & 0x03;
|
|
122
|
+
const b = (packed >> 2) & 0x03;
|
|
123
|
+
const c = (packed >> 4) & 0x03;
|
|
124
|
+
const d = (packed >> 6) & 0x03;
|
|
125
|
+
if (storageEncoding === 'offset_binary') {
|
|
126
|
+
total += a + b + c + d;
|
|
127
|
+
} else {
|
|
128
|
+
total += (a >= 2 ? a - 4 : a);
|
|
129
|
+
total += (b >= 2 ? b - 4 : b);
|
|
130
|
+
total += (c >= 2 ? c - 4 : c);
|
|
131
|
+
total += (d >= 2 ? d - 4 : d);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return total;
|
|
135
|
+
}
|
|
136
|
+
for (let index = 0; index < bytes.byteLength; index++) {
|
|
137
|
+
const packed = bytes[index];
|
|
138
|
+
const a = packed & 0x0f;
|
|
139
|
+
const b = packed >> 4;
|
|
140
|
+
if (storageEncoding === 'offset_binary') {
|
|
141
|
+
total += a + b;
|
|
142
|
+
} else {
|
|
143
|
+
total += (a >= 8 ? a - 16 : a);
|
|
144
|
+
total += (b >= 8 ? b - 16 : b);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return total;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function resolveAffineDequantTransform(location, tensorName) {
|
|
151
|
+
const transform = location?.sourceTransform;
|
|
152
|
+
if (transform.kind !== 'affine_dequant') {
|
|
153
|
+
throw new Error(
|
|
154
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.kind "${transform.kind}".`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (transform.scheme !== 'per_tensor_affine') {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.scheme "${transform.scheme}".`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (transform.targetDtype !== 'F16') {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.targetDtype "${transform.targetDtype}".`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (String(location?.dtype || '').toUpperCase() !== transform.targetDtype) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`[DopplerLoader] Tensor "${tensorName}" sourceTransform targetDtype "${transform.targetDtype}" ` +
|
|
170
|
+
`does not match location.dtype "${location?.dtype}".`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const scale = Number(transform.scale);
|
|
174
|
+
const zeroPoint = Number(transform.zeroPoint);
|
|
175
|
+
if (!Number.isFinite(scale) || scale <= 0) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid sourceTransform.scale ${transform.scale}.`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (!Number.isSafeInteger(zeroPoint)) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid sourceTransform.zeroPoint ${transform.zeroPoint}.`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
...transform,
|
|
187
|
+
scale,
|
|
188
|
+
zeroPoint,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function validateLiteRTTransformTarget(location, tensorName, transform, label) {
|
|
193
|
+
if (transform.targetDtype !== 'F16') {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported ${label} targetDtype "${transform.targetDtype}".`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
if (String(location?.dtype || '').toUpperCase() !== transform.targetDtype) {
|
|
199
|
+
throw new Error(
|
|
200
|
+
`[DopplerLoader] Tensor "${tensorName}" ${label} targetDtype "${transform.targetDtype}" ` +
|
|
201
|
+
`does not match location.dtype "${location?.dtype}".`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function validateLiteRTStorageEncoding(storageEncoding, tensorName) {
|
|
207
|
+
if (storageEncoding !== 'signed' && storageEncoding !== 'offset_binary') {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported LiteRT storageEncoding "${storageEncoding}".`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function resolveLiteRTScaleValue(storedScale, transform, tensorName, rowLabel) {
|
|
215
|
+
const scaleSemantics = String(transform?.scaleSemantics || '').trim().toLowerCase();
|
|
216
|
+
if (scaleSemantics === 'step') {
|
|
217
|
+
return storedScale;
|
|
218
|
+
}
|
|
219
|
+
if (scaleSemantics === 'qmax_abs') {
|
|
220
|
+
const scaleDivisor = Number(transform?.scaleDivisor);
|
|
221
|
+
if (!Number.isFinite(scaleDivisor) || scaleDivisor <= 0) {
|
|
222
|
+
throw new Error(
|
|
223
|
+
`[DopplerLoader] Tensor "${tensorName}" ${rowLabel} is missing a valid LiteRT scaleDivisor for scaleSemantics="qmax_abs".`
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
return storedScale / scaleDivisor;
|
|
227
|
+
}
|
|
228
|
+
throw new Error(
|
|
229
|
+
`[DopplerLoader] Tensor "${tensorName}" ${rowLabel} has unsupported LiteRT scaleSemantics "${transform?.scaleSemantics}".`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function getLiteRTCompanionByteLength(companionSource, tensorName, label, expectedByteLength) {
|
|
234
|
+
if (!companionSource || typeof companionSource !== 'object') {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const byteLength = Number(companionSource.size);
|
|
238
|
+
if (!Number.isInteger(byteLength) || byteLength !== expectedByteLength) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT ${label} bytes must equal ${expectedByteLength}. ` +
|
|
241
|
+
`Got ${companionSource?.size}.`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return byteLength;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function getSourceTransformSpec(location, tensorName) {
|
|
248
|
+
if (!hasSourceTransform(location)) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
const transform = location.sourceTransform;
|
|
252
|
+
if (transform.kind === 'affine_dequant') {
|
|
253
|
+
const elementCount = computeElementCount(location.shape, tensorName);
|
|
254
|
+
return {
|
|
255
|
+
kind: 'affine_dequant',
|
|
256
|
+
elementCount,
|
|
257
|
+
outputByteLength: elementCount * 2,
|
|
258
|
+
sourceByteLength: computeSourceByteLength(
|
|
259
|
+
elementCount,
|
|
260
|
+
transform.sourceDtype,
|
|
261
|
+
tensorName
|
|
262
|
+
),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
if (!Array.isArray(location?.shape) || location.shape.length !== 2) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT sourceTransform requires a 2D shape.`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const rows = Number(location.shape[0]);
|
|
271
|
+
const cols = Number(location.shape[1]);
|
|
272
|
+
if (!Number.isInteger(rows) || rows <= 0 || !Number.isInteger(cols) || cols <= 0) {
|
|
273
|
+
throw new Error(
|
|
274
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT shape ${JSON.stringify(location.shape)}.`
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (transform.kind === 'litert_rowwise_dequant') {
|
|
279
|
+
if (transform.scheme !== 'per_row_affine') {
|
|
280
|
+
throw new Error(
|
|
281
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.scheme "${transform.scheme}".`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
validateLiteRTTransformTarget(location, tensorName, transform, 'LiteRT row-wise sourceTransform');
|
|
285
|
+
validateLiteRTStorageEncoding(transform.storageEncoding, tensorName);
|
|
286
|
+
const rawRowBytes = computeSourceByteLength(cols, transform.sourceDtype, tensorName);
|
|
287
|
+
const sourceByteLength = rows * rawRowBytes;
|
|
288
|
+
const scaleSource = transform.scaleSource;
|
|
289
|
+
if (!scaleSource || typeof scaleSource !== 'object') {
|
|
290
|
+
throw new Error(
|
|
291
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise transform is missing scaleSource.`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
getLiteRTCompanionByteLength(scaleSource, tensorName, 'row-wise scale', rows * 4);
|
|
295
|
+
if (transform.rowSumSource != null && typeof transform.rowSumSource !== 'object') {
|
|
296
|
+
throw new Error(
|
|
297
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise transform has invalid rowSumSource.`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
if (transform.rowSumSource != null) {
|
|
301
|
+
getLiteRTCompanionByteLength(transform.rowSumSource, tensorName, 'row-wise row-sum', rows * 4);
|
|
302
|
+
}
|
|
303
|
+
if (transform.scaleSemantics !== 'step' && transform.scaleSemantics !== 'qmax_abs') {
|
|
304
|
+
throw new Error(
|
|
305
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise transform has unsupported scaleSemantics "${transform.scaleSemantics}".`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
if (transform.scaleSemantics === 'qmax_abs') {
|
|
309
|
+
const scaleDivisor = Number(transform.scaleDivisor);
|
|
310
|
+
if (!Number.isFinite(scaleDivisor) || scaleDivisor <= 0) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise transform requires scaleDivisor > 0 for scaleSemantics="qmax_abs".`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
kind: 'litert_rowwise_dequant',
|
|
318
|
+
rows,
|
|
319
|
+
cols,
|
|
320
|
+
rawRowBytes,
|
|
321
|
+
scaleRowBytes: 4,
|
|
322
|
+
targetRowBytes: cols * 2,
|
|
323
|
+
outputByteLength: rows * cols * 2,
|
|
324
|
+
sourceByteLength,
|
|
325
|
+
storageValuesPerByte: getPackedValuesPerByte(transform.sourceDtype, tensorName),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (transform.kind === 'litert_axis_dequant') {
|
|
330
|
+
if (transform.scheme !== 'per_axis_affine') {
|
|
331
|
+
throw new Error(
|
|
332
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.scheme "${transform.scheme}".`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
validateLiteRTTransformTarget(location, tensorName, transform, 'LiteRT axis sourceTransform');
|
|
336
|
+
validateLiteRTStorageEncoding(transform.storageEncoding, tensorName);
|
|
337
|
+
if (!Array.isArray(transform.storageShape) || transform.storageShape.length !== 2) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis transform requires storageShape=[rows, cols].`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
const storageRows = Number(transform.storageShape[0]);
|
|
343
|
+
const storageCols = Number(transform.storageShape[1]);
|
|
344
|
+
if (
|
|
345
|
+
!Number.isInteger(storageRows)
|
|
346
|
+
|| storageRows <= 0
|
|
347
|
+
|| !Number.isInteger(storageCols)
|
|
348
|
+
|| storageCols <= 0
|
|
349
|
+
) {
|
|
350
|
+
throw new Error(
|
|
351
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT storageShape ${JSON.stringify(transform.storageShape)}.`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
if (transform.quantAxis !== 0 && transform.quantAxis !== 1) {
|
|
355
|
+
throw new Error(
|
|
356
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT quantAxis ${transform.quantAxis}.`
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
if (transform.quantAxis === 0) {
|
|
360
|
+
if (storageRows !== cols || storageCols !== rows) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis transform expects storageShape ` +
|
|
363
|
+
`[${cols}, ${rows}] for quantAxis=0, got [${storageRows}, ${storageCols}].`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
} else if (storageRows !== rows || storageCols !== cols) {
|
|
367
|
+
throw new Error(
|
|
368
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis transform expects storageShape ` +
|
|
369
|
+
`[${rows}, ${cols}] for quantAxis=1, got [${storageRows}, ${storageCols}].`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
const scaleSource = transform.scaleSource;
|
|
373
|
+
if (!scaleSource || typeof scaleSource !== 'object') {
|
|
374
|
+
throw new Error(
|
|
375
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis transform is missing scaleSource.`
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
getLiteRTCompanionByteLength(scaleSource, tensorName, 'axis scale', rows * 4);
|
|
379
|
+
if (transform.sumSource != null && typeof transform.sumSource !== 'object') {
|
|
380
|
+
throw new Error(
|
|
381
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis transform has invalid sumSource.`
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
if (transform.sumSource != null) {
|
|
385
|
+
getLiteRTCompanionByteLength(transform.sumSource, tensorName, 'axis sum', rows * 4);
|
|
386
|
+
}
|
|
387
|
+
if (transform.scaleSemantics !== 'step' && transform.scaleSemantics !== 'qmax_abs') {
|
|
388
|
+
throw new Error(
|
|
389
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis transform has unsupported scaleSemantics "${transform.scaleSemantics}".`
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
if (transform.scaleSemantics === 'qmax_abs') {
|
|
393
|
+
const scaleDivisor = Number(transform.scaleDivisor);
|
|
394
|
+
if (!Number.isFinite(scaleDivisor) || scaleDivisor <= 0) {
|
|
395
|
+
throw new Error(
|
|
396
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis transform requires scaleDivisor > 0 for scaleSemantics="qmax_abs".`
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const rawStorageRowBytes = computeSourceByteLength(storageCols, transform.sourceDtype, tensorName);
|
|
401
|
+
const sourceByteLength = computeSourceByteLength(
|
|
402
|
+
storageRows * storageCols,
|
|
403
|
+
transform.sourceDtype,
|
|
404
|
+
tensorName
|
|
405
|
+
);
|
|
406
|
+
return {
|
|
407
|
+
kind: 'litert_axis_dequant',
|
|
408
|
+
rows,
|
|
409
|
+
cols,
|
|
410
|
+
storageRows,
|
|
411
|
+
storageCols,
|
|
412
|
+
rawStorageRowBytes,
|
|
413
|
+
scaleRowBytes: 4,
|
|
414
|
+
targetRowBytes: cols * 2,
|
|
415
|
+
outputByteLength: rows * cols * 2,
|
|
416
|
+
sourceByteLength,
|
|
417
|
+
quantAxis: transform.quantAxis,
|
|
418
|
+
storageValuesPerByte: getPackedValuesPerByte(transform.sourceDtype, tensorName),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
throw new Error(
|
|
423
|
+
`[DopplerLoader] Tensor "${tensorName}" has unsupported sourceTransform.kind "${transform.kind}".`
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export function hasSourceTransform(location) {
|
|
428
|
+
return Boolean(location?.sourceTransform && typeof location.sourceTransform === 'object');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export function materializeTensorSourceTransform(rawBytes, location, tensorName, options = {}) {
|
|
432
|
+
if (!(rawBytes instanceof Uint8Array)) {
|
|
433
|
+
throw new Error(
|
|
434
|
+
`[DopplerLoader] Tensor "${tensorName}" sourceTransform requires Uint8Array input bytes.`
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
if (!hasSourceTransform(location)) {
|
|
438
|
+
return rawBytes;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const transform = location.sourceTransform;
|
|
442
|
+
if (transform.kind === 'litert_rowwise_dequant') {
|
|
443
|
+
const spec = getSourceTransformSpec(location, tensorName);
|
|
444
|
+
const scaleBytes = options.scaleBytes;
|
|
445
|
+
if (!(scaleBytes instanceof Uint8Array)) {
|
|
446
|
+
throw new Error(
|
|
447
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise sourceTransform requires scaleBytes.`
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
const rowSumBytes = options.rowSumBytes ?? null;
|
|
451
|
+
const hasRowSumSource = transform.rowSumSource != null;
|
|
452
|
+
if (hasRowSumSource && !(rowSumBytes instanceof Uint8Array)) {
|
|
453
|
+
throw new Error(
|
|
454
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise sourceTransform requires rowSumBytes.`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
const rowStart = options.rowStart == null ? 0 : Number(options.rowStart);
|
|
458
|
+
const rowCount = options.rowCount == null ? spec.rows : Number(options.rowCount);
|
|
459
|
+
if (!Number.isInteger(rowStart) || rowStart < 0) {
|
|
460
|
+
throw new Error(
|
|
461
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT rowStart ${options.rowStart}.`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
if (!Number.isInteger(rowCount) || rowCount <= 0) {
|
|
465
|
+
throw new Error(
|
|
466
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT rowCount ${options.rowCount}.`
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
if (rowStart + rowCount > spec.rows) {
|
|
470
|
+
throw new Error(
|
|
471
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row range (${rowStart}..${rowStart + rowCount}) exceeds ${spec.rows} rows.`
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
const expectedRawBytes = rowCount * spec.rawRowBytes;
|
|
475
|
+
const expectedScaleBytes = rowCount * spec.scaleRowBytes;
|
|
476
|
+
if (rawBytes.byteLength !== expectedRawBytes) {
|
|
477
|
+
throw new Error(
|
|
478
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise raw byte size mismatch. ` +
|
|
479
|
+
`Expected ${expectedRawBytes}, got ${rawBytes.byteLength}.`
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
if (scaleBytes.byteLength !== expectedScaleBytes) {
|
|
483
|
+
throw new Error(
|
|
484
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise scale byte size mismatch. ` +
|
|
485
|
+
`Expected ${expectedScaleBytes}, got ${scaleBytes.byteLength}.`
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
if (hasRowSumSource && rowSumBytes.byteLength !== rowCount * 4) {
|
|
489
|
+
throw new Error(
|
|
490
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row-wise row-sum byte size mismatch. ` +
|
|
491
|
+
`Expected ${rowCount * 4}, got ${rowSumBytes.byteLength}.`
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
const scaleView = new DataView(scaleBytes.buffer, scaleBytes.byteOffset, scaleBytes.byteLength);
|
|
495
|
+
const rowSumView = hasRowSumSource
|
|
496
|
+
? new DataView(rowSumBytes.buffer, rowSumBytes.byteOffset, rowSumBytes.byteLength)
|
|
497
|
+
: null;
|
|
498
|
+
const out = new Uint16Array(rowCount * spec.cols);
|
|
499
|
+
for (let row = 0; row < rowCount; row++) {
|
|
500
|
+
const scale = scaleView.getFloat32(row * spec.scaleRowBytes, true);
|
|
501
|
+
if (!Number.isFinite(scale) || scale <= 0) {
|
|
502
|
+
throw new Error(
|
|
503
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row ${rowStart + row} has invalid scale ${scale}.`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
const resolvedScale = resolveLiteRTScaleValue(
|
|
507
|
+
scale,
|
|
508
|
+
transform,
|
|
509
|
+
tensorName,
|
|
510
|
+
`LiteRT row ${rowStart + row}`
|
|
511
|
+
);
|
|
512
|
+
const rawRowOffset = row * spec.rawRowBytes;
|
|
513
|
+
const outRowOffset = row * spec.cols;
|
|
514
|
+
const rowBytes = rawBytes.subarray(rawRowOffset, rawRowOffset + spec.rawRowBytes);
|
|
515
|
+
const rowZeroPoint = rowSumView
|
|
516
|
+
? (
|
|
517
|
+
computeStoredQuantizedSum(
|
|
518
|
+
rowBytes,
|
|
519
|
+
transform.sourceDtype,
|
|
520
|
+
transform.storageEncoding
|
|
521
|
+
) - rowSumView.getInt32(row * 4, true)
|
|
522
|
+
) / spec.cols
|
|
523
|
+
: null;
|
|
524
|
+
if (rowZeroPoint != null && !Number.isFinite(rowZeroPoint)) {
|
|
525
|
+
throw new Error(
|
|
526
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT row ${rowStart + row} has invalid derived rowZeroPoint ${rowZeroPoint}.`
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
for (let col = 0; col < spec.cols; col++) {
|
|
530
|
+
const quantized = rowZeroPoint == null
|
|
531
|
+
? readQuantizedValue(
|
|
532
|
+
rowBytes,
|
|
533
|
+
col,
|
|
534
|
+
transform.sourceDtype,
|
|
535
|
+
transform.storageEncoding
|
|
536
|
+
)
|
|
537
|
+
: (
|
|
538
|
+
readStoredQuantizedValue(
|
|
539
|
+
rowBytes,
|
|
540
|
+
col,
|
|
541
|
+
transform.sourceDtype,
|
|
542
|
+
transform.storageEncoding
|
|
543
|
+
) - rowZeroPoint
|
|
544
|
+
);
|
|
545
|
+
out[outRowOffset + col] = float32ToFloat16(quantized * resolvedScale);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return new Uint8Array(out.buffer, out.byteOffset, out.byteLength);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (transform.kind === 'litert_axis_dequant') {
|
|
552
|
+
const spec = getSourceTransformSpec(location, tensorName);
|
|
553
|
+
const scaleBytes = options.scaleBytes;
|
|
554
|
+
if (!(scaleBytes instanceof Uint8Array)) {
|
|
555
|
+
throw new Error(
|
|
556
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis sourceTransform requires scaleBytes.`
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
const sumBytes = options.sumBytes ?? null;
|
|
560
|
+
const hasSumSource = transform.sumSource != null;
|
|
561
|
+
if (hasSumSource && !(sumBytes instanceof Uint8Array)) {
|
|
562
|
+
throw new Error(
|
|
563
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis sourceTransform requires sumBytes.`
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
const rowStart = options.rowStart == null ? 0 : Number(options.rowStart);
|
|
567
|
+
const rowCount = options.rowCount == null ? spec.rows : Number(options.rowCount);
|
|
568
|
+
if (!Number.isInteger(rowStart) || rowStart < 0) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT axis rowStart ${options.rowStart}.`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
if (!Number.isInteger(rowCount) || rowCount <= 0) {
|
|
574
|
+
throw new Error(
|
|
575
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT axis rowCount ${options.rowCount}.`
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
if (rowStart + rowCount > spec.rows) {
|
|
579
|
+
throw new Error(
|
|
580
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis row range (${rowStart}..${rowStart + rowCount}) exceeds ${spec.rows} rows.`
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
if (scaleBytes.byteLength !== rowCount * spec.scaleRowBytes) {
|
|
584
|
+
throw new Error(
|
|
585
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis scale byte size mismatch. ` +
|
|
586
|
+
`Expected ${rowCount * spec.scaleRowBytes}, got ${scaleBytes.byteLength}.`
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
if (hasSumSource && sumBytes.byteLength !== rowCount * 4) {
|
|
590
|
+
throw new Error(
|
|
591
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis sum byte size mismatch. ` +
|
|
592
|
+
`Expected ${rowCount * 4}, got ${sumBytes.byteLength}.`
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const scaleView = new DataView(scaleBytes.buffer, scaleBytes.byteOffset, scaleBytes.byteLength);
|
|
597
|
+
const sumView = hasSumSource
|
|
598
|
+
? new DataView(sumBytes.buffer, sumBytes.byteOffset, sumBytes.byteLength)
|
|
599
|
+
: null;
|
|
600
|
+
const out = new Uint16Array(rowCount * spec.cols);
|
|
601
|
+
|
|
602
|
+
if (spec.quantAxis === 1) {
|
|
603
|
+
const expectedRawBytes = rowCount * spec.rawStorageRowBytes;
|
|
604
|
+
if (rawBytes.byteLength !== expectedRawBytes) {
|
|
605
|
+
throw new Error(
|
|
606
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis raw byte size mismatch. ` +
|
|
607
|
+
`Expected ${expectedRawBytes}, got ${rawBytes.byteLength}.`
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
for (let row = 0; row < rowCount; row++) {
|
|
611
|
+
const scale = scaleView.getFloat32(row * spec.scaleRowBytes, true);
|
|
612
|
+
if (!Number.isFinite(scale) || scale <= 0) {
|
|
613
|
+
throw new Error(
|
|
614
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis row ${rowStart + row} has invalid scale ${scale}.`
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
const resolvedScale = resolveLiteRTScaleValue(
|
|
618
|
+
scale,
|
|
619
|
+
transform,
|
|
620
|
+
tensorName,
|
|
621
|
+
`LiteRT axis row ${rowStart + row}`
|
|
622
|
+
);
|
|
623
|
+
const rawRowOffset = row * spec.rawStorageRowBytes;
|
|
624
|
+
const rowBytes = rawBytes.subarray(rawRowOffset, rawRowOffset + spec.rawStorageRowBytes);
|
|
625
|
+
const storedRowSum = hasSumSource
|
|
626
|
+
? sumView.getInt32(row * 4, true)
|
|
627
|
+
: null;
|
|
628
|
+
const rowZeroPoint = storedRowSum == null
|
|
629
|
+
? null
|
|
630
|
+
: (
|
|
631
|
+
computeStoredQuantizedSum(
|
|
632
|
+
rowBytes,
|
|
633
|
+
transform.sourceDtype,
|
|
634
|
+
transform.storageEncoding
|
|
635
|
+
) - storedRowSum
|
|
636
|
+
) / spec.cols;
|
|
637
|
+
if (rowZeroPoint != null && !Number.isFinite(rowZeroPoint)) {
|
|
638
|
+
throw new Error(
|
|
639
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis row ${rowStart + row} has invalid derived rowZeroPoint ${rowZeroPoint}.`
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
const outRowOffset = row * spec.cols;
|
|
643
|
+
for (let col = 0; col < spec.cols; col++) {
|
|
644
|
+
const quantized = rowZeroPoint == null
|
|
645
|
+
? readQuantizedValue(
|
|
646
|
+
rowBytes,
|
|
647
|
+
col,
|
|
648
|
+
transform.sourceDtype,
|
|
649
|
+
transform.storageEncoding
|
|
650
|
+
)
|
|
651
|
+
: (
|
|
652
|
+
readStoredQuantizedValue(
|
|
653
|
+
rowBytes,
|
|
654
|
+
col,
|
|
655
|
+
transform.sourceDtype,
|
|
656
|
+
transform.storageEncoding
|
|
657
|
+
) - rowZeroPoint
|
|
658
|
+
);
|
|
659
|
+
out[outRowOffset + col] = float32ToFloat16(quantized * resolvedScale);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return new Uint8Array(out.buffer, out.byteOffset, out.byteLength);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const storageColumnStart = options.storageColumnStart == null
|
|
666
|
+
? 0
|
|
667
|
+
: Number(options.storageColumnStart);
|
|
668
|
+
if (!Number.isInteger(storageColumnStart) || storageColumnStart < 0) {
|
|
669
|
+
throw new Error(
|
|
670
|
+
`[DopplerLoader] Tensor "${tensorName}" has invalid LiteRT axis storageColumnStart ${options.storageColumnStart}.`
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
if (rawBytes.byteLength % spec.storageRows !== 0) {
|
|
674
|
+
throw new Error(
|
|
675
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis raw byte size ${rawBytes.byteLength} ` +
|
|
676
|
+
`is not divisible by storageRows=${spec.storageRows}.`
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
const rawSliceRowBytes = rawBytes.byteLength / spec.storageRows;
|
|
680
|
+
const windowColumns = rawSliceRowBytes * spec.storageValuesPerByte;
|
|
681
|
+
if (
|
|
682
|
+
rowStart < storageColumnStart
|
|
683
|
+
|| rowStart + rowCount > storageColumnStart + windowColumns
|
|
684
|
+
) {
|
|
685
|
+
throw new Error(
|
|
686
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis raw window [${storageColumnStart}, ${storageColumnStart + windowColumns}) ` +
|
|
687
|
+
`does not cover requested rows [${rowStart}, ${rowStart + rowCount}).`
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
const localColumnBase = rowStart - storageColumnStart;
|
|
691
|
+
const rowSlices = new Array(spec.storageRows);
|
|
692
|
+
for (let storageRow = 0; storageRow < spec.storageRows; storageRow++) {
|
|
693
|
+
const sliceOffset = storageRow * rawSliceRowBytes;
|
|
694
|
+
rowSlices[storageRow] = rawBytes.subarray(sliceOffset, sliceOffset + rawSliceRowBytes);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
for (let row = 0; row < rowCount; row++) {
|
|
698
|
+
const logicalRow = rowStart + row;
|
|
699
|
+
const localColumnIndex = localColumnBase + row;
|
|
700
|
+
const scale = scaleView.getFloat32(row * spec.scaleRowBytes, true);
|
|
701
|
+
if (!Number.isFinite(scale) || scale <= 0) {
|
|
702
|
+
throw new Error(
|
|
703
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis row ${logicalRow} has invalid scale ${scale}.`
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
const resolvedScale = resolveLiteRTScaleValue(
|
|
707
|
+
scale,
|
|
708
|
+
transform,
|
|
709
|
+
tensorName,
|
|
710
|
+
`LiteRT axis row ${logicalRow}`
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
const storedValues = new Array(spec.cols);
|
|
714
|
+
let storedSum = 0;
|
|
715
|
+
for (let col = 0; col < spec.cols; col++) {
|
|
716
|
+
const stored = readStoredQuantizedValue(
|
|
717
|
+
rowSlices[col],
|
|
718
|
+
localColumnIndex,
|
|
719
|
+
transform.sourceDtype,
|
|
720
|
+
transform.storageEncoding
|
|
721
|
+
);
|
|
722
|
+
storedValues[col] = stored;
|
|
723
|
+
storedSum += stored;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const storedRowSum = hasSumSource
|
|
727
|
+
? sumView.getInt32(row * 4, true)
|
|
728
|
+
: null;
|
|
729
|
+
const rowZeroPoint = storedRowSum == null
|
|
730
|
+
? null
|
|
731
|
+
: (storedSum - storedRowSum) / spec.cols;
|
|
732
|
+
if (rowZeroPoint != null && !Number.isFinite(rowZeroPoint)) {
|
|
733
|
+
throw new Error(
|
|
734
|
+
`[DopplerLoader] Tensor "${tensorName}" LiteRT axis row ${logicalRow} has invalid derived rowZeroPoint ${rowZeroPoint}.`
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const outRowOffset = row * spec.cols;
|
|
739
|
+
for (let col = 0; col < spec.cols; col++) {
|
|
740
|
+
const quantized = rowZeroPoint == null
|
|
741
|
+
? readQuantizedValue(
|
|
742
|
+
rowSlices[col],
|
|
743
|
+
localColumnIndex,
|
|
744
|
+
transform.sourceDtype,
|
|
745
|
+
transform.storageEncoding
|
|
746
|
+
)
|
|
747
|
+
: (storedValues[col] - rowZeroPoint);
|
|
748
|
+
out[outRowOffset + col] = float32ToFloat16(quantized * resolvedScale);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
return new Uint8Array(out.buffer, out.byteOffset, out.byteLength);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
const affineTransform = resolveAffineDequantTransform(location, tensorName);
|
|
755
|
+
|
|
756
|
+
const elementCount = computeElementCount(location.shape, tensorName);
|
|
757
|
+
const expectedBytes = computeSourceByteLength(
|
|
758
|
+
elementCount,
|
|
759
|
+
affineTransform.sourceDtype,
|
|
760
|
+
tensorName
|
|
761
|
+
);
|
|
762
|
+
if (rawBytes.byteLength !== expectedBytes) {
|
|
763
|
+
throw new Error(
|
|
764
|
+
`[DopplerLoader] Tensor "${tensorName}" sourceTransform byte size mismatch. ` +
|
|
765
|
+
`Expected ${expectedBytes} bytes for ${elementCount} elements, got ${rawBytes.byteLength}.`
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const out = new Uint16Array(elementCount);
|
|
770
|
+
for (let index = 0; index < elementCount; index++) {
|
|
771
|
+
const quantized = readQuantizedValue(rawBytes, index, affineTransform.sourceDtype);
|
|
772
|
+
const value = (quantized - affineTransform.zeroPoint) * affineTransform.scale;
|
|
773
|
+
out[index] = float32ToFloat16(value);
|
|
774
|
+
}
|
|
775
|
+
return new Uint8Array(out.buffer, out.byteOffset, out.byteLength);
|
|
776
|
+
}
|