@simulatte/doppler 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BRANDING.md +14 -0
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +85 -0
- package/SECURITY.md +19 -0
- package/package.json +144 -0
- package/src/adapters/adapter-manager.d.ts +200 -0
- package/src/adapters/adapter-manager.js +509 -0
- package/src/adapters/adapter-manifest.d.ts +290 -0
- package/src/adapters/adapter-manifest.js +320 -0
- package/src/adapters/adapter-registry.d.ts +192 -0
- package/src/adapters/adapter-registry.js +466 -0
- package/src/adapters/index.d.ts +89 -0
- package/src/adapters/index.js +42 -0
- package/src/adapters/lora-loader.d.ts +105 -0
- package/src/adapters/lora-loader.js +397 -0
- package/src/bootstrap.d.ts +1 -0
- package/src/bootstrap.js +30 -0
- package/src/bridge/extension/background.d.ts +14 -0
- package/src/bridge/extension/background.js +168 -0
- package/src/bridge/extension/manifest.json +34 -0
- package/src/bridge/extension-client.d.ts +109 -0
- package/src/bridge/extension-client.js +369 -0
- package/src/bridge/index.d.ts +68 -0
- package/src/bridge/index.js +51 -0
- package/src/bridge/protocol.d.ts +96 -0
- package/src/bridge/protocol.js +130 -0
- package/src/browser/browser-converter.d.ts +71 -0
- package/src/browser/browser-converter.js +947 -0
- package/src/browser/file-picker.d.ts +63 -0
- package/src/browser/file-picker.js +275 -0
- package/src/browser/gguf-importer.d.ts +136 -0
- package/src/browser/gguf-importer.js +532 -0
- package/src/browser/gguf-parser-browser.d.ts +14 -0
- package/src/browser/gguf-parser-browser.js +17 -0
- package/src/browser/quantization.d.ts +69 -0
- package/src/browser/quantization.js +328 -0
- package/src/browser/safetensors-parser-browser.d.ts +193 -0
- package/src/browser/safetensors-parser-browser.js +264 -0
- package/src/browser/shard-io-browser.d.ts +57 -0
- package/src/browser/shard-io-browser.js +89 -0
- package/src/browser/tensor-source-download.d.ts +27 -0
- package/src/browser/tensor-source-download.js +239 -0
- package/src/browser/tensor-source-file.d.ts +26 -0
- package/src/browser/tensor-source-file.js +53 -0
- package/src/browser/tensor-source-http.d.ts +28 -0
- package/src/browser/tensor-source-http.js +126 -0
- package/src/client/doppler-provider/generation.d.ts +25 -0
- package/src/client/doppler-provider/generation.js +114 -0
- package/src/client/doppler-provider/index.d.ts +2 -0
- package/src/client/doppler-provider/index.js +3 -0
- package/src/client/doppler-provider/model-manager.d.ts +61 -0
- package/src/client/doppler-provider/model-manager.js +667 -0
- package/src/client/doppler-provider/provider.d.ts +5 -0
- package/src/client/doppler-provider/provider.js +102 -0
- package/src/client/doppler-provider/source-runtime.d.ts +22 -0
- package/src/client/doppler-provider/source-runtime.js +522 -0
- package/src/client/doppler-provider/types.d.ts +127 -0
- package/src/client/doppler-provider/types.js +17 -0
- package/src/client/doppler-provider.d.ts +46 -0
- package/src/client/doppler-provider.js +36 -0
- package/src/config/README.md +69 -0
- package/src/config/backward-registry-loader.d.ts +3 -0
- package/src/config/backward-registry-loader.js +8 -0
- package/src/config/index.d.ts +63 -0
- package/src/config/index.js +31 -0
- package/src/config/kernel-path-loader.d.ts +149 -0
- package/src/config/kernel-path-loader.js +534 -0
- package/src/config/kernels/backward-registry.json +99 -0
- package/src/config/kernels/kernel-ref-digests.d.ts +1 -0
- package/src/config/kernels/kernel-ref-digests.js +214 -0
- package/src/config/kernels/kernel-ref.d.ts +17 -0
- package/src/config/kernels/kernel-ref.js +75 -0
- package/src/config/kernels/moe/gpt-oss.paths.json +49 -0
- package/src/config/kernels/registry.d.ts +86 -0
- package/src/config/kernels/registry.js +103 -0
- package/src/config/kernels/registry.json +6771 -0
- package/src/config/loader.d.ts +57 -0
- package/src/config/loader.js +513 -0
- package/src/config/merge.d.ts +142 -0
- package/src/config/merge.js +389 -0
- package/src/config/param-categories.d.ts +17 -0
- package/src/config/param-categories.js +72 -0
- package/src/config/param-validator.d.ts +26 -0
- package/src/config/param-validator.js +235 -0
- package/src/config/platforms/amd-rdna3.json +16 -0
- package/src/config/platforms/apple-m1.json +16 -0
- package/src/config/platforms/apple-m2.json +16 -0
- package/src/config/platforms/apple-m3.json +16 -0
- package/src/config/platforms/generic.json +14 -0
- package/src/config/platforms/loader.d.ts +65 -0
- package/src/config/platforms/loader.js +153 -0
- package/src/config/platforms/nvidia-rtx30.json +16 -0
- package/src/config/platforms/nvidia-rtx40.json +16 -0
- package/src/config/presets/kernel-paths/embeddinggemma-f16-f32a.json +60 -0
- package/src/config/presets/kernel-paths/embeddinggemma-f32-f32a.json +60 -0
- package/src/config/presets/kernel-paths/embeddinggemma-q4k-dequant-f32a.json +60 -0
- package/src/config/presets/kernel-paths/gemma2-f16-f16a.json +61 -0
- package/src/config/presets/kernel-paths/gemma2-f16-f32a.json +60 -0
- package/src/config/presets/kernel-paths/gemma2-q4k-dequant-f16a.json +61 -0
- package/src/config/presets/kernel-paths/gemma2-q4k-dequant-f32a.json +60 -0
- package/src/config/presets/kernel-paths/gemma2-q4k-fused-f32a.json +57 -0
- package/src/config/presets/kernel-paths/gemma3-f16-fused-f16a-online.json +200 -0
- package/src/config/presets/kernel-paths/gemma3-f16-fused-f32a-online.json +223 -0
- package/src/config/presets/kernel-paths/gemma3-q4k-dequant-f16a-online.json +60 -0
- package/src/config/presets/kernel-paths/gemma3-q4k-dequant-f32a-online.json +61 -0
- package/src/config/presets/kernel-paths/gemma3-q4k-dequant-f32a.json +61 -0
- package/src/config/presets/kernel-paths/lfm2-q4k-dequant-f32a-online.json +61 -0
- package/src/config/presets/kernel-paths/registry.json +103 -0
- package/src/config/presets/models/deepseek.json +20 -0
- package/src/config/presets/models/diffusion.json +10 -0
- package/src/config/presets/models/embeddinggemma.json +74 -0
- package/src/config/presets/models/functiongemma.json +31 -0
- package/src/config/presets/models/gemma2.json +59 -0
- package/src/config/presets/models/gemma3.json +75 -0
- package/src/config/presets/models/gpt-oss.json +68 -0
- package/src/config/presets/models/kimi-k2.json +25 -0
- package/src/config/presets/models/lfm2.json +83 -0
- package/src/config/presets/models/llama3.json +40 -0
- package/src/config/presets/models/mamba.json +34 -0
- package/src/config/presets/models/mixtral.json +37 -0
- package/src/config/presets/models/modernbert.json +32 -0
- package/src/config/presets/models/qwen3.json +41 -0
- package/src/config/presets/models/transformer.json +73 -0
- package/src/config/presets/models/translategemma.json +30 -0
- package/src/config/presets/platforms/nvidia-gb200-8gpu.json +45 -0
- package/src/config/presets/platforms/nvidia-gb200-nvl72.json +45 -0
- package/src/config/presets/platforms/nvidia-gh200-nvl2.json +44 -0
- package/src/config/presets/platforms/nvidia-gh200.json +44 -0
- package/src/config/presets/runtime/compute/f16-activations.json +30 -0
- package/src/config/presets/runtime/compute/f16-batched.json +32 -0
- package/src/config/presets/runtime/default.json +101 -0
- package/src/config/presets/runtime/diagnostics/debug-logits.json +53 -0
- package/src/config/presets/runtime/experiments/bench/gemma3-bench-q4k.json +53 -0
- package/src/config/presets/runtime/experiments/debug/gemma3-debug-q4k.json +210 -0
- package/src/config/presets/runtime/experiments/verify/gemma3-verify.json +39 -0
- package/src/config/presets/runtime/kernels/dequant-f16-q4k.json +20 -0
- package/src/config/presets/runtime/kernels/dequant-f32-q4k.json +20 -0
- package/src/config/presets/runtime/kernels/fused-q4k.json +20 -0
- package/src/config/presets/runtime/kernels/safe-q4k.json +20 -0
- package/src/config/presets/runtime/model/gemma2-debug.json +77 -0
- package/src/config/presets/runtime/model/gemma2-pipeline-debug.json +66 -0
- package/src/config/presets/runtime/model/gemma2-pipeline.json +75 -0
- package/src/config/presets/runtime/model/gemma3-layer-probe.json +85 -0
- package/src/config/presets/runtime/modes/bench.json +37 -0
- package/src/config/presets/runtime/modes/debug.json +39 -0
- package/src/config/presets/runtime/modes/default.json +10 -0
- package/src/config/presets/runtime/modes/embedding-bench.json +28 -0
- package/src/config/presets/runtime/modes/embedding.json +54 -0
- package/src/config/presets/runtime/modes/low-memory.json +40 -0
- package/src/config/presets/runtime/modes/production.json +48 -0
- package/src/config/presets/runtime/modes/simulation.json +30 -0
- package/src/config/presets/runtime/modes/trace-layers.json +126 -0
- package/src/config/presets/runtime/platform/metal-apple-q4k.json +11 -0
- package/src/config/runtime-merge.d.ts +5 -0
- package/src/config/runtime-merge.js +21 -0
- package/src/config/runtime.d.ts +28 -0
- package/src/config/runtime.js +56 -0
- package/src/config/schema/adapter.schema.d.ts +53 -0
- package/src/config/schema/adapter.schema.js +60 -0
- package/src/config/schema/backward-registry.schema.d.ts +14 -0
- package/src/config/schema/backward-registry.schema.js +46 -0
- package/src/config/schema/benchmark.schema.d.ts +54 -0
- package/src/config/schema/benchmark.schema.js +74 -0
- package/src/config/schema/bridge.schema.d.ts +25 -0
- package/src/config/schema/bridge.schema.js +22 -0
- package/src/config/schema/buffer-pool.schema.d.ts +92 -0
- package/src/config/schema/buffer-pool.schema.js +50 -0
- package/src/config/schema/conversion.schema.d.ts +183 -0
- package/src/config/schema/conversion.schema.js +13 -0
- package/src/config/schema/converter.schema.d.ts +123 -0
- package/src/config/schema/converter.schema.js +136 -0
- package/src/config/schema/debug.schema.d.ts +245 -0
- package/src/config/schema/debug.schema.js +106 -0
- package/src/config/schema/diffusion.schema.d.ts +88 -0
- package/src/config/schema/diffusion.schema.js +62 -0
- package/src/config/schema/distill-training.schema.d.ts +48 -0
- package/src/config/schema/distill-training.schema.js +139 -0
- package/src/config/schema/distribution.schema.d.ts +155 -0
- package/src/config/schema/distribution.schema.js +81 -0
- package/src/config/schema/doppler.schema.d.ts +75 -0
- package/src/config/schema/doppler.schema.js +352 -0
- package/src/config/schema/ecosystem.schema.d.ts +255 -0
- package/src/config/schema/ecosystem.schema.js +534 -0
- package/src/config/schema/emulation.schema.d.ts +351 -0
- package/src/config/schema/emulation.schema.js +299 -0
- package/src/config/schema/energy.schema.d.ts +102 -0
- package/src/config/schema/energy.schema.js +72 -0
- package/src/config/schema/execution-v0.schema.d.ts +187 -0
- package/src/config/schema/execution-v0.schema.js +55 -0
- package/src/config/schema/gpu-cache.schema.d.ts +26 -0
- package/src/config/schema/gpu-cache.schema.js +8 -0
- package/src/config/schema/harness.schema.d.ts +32 -0
- package/src/config/schema/harness.schema.js +20 -0
- package/src/config/schema/hotswap.schema.d.ts +55 -0
- package/src/config/schema/hotswap.schema.js +18 -0
- package/src/config/schema/index.d.ts +863 -0
- package/src/config/schema/index.js +471 -0
- package/src/config/schema/inference-defaults.schema.d.ts +276 -0
- package/src/config/schema/inference-defaults.schema.js +185 -0
- package/src/config/schema/inference.schema.d.ts +289 -0
- package/src/config/schema/inference.schema.js +39 -0
- package/src/config/schema/intent-bundle.schema.d.ts +28 -0
- package/src/config/schema/intent-bundle.schema.js +12 -0
- package/src/config/schema/kernel-path.schema.d.ts +173 -0
- package/src/config/schema/kernel-path.schema.js +9 -0
- package/src/config/schema/kernel-registry.schema.d.ts +199 -0
- package/src/config/schema/kernel-registry.schema.js +46 -0
- package/src/config/schema/kernel-thresholds.schema.d.ts +302 -0
- package/src/config/schema/kernel-thresholds.schema.js +187 -0
- package/src/config/schema/kernel-warmup.schema.d.ts +19 -0
- package/src/config/schema/kernel-warmup.schema.js +5 -0
- package/src/config/schema/kvcache.schema.d.ts +131 -0
- package/src/config/schema/kvcache.schema.js +31 -0
- package/src/config/schema/loading.schema.d.ts +153 -0
- package/src/config/schema/loading.schema.js +84 -0
- package/src/config/schema/lora.schema.d.ts +12 -0
- package/src/config/schema/lora.schema.js +12 -0
- package/src/config/schema/manifest.schema.d.ts +500 -0
- package/src/config/schema/manifest.schema.js +130 -0
- package/src/config/schema/memory-limits.schema.d.ts +107 -0
- package/src/config/schema/memory-limits.schema.js +57 -0
- package/src/config/schema/moe.schema.d.ts +78 -0
- package/src/config/schema/moe.schema.js +31 -0
- package/src/config/schema/platform.schema.d.ts +121 -0
- package/src/config/schema/platform.schema.js +1 -0
- package/src/config/schema/preset.schema.d.ts +124 -0
- package/src/config/schema/preset.schema.js +1 -0
- package/src/config/schema/quantization-defaults.schema.d.ts +34 -0
- package/src/config/schema/quantization-defaults.schema.js +5 -0
- package/src/config/schema/quantization.schema.d.ts +10 -0
- package/src/config/schema/quantization.schema.js +33 -0
- package/src/config/schema/shared-runtime.schema.d.ts +75 -0
- package/src/config/schema/shared-runtime.schema.js +45 -0
- package/src/config/schema/speculative.schema.d.ts +21 -0
- package/src/config/schema/speculative.schema.js +11 -0
- package/src/config/schema/storage.schema.d.ts +123 -0
- package/src/config/schema/storage.schema.js +66 -0
- package/src/config/schema/tooling.schema.d.ts +29 -0
- package/src/config/schema/tooling.schema.js +12 -0
- package/src/config/schema/training-metrics.schema.d.ts +89 -0
- package/src/config/schema/training-metrics.schema.js +374 -0
- package/src/config/schema/training.schema.d.ts +88 -0
- package/src/config/schema/training.schema.js +106 -0
- package/src/config/schema/tuner.schema.d.ts +39 -0
- package/src/config/schema/tuner.schema.js +13 -0
- package/src/config/schema/ul-training.schema.d.ts +61 -0
- package/src/config/schema/ul-training.schema.js +140 -0
- package/src/config/schema/units.schema.d.ts +27 -0
- package/src/config/schema/units.schema.js +26 -0
- package/src/config/training-defaults.d.ts +24 -0
- package/src/config/training-defaults.js +91 -0
- package/src/converter/conversion-plan.d.ts +64 -0
- package/src/converter/conversion-plan.js +472 -0
- package/src/converter/core.d.ts +247 -0
- package/src/converter/core.js +1329 -0
- package/src/converter/execution-v0-manifest.d.ts +15 -0
- package/src/converter/execution-v0-manifest.js +146 -0
- package/src/converter/index.d.ts +98 -0
- package/src/converter/index.js +59 -0
- package/src/converter/manifest-inference.d.ts +20 -0
- package/src/converter/manifest-inference.js +492 -0
- package/src/converter/parsers/diffusion.d.ts +50 -0
- package/src/converter/parsers/diffusion.js +270 -0
- package/src/converter/parsers/gguf.d.ts +22 -0
- package/src/converter/parsers/gguf.js +46 -0
- package/src/converter/parsers/index.d.ts +21 -0
- package/src/converter/parsers/index.js +12 -0
- package/src/converter/parsers/transformer.d.ts +16 -0
- package/src/converter/parsers/transformer.js +25 -0
- package/src/converter/quantization-info.d.ts +37 -0
- package/src/converter/quantization-info.js +398 -0
- package/src/converter/quantizer.d.ts +96 -0
- package/src/converter/quantizer.js +422 -0
- package/src/converter/rope-config.d.ts +15 -0
- package/src/converter/rope-config.js +218 -0
- package/src/converter/shard-packer.d.ts +138 -0
- package/src/converter/shard-packer.js +422 -0
- package/src/converter/tokenizer-utils.d.ts +11 -0
- package/src/converter/tokenizer-utils.js +87 -0
- package/src/debug/config.d.ts +78 -0
- package/src/debug/config.js +235 -0
- package/src/debug/history.d.ts +65 -0
- package/src/debug/history.js +71 -0
- package/src/debug/index.d.ts +268 -0
- package/src/debug/index.js +192 -0
- package/src/debug/log.d.ts +46 -0
- package/src/debug/log.js +132 -0
- package/src/debug/perf.d.ts +33 -0
- package/src/debug/perf.js +51 -0
- package/src/debug/reference/README.md +114 -0
- package/src/debug/reference/hf_attn_debug.py +114 -0
- package/src/debug/reference/hf_embed_check.py +89 -0
- package/src/debug/reference/hf_layer_out.py +100 -0
- package/src/debug/reference/hf_rope_check.py +116 -0
- package/src/debug/reference/hf_weights.py +75 -0
- package/src/debug/signals.d.ts +63 -0
- package/src/debug/signals.js +33 -0
- package/src/debug/stats.d.ts +47 -0
- package/src/debug/stats.js +160 -0
- package/src/debug/tensor.d.ts +123 -0
- package/src/debug/tensor.js +257 -0
- package/src/debug/trace.d.ts +17 -0
- package/src/debug/trace.js +167 -0
- package/src/diffusion/image-regression.d.ts +31 -0
- package/src/diffusion/image-regression.js +107 -0
- package/src/diffusion/index.d.ts +8 -0
- package/src/diffusion/index.js +8 -0
- package/src/distribution/p2p-control-plane.d.ts +52 -0
- package/src/distribution/p2p-control-plane.js +232 -0
- package/src/distribution/p2p-observability.d.ts +116 -0
- package/src/distribution/p2p-observability.js +267 -0
- package/src/distribution/p2p-transport-contract.d.ts +57 -0
- package/src/distribution/p2p-transport-contract.js +310 -0
- package/src/distribution/p2p-webrtc-browser.d.ts +37 -0
- package/src/distribution/p2p-webrtc-browser.js +434 -0
- package/src/distribution/shard-delivery.d.ts +251 -0
- package/src/distribution/shard-delivery.js +2096 -0
- package/src/energy/index.d.ts +2 -0
- package/src/energy/index.js +2 -0
- package/src/errors/doppler-error.d.ts +21 -0
- package/src/errors/doppler-error.js +25 -0
- package/src/errors/index.d.ts +1 -0
- package/src/errors/index.js +1 -0
- package/src/formats/gguf/index.d.ts +8 -0
- package/src/formats/gguf/index.js +4 -0
- package/src/formats/gguf/types.d.ts +137 -0
- package/src/formats/gguf/types.js +443 -0
- package/src/formats/index.d.ts +51 -0
- package/src/formats/index.js +13 -0
- package/src/formats/rdrr/classification.d.ts +39 -0
- package/src/formats/rdrr/classification.js +275 -0
- package/src/formats/rdrr/groups.d.ts +27 -0
- package/src/formats/rdrr/groups.js +76 -0
- package/src/formats/rdrr/index.d.ts +25 -0
- package/src/formats/rdrr/index.js +19 -0
- package/src/formats/rdrr/manifest.d.ts +32 -0
- package/src/formats/rdrr/manifest.js +108 -0
- package/src/formats/rdrr/parsing.d.ts +23 -0
- package/src/formats/rdrr/parsing.js +101 -0
- package/src/formats/rdrr/tensor-config-validator.d.ts +42 -0
- package/src/formats/rdrr/tensor-config-validator.js +156 -0
- package/src/formats/rdrr/types.d.ts +200 -0
- package/src/formats/rdrr/types.js +16 -0
- package/src/formats/rdrr/validation.d.ts +9 -0
- package/src/formats/rdrr/validation.js +200 -0
- package/src/formats/safetensors/index.d.ts +8 -0
- package/src/formats/safetensors/index.js +4 -0
- package/src/formats/safetensors/types.d.ts +67 -0
- package/src/formats/safetensors/types.js +102 -0
- package/src/formats/tokenizer/index.d.ts +5 -0
- package/src/formats/tokenizer/index.js +3 -0
- package/src/formats/tokenizer/types.d.ts +9 -0
- package/src/formats/tokenizer/types.js +22 -0
- package/src/generation/index.d.ts +18 -0
- package/src/generation/index.js +12 -0
- package/src/gpu/command-recorder.d.ts +175 -0
- package/src/gpu/command-recorder.js +473 -0
- package/src/gpu/device.d.ts +141 -0
- package/src/gpu/device.js +350 -0
- package/src/gpu/kernel-runtime.d.ts +20 -0
- package/src/gpu/kernel-runtime.js +37 -0
- package/src/gpu/kernel-selection-cache.d.ts +13 -0
- package/src/gpu/kernel-selection-cache.js +13 -0
- package/src/gpu/kernel-selection-log.d.ts +12 -0
- package/src/gpu/kernel-selection-log.js +28 -0
- package/src/gpu/kernel-selector.d.ts +11 -0
- package/src/gpu/kernel-selector.js +10 -0
- package/src/gpu/kernel-tuner/benchmarks.d.ts +144 -0
- package/src/gpu/kernel-tuner/benchmarks.js +892 -0
- package/src/gpu/kernel-tuner/cache.d.ts +55 -0
- package/src/gpu/kernel-tuner/cache.js +66 -0
- package/src/gpu/kernel-tuner/index.d.ts +59 -0
- package/src/gpu/kernel-tuner/index.js +38 -0
- package/src/gpu/kernel-tuner/tuner.d.ts +82 -0
- package/src/gpu/kernel-tuner/tuner.js +229 -0
- package/src/gpu/kernel-tuner/types.d.ts +101 -0
- package/src/gpu/kernel-tuner/types.js +4 -0
- package/src/gpu/kernel-tuner.d.ts +33 -0
- package/src/gpu/kernel-tuner.js +12 -0
- package/src/gpu/kernels/README.md +127 -0
- package/src/gpu/kernels/attention.d.ts +236 -0
- package/src/gpu/kernels/attention.js +1359 -0
- package/src/gpu/kernels/attention.wgsl +249 -0
- package/src/gpu/kernels/attention_bdpa_decode_f16.wgsl +246 -0
- package/src/gpu/kernels/attention_decode.wgsl +233 -0
- package/src/gpu/kernels/attention_decode_chunked_f16.wgsl +183 -0
- package/src/gpu/kernels/attention_decode_chunked_f16kv.wgsl +208 -0
- package/src/gpu/kernels/attention_decode_f16.wgsl +202 -0
- package/src/gpu/kernels/attention_decode_f16kv.wgsl +224 -0
- package/src/gpu/kernels/attention_decode_online_f16.wgsl +223 -0
- package/src/gpu/kernels/attention_decode_online_f16kv.wgsl +225 -0
- package/src/gpu/kernels/attention_decode_optimized.wgsl +445 -0
- package/src/gpu/kernels/attention_decode_paged_f16.wgsl +172 -0
- package/src/gpu/kernels/attention_decode_paged_f16kv.wgsl +174 -0
- package/src/gpu/kernels/attention_decode_subgroup.wgsl +233 -0
- package/src/gpu/kernels/attention_decode_tiered_f16.wgsl +218 -0
- package/src/gpu/kernels/attention_decode_tiered_f16kv.wgsl +220 -0
- package/src/gpu/kernels/attention_decode_tiered_int4_f16kv.wgsl +242 -0
- package/src/gpu/kernels/attention_decode_tiered_int8_f16kv.wgsl +242 -0
- package/src/gpu/kernels/attention_f16.wgsl +214 -0
- package/src/gpu/kernels/attention_f16kv.wgsl +242 -0
- package/src/gpu/kernels/attention_small.wgsl +260 -0
- package/src/gpu/kernels/attention_small_f16.wgsl +240 -0
- package/src/gpu/kernels/attention_small_f16kv.wgsl +266 -0
- package/src/gpu/kernels/attention_streaming.wgsl +149 -0
- package/src/gpu/kernels/attention_streaming_f16.wgsl +147 -0
- package/src/gpu/kernels/attention_streaming_f16kv.wgsl +151 -0
- package/src/gpu/kernels/backward/adam.d.ts +28 -0
- package/src/gpu/kernels/backward/adam.js +199 -0
- package/src/gpu/kernels/backward/adam.wgsl +50 -0
- package/src/gpu/kernels/backward/attention_backward.d.ts +22 -0
- package/src/gpu/kernels/backward/attention_backward.js +276 -0
- package/src/gpu/kernels/backward/attention_backward.wgsl +49 -0
- package/src/gpu/kernels/backward/bias_add_backward.d.ts +17 -0
- package/src/gpu/kernels/backward/bias_add_backward.js +24 -0
- package/src/gpu/kernels/backward/bias_add_backward.wgsl +33 -0
- package/src/gpu/kernels/backward/conv2d_backward.d.ts +31 -0
- package/src/gpu/kernels/backward/conv2d_backward.js +135 -0
- package/src/gpu/kernels/backward/conv2d_backward_input.wgsl +83 -0
- package/src/gpu/kernels/backward/conv2d_backward_weight.wgsl +70 -0
- package/src/gpu/kernels/backward/cross_entropy_backward.d.ts +23 -0
- package/src/gpu/kernels/backward/cross_entropy_backward.js +29 -0
- package/src/gpu/kernels/backward/cross_entropy_backward.wgsl +39 -0
- package/src/gpu/kernels/backward/embed_backward.d.ts +29 -0
- package/src/gpu/kernels/backward/embed_backward.js +118 -0
- package/src/gpu/kernels/backward/embed_backward.wgsl +73 -0
- package/src/gpu/kernels/backward/gelu_backward.d.ts +16 -0
- package/src/gpu/kernels/backward/gelu_backward.js +39 -0
- package/src/gpu/kernels/backward/gelu_backward.wgsl +38 -0
- package/src/gpu/kernels/backward/groupnorm_backward.d.ts +24 -0
- package/src/gpu/kernels/backward/groupnorm_backward.js +29 -0
- package/src/gpu/kernels/backward/groupnorm_backward.wgsl +143 -0
- package/src/gpu/kernels/backward/index.d.ts +17 -0
- package/src/gpu/kernels/backward/index.js +23 -0
- package/src/gpu/kernels/backward/layernorm_backward.d.ts +22 -0
- package/src/gpu/kernels/backward/layernorm_backward.js +135 -0
- package/src/gpu/kernels/backward/layernorm_backward.wgsl +194 -0
- package/src/gpu/kernels/backward/matmul_backward.d.ts +32 -0
- package/src/gpu/kernels/backward/matmul_backward.js +124 -0
- package/src/gpu/kernels/backward/matmul_backward.wgsl +90 -0
- package/src/gpu/kernels/backward/matmul_transpose_a.wgsl +84 -0
- package/src/gpu/kernels/backward/pixel_shuffle_backward.d.ts +22 -0
- package/src/gpu/kernels/backward/pixel_shuffle_backward.js +30 -0
- package/src/gpu/kernels/backward/pixel_shuffle_backward.wgsl +54 -0
- package/src/gpu/kernels/backward/rmsnorm_backward.d.ts +24 -0
- package/src/gpu/kernels/backward/rmsnorm_backward.js +101 -0
- package/src/gpu/kernels/backward/rmsnorm_backward.wgsl +78 -0
- package/src/gpu/kernels/backward/rope_backward.d.ts +25 -0
- package/src/gpu/kernels/backward/rope_backward.js +109 -0
- package/src/gpu/kernels/backward/rope_backward.wgsl +59 -0
- package/src/gpu/kernels/backward/scale_backward.d.ts +16 -0
- package/src/gpu/kernels/backward/scale_backward.js +84 -0
- package/src/gpu/kernels/backward/scale_backward.wgsl +27 -0
- package/src/gpu/kernels/backward/silu_backward.d.ts +16 -0
- package/src/gpu/kernels/backward/silu_backward.js +39 -0
- package/src/gpu/kernels/backward/silu_backward.wgsl +31 -0
- package/src/gpu/kernels/backward/softmax_backward.d.ts +16 -0
- package/src/gpu/kernels/backward/softmax_backward.js +43 -0
- package/src/gpu/kernels/backward/softmax_backward.wgsl +44 -0
- package/src/gpu/kernels/backward/upsample2d_backward.d.ts +21 -0
- package/src/gpu/kernels/backward/upsample2d_backward.js +30 -0
- package/src/gpu/kernels/backward/upsample2d_backward.wgsl +59 -0
- package/src/gpu/kernels/backward/utils.d.ts +45 -0
- package/src/gpu/kernels/backward/utils.js +371 -0
- package/src/gpu/kernels/bf16_to_f16.wgsl +54 -0
- package/src/gpu/kernels/bf16_to_f32.wgsl +70 -0
- package/src/gpu/kernels/bias_add.wgsl +40 -0
- package/src/gpu/kernels/bias_add_f16.wgsl +44 -0
- package/src/gpu/kernels/cast.d.ts +67 -0
- package/src/gpu/kernels/cast.js +422 -0
- package/src/gpu/kernels/cast_f16_to_f32.wgsl +31 -0
- package/src/gpu/kernels/cast_f32_to_f16.wgsl +36 -0
- package/src/gpu/kernels/check-finiteness.d.ts +15 -0
- package/src/gpu/kernels/check-finiteness.js +149 -0
- package/src/gpu/kernels/check-stop.d.ts +31 -0
- package/src/gpu/kernels/check-stop.js +181 -0
- package/src/gpu/kernels/clamp.d.ts +22 -0
- package/src/gpu/kernels/clamp.js +42 -0
- package/src/gpu/kernels/clamp.wgsl +24 -0
- package/src/gpu/kernels/constants.d.ts +168 -0
- package/src/gpu/kernels/constants.js +129 -0
- package/src/gpu/kernels/conv2d.d.ts +34 -0
- package/src/gpu/kernels/conv2d.js +81 -0
- package/src/gpu/kernels/conv2d.wgsl +71 -0
- package/src/gpu/kernels/conv2d_f16.wgsl +73 -0
- package/src/gpu/kernels/cross_entropy_loss.d.ts +21 -0
- package/src/gpu/kernels/cross_entropy_loss.js +54 -0
- package/src/gpu/kernels/cross_entropy_loss.wgsl +39 -0
- package/src/gpu/kernels/dequant.d.ts +108 -0
- package/src/gpu/kernels/dequant.js +524 -0
- package/src/gpu/kernels/dequant_f16_out.wgsl +151 -0
- package/src/gpu/kernels/dequant_f16_out_vec4.wgsl +149 -0
- package/src/gpu/kernels/dequant_f16_rowwise.wgsl +139 -0
- package/src/gpu/kernels/dequant_f32_rowwise.wgsl +133 -0
- package/src/gpu/kernels/dequant_mxfp4.wgsl +120 -0
- package/src/gpu/kernels/dequant_mxfp4_expert.wgsl +129 -0
- package/src/gpu/kernels/dequant_mxfp4_expert_f16.wgsl +105 -0
- package/src/gpu/kernels/dequant_mxfp4_vec4.wgsl +116 -0
- package/src/gpu/kernels/dequant_q6k.wgsl +140 -0
- package/src/gpu/kernels/dequant_q8_0.wgsl +98 -0
- package/src/gpu/kernels/dequant_shared.wgsl +202 -0
- package/src/gpu/kernels/dequant_shared_vec4.wgsl +153 -0
- package/src/gpu/kernels/dequant_subgroup.wgsl +202 -0
- package/src/gpu/kernels/dispatch.d.ts +157 -0
- package/src/gpu/kernels/dispatch.js +235 -0
- package/src/gpu/kernels/energy.d.ts +131 -0
- package/src/gpu/kernels/energy.js +425 -0
- package/src/gpu/kernels/energy_eval.wgsl +26 -0
- package/src/gpu/kernels/energy_eval_f16.wgsl +30 -0
- package/src/gpu/kernels/energy_quintel_grad.wgsl +92 -0
- package/src/gpu/kernels/energy_quintel_grad_f16.wgsl +96 -0
- package/src/gpu/kernels/energy_quintel_reduce.wgsl +112 -0
- package/src/gpu/kernels/energy_quintel_reduce_f16.wgsl +116 -0
- package/src/gpu/kernels/energy_quintel_update.wgsl +92 -0
- package/src/gpu/kernels/energy_quintel_update_f16.wgsl +96 -0
- package/src/gpu/kernels/energy_update.wgsl +25 -0
- package/src/gpu/kernels/energy_update_f16.wgsl +30 -0
- package/src/gpu/kernels/feature-check.d.ts +42 -0
- package/src/gpu/kernels/feature-check.js +70 -0
- package/src/gpu/kernels/fused_ffn.d.ts +65 -0
- package/src/gpu/kernels/fused_ffn.js +318 -0
- package/src/gpu/kernels/fused_ffn.wgsl +420 -0
- package/src/gpu/kernels/fused_ffn_f16.wgsl +213 -0
- package/src/gpu/kernels/fused_ffn_q4k.wgsl +375 -0
- package/src/gpu/kernels/fused_matmul_q4.wgsl +404 -0
- package/src/gpu/kernels/fused_matmul_q4_batched.wgsl +194 -0
- package/src/gpu/kernels/fused_matmul_q4_batched_f16.wgsl +170 -0
- package/src/gpu/kernels/fused_matmul_q4_batched_f16a.wgsl +154 -0
- package/src/gpu/kernels/fused_matmul_q4_f16a.wgsl +219 -0
- package/src/gpu/kernels/fused_matmul_q4_multicol_f16.wgsl +216 -0
- package/src/gpu/kernels/fused_matmul_q4_multicol_f16a.wgsl +204 -0
- package/src/gpu/kernels/fused_matmul_residual.d.ts +46 -0
- package/src/gpu/kernels/fused_matmul_residual.js +152 -0
- package/src/gpu/kernels/fused_matmul_rmsnorm.d.ts +64 -0
- package/src/gpu/kernels/fused_matmul_rmsnorm.js +273 -0
- package/src/gpu/kernels/fused_matmul_rmsnorm.wgsl +324 -0
- package/src/gpu/kernels/fused_matmul_rmsnorm_f16.wgsl +303 -0
- package/src/gpu/kernels/fused_swiglu.wgsl +63 -0
- package/src/gpu/kernels/fused_swiglu_f16.wgsl +57 -0
- package/src/gpu/kernels/gather.d.ts +64 -0
- package/src/gpu/kernels/gather.js +119 -0
- package/src/gpu/kernels/gather.wgsl +61 -0
- package/src/gpu/kernels/gather_f16.wgsl +65 -0
- package/src/gpu/kernels/gather_f16_f16_out.wgsl +55 -0
- package/src/gpu/kernels/gather_f16_out.wgsl +55 -0
- package/src/gpu/kernels/gather_f16_vec4.wgsl +76 -0
- package/src/gpu/kernels/gather_f16_vec4_f16_out.wgsl +68 -0
- package/src/gpu/kernels/gather_vec4.wgsl +74 -0
- package/src/gpu/kernels/gather_vec4_f16_out.wgsl +68 -0
- package/src/gpu/kernels/gelu.d.ts +33 -0
- package/src/gpu/kernels/gelu.js +47 -0
- package/src/gpu/kernels/gelu.wgsl +64 -0
- package/src/gpu/kernels/gelu_f16.wgsl +66 -0
- package/src/gpu/kernels/gptoss_mxfp4_expert_fused.wgsl +127 -0
- package/src/gpu/kernels/gptoss_router_topk.wgsl +119 -0
- package/src/gpu/kernels/groupnorm.d.ts +31 -0
- package/src/gpu/kernels/groupnorm.js +91 -0
- package/src/gpu/kernels/groupnorm_apply.wgsl +41 -0
- package/src/gpu/kernels/groupnorm_apply_f16.wgsl +46 -0
- package/src/gpu/kernels/groupnorm_stats.wgsl +76 -0
- package/src/gpu/kernels/groupnorm_stats_f16.wgsl +79 -0
- package/src/gpu/kernels/index.d.ts +336 -0
- package/src/gpu/kernels/index.js +284 -0
- package/src/gpu/kernels/kernel-base.d.ts +33 -0
- package/src/gpu/kernels/kernel-base.js +46 -0
- package/src/gpu/kernels/kernel-configs.d.ts +65 -0
- package/src/gpu/kernels/kernel-configs.js +50 -0
- package/src/gpu/kernels/kernel-tuning.d.ts +42 -0
- package/src/gpu/kernels/kernel-tuning.js +149 -0
- package/src/gpu/kernels/kv-quantize.d.ts +37 -0
- package/src/gpu/kernels/kv-quantize.js +138 -0
- package/src/gpu/kernels/kv_quantize_int4.wgsl +119 -0
- package/src/gpu/kernels/kv_quantize_int8.wgsl +119 -0
- package/src/gpu/kernels/layernorm.d.ts +37 -0
- package/src/gpu/kernels/layernorm.js +80 -0
- package/src/gpu/kernels/layernorm.wgsl +121 -0
- package/src/gpu/kernels/layernorm_f16.wgsl +103 -0
- package/src/gpu/kernels/linear-attention-core.d.ts +39 -0
- package/src/gpu/kernels/linear-attention-core.js +535 -0
- package/src/gpu/kernels/logit-merge.d.ts +110 -0
- package/src/gpu/kernels/logit-merge.js +392 -0
- package/src/gpu/kernels/matmul-dispatch.d.ts +38 -0
- package/src/gpu/kernels/matmul-dispatch.js +155 -0
- package/src/gpu/kernels/matmul-selection.d.ts +87 -0
- package/src/gpu/kernels/matmul-selection.js +474 -0
- package/src/gpu/kernels/matmul.d.ts +109 -0
- package/src/gpu/kernels/matmul.js +271 -0
- package/src/gpu/kernels/matmul_f16.wgsl +170 -0
- package/src/gpu/kernels/matmul_f16_tiled.wgsl +165 -0
- package/src/gpu/kernels/matmul_f16w_f32a.wgsl +89 -0
- package/src/gpu/kernels/matmul_f16w_f32a_tiled.wgsl +154 -0
- package/src/gpu/kernels/matmul_f32.wgsl +100 -0
- package/src/gpu/kernels/matmul_gemv.wgsl +80 -0
- package/src/gpu/kernels/matmul_gemv_f16a.wgsl +81 -0
- package/src/gpu/kernels/matmul_gemv_residual.wgsl +119 -0
- package/src/gpu/kernels/matmul_gemv_residual_f16.wgsl +78 -0
- package/src/gpu/kernels/matmul_gemv_subgroup.wgsl +345 -0
- package/src/gpu/kernels/matmul_gemv_subgroup_f16a.wgsl +514 -0
- package/src/gpu/kernels/modulate.d.ts +29 -0
- package/src/gpu/kernels/modulate.js +49 -0
- package/src/gpu/kernels/modulate.wgsl +40 -0
- package/src/gpu/kernels/modulate_f16.wgsl +43 -0
- package/src/gpu/kernels/moe.d.ts +164 -0
- package/src/gpu/kernels/moe.js +496 -0
- package/src/gpu/kernels/moe_gather.wgsl +170 -0
- package/src/gpu/kernels/moe_gather_f16.wgsl +82 -0
- package/src/gpu/kernels/moe_gather_vec4.wgsl +74 -0
- package/src/gpu/kernels/moe_offsets.wgsl +48 -0
- package/src/gpu/kernels/pipeline-cache.d.ts +88 -0
- package/src/gpu/kernels/pipeline-cache.js +305 -0
- package/src/gpu/kernels/pixel_shuffle.d.ts +27 -0
- package/src/gpu/kernels/pixel_shuffle.js +49 -0
- package/src/gpu/kernels/pixel_shuffle.wgsl +44 -0
- package/src/gpu/kernels/pixel_shuffle_f16.wgsl +47 -0
- package/src/gpu/kernels/residual.d.ts +74 -0
- package/src/gpu/kernels/residual.js +127 -0
- package/src/gpu/kernels/residual.wgsl +53 -0
- package/src/gpu/kernels/residual_f16.wgsl +35 -0
- package/src/gpu/kernels/residual_f16_vec4.wgsl +47 -0
- package/src/gpu/kernels/residual_vec4.wgsl +46 -0
- package/src/gpu/kernels/rmsnorm.d.ts +53 -0
- package/src/gpu/kernels/rmsnorm.js +140 -0
- package/src/gpu/kernels/rmsnorm.wgsl +417 -0
- package/src/gpu/kernels/rmsnorm_f16.wgsl +164 -0
- package/src/gpu/kernels/rope.d.ts +48 -0
- package/src/gpu/kernels/rope.js +53 -0
- package/src/gpu/kernels/rope.wgsl +328 -0
- package/src/gpu/kernels/rope_f16.wgsl +271 -0
- package/src/gpu/kernels/rule-matcher.d.ts +30 -0
- package/src/gpu/kernels/rule-matcher.js +42 -0
- package/src/gpu/kernels/rule-registry.d.ts +7 -0
- package/src/gpu/kernels/rule-registry.js +41 -0
- package/src/gpu/kernels/sample.d.ts +75 -0
- package/src/gpu/kernels/sample.js +578 -0
- package/src/gpu/kernels/sample.wgsl +377 -0
- package/src/gpu/kernels/sample_f16.wgsl +331 -0
- package/src/gpu/kernels/scale.d.ts +35 -0
- package/src/gpu/kernels/scale.js +37 -0
- package/src/gpu/kernels/scale.wgsl +38 -0
- package/src/gpu/kernels/scatter_add.wgsl +88 -0
- package/src/gpu/kernels/scatter_add_dynamic.wgsl +59 -0
- package/src/gpu/kernels/scatter_add_dynamic_f16.wgsl +52 -0
- package/src/gpu/kernels/scatter_add_dynamic_f16_weights.wgsl +50 -0
- package/src/gpu/kernels/scatter_add_vec4.wgsl +70 -0
- package/src/gpu/kernels/shader-cache.d.ts +56 -0
- package/src/gpu/kernels/shader-cache.js +206 -0
- package/src/gpu/kernels/silu.d.ts +75 -0
- package/src/gpu/kernels/silu.js +340 -0
- package/src/gpu/kernels/silu.wgsl +99 -0
- package/src/gpu/kernels/silu_f16.wgsl +98 -0
- package/src/gpu/kernels/softmax.d.ts +57 -0
- package/src/gpu/kernels/softmax.js +106 -0
- package/src/gpu/kernels/softmax.wgsl +388 -0
- package/src/gpu/kernels/softmax_subgroup.wgsl +175 -0
- package/src/gpu/kernels/split_qkv.d.ts +51 -0
- package/src/gpu/kernels/split_qkv.js +41 -0
- package/src/gpu/kernels/split_qkv.wgsl +71 -0
- package/src/gpu/kernels/split_qkv_f16.wgsl +75 -0
- package/src/gpu/kernels/topk.wgsl +243 -0
- package/src/gpu/kernels/topk_f16.wgsl +108 -0
- package/src/gpu/kernels/topk_f16_weights.wgsl +101 -0
- package/src/gpu/kernels/transpose.d.ts +21 -0
- package/src/gpu/kernels/transpose.js +30 -0
- package/src/gpu/kernels/transpose.wgsl +32 -0
- package/src/gpu/kernels/types.d.ts +21 -0
- package/src/gpu/kernels/types.js +4 -0
- package/src/gpu/kernels/uniform-utils.d.ts +48 -0
- package/src/gpu/kernels/uniform-utils.js +94 -0
- package/src/gpu/kernels/upsample2d.d.ts +25 -0
- package/src/gpu/kernels/upsample2d.js +58 -0
- package/src/gpu/kernels/upsample2d.wgsl +37 -0
- package/src/gpu/kernels/upsample2d_f16.wgsl +41 -0
- package/src/gpu/kernels/utils.d.ts +106 -0
- package/src/gpu/kernels/utils.js +224 -0
- package/src/gpu/multi-model-recorder.d.ts +21 -0
- package/src/gpu/multi-model-recorder.js +31 -0
- package/src/gpu/partitioned-buffer-pool.d.ts +28 -0
- package/src/gpu/partitioned-buffer-pool.js +49 -0
- package/src/gpu/perf-guards.d.ts +25 -0
- package/src/gpu/perf-guards.js +140 -0
- package/src/gpu/profiler.d.ts +114 -0
- package/src/gpu/profiler.js +391 -0
- package/src/gpu/submit-tracker.d.ts +111 -0
- package/src/gpu/submit-tracker.js +229 -0
- package/src/gpu/tensor.d.ts +69 -0
- package/src/gpu/tensor.js +75 -0
- package/src/gpu/uniform-cache.d.ts +108 -0
- package/src/gpu/uniform-cache.js +242 -0
- package/src/gpu/weight-buffer.d.ts +115 -0
- package/src/gpu/weight-buffer.js +118 -0
- package/src/hotswap/intent-bundle.d.ts +37 -0
- package/src/hotswap/intent-bundle.js +123 -0
- package/src/hotswap/manifest.d.ts +33 -0
- package/src/hotswap/manifest.js +114 -0
- package/src/hotswap/runtime.d.ts +31 -0
- package/src/hotswap/runtime.js +128 -0
- package/src/index-browser.d.ts +47 -0
- package/src/index-browser.js +53 -0
- package/src/index-internal.d.ts +2 -0
- package/src/index-internal.js +2 -0
- package/src/index.d.ts +102 -0
- package/src/index.js +75 -0
- package/src/inference/README.md +593 -0
- package/src/inference/browser-harness.d.ts +234 -0
- package/src/inference/browser-harness.js +2665 -0
- package/src/inference/decode-buffers.d.ts +108 -0
- package/src/inference/decode-buffers.js +181 -0
- package/src/inference/decode-ring.d.ts +52 -0
- package/src/inference/decode-ring.js +273 -0
- package/src/inference/expert-router.d.ts +27 -0
- package/src/inference/expert-router.js +55 -0
- package/src/inference/functiongemma.d.ts +15 -0
- package/src/inference/functiongemma.js +1 -0
- package/src/inference/kv-cache/base.d.ts +150 -0
- package/src/inference/kv-cache/base.js +1037 -0
- package/src/inference/kv-cache/basis-decomposed-paged.d.ts +50 -0
- package/src/inference/kv-cache/basis-decomposed-paged.js +276 -0
- package/src/inference/kv-cache/index.d.ts +35 -0
- package/src/inference/kv-cache/index.js +20 -0
- package/src/inference/kv-cache/sliding-window.d.ts +72 -0
- package/src/inference/kv-cache/sliding-window.js +243 -0
- package/src/inference/kv-cache/tiered.d.ts +89 -0
- package/src/inference/kv-cache/tiered.js +574 -0
- package/src/inference/kv-cache/types.d.ts +188 -0
- package/src/inference/kv-cache/types.js +80 -0
- package/src/inference/kv-cache.d.ts +36 -0
- package/src/inference/kv-cache.js +18 -0
- package/src/inference/moe-router.d.ts +212 -0
- package/src/inference/moe-router.js +553 -0
- package/src/inference/multi-model-network.d.ts +139 -0
- package/src/inference/multi-model-network.js +769 -0
- package/src/inference/multi-pipeline-pool.d.ts +62 -0
- package/src/inference/multi-pipeline-pool.js +161 -0
- package/src/inference/network-evolution.d.ts +46 -0
- package/src/inference/network-evolution.js +80 -0
- package/src/inference/pipelines/context.d.ts +18 -0
- package/src/inference/pipelines/context.js +44 -0
- package/src/inference/pipelines/diffusion/helpers.d.ts +29 -0
- package/src/inference/pipelines/diffusion/helpers.js +112 -0
- package/src/inference/pipelines/diffusion/index.d.ts +3 -0
- package/src/inference/pipelines/diffusion/index.js +3 -0
- package/src/inference/pipelines/diffusion/init.d.ts +24 -0
- package/src/inference/pipelines/diffusion/init.js +124 -0
- package/src/inference/pipelines/diffusion/pipeline.d.ts +38 -0
- package/src/inference/pipelines/diffusion/pipeline.js +632 -0
- package/src/inference/pipelines/diffusion/scheduler.d.ts +19 -0
- package/src/inference/pipelines/diffusion/scheduler.js +65 -0
- package/src/inference/pipelines/diffusion/sd3-transformer.d.ts +20 -0
- package/src/inference/pipelines/diffusion/sd3-transformer.js +1194 -0
- package/src/inference/pipelines/diffusion/sd3-weights.d.ts +21 -0
- package/src/inference/pipelines/diffusion/sd3-weights.js +287 -0
- package/src/inference/pipelines/diffusion/text-encoder-gpu.d.ts +80 -0
- package/src/inference/pipelines/diffusion/text-encoder-gpu.js +935 -0
- package/src/inference/pipelines/diffusion/text-encoder.d.ts +29 -0
- package/src/inference/pipelines/diffusion/text-encoder.js +178 -0
- package/src/inference/pipelines/diffusion/types.d.ts +112 -0
- package/src/inference/pipelines/diffusion/types.js +1 -0
- package/src/inference/pipelines/diffusion/vae.d.ts +20 -0
- package/src/inference/pipelines/diffusion/vae.js +675 -0
- package/src/inference/pipelines/diffusion/weights.d.ts +40 -0
- package/src/inference/pipelines/diffusion/weights.js +150 -0
- package/src/inference/pipelines/dream/energy-head-pipeline.d.ts +29 -0
- package/src/inference/pipelines/dream/energy-head-pipeline.js +6 -0
- package/src/inference/pipelines/dream/pipeline.d.ts +17 -0
- package/src/inference/pipelines/dream/pipeline.js +8 -0
- package/src/inference/pipelines/energy/index.d.ts +1 -0
- package/src/inference/pipelines/energy/index.js +1 -0
- package/src/inference/pipelines/energy/pipeline.d.ts +27 -0
- package/src/inference/pipelines/energy/pipeline.js +680 -0
- package/src/inference/pipelines/energy/quintel.d.ts +87 -0
- package/src/inference/pipelines/energy/quintel.js +207 -0
- package/src/inference/pipelines/energy/types.d.ts +63 -0
- package/src/inference/pipelines/energy/types.js +1 -0
- package/src/inference/pipelines/energy-head/index.d.ts +6 -0
- package/src/inference/pipelines/energy-head/index.js +6 -0
- package/src/inference/pipelines/energy-head/row-head-pipeline.d.ts +103 -0
- package/src/inference/pipelines/energy-head/row-head-pipeline.js +487 -0
- package/src/inference/pipelines/factory.d.ts +10 -0
- package/src/inference/pipelines/factory.js +6 -0
- package/src/inference/pipelines/index.d.ts +22 -0
- package/src/inference/pipelines/index.js +19 -0
- package/src/inference/pipelines/registry.d.ts +15 -0
- package/src/inference/pipelines/registry.js +23 -0
- package/src/inference/pipelines/rng.d.ts +2 -0
- package/src/inference/pipelines/rng.js +17 -0
- package/src/inference/pipelines/structured/index.d.ts +8 -0
- package/src/inference/pipelines/structured/index.js +8 -0
- package/src/inference/pipelines/structured/json-head-pipeline.d.ts +58 -0
- package/src/inference/pipelines/structured/json-head-pipeline.js +181 -0
- package/src/inference/pipelines/text/attention/index.d.ts +24 -0
- package/src/inference/pipelines/text/attention/index.js +17 -0
- package/src/inference/pipelines/text/attention/projections.d.ts +101 -0
- package/src/inference/pipelines/text/attention/projections.js +435 -0
- package/src/inference/pipelines/text/attention/record.d.ts +36 -0
- package/src/inference/pipelines/text/attention/record.js +613 -0
- package/src/inference/pipelines/text/attention/run.d.ts +38 -0
- package/src/inference/pipelines/text/attention/run.js +826 -0
- package/src/inference/pipelines/text/attention/types.d.ts +98 -0
- package/src/inference/pipelines/text/attention/types.js +67 -0
- package/src/inference/pipelines/text/attention.d.ts +23 -0
- package/src/inference/pipelines/text/attention.js +12 -0
- package/src/inference/pipelines/text/bdpa-steamroller.d.ts +22 -0
- package/src/inference/pipelines/text/bdpa-steamroller.js +158 -0
- package/src/inference/pipelines/text/buffer-types.d.ts +7 -0
- package/src/inference/pipelines/text/buffer-types.js +4 -0
- package/src/inference/pipelines/text/chat-format.d.ts +46 -0
- package/src/inference/pipelines/text/chat-format.js +366 -0
- package/src/inference/pipelines/text/config.d.ts +235 -0
- package/src/inference/pipelines/text/config.js +623 -0
- package/src/inference/pipelines/text/debug-utils/config.d.ts +144 -0
- package/src/inference/pipelines/text/debug-utils/config.js +156 -0
- package/src/inference/pipelines/text/debug-utils/index.d.ts +53 -0
- package/src/inference/pipelines/text/debug-utils/index.js +44 -0
- package/src/inference/pipelines/text/debug-utils/logging.d.ts +106 -0
- package/src/inference/pipelines/text/debug-utils/logging.js +152 -0
- package/src/inference/pipelines/text/debug-utils/tensor.d.ts +119 -0
- package/src/inference/pipelines/text/debug-utils/tensor.js +268 -0
- package/src/inference/pipelines/text/debug-utils/utils.d.ts +77 -0
- package/src/inference/pipelines/text/debug-utils/utils.js +139 -0
- package/src/inference/pipelines/text/debug-utils.d.ts +42 -0
- package/src/inference/pipelines/text/debug-utils.js +34 -0
- package/src/inference/pipelines/text/embed.d.ts +67 -0
- package/src/inference/pipelines/text/embed.js +461 -0
- package/src/inference/pipelines/text/execution-plan.d.ts +116 -0
- package/src/inference/pipelines/text/execution-plan.js +314 -0
- package/src/inference/pipelines/text/execution-v0.d.ts +66 -0
- package/src/inference/pipelines/text/execution-v0.js +1139 -0
- package/src/inference/pipelines/text/ffn/dense.d.ts +40 -0
- package/src/inference/pipelines/text/ffn/dense.js +759 -0
- package/src/inference/pipelines/text/ffn/index.d.ts +23 -0
- package/src/inference/pipelines/text/ffn/index.js +16 -0
- package/src/inference/pipelines/text/ffn/moe.d.ts +21 -0
- package/src/inference/pipelines/text/ffn/moe.js +49 -0
- package/src/inference/pipelines/text/ffn/sandwich.d.ts +25 -0
- package/src/inference/pipelines/text/ffn/sandwich.js +196 -0
- package/src/inference/pipelines/text/ffn/standard.d.ts +23 -0
- package/src/inference/pipelines/text/ffn/standard.js +84 -0
- package/src/inference/pipelines/text/ffn/types.d.ts +30 -0
- package/src/inference/pipelines/text/ffn/types.js +25 -0
- package/src/inference/pipelines/text/ffn.d.ts +31 -0
- package/src/inference/pipelines/text/ffn.js +18 -0
- package/src/inference/pipelines/text/finiteness-guard-status.d.ts +11 -0
- package/src/inference/pipelines/text/finiteness-guard-status.js +21 -0
- package/src/inference/pipelines/text/finiteness-policy.d.ts +35 -0
- package/src/inference/pipelines/text/finiteness-policy.js +45 -0
- package/src/inference/pipelines/text/generator-helpers.d.ts +34 -0
- package/src/inference/pipelines/text/generator-helpers.js +175 -0
- package/src/inference/pipelines/text/generator-runtime.d.ts +93 -0
- package/src/inference/pipelines/text/generator-runtime.js +373 -0
- package/src/inference/pipelines/text/generator-steps.d.ts +75 -0
- package/src/inference/pipelines/text/generator-steps.js +1078 -0
- package/src/inference/pipelines/text/generator.d.ts +41 -0
- package/src/inference/pipelines/text/generator.js +1345 -0
- package/src/inference/pipelines/text/index.d.ts +5 -0
- package/src/inference/pipelines/text/index.js +6 -0
- package/src/inference/pipelines/text/init.d.ts +295 -0
- package/src/inference/pipelines/text/init.js +965 -0
- package/src/inference/pipelines/text/kernel-path-auto-select.d.ts +12 -0
- package/src/inference/pipelines/text/kernel-path-auto-select.js +90 -0
- package/src/inference/pipelines/text/kernel-trace.d.ts +150 -0
- package/src/inference/pipelines/text/kernel-trace.js +324 -0
- package/src/inference/pipelines/text/layer-plan.d.ts +65 -0
- package/src/inference/pipelines/text/layer-plan.js +249 -0
- package/src/inference/pipelines/text/layer.d.ts +56 -0
- package/src/inference/pipelines/text/layer.js +916 -0
- package/src/inference/pipelines/text/linear-attention.d.ts +94 -0
- package/src/inference/pipelines/text/linear-attention.js +803 -0
- package/src/inference/pipelines/text/logits/cpu.d.ts +81 -0
- package/src/inference/pipelines/text/logits/cpu.js +91 -0
- package/src/inference/pipelines/text/logits/gpu.d.ts +113 -0
- package/src/inference/pipelines/text/logits/gpu.js +406 -0
- package/src/inference/pipelines/text/logits/index.d.ts +57 -0
- package/src/inference/pipelines/text/logits/index.js +305 -0
- package/src/inference/pipelines/text/logits/types.d.ts +46 -0
- package/src/inference/pipelines/text/logits/types.js +4 -0
- package/src/inference/pipelines/text/logits/utils.d.ts +49 -0
- package/src/inference/pipelines/text/logits/utils.js +59 -0
- package/src/inference/pipelines/text/logits.d.ts +27 -0
- package/src/inference/pipelines/text/logits.js +16 -0
- package/src/inference/pipelines/text/lora-apply.d.ts +28 -0
- package/src/inference/pipelines/text/lora-apply.js +58 -0
- package/src/inference/pipelines/text/lora-types.d.ts +39 -0
- package/src/inference/pipelines/text/lora-types.js +18 -0
- package/src/inference/pipelines/text/lora.d.ts +18 -0
- package/src/inference/pipelines/text/lora.js +12 -0
- package/src/inference/pipelines/text/model-load.d.ts +58 -0
- package/src/inference/pipelines/text/model-load.js +561 -0
- package/src/inference/pipelines/text/moe-cache.d.ts +32 -0
- package/src/inference/pipelines/text/moe-cache.js +107 -0
- package/src/inference/pipelines/text/moe-cpu-gptoss.d.ts +9 -0
- package/src/inference/pipelines/text/moe-cpu-gptoss.js +110 -0
- package/src/inference/pipelines/text/moe-cpu.d.ts +13 -0
- package/src/inference/pipelines/text/moe-cpu.js +116 -0
- package/src/inference/pipelines/text/moe-gpu.d.ts +13 -0
- package/src/inference/pipelines/text/moe-gpu.js +611 -0
- package/src/inference/pipelines/text/moe-helpers.d.ts +12 -0
- package/src/inference/pipelines/text/moe-helpers.js +21 -0
- package/src/inference/pipelines/text/moe-impl.d.ts +117 -0
- package/src/inference/pipelines/text/moe-impl.js +9 -0
- package/src/inference/pipelines/text/moe-shape-validator.d.ts +31 -0
- package/src/inference/pipelines/text/moe-shape-validator.js +78 -0
- package/src/inference/pipelines/text/ops.d.ts +167 -0
- package/src/inference/pipelines/text/ops.js +367 -0
- package/src/inference/pipelines/text/probes.d.ts +31 -0
- package/src/inference/pipelines/text/probes.js +170 -0
- package/src/inference/pipelines/text/sampling.d.ts +54 -0
- package/src/inference/pipelines/text/sampling.js +203 -0
- package/src/inference/pipelines/text/state.d.ts +112 -0
- package/src/inference/pipelines/text/state.js +152 -0
- package/src/inference/pipelines/text/types.d.ts +627 -0
- package/src/inference/pipelines/text/types.js +4 -0
- package/src/inference/pipelines/text/weights.d.ts +110 -0
- package/src/inference/pipelines/text/weights.js +163 -0
- package/src/inference/pipelines/text.d.ts +157 -0
- package/src/inference/pipelines/text.js +586 -0
- package/src/inference/speculative.d.ts +239 -0
- package/src/inference/speculative.js +416 -0
- package/src/inference/test-harness.d.ts +178 -0
- package/src/inference/test-harness.js +349 -0
- package/src/inference/tokenizer.d.ts +77 -0
- package/src/inference/tokenizer.js +258 -0
- package/src/inference/tokenizers/base.d.ts +39 -0
- package/src/inference/tokenizers/base.js +69 -0
- package/src/inference/tokenizers/bpe.d.ts +27 -0
- package/src/inference/tokenizers/bpe.js +171 -0
- package/src/inference/tokenizers/bundled.d.ts +63 -0
- package/src/inference/tokenizers/bundled.js +866 -0
- package/src/inference/tokenizers/sentencepiece.d.ts +28 -0
- package/src/inference/tokenizers/sentencepiece.js +389 -0
- package/src/inference/tokenizers/types.d.ts +166 -0
- package/src/inference/tokenizers/types.js +7 -0
- package/src/loader/doppler-loader.d.ts +134 -0
- package/src/loader/doppler-loader.js +1036 -0
- package/src/loader/dtype-utils.d.ts +40 -0
- package/src/loader/dtype-utils.js +102 -0
- package/src/loader/embedding-loader.d.ts +56 -0
- package/src/loader/embedding-loader.js +207 -0
- package/src/loader/experts/expert-cache.d.ts +156 -0
- package/src/loader/experts/expert-cache.js +375 -0
- package/src/loader/experts/expert-loader.d.ts +108 -0
- package/src/loader/experts/expert-loader.js +384 -0
- package/src/loader/final-weights-loader.d.ts +68 -0
- package/src/loader/final-weights-loader.js +262 -0
- package/src/loader/index.d.ts +150 -0
- package/src/loader/index.js +124 -0
- package/src/loader/layer-loader.d.ts +63 -0
- package/src/loader/layer-loader.js +417 -0
- package/src/loader/loader-state.d.ts +51 -0
- package/src/loader/loader-state.js +142 -0
- package/src/loader/loader-types.d.ts +236 -0
- package/src/loader/loader-types.js +4 -0
- package/src/loader/manifest-config.d.ts +97 -0
- package/src/loader/manifest-config.js +132 -0
- package/src/loader/memory-monitor.d.ts +112 -0
- package/src/loader/memory-monitor.js +276 -0
- package/src/loader/multi-model-loader.d.ts +37 -0
- package/src/loader/multi-model-loader.js +87 -0
- package/src/loader/quantization-constants.d.ts +23 -0
- package/src/loader/quantization-constants.js +14 -0
- package/src/loader/shard-cache.d.ts +60 -0
- package/src/loader/shard-cache.js +568 -0
- package/src/loader/shard-resolver.d.ts +12 -0
- package/src/loader/shard-resolver.js +83 -0
- package/src/loader/tensors/tensor-loader.d.ts +154 -0
- package/src/loader/tensors/tensor-loader.js +427 -0
- package/src/loader/tensors/tensor-reader.d.ts +22 -0
- package/src/loader/tensors/tensor-reader.js +56 -0
- package/src/loader/tensors/tensor-role.d.ts +7 -0
- package/src/loader/tensors/tensor-role.js +12 -0
- package/src/loader/weight-downcast.d.ts +62 -0
- package/src/loader/weight-downcast.js +213 -0
- package/src/loader/weights.d.ts +22 -0
- package/src/loader/weights.js +4 -0
- package/src/memory/address-table.d.ts +104 -0
- package/src/memory/address-table.js +114 -0
- package/src/memory/buffer-pool.d.ts +196 -0
- package/src/memory/buffer-pool.js +756 -0
- package/src/memory/capability.d.ts +49 -0
- package/src/memory/capability.js +95 -0
- package/src/memory/heap-manager.d.ts +104 -0
- package/src/memory/heap-manager.js +264 -0
- package/src/memory/unified-detect.d.ts +59 -0
- package/src/memory/unified-detect.js +192 -0
- package/src/rules/converter/execution.rules.json +20 -0
- package/src/rules/converter/tensor-roles.rules.json +13 -0
- package/src/rules/converter/tokenizer.rules.json +7 -0
- package/src/rules/inference/attention.rules.json +54 -0
- package/src/rules/inference/config.rules.json +58 -0
- package/src/rules/inference/dtype.rules.json +94 -0
- package/src/rules/inference/execution.rules.json +45 -0
- package/src/rules/inference/ffn.rules.json +35 -0
- package/src/rules/inference/kernel-path.rules.json +76 -0
- package/src/rules/inference/layer-pattern.rules.json +16 -0
- package/src/rules/inference/layer.rules.json +7 -0
- package/src/rules/inference/moe.rules.json +48 -0
- package/src/rules/kernels/attention.rules.json +61 -0
- package/src/rules/kernels/conv2d.rules.json +6 -0
- package/src/rules/kernels/dequant.rules.json +58 -0
- package/src/rules/kernels/energy.rules.json +22 -0
- package/src/rules/kernels/fused-ffn.rules.json +13 -0
- package/src/rules/kernels/fused-matmul-residual.rules.json +6 -0
- package/src/rules/kernels/fused-matmul-rmsnorm.rules.json +8 -0
- package/src/rules/kernels/gather.rules.json +12 -0
- package/src/rules/kernels/gelu.rules.json +11 -0
- package/src/rules/kernels/groupnorm.rules.json +10 -0
- package/src/rules/kernels/kernel-validator.d.ts +24 -0
- package/src/rules/kernels/kernel-validator.js +160 -0
- package/src/rules/kernels/kv_quantize.rules.json +7 -0
- package/src/rules/kernels/layernorm.rules.json +6 -0
- package/src/rules/kernels/matmul.rules.json +60 -0
- package/src/rules/kernels/modulate.rules.json +6 -0
- package/src/rules/kernels/moe.rules.gptoss.json +105 -0
- package/src/rules/kernels/moe.rules.json +11 -0
- package/src/rules/kernels/pixel_shuffle.rules.json +6 -0
- package/src/rules/kernels/residual.rules.json +12 -0
- package/src/rules/kernels/rmsnorm.rules.json +11 -0
- package/src/rules/kernels/rope.rules.json +6 -0
- package/src/rules/kernels/sample.rules.json +6 -0
- package/src/rules/kernels/scale.rules.json +6 -0
- package/src/rules/kernels/silu.rules.json +21 -0
- package/src/rules/kernels/softmax.rules.json +23 -0
- package/src/rules/kernels/split-qkv.rules.json +6 -0
- package/src/rules/kernels/upsample2d.rules.json +6 -0
- package/src/rules/loader/tensor-loader.rules.json +15 -0
- package/src/rules/loader/weights.rules.json +41 -0
- package/src/rules/rule-registry.d.ts +48 -0
- package/src/rules/rule-registry.js +177 -0
- package/src/rules/tooling/command-runtime.rules.json +38 -0
- package/src/storage/backends/idb-store.d.ts +52 -0
- package/src/storage/backends/idb-store.js +590 -0
- package/src/storage/backends/memory-store.d.ts +36 -0
- package/src/storage/backends/memory-store.js +242 -0
- package/src/storage/backends/opfs-store.d.ts +41 -0
- package/src/storage/backends/opfs-store.js +429 -0
- package/src/storage/blake3.d.ts +17 -0
- package/src/storage/blake3.js +269 -0
- package/src/storage/download-types.d.ts +157 -0
- package/src/storage/download-types.js +48 -0
- package/src/storage/downloader.d.ts +103 -0
- package/src/storage/downloader.js +839 -0
- package/src/storage/emulated-vram.d.ts +264 -0
- package/src/storage/emulated-vram.js +576 -0
- package/src/storage/export.d.ts +20 -0
- package/src/storage/export.js +159 -0
- package/src/storage/index.d.ts +253 -0
- package/src/storage/index.js +185 -0
- package/src/storage/inventory.d.ts +26 -0
- package/src/storage/inventory.js +218 -0
- package/src/storage/preflight.d.ts +144 -0
- package/src/storage/preflight.js +294 -0
- package/src/storage/quickstart-downloader.d.ts +154 -0
- package/src/storage/quickstart-downloader.js +265 -0
- package/src/storage/quota.d.ts +150 -0
- package/src/storage/quota.js +304 -0
- package/src/storage/registry.d.ts +28 -0
- package/src/storage/registry.js +125 -0
- package/src/storage/reports.d.ts +20 -0
- package/src/storage/reports.js +94 -0
- package/src/storage/shard-manager.d.ts +137 -0
- package/src/storage/shard-manager.js +801 -0
- package/src/sw.d.ts +1 -0
- package/src/sw.js +187 -0
- package/src/tooling/browser-command-runner.d.ts +28 -0
- package/src/tooling/browser-command-runner.js +82 -0
- package/src/tooling/command-api.d.ts +147 -0
- package/src/tooling/command-api.js +523 -0
- package/src/tooling/command-envelope.d.ts +81 -0
- package/src/tooling/command-envelope.js +195 -0
- package/src/tooling/command-runner-shared.d.ts +73 -0
- package/src/tooling/command-runner-shared.js +146 -0
- package/src/tooling/command-runner.html +45 -0
- package/src/tooling/node-browser-command-runner.d.ts +30 -0
- package/src/tooling/node-browser-command-runner.js +868 -0
- package/src/tooling/node-command-runner.d.ts +36 -0
- package/src/tooling/node-command-runner.js +127 -0
- package/src/tooling/node-convert-worker-pool.d.ts +16 -0
- package/src/tooling/node-convert-worker-pool.js +186 -0
- package/src/tooling/node-convert-worker.d.ts +1 -0
- package/src/tooling/node-convert-worker.js +60 -0
- package/src/tooling/node-convert.d.ts +44 -0
- package/src/tooling/node-converter.d.ts +1 -0
- package/src/tooling/node-converter.js +1227 -0
- package/src/tooling/node-file-fetch.d.ts +1 -0
- package/src/tooling/node-file-fetch.js +38 -0
- package/src/tooling/node-source-runtime.d.ts +19 -0
- package/src/tooling/node-source-runtime.js +469 -0
- package/src/tooling/node-webgpu.d.ts +6 -0
- package/src/tooling/node-webgpu.js +321 -0
- package/src/tooling/opfs-cache.d.ts +11 -0
- package/src/tooling/opfs-cache.js +174 -0
- package/src/tooling/source-runtime-bundle.d.ts +102 -0
- package/src/tooling/source-runtime-bundle.js +484 -0
- package/src/tooling-exports.browser.d.ts +7 -0
- package/src/tooling-exports.browser.js +2 -0
- package/src/tooling-exports.d.ts +22 -0
- package/src/tooling-exports.js +7 -0
- package/src/tooling-exports.shared.d.ts +105 -0
- package/src/tooling-exports.shared.js +92 -0
- package/src/training/README.md +153 -0
- package/src/training/artifacts.d.ts +160 -0
- package/src/training/artifacts.js +896 -0
- package/src/training/attention-backward.d.ts +30 -0
- package/src/training/attention-backward.js +217 -0
- package/src/training/attention-forward.d.ts +22 -0
- package/src/training/attention-forward.js +82 -0
- package/src/training/autograd.d.ts +51 -0
- package/src/training/autograd.js +380 -0
- package/src/training/checkpoint.d.ts +31 -0
- package/src/training/checkpoint.js +238 -0
- package/src/training/clip.d.ts +9 -0
- package/src/training/clip.js +54 -0
- package/src/training/dataloader.d.ts +8 -0
- package/src/training/dataloader.js +44 -0
- package/src/training/datasets/index.d.ts +12 -0
- package/src/training/datasets/index.js +6 -0
- package/src/training/datasets/jsonl.d.ts +11 -0
- package/src/training/datasets/jsonl.js +50 -0
- package/src/training/datasets/reploid.d.ts +3 -0
- package/src/training/datasets/reploid.js +36 -0
- package/src/training/datasets/text-pairs.d.ts +21 -0
- package/src/training/datasets/text-pairs.js +42 -0
- package/src/training/datasets/token-batch.d.ts +21 -0
- package/src/training/datasets/token-batch.js +40 -0
- package/src/training/datasets/translation-pairs.d.ts +34 -0
- package/src/training/datasets/translation-pairs.js +49 -0
- package/src/training/export.d.ts +32 -0
- package/src/training/export.js +112 -0
- package/src/training/index.d.ts +52 -0
- package/src/training/index.js +41 -0
- package/src/training/lora.d.ts +19 -0
- package/src/training/lora.js +57 -0
- package/src/training/loss-scaling.d.ts +21 -0
- package/src/training/loss-scaling.js +80 -0
- package/src/training/loss.d.ts +10 -0
- package/src/training/loss.js +41 -0
- package/src/training/objectives/base.d.ts +58 -0
- package/src/training/objectives/base.js +38 -0
- package/src/training/objectives/cross_entropy.d.ts +18 -0
- package/src/training/objectives/cross_entropy.js +37 -0
- package/src/training/objectives/distill_kd.d.ts +16 -0
- package/src/training/objectives/distill_kd.js +369 -0
- package/src/training/objectives/distill_triplet.d.ts +16 -0
- package/src/training/objectives/distill_triplet.js +412 -0
- package/src/training/objectives/index.d.ts +12 -0
- package/src/training/objectives/index.js +6 -0
- package/src/training/objectives/ul_stage1_joint.d.ts +16 -0
- package/src/training/objectives/ul_stage1_joint.js +188 -0
- package/src/training/objectives/ul_stage2_base.d.ts +16 -0
- package/src/training/objectives/ul_stage2_base.js +222 -0
- package/src/training/optimizer.d.ts +22 -0
- package/src/training/optimizer.js +115 -0
- package/src/training/runner.d.ts +196 -0
- package/src/training/runner.js +1194 -0
- package/src/training/suite.d.ts +187 -0
- package/src/training/suite.js +3156 -0
- package/src/training/trainer.d.ts +89 -0
- package/src/training/trainer.js +301 -0
- package/src/training/ul_dataset.d.ts +47 -0
- package/src/training/ul_dataset.js +153 -0
- package/src/training/ul_schedule.d.ts +6 -0
- package/src/training/ul_schedule.js +29 -0
- package/src/types/chrome.d.ts +36 -0
- package/src/types/chrome.js +1 -0
- package/src/types/gpu.d.ts +185 -0
- package/src/types/gpu.js +5 -0
- package/src/types/index.d.ts +3 -0
- package/src/types/index.js +3 -0
- package/src/types/inference.d.ts +197 -0
- package/src/types/inference.js +5 -0
- package/src/types/model.d.ts +125 -0
- package/src/types/model.js +5 -0
- package/src/utils/index.d.ts +7 -0
- package/src/utils/index.js +7 -0
- package/src/utils/load-json.d.ts +5 -0
- package/src/utils/load-json.js +23 -0
- package/src/utils/plain-object.d.ts +1 -0
- package/src/utils/plain-object.js +3 -0
- package/src/utils/sha256.d.ts +4 -0
- package/src/utils/sha256.js +135 -0
- package/tools/convert-safetensors-node.js +180 -0
- package/tools/doppler-cli.js +1170 -0
|
@@ -0,0 +1,1194 @@
|
|
|
1
|
+
|
|
2
|
+
import { trainStep } from './trainer.js';
|
|
3
|
+
import { crossEntropyLoss } from './loss.js';
|
|
4
|
+
import { clipGradients } from './clip.js';
|
|
5
|
+
import { AdamOptimizer } from './optimizer.js';
|
|
6
|
+
import { DynamicLossScaler, detectOverflow } from './loss-scaling.js';
|
|
7
|
+
import { readBuffer, uploadData } from '../memory/buffer-pool.js';
|
|
8
|
+
import { f16ToF32Array } from '../inference/kv-cache/types.js';
|
|
9
|
+
import { DataLoader } from './dataloader.js';
|
|
10
|
+
import { createCrossEntropyObjective } from './objectives/cross_entropy.js';
|
|
11
|
+
import { createDistillKdObjective } from './objectives/distill_kd.js';
|
|
12
|
+
import { createDistillTripletObjective } from './objectives/distill_triplet.js';
|
|
13
|
+
import { createUlStage1JointObjective } from './objectives/ul_stage1_joint.js';
|
|
14
|
+
import { createUlStage2BaseObjective } from './objectives/ul_stage2_base.js';
|
|
15
|
+
import {
|
|
16
|
+
createDistillArtifactSession,
|
|
17
|
+
createUlArtifactSession,
|
|
18
|
+
resolveDistillTrainingContract,
|
|
19
|
+
resolveStageAArtifactContext,
|
|
20
|
+
resolveUlTrainingContract,
|
|
21
|
+
resolveStage1ArtifactContext,
|
|
22
|
+
} from './artifacts.js';
|
|
23
|
+
import { loadCheckpoint, saveCheckpoint } from './checkpoint.js';
|
|
24
|
+
import { validateTrainingMetricsEntry } from '../config/schema/training-metrics.schema.js';
|
|
25
|
+
import { sha256Hex } from '../utils/sha256.js';
|
|
26
|
+
|
|
27
|
+
function toFloat32(buffer, dtype) {
|
|
28
|
+
if (dtype === 'f16') {
|
|
29
|
+
return f16ToF32Array(new Uint16Array(buffer));
|
|
30
|
+
}
|
|
31
|
+
return new Float32Array(buffer);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function computeLossMean(loss) {
|
|
35
|
+
const data = toFloat32(await readBuffer(loss.buffer), loss.dtype);
|
|
36
|
+
if (!data.length) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
let sum = 0;
|
|
40
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
41
|
+
sum += data[i];
|
|
42
|
+
}
|
|
43
|
+
return sum / data.length;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function resolveBatches(dataset, batchSize, shuffle) {
|
|
47
|
+
if (dataset && typeof dataset.batches === 'function') {
|
|
48
|
+
return dataset.batches();
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(dataset)) {
|
|
51
|
+
const loader = new DataLoader(dataset, batchSize, shuffle);
|
|
52
|
+
return loader.batches();
|
|
53
|
+
}
|
|
54
|
+
throw new Error('TrainingRunner requires dataset array or DataLoader');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function resolveTrainingObjective(config, options) {
|
|
58
|
+
if (options.trainingObjective) {
|
|
59
|
+
return options.trainingObjective;
|
|
60
|
+
}
|
|
61
|
+
const distill = config.training?.distill;
|
|
62
|
+
if (distill?.enabled) {
|
|
63
|
+
if (distill.stage === 'stage_a') {
|
|
64
|
+
return createDistillKdObjective({ crossEntropyLoss: options.crossEntropyLoss });
|
|
65
|
+
}
|
|
66
|
+
if (distill.stage === 'stage_b') {
|
|
67
|
+
return createDistillTripletObjective({ crossEntropyLoss: options.crossEntropyLoss });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const ul = config.training?.ul;
|
|
71
|
+
if (!ul?.enabled) {
|
|
72
|
+
return createCrossEntropyObjective({ crossEntropyLoss: options.crossEntropyLoss });
|
|
73
|
+
}
|
|
74
|
+
if (ul.stage === 'stage1_joint') {
|
|
75
|
+
return createUlStage1JointObjective({ crossEntropyLoss: options.crossEntropyLoss });
|
|
76
|
+
}
|
|
77
|
+
if (ul.stage === 'stage2_base') {
|
|
78
|
+
return createUlStage2BaseObjective({ crossEntropyLoss: options.crossEntropyLoss });
|
|
79
|
+
}
|
|
80
|
+
return createCrossEntropyObjective({ crossEntropyLoss: options.crossEntropyLoss });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function toMetricNumber(value, fallback = null) {
|
|
84
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) return fallback;
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function resolveTelemetrySettings(config) {
|
|
89
|
+
const telemetry = config?.training?.telemetry || {};
|
|
90
|
+
const mode = telemetry.mode === 'window' || telemetry.mode === 'epoch'
|
|
91
|
+
? telemetry.mode
|
|
92
|
+
: 'step';
|
|
93
|
+
const windowSize = Math.max(1, Math.floor(Number(telemetry.windowSize) || 1));
|
|
94
|
+
const emitNaNInfCounters = telemetry.emitNaNInfCounters !== false;
|
|
95
|
+
const alerts = telemetry.alerts && typeof telemetry.alerts === 'object'
|
|
96
|
+
? telemetry.alerts
|
|
97
|
+
: {};
|
|
98
|
+
const thresholds = alerts.thresholds && typeof alerts.thresholds === 'object'
|
|
99
|
+
? alerts.thresholds
|
|
100
|
+
: {};
|
|
101
|
+
const normalizeThreshold = (value) => {
|
|
102
|
+
if (value === null || value === undefined) return null;
|
|
103
|
+
const parsed = Number(value);
|
|
104
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
mode,
|
|
108
|
+
windowSize,
|
|
109
|
+
emitNaNInfCounters,
|
|
110
|
+
alertsEnabled: alerts.enabled === true,
|
|
111
|
+
failOnAlert: alerts.failOnAlert === true,
|
|
112
|
+
thresholds: {
|
|
113
|
+
maxStepTimeMs: normalizeThreshold(thresholds.maxStepTimeMs),
|
|
114
|
+
maxGradientNorm: normalizeThreshold(thresholds.maxGradientNorm),
|
|
115
|
+
maxNaNCount: normalizeThreshold(thresholds.maxNaNCount),
|
|
116
|
+
maxInfCount: normalizeThreshold(thresholds.maxInfCount),
|
|
117
|
+
maxSaturationCount: normalizeThreshold(thresholds.maxSaturationCount),
|
|
118
|
+
minEffectiveLr: normalizeThreshold(thresholds.minEffectiveLr),
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function pushRolling(windowValues, value, maxSize) {
|
|
124
|
+
windowValues.push(value);
|
|
125
|
+
while (windowValues.length > maxSize) {
|
|
126
|
+
windowValues.shift();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function average(values) {
|
|
131
|
+
if (!Array.isArray(values) || values.length === 0) return null;
|
|
132
|
+
let sum = 0;
|
|
133
|
+
for (const value of values) {
|
|
134
|
+
sum += value;
|
|
135
|
+
}
|
|
136
|
+
return sum / values.length;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function resolveObjectiveStage(objectiveName) {
|
|
140
|
+
if (objectiveName === 'ul_stage1_joint') return 'stage1_joint';
|
|
141
|
+
if (objectiveName === 'ul_stage2_base') return 'stage2_base';
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function resolveObjectiveDistillStage(objectiveName) {
|
|
146
|
+
if (objectiveName === 'kd') return 'stage_a';
|
|
147
|
+
if (objectiveName === 'triplet') return 'stage_b';
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function toPositiveIntegerOrNull(value) {
|
|
152
|
+
if (value === null || value === undefined) return null;
|
|
153
|
+
const parsed = Number(value);
|
|
154
|
+
if (!Number.isFinite(parsed)) return null;
|
|
155
|
+
const floored = Math.floor(parsed);
|
|
156
|
+
return floored >= 1 ? floored : null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function resolveProgressContext(config, runOptions = {}) {
|
|
160
|
+
const distillConfig = config?.training?.distill || {};
|
|
161
|
+
const shardIndexInput = toPositiveIntegerOrNull(
|
|
162
|
+
runOptions.distillShardIndex ?? distillConfig.shardIndex ?? null
|
|
163
|
+
);
|
|
164
|
+
const shardCountInput = toPositiveIntegerOrNull(
|
|
165
|
+
runOptions.distillShardCount ?? distillConfig.shardCount ?? null
|
|
166
|
+
);
|
|
167
|
+
if (
|
|
168
|
+
shardIndexInput !== null
|
|
169
|
+
&& shardCountInput !== null
|
|
170
|
+
&& shardIndexInput > shardCountInput
|
|
171
|
+
) {
|
|
172
|
+
throw new Error('TrainingRunner: distillShardIndex must be <= distillShardCount.');
|
|
173
|
+
}
|
|
174
|
+
const shardCount = shardCountInput ?? 1;
|
|
175
|
+
const shardIndex = shardIndexInput ?? 1;
|
|
176
|
+
const stepsPerShard = toPositiveIntegerOrNull(runOptions.maxSteps);
|
|
177
|
+
return {
|
|
178
|
+
shardIndex: Math.min(Math.max(1, shardIndex), shardCount),
|
|
179
|
+
shardCount: Math.max(1, shardCount),
|
|
180
|
+
stepsPerShard,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function buildProgressSnapshot(step, elapsedMs, context) {
|
|
185
|
+
const shardIndex = context?.shardIndex ?? 1;
|
|
186
|
+
const shardCount = context?.shardCount ?? 1;
|
|
187
|
+
const stepsPerShard = context?.stepsPerShard ?? null;
|
|
188
|
+
const stepInShard = stepsPerShard !== null
|
|
189
|
+
? Math.min(step, stepsPerShard)
|
|
190
|
+
: step;
|
|
191
|
+
const globalStep = stepsPerShard !== null
|
|
192
|
+
? (((shardIndex - 1) * stepsPerShard) + stepInShard)
|
|
193
|
+
: null;
|
|
194
|
+
const globalSteps = stepsPerShard !== null
|
|
195
|
+
? (stepsPerShard * shardCount)
|
|
196
|
+
: null;
|
|
197
|
+
const percentComplete = (
|
|
198
|
+
Number.isFinite(globalStep)
|
|
199
|
+
&& Number.isFinite(globalSteps)
|
|
200
|
+
&& globalSteps > 0
|
|
201
|
+
)
|
|
202
|
+
? Math.min(100, (globalStep / globalSteps) * 100)
|
|
203
|
+
: null;
|
|
204
|
+
let etaMs = null;
|
|
205
|
+
if (
|
|
206
|
+
Number.isFinite(globalStep)
|
|
207
|
+
&& Number.isFinite(globalSteps)
|
|
208
|
+
&& globalStep > 0
|
|
209
|
+
&& globalSteps >= globalStep
|
|
210
|
+
&& Number.isFinite(elapsedMs)
|
|
211
|
+
) {
|
|
212
|
+
const meanStepMs = elapsedMs / globalStep;
|
|
213
|
+
const remainingSteps = globalSteps - globalStep;
|
|
214
|
+
if (Number.isFinite(meanStepMs)) {
|
|
215
|
+
etaMs = Math.max(0, remainingSteps * meanStepMs);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
shardIndex,
|
|
220
|
+
shardCount,
|
|
221
|
+
stepInShard,
|
|
222
|
+
stepsPerShard,
|
|
223
|
+
globalStep,
|
|
224
|
+
globalSteps,
|
|
225
|
+
percentComplete,
|
|
226
|
+
elapsedMs: Number.isFinite(elapsedMs) ? Math.max(0, elapsedMs) : null,
|
|
227
|
+
etaMs,
|
|
228
|
+
etaIso: Number.isFinite(etaMs) ? new Date(Date.now() + etaMs).toISOString() : null,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function countNumericAnomaliesFromObject(value, counters) {
|
|
233
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return;
|
|
234
|
+
for (const candidate of Object.values(value)) {
|
|
235
|
+
if (typeof candidate !== 'number') continue;
|
|
236
|
+
if (Number.isNaN(candidate)) {
|
|
237
|
+
counters.nan += 1;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (!Number.isFinite(candidate)) {
|
|
241
|
+
counters.inf += 1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function evaluateTelemetryAlerts(entry, telemetry) {
|
|
247
|
+
if (!telemetry?.alertsEnabled) return [];
|
|
248
|
+
const alerts = [];
|
|
249
|
+
const thresholds = telemetry.thresholds || {};
|
|
250
|
+
if (Number.isFinite(thresholds.maxStepTimeMs) && entry.step_time_ms > thresholds.maxStepTimeMs) {
|
|
251
|
+
alerts.push('max_step_time_ms_exceeded');
|
|
252
|
+
}
|
|
253
|
+
if (
|
|
254
|
+
Number.isFinite(thresholds.maxGradientNorm)
|
|
255
|
+
&& Number.isFinite(entry.gradient_norm_unclipped)
|
|
256
|
+
&& entry.gradient_norm_unclipped > thresholds.maxGradientNorm
|
|
257
|
+
) {
|
|
258
|
+
alerts.push('max_gradient_norm_exceeded');
|
|
259
|
+
}
|
|
260
|
+
if (Number.isFinite(thresholds.maxNaNCount) && Number.isFinite(entry.nan_count) && entry.nan_count > thresholds.maxNaNCount) {
|
|
261
|
+
alerts.push('max_nan_count_exceeded');
|
|
262
|
+
}
|
|
263
|
+
if (Number.isFinite(thresholds.maxInfCount) && Number.isFinite(entry.inf_count) && entry.inf_count > thresholds.maxInfCount) {
|
|
264
|
+
alerts.push('max_inf_count_exceeded');
|
|
265
|
+
}
|
|
266
|
+
if (
|
|
267
|
+
Number.isFinite(thresholds.maxSaturationCount)
|
|
268
|
+
&& Number.isFinite(entry.saturation_count)
|
|
269
|
+
&& entry.saturation_count > thresholds.maxSaturationCount
|
|
270
|
+
) {
|
|
271
|
+
alerts.push('max_saturation_count_exceeded');
|
|
272
|
+
}
|
|
273
|
+
if (
|
|
274
|
+
Number.isFinite(thresholds.minEffectiveLr)
|
|
275
|
+
&& Number.isFinite(entry.effective_lr)
|
|
276
|
+
&& entry.effective_lr < thresholds.minEffectiveLr
|
|
277
|
+
) {
|
|
278
|
+
alerts.push('min_effective_lr_below_threshold');
|
|
279
|
+
}
|
|
280
|
+
return alerts;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function collectObjectiveMetrics(entry, objectiveMetrics) {
|
|
284
|
+
if (!objectiveMetrics || typeof objectiveMetrics !== 'object') {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
for (const [key, value] of Object.entries(objectiveMetrics)) {
|
|
288
|
+
if (typeof key !== 'string' || !key) continue;
|
|
289
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
290
|
+
entry[key] = value;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (value === null) {
|
|
294
|
+
entry[key] = null;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (
|
|
298
|
+
(key === 'distill_stage' || key === 'distill_teacher_model_id' || key === 'distill_student_model_id')
|
|
299
|
+
&& typeof value === 'string'
|
|
300
|
+
&& value.trim()
|
|
301
|
+
) {
|
|
302
|
+
entry[key] = value.trim();
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (
|
|
306
|
+
(key === 'latent_shape' && Array.isArray(value))
|
|
307
|
+
|| ((key === 'latent_clean_values' || key === 'latent_noise_values' || key === 'latent_noisy_values')
|
|
308
|
+
&& Array.isArray(value))
|
|
309
|
+
) {
|
|
310
|
+
entry[key] = value;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function resolveModelParamGroups(model) {
|
|
316
|
+
if (model && typeof model.paramGroups === 'function') {
|
|
317
|
+
const groups = model.paramGroups();
|
|
318
|
+
if (!groups || typeof groups !== 'object') {
|
|
319
|
+
throw new Error('model.paramGroups() must return an object of tensor arrays.');
|
|
320
|
+
}
|
|
321
|
+
return groups;
|
|
322
|
+
}
|
|
323
|
+
if (model && typeof model.loraParams === 'function') {
|
|
324
|
+
return { lora: model.loraParams() };
|
|
325
|
+
}
|
|
326
|
+
return {};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function selectTrainableParamGroups(paramGroups, freezeMap) {
|
|
330
|
+
const trainableGroups = {};
|
|
331
|
+
const frozenGroups = [];
|
|
332
|
+
for (const [groupName, params] of Object.entries(paramGroups)) {
|
|
333
|
+
const normalizedParams = Array.isArray(params) ? params.filter(Boolean) : [];
|
|
334
|
+
if (freezeMap?.[groupName] === true) {
|
|
335
|
+
frozenGroups.push(groupName);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
trainableGroups[groupName] = normalizedParams;
|
|
339
|
+
}
|
|
340
|
+
return { trainableGroups, frozenGroups };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function flattenUniqueParams(paramGroups) {
|
|
344
|
+
const unique = new Set();
|
|
345
|
+
const output = [];
|
|
346
|
+
for (const params of Object.values(paramGroups)) {
|
|
347
|
+
for (const tensor of params) {
|
|
348
|
+
if (!tensor || unique.has(tensor)) continue;
|
|
349
|
+
unique.add(tensor);
|
|
350
|
+
output.push(tensor);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return output;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function isTensorLike(value) {
|
|
357
|
+
return !!value
|
|
358
|
+
&& typeof value === 'object'
|
|
359
|
+
&& Array.isArray(value.shape)
|
|
360
|
+
&& value.buffer != null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function isNodeRuntime() {
|
|
364
|
+
return typeof process !== 'undefined' && !!process.versions?.node;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function normalizeOptionalString(value) {
|
|
368
|
+
if (value === undefined || value === null) return null;
|
|
369
|
+
const trimmed = String(value).trim();
|
|
370
|
+
return trimmed || null;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function normalizeOptionalStringArray(value) {
|
|
374
|
+
if (!Array.isArray(value)) return null;
|
|
375
|
+
const normalized = value
|
|
376
|
+
.map((entry) => normalizeOptionalString(entry))
|
|
377
|
+
.filter(Boolean);
|
|
378
|
+
if (normalized.length === 0) return null;
|
|
379
|
+
normalized.sort((left, right) => left.localeCompare(right));
|
|
380
|
+
return normalized;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function sanitizeGpuAdapterInfo(value) {
|
|
384
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
const sources = [value];
|
|
388
|
+
if (value.adapter && typeof value.adapter === 'object' && !Array.isArray(value.adapter)) {
|
|
389
|
+
sources.push(value.adapter);
|
|
390
|
+
}
|
|
391
|
+
if (value.gpu && typeof value.gpu === 'object' && !Array.isArray(value.gpu)) {
|
|
392
|
+
sources.push(value.gpu);
|
|
393
|
+
}
|
|
394
|
+
const out = {};
|
|
395
|
+
const keyMap = [
|
|
396
|
+
['name', ['name', 'adapterName']],
|
|
397
|
+
['vendor', ['vendor']],
|
|
398
|
+
['vendorId', ['vendorId']],
|
|
399
|
+
['architecture', ['architecture']],
|
|
400
|
+
['device', ['device']],
|
|
401
|
+
['deviceId', ['deviceId']],
|
|
402
|
+
['description', ['description']],
|
|
403
|
+
['driver', ['driver']],
|
|
404
|
+
['backend', ['backend']],
|
|
405
|
+
['adapterType', ['adapterType']],
|
|
406
|
+
['isFallbackAdapter', ['isFallbackAdapter']],
|
|
407
|
+
];
|
|
408
|
+
for (const [targetKey, sourceKeys] of keyMap) {
|
|
409
|
+
for (const source of sources) {
|
|
410
|
+
for (const sourceKey of sourceKeys) {
|
|
411
|
+
if (!(sourceKey in source)) continue;
|
|
412
|
+
const candidate = source[sourceKey];
|
|
413
|
+
if (
|
|
414
|
+
typeof candidate === 'string'
|
|
415
|
+
|| typeof candidate === 'number'
|
|
416
|
+
|| typeof candidate === 'boolean'
|
|
417
|
+
) {
|
|
418
|
+
out[targetKey] = candidate;
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (targetKey in out) break;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function stableSortObject(value) {
|
|
429
|
+
if (Array.isArray(value)) {
|
|
430
|
+
return value.map((entry) => stableSortObject(entry));
|
|
431
|
+
}
|
|
432
|
+
if (!value || typeof value !== 'object') {
|
|
433
|
+
return value;
|
|
434
|
+
}
|
|
435
|
+
const sorted = {};
|
|
436
|
+
for (const key of Object.keys(value).sort()) {
|
|
437
|
+
sorted[key] = stableSortObject(value[key]);
|
|
438
|
+
}
|
|
439
|
+
return sorted;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function stableJson(value) {
|
|
443
|
+
return JSON.stringify(stableSortObject(value));
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function hashStableJson(value) {
|
|
447
|
+
return sha256Hex(stableJson(value));
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function resolveRuntimeEnvironmentMetadata(runOptions = {}) {
|
|
451
|
+
const environment = {
|
|
452
|
+
runtime: isNodeRuntime() ? 'node' : 'browser',
|
|
453
|
+
};
|
|
454
|
+
const command = normalizeOptionalString(runOptions.command);
|
|
455
|
+
const surface = normalizeOptionalString(runOptions.surface);
|
|
456
|
+
if (command) {
|
|
457
|
+
environment.command = command;
|
|
458
|
+
}
|
|
459
|
+
if (surface) {
|
|
460
|
+
environment.surface = surface;
|
|
461
|
+
}
|
|
462
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
463
|
+
environment.nodeVersion = process.versions.node;
|
|
464
|
+
environment.platform = process.platform;
|
|
465
|
+
environment.arch = process.arch;
|
|
466
|
+
}
|
|
467
|
+
if (typeof navigator !== 'undefined') {
|
|
468
|
+
environment.userAgent = normalizeOptionalString(navigator.userAgent);
|
|
469
|
+
environment.hardwareConcurrency = Number.isFinite(navigator.hardwareConcurrency)
|
|
470
|
+
? navigator.hardwareConcurrency
|
|
471
|
+
: null;
|
|
472
|
+
}
|
|
473
|
+
const gpuAdapter = sanitizeGpuAdapterInfo(runOptions.gpuAdapterInfo);
|
|
474
|
+
if (gpuAdapter) {
|
|
475
|
+
environment.gpuAdapter = gpuAdapter;
|
|
476
|
+
}
|
|
477
|
+
return environment;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function normalizeIsoTimestamp(value) {
|
|
481
|
+
if (value === undefined || value === null || value === '') return null;
|
|
482
|
+
if (value instanceof Date) {
|
|
483
|
+
return Number.isFinite(value.getTime()) ? value.toISOString() : null;
|
|
484
|
+
}
|
|
485
|
+
if (typeof value === 'number') {
|
|
486
|
+
return Number.isFinite(value) ? new Date(value).toISOString() : null;
|
|
487
|
+
}
|
|
488
|
+
if (typeof value === 'string') {
|
|
489
|
+
const trimmed = value.trim();
|
|
490
|
+
if (!trimmed) return null;
|
|
491
|
+
const parsedNumeric = Number(trimmed);
|
|
492
|
+
if (Number.isFinite(parsedNumeric)) {
|
|
493
|
+
return new Date(parsedNumeric).toISOString();
|
|
494
|
+
}
|
|
495
|
+
const parsedDate = new Date(trimmed);
|
|
496
|
+
return Number.isFinite(parsedDate.getTime()) ? parsedDate.toISOString() : null;
|
|
497
|
+
}
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function resolveBuildProvenance(runOptions = {}) {
|
|
502
|
+
const optionsProvenance = (
|
|
503
|
+
runOptions.buildProvenance
|
|
504
|
+
&& typeof runOptions.buildProvenance === 'object'
|
|
505
|
+
&& !Array.isArray(runOptions.buildProvenance)
|
|
506
|
+
)
|
|
507
|
+
? runOptions.buildProvenance
|
|
508
|
+
: {};
|
|
509
|
+
const env = (typeof process !== 'undefined' && process.env) ? process.env : {};
|
|
510
|
+
const commitHash = normalizeOptionalString(
|
|
511
|
+
optionsProvenance.commitHash
|
|
512
|
+
|| runOptions.buildCommitHash
|
|
513
|
+
|| env.DOPPLER_BUILD_COMMIT
|
|
514
|
+
|| env.GIT_COMMIT
|
|
515
|
+
|| env.COMMIT_SHA
|
|
516
|
+
|| env.SOURCE_VERSION
|
|
517
|
+
|| env.VERCEL_GIT_COMMIT_SHA
|
|
518
|
+
);
|
|
519
|
+
const buildId = normalizeOptionalString(
|
|
520
|
+
optionsProvenance.buildId
|
|
521
|
+
|| runOptions.buildId
|
|
522
|
+
|| env.DOPPLER_BUILD_ID
|
|
523
|
+
|| env.BUILD_ID
|
|
524
|
+
|| env.VERCEL_BUILD_ID
|
|
525
|
+
|| env.GITHUB_RUN_ID
|
|
526
|
+
);
|
|
527
|
+
const buildTimestamp = normalizeIsoTimestamp(
|
|
528
|
+
optionsProvenance.buildTimestamp
|
|
529
|
+
|| runOptions.buildTimestamp
|
|
530
|
+
|| env.DOPPLER_BUILD_TIMESTAMP
|
|
531
|
+
|| env.BUILD_TIMESTAMP
|
|
532
|
+
|| env.VERCEL_GIT_COMMIT_TIMESTAMP
|
|
533
|
+
);
|
|
534
|
+
return {
|
|
535
|
+
commitHash,
|
|
536
|
+
buildId,
|
|
537
|
+
buildTimestamp,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function resolveTrainingSeed(config, runOptions = {}) {
|
|
542
|
+
const candidates = [
|
|
543
|
+
runOptions.seed,
|
|
544
|
+
config?.training?.seed,
|
|
545
|
+
config?.training?.distill?.seed,
|
|
546
|
+
config?.training?.ul?.seed,
|
|
547
|
+
];
|
|
548
|
+
for (const candidate of candidates) {
|
|
549
|
+
const parsed = Number(candidate);
|
|
550
|
+
if (Number.isFinite(parsed)) {
|
|
551
|
+
return Math.floor(parsed);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return 1337;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function resolveRuntimeMemoryStats() {
|
|
558
|
+
const perf = globalThis.performance;
|
|
559
|
+
const memory = perf && typeof perf === 'object' ? perf.memory : null;
|
|
560
|
+
if (!memory || typeof memory !== 'object') {
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
return {
|
|
564
|
+
js_heap_used_bytes: Number.isFinite(memory.usedJSHeapSize) ? memory.usedJSHeapSize : null,
|
|
565
|
+
js_heap_total_bytes: Number.isFinite(memory.totalJSHeapSize) ? memory.totalJSHeapSize : null,
|
|
566
|
+
js_heap_limit_bytes: Number.isFinite(memory.jsHeapSizeLimit) ? memory.jsHeapSizeLimit : null,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function resolveCheckpointMetadataContext(config, runOptions = {}) {
|
|
571
|
+
const runtimePresetId = normalizeOptionalString(runOptions.runtimePreset);
|
|
572
|
+
const kernelPathId = normalizeOptionalString(
|
|
573
|
+
runOptions.kernelPathId
|
|
574
|
+
|| config?.runtime?.inference?.kernelPath
|
|
575
|
+
|| config?.inference?.defaultKernelPath
|
|
576
|
+
);
|
|
577
|
+
const datasetIdentity = {
|
|
578
|
+
modelId: normalizeOptionalString(runOptions.modelId),
|
|
579
|
+
modelUrl: normalizeOptionalString(runOptions.modelUrl),
|
|
580
|
+
distillDatasetId: normalizeOptionalString(runOptions.distillDatasetId),
|
|
581
|
+
distillDatasetPath: normalizeOptionalString(runOptions.distillDatasetPath),
|
|
582
|
+
distillLanguagePair: normalizeOptionalString(runOptions.distillLanguagePair),
|
|
583
|
+
distillSourceLangs: normalizeOptionalStringArray(runOptions.distillSourceLangs),
|
|
584
|
+
distillTargetLangs: normalizeOptionalStringArray(runOptions.distillTargetLangs),
|
|
585
|
+
distillPairAllowlist: normalizeOptionalStringArray(runOptions.distillPairAllowlist),
|
|
586
|
+
strictPairContract: runOptions.strictPairContract === true,
|
|
587
|
+
distillShardIndex: Number.isInteger(runOptions.distillShardIndex) ? runOptions.distillShardIndex : null,
|
|
588
|
+
distillShardCount: Number.isInteger(runOptions.distillShardCount) ? runOptions.distillShardCount : null,
|
|
589
|
+
trainingStage: normalizeOptionalString(
|
|
590
|
+
runOptions.trainingStage
|
|
591
|
+
|| config?.training?.distill?.stage
|
|
592
|
+
|| config?.training?.ul?.stage
|
|
593
|
+
),
|
|
594
|
+
};
|
|
595
|
+
const configHash = hashStableJson(config?.training || {});
|
|
596
|
+
const datasetHash = hashStableJson(datasetIdentity);
|
|
597
|
+
const tokenizerHash = normalizeOptionalString(runOptions.tokenizerHash);
|
|
598
|
+
const optimizerHash = hashStableJson({
|
|
599
|
+
optimizerConfig: config?.training?.optimizer || null,
|
|
600
|
+
stepCount: Number.isInteger(runOptions.optimizerStepCount) ? runOptions.optimizerStepCount : null,
|
|
601
|
+
});
|
|
602
|
+
return {
|
|
603
|
+
configHash,
|
|
604
|
+
datasetHash,
|
|
605
|
+
tokenizerHash,
|
|
606
|
+
optimizerHash,
|
|
607
|
+
runtimePresetId,
|
|
608
|
+
kernelPathId,
|
|
609
|
+
environmentMetadata: resolveRuntimeEnvironmentMetadata(runOptions),
|
|
610
|
+
buildProvenance: resolveBuildProvenance(runOptions),
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function buildExpectedCheckpointMetadata(metadata) {
|
|
615
|
+
const expected = {};
|
|
616
|
+
for (const key of [
|
|
617
|
+
'configHash',
|
|
618
|
+
'datasetHash',
|
|
619
|
+
'tokenizerHash',
|
|
620
|
+
'optimizerHash',
|
|
621
|
+
'runtimePresetId',
|
|
622
|
+
'kernelPathId',
|
|
623
|
+
]) {
|
|
624
|
+
const value = metadata?.[key];
|
|
625
|
+
if (value !== null && value !== undefined) {
|
|
626
|
+
expected[key] = value;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return Object.keys(expected).length > 0 ? expected : null;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function resolveForceResumeSource(runOptions = {}) {
|
|
633
|
+
return normalizeOptionalString(
|
|
634
|
+
runOptions.forceResumeSource
|
|
635
|
+
|| (
|
|
636
|
+
runOptions.command && runOptions.surface
|
|
637
|
+
? `${runOptions.command}:${runOptions.surface}`
|
|
638
|
+
: null
|
|
639
|
+
)
|
|
640
|
+
|| runOptions.command
|
|
641
|
+
|| 'training_runner'
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function toBase64(bytes) {
|
|
646
|
+
if (typeof Buffer !== 'undefined') {
|
|
647
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64');
|
|
648
|
+
}
|
|
649
|
+
let binary = '';
|
|
650
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
651
|
+
binary += String.fromCharCode(bytes[i]);
|
|
652
|
+
}
|
|
653
|
+
return btoa(binary);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function fromBase64(base64) {
|
|
657
|
+
if (typeof Buffer !== 'undefined') {
|
|
658
|
+
const buffer = Buffer.from(base64, 'base64');
|
|
659
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
660
|
+
}
|
|
661
|
+
const binary = atob(base64);
|
|
662
|
+
const bytes = new Uint8Array(binary.length);
|
|
663
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
664
|
+
bytes[i] = binary.charCodeAt(i);
|
|
665
|
+
}
|
|
666
|
+
return bytes;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
async function serializeTensorSnapshot(tensor) {
|
|
670
|
+
const raw = await readBuffer(tensor.buffer);
|
|
671
|
+
const bytes = new Uint8Array(raw);
|
|
672
|
+
return {
|
|
673
|
+
dtype: tensor.dtype,
|
|
674
|
+
shape: Array.isArray(tensor.shape) ? [...tensor.shape] : [],
|
|
675
|
+
dataBase64: toBase64(bytes),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
async function restoreTensorSnapshot(tensor, snapshot) {
|
|
680
|
+
if (!isTensorLike(tensor)) return false;
|
|
681
|
+
if (!snapshot || typeof snapshot !== 'object') return false;
|
|
682
|
+
const encoded = normalizeOptionalString(snapshot.dataBase64);
|
|
683
|
+
if (!encoded) return false;
|
|
684
|
+
const decoded = fromBase64(encoded);
|
|
685
|
+
uploadData(tensor.buffer, decoded);
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function buildTrainableParamRefs(model, freezeMap = null) {
|
|
690
|
+
const paramGroups = resolveModelParamGroups(model);
|
|
691
|
+
const { trainableGroups } = selectTrainableParamGroups(paramGroups, freezeMap || {});
|
|
692
|
+
const refs = [];
|
|
693
|
+
const seen = new Set();
|
|
694
|
+
for (const [groupName, params] of Object.entries(trainableGroups)) {
|
|
695
|
+
for (let index = 0; index < params.length; index += 1) {
|
|
696
|
+
const tensor = params[index];
|
|
697
|
+
if (!isTensorLike(tensor) || seen.has(tensor)) continue;
|
|
698
|
+
seen.add(tensor);
|
|
699
|
+
refs.push({
|
|
700
|
+
key: `${groupName}[${index}]`,
|
|
701
|
+
tensor,
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return refs;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function looksLikeTrainingCheckpointRecord(value) {
|
|
709
|
+
const trainingState = value?.trainingState;
|
|
710
|
+
if (!trainingState || typeof trainingState !== 'object') return false;
|
|
711
|
+
const progress = trainingState.progress;
|
|
712
|
+
if (!progress || typeof progress !== 'object') return false;
|
|
713
|
+
return Number.isInteger(progress.step) && progress.step >= 0;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
async function createTrainingCheckpointPayload(model, optimizer, context) {
|
|
717
|
+
const freezeMap = context.config?.training?.ul?.freeze
|
|
718
|
+
?? context.config?.training?.distill?.freeze
|
|
719
|
+
?? {};
|
|
720
|
+
const refs = buildTrainableParamRefs(model, freezeMap);
|
|
721
|
+
const params = {};
|
|
722
|
+
const optimizerSlots = {};
|
|
723
|
+
for (const ref of refs) {
|
|
724
|
+
params[ref.key] = await serializeTensorSnapshot(ref.tensor);
|
|
725
|
+
const optimizerStateEntry = optimizer?.state instanceof Map
|
|
726
|
+
? optimizer.state.get(ref.tensor)
|
|
727
|
+
: null;
|
|
728
|
+
if (optimizerStateEntry?.m && optimizerStateEntry?.v) {
|
|
729
|
+
optimizerSlots[ref.key] = {
|
|
730
|
+
m: await serializeTensorSnapshot(optimizerStateEntry.m),
|
|
731
|
+
v: await serializeTensorSnapshot(optimizerStateEntry.v),
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return {
|
|
736
|
+
trainingState: {
|
|
737
|
+
schemaVersion: 1,
|
|
738
|
+
progress: {
|
|
739
|
+
step: context.step,
|
|
740
|
+
epoch: context.epoch,
|
|
741
|
+
batch: context.batch,
|
|
742
|
+
},
|
|
743
|
+
optimizerStepCount: Number.isInteger(optimizer?.stepCount) ? optimizer.stepCount : 0,
|
|
744
|
+
params,
|
|
745
|
+
optimizerSlots,
|
|
746
|
+
},
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
async function restoreTrainingCheckpointState(model, optimizer, checkpointRecord, config) {
|
|
751
|
+
if (!looksLikeTrainingCheckpointRecord(checkpointRecord)) {
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
const trainingState = checkpointRecord.trainingState;
|
|
755
|
+
const freezeMap = config?.training?.ul?.freeze
|
|
756
|
+
?? config?.training?.distill?.freeze
|
|
757
|
+
?? {};
|
|
758
|
+
const refs = buildTrainableParamRefs(model, freezeMap);
|
|
759
|
+
const refMap = new Map(refs.map((entry) => [entry.key, entry.tensor]));
|
|
760
|
+
const params = trainingState.params && typeof trainingState.params === 'object'
|
|
761
|
+
? trainingState.params
|
|
762
|
+
: {};
|
|
763
|
+
for (const [key, snapshot] of Object.entries(params)) {
|
|
764
|
+
const tensor = refMap.get(key);
|
|
765
|
+
if (!tensor) continue;
|
|
766
|
+
await restoreTensorSnapshot(tensor, snapshot);
|
|
767
|
+
}
|
|
768
|
+
if (optimizer && Number.isInteger(trainingState.optimizerStepCount)) {
|
|
769
|
+
optimizer.stepCount = trainingState.optimizerStepCount;
|
|
770
|
+
}
|
|
771
|
+
const optimizerSlots = trainingState.optimizerSlots && typeof trainingState.optimizerSlots === 'object'
|
|
772
|
+
? trainingState.optimizerSlots
|
|
773
|
+
: {};
|
|
774
|
+
if (optimizer && typeof optimizer.getState === 'function') {
|
|
775
|
+
for (const [key, snapshot] of Object.entries(optimizerSlots)) {
|
|
776
|
+
const tensor = refMap.get(key);
|
|
777
|
+
if (!tensor) continue;
|
|
778
|
+
const slot = optimizer.getState(tensor);
|
|
779
|
+
if (slot?.m) {
|
|
780
|
+
await restoreTensorSnapshot(slot.m, snapshot?.m);
|
|
781
|
+
}
|
|
782
|
+
if (slot?.v) {
|
|
783
|
+
await restoreTensorSnapshot(slot.v, snapshot?.v);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const progress = trainingState.progress || {};
|
|
788
|
+
const resumeAudits = Array.isArray(checkpointRecord?.metadata?.resumeAudits)
|
|
789
|
+
? checkpointRecord.metadata.resumeAudits
|
|
790
|
+
.filter((entry) => entry && typeof entry === 'object')
|
|
791
|
+
.map((entry) => ({ ...entry }))
|
|
792
|
+
: [];
|
|
793
|
+
return {
|
|
794
|
+
step: Number.isInteger(progress.step) ? progress.step : 0,
|
|
795
|
+
epoch: Number.isInteger(progress.epoch) ? progress.epoch : 0,
|
|
796
|
+
batch: Number.isInteger(progress.batch) ? progress.batch : 0,
|
|
797
|
+
checkpointHash: checkpointRecord?.metadata?.checkpointHash || null,
|
|
798
|
+
previousCheckpointHash: checkpointRecord?.metadata?.lineage?.previousCheckpointHash || null,
|
|
799
|
+
checkpointKey: checkpointRecord?.metadata?.lineage?.checkpointKey || null,
|
|
800
|
+
resumeAudits,
|
|
801
|
+
resumeAuditCount: resumeAudits.length,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
async function resolveDefaultCheckpointKey(runOptions, distillContract, ulContract) {
|
|
806
|
+
const artifactDir = normalizeOptionalString(
|
|
807
|
+
runOptions.distillArtifactDir
|
|
808
|
+
|| runOptions.ulArtifactDir
|
|
809
|
+
|| distillContract?.artifactDir
|
|
810
|
+
|| ulContract?.artifactDir
|
|
811
|
+
);
|
|
812
|
+
if (!artifactDir) return null;
|
|
813
|
+
if (!isNodeRuntime()) {
|
|
814
|
+
const mode = distillContract?.enabled ? 'distill' : (ulContract?.enabled ? 'ul' : 'training');
|
|
815
|
+
return `${mode}.latest.checkpoint`;
|
|
816
|
+
}
|
|
817
|
+
const { resolve, join } = await import('node:path');
|
|
818
|
+
const mode = distillContract?.enabled ? 'distill' : (ulContract?.enabled ? 'ul' : 'training');
|
|
819
|
+
return resolve(join(artifactDir, `${mode}.latest.checkpoint.json`));
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
async function resolveCheckpointKey(runOptions, distillContract, ulContract) {
|
|
823
|
+
const explicit = normalizeOptionalString(runOptions.resumeFrom);
|
|
824
|
+
if (explicit) {
|
|
825
|
+
return { explicit, fallback: await resolveDefaultCheckpointKey(runOptions, distillContract, ulContract) };
|
|
826
|
+
}
|
|
827
|
+
return { explicit: null, fallback: await resolveDefaultCheckpointKey(runOptions, distillContract, ulContract) };
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
export class TrainingRunner {
|
|
831
|
+
constructor(config, options = {}) {
|
|
832
|
+
this.config = config;
|
|
833
|
+
this.optimizer = options.optimizer || new AdamOptimizer(config);
|
|
834
|
+
this.lossFn = options.crossEntropyLoss || crossEntropyLoss;
|
|
835
|
+
this.clipFn = options.clipGradients || clipGradients;
|
|
836
|
+
this.trainingObjective = resolveTrainingObjective(config, options);
|
|
837
|
+
this.lossScaler = options.lossScaler || new DynamicLossScaler(config.training.lossScaling);
|
|
838
|
+
this.onStep = options.onStep || null;
|
|
839
|
+
this.onEpoch = options.onEpoch || null;
|
|
840
|
+
this.lastArtifact = null;
|
|
841
|
+
this.lastCheckpoint = null;
|
|
842
|
+
this.resumeState = null;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
async run(model, dataset, options = {}) {
|
|
846
|
+
const {
|
|
847
|
+
epochs = 1,
|
|
848
|
+
batchSize = 1,
|
|
849
|
+
shuffle = true,
|
|
850
|
+
maxSteps = null,
|
|
851
|
+
logEvery = 1,
|
|
852
|
+
prepareBatch = null,
|
|
853
|
+
} = options;
|
|
854
|
+
|
|
855
|
+
const distillContract = resolveDistillTrainingContract(this.config.training?.distill);
|
|
856
|
+
const ulContract = resolveUlTrainingContract(this.config.training?.ul);
|
|
857
|
+
if (distillContract.enabled && ulContract.enabled) {
|
|
858
|
+
throw new Error('TrainingRunner cannot run distill and ul modes simultaneously.');
|
|
859
|
+
}
|
|
860
|
+
const checkpointInterval = toPositiveIntegerOrNull(options.checkpointEvery) ?? 1;
|
|
861
|
+
const checkpointMetadata = resolveCheckpointMetadataContext(this.config, {
|
|
862
|
+
...options,
|
|
863
|
+
optimizerStepCount: this.optimizer?.stepCount,
|
|
864
|
+
});
|
|
865
|
+
const trainingSeed = resolveTrainingSeed(this.config, options);
|
|
866
|
+
const trainingModelId = normalizeOptionalString(
|
|
867
|
+
options.modelId || options.studentModelId
|
|
868
|
+
) || 'training';
|
|
869
|
+
const runtimePreset = normalizeOptionalString(options.runtimePreset);
|
|
870
|
+
const kernelPath = normalizeOptionalString(checkpointMetadata.kernelPathId);
|
|
871
|
+
const environmentMetadata = checkpointMetadata.environmentMetadata || resolveRuntimeEnvironmentMetadata();
|
|
872
|
+
const buildProvenance = checkpointMetadata.buildProvenance || null;
|
|
873
|
+
const expectedCheckpointMetadata = buildExpectedCheckpointMetadata(checkpointMetadata);
|
|
874
|
+
const forceResumeEnabled = options.forceResume === true;
|
|
875
|
+
const forceResumeReason = normalizeOptionalString(options.forceResumeReason);
|
|
876
|
+
const checkpointLoadOptions = {
|
|
877
|
+
...checkpointMetadata,
|
|
878
|
+
...(expectedCheckpointMetadata ? { expectedMetadata: expectedCheckpointMetadata } : {}),
|
|
879
|
+
forceResume: forceResumeEnabled,
|
|
880
|
+
forceResumeReason: forceResumeReason || undefined,
|
|
881
|
+
forceResumeSource: resolveForceResumeSource(options),
|
|
882
|
+
forceResumeOperator: normalizeOptionalString(options.checkpointOperator),
|
|
883
|
+
};
|
|
884
|
+
const checkpointKeys = await resolveCheckpointKey(options, distillContract, ulContract);
|
|
885
|
+
let checkpointKey = checkpointKeys.fallback;
|
|
886
|
+
let restoredProgress = null;
|
|
887
|
+
const tryRestoreCheckpoint = async (key) => {
|
|
888
|
+
if (!key) return null;
|
|
889
|
+
const checkpointRecord = await loadCheckpoint(key, checkpointLoadOptions);
|
|
890
|
+
if (!checkpointRecord) {
|
|
891
|
+
return null;
|
|
892
|
+
}
|
|
893
|
+
return restoreTrainingCheckpointState(model, this.optimizer, checkpointRecord, this.config);
|
|
894
|
+
};
|
|
895
|
+
if (checkpointKeys.explicit) {
|
|
896
|
+
restoredProgress = await tryRestoreCheckpoint(checkpointKeys.explicit);
|
|
897
|
+
if (!restoredProgress) {
|
|
898
|
+
throw new Error(`TrainingRunner: resume checkpoint not found or invalid: ${checkpointKeys.explicit}`);
|
|
899
|
+
}
|
|
900
|
+
checkpointKey = checkpointKeys.explicit;
|
|
901
|
+
}
|
|
902
|
+
if (!restoredProgress && checkpointKeys.fallback && checkpointKeys.fallback !== checkpointKeys.explicit) {
|
|
903
|
+
restoredProgress = await tryRestoreCheckpoint(checkpointKeys.fallback);
|
|
904
|
+
}
|
|
905
|
+
this.resumeState = restoredProgress || null;
|
|
906
|
+
const persistCheckpoint = async (checkpointContext) => {
|
|
907
|
+
if (!checkpointKey) return;
|
|
908
|
+
const payload = await createTrainingCheckpointPayload(model, this.optimizer, {
|
|
909
|
+
step: checkpointContext.step,
|
|
910
|
+
epoch: checkpointContext.epoch,
|
|
911
|
+
batch: checkpointContext.batch,
|
|
912
|
+
config: this.config,
|
|
913
|
+
});
|
|
914
|
+
await saveCheckpoint(checkpointKey, payload, {
|
|
915
|
+
...checkpointMetadata,
|
|
916
|
+
optimizerHash: hashStableJson(payload?.trainingState?.optimizerSlots || {}),
|
|
917
|
+
});
|
|
918
|
+
this.lastCheckpoint = {
|
|
919
|
+
key: checkpointKey,
|
|
920
|
+
step: checkpointContext.step,
|
|
921
|
+
epoch: checkpointContext.epoch,
|
|
922
|
+
batch: checkpointContext.batch,
|
|
923
|
+
};
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
const artifactSession = distillContract.enabled
|
|
927
|
+
? await createDistillArtifactSession({
|
|
928
|
+
config: this.config,
|
|
929
|
+
stage: distillContract.stage,
|
|
930
|
+
runOptions: options,
|
|
931
|
+
})
|
|
932
|
+
: (ulContract.enabled
|
|
933
|
+
? await createUlArtifactSession({
|
|
934
|
+
config: this.config,
|
|
935
|
+
stage: ulContract.stage,
|
|
936
|
+
runOptions: options,
|
|
937
|
+
})
|
|
938
|
+
: null);
|
|
939
|
+
const stage1ArtifactContext = ulContract.enabled && ulContract.stage === 'stage2_base'
|
|
940
|
+
? await resolveStage1ArtifactContext(this.config)
|
|
941
|
+
: null;
|
|
942
|
+
const stageAArtifactContext = distillContract.enabled && distillContract.stage === 'stage_b'
|
|
943
|
+
? await resolveStageAArtifactContext(this.config)
|
|
944
|
+
: null;
|
|
945
|
+
|
|
946
|
+
let step = restoredProgress?.step || 0;
|
|
947
|
+
let resumeSkipRemaining = restoredProgress?.step || 0;
|
|
948
|
+
const metrics = [];
|
|
949
|
+
const telemetry = resolveTelemetrySettings(this.config);
|
|
950
|
+
const lossWindow = [];
|
|
951
|
+
const stepTimeWindow = [];
|
|
952
|
+
const progressContext = resolveProgressContext(this.config, { ...options, maxSteps });
|
|
953
|
+
const runStartMs = globalThis.performance.now();
|
|
954
|
+
|
|
955
|
+
for (let epoch = 0; epoch < epochs; epoch += 1) {
|
|
956
|
+
const batches = await resolveBatches(dataset, batchSize, shuffle);
|
|
957
|
+
let batchIndex = 0;
|
|
958
|
+
for await (const rawBatch of batches) {
|
|
959
|
+
if (resumeSkipRemaining > 0) {
|
|
960
|
+
resumeSkipRemaining -= 1;
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
step += 1;
|
|
964
|
+
batchIndex += 1;
|
|
965
|
+
const batch = prepareBatch ? await prepareBatch(rawBatch) : rawBatch;
|
|
966
|
+
const step_start_ms = globalThis.performance.now();
|
|
967
|
+
const stepResult = await this._runStep(model, batch, {
|
|
968
|
+
stepIndex: step - 1,
|
|
969
|
+
epoch,
|
|
970
|
+
batch: batchIndex,
|
|
971
|
+
stage1ArtifactContext,
|
|
972
|
+
stageAArtifactContext,
|
|
973
|
+
});
|
|
974
|
+
const step_time_ms = globalThis.performance.now() - step_start_ms;
|
|
975
|
+
const progressSnapshot = buildProgressSnapshot(
|
|
976
|
+
step,
|
|
977
|
+
globalThis.performance.now() - runStartMs,
|
|
978
|
+
progressContext
|
|
979
|
+
);
|
|
980
|
+
const meanLoss = await computeLossMean(stepResult.loss);
|
|
981
|
+
pushRolling(lossWindow, meanLoss, telemetry.windowSize);
|
|
982
|
+
pushRolling(stepTimeWindow, step_time_ms, telemetry.windowSize);
|
|
983
|
+
const objectiveName = stepResult.objectiveName || this.trainingObjective?.name || 'cross_entropy';
|
|
984
|
+
const objectiveStage = resolveObjectiveStage(objectiveName);
|
|
985
|
+
const objectiveDistillStage = resolveObjectiveDistillStage(objectiveName);
|
|
986
|
+
|
|
987
|
+
const entry = {
|
|
988
|
+
schemaVersion: 1,
|
|
989
|
+
step,
|
|
990
|
+
epoch,
|
|
991
|
+
batch: batchIndex,
|
|
992
|
+
objective: objectiveName,
|
|
993
|
+
total_loss: meanLoss,
|
|
994
|
+
step_time_ms,
|
|
995
|
+
forward_ms: stepResult.forward_ms,
|
|
996
|
+
backward_ms: stepResult.backward_ms,
|
|
997
|
+
optimizer_ms: stepResult.optimizerMetrics?.optimizer_ms,
|
|
998
|
+
effective_lr: toMetricNumber(stepResult.optimizerMetrics?.effective_lr, null),
|
|
999
|
+
lr: toMetricNumber(stepResult.optimizerMetrics?.effective_lr, null),
|
|
1000
|
+
scheduler_index: Number.isInteger(stepResult.optimizerMetrics?.scheduler_index)
|
|
1001
|
+
? stepResult.optimizerMetrics.scheduler_index
|
|
1002
|
+
: null,
|
|
1003
|
+
scheduler_phase: stepResult.optimizerMetrics?.scheduler_phase ?? null,
|
|
1004
|
+
seed: trainingSeed,
|
|
1005
|
+
model_id: trainingModelId,
|
|
1006
|
+
runtime_preset: runtimePreset,
|
|
1007
|
+
kernel_path: kernelPath,
|
|
1008
|
+
environment_metadata: environmentMetadata,
|
|
1009
|
+
memory_stats: resolveRuntimeMemoryStats(),
|
|
1010
|
+
build_provenance: buildProvenance,
|
|
1011
|
+
gradient_norm_unclipped: stepResult.clipMetrics?.gradient_norm_unclipped,
|
|
1012
|
+
gradient_norm_clipped: stepResult.clipMetrics?.gradient_norm_clipped,
|
|
1013
|
+
clipped_event_count: stepResult.clipMetrics?.clipped_event_count,
|
|
1014
|
+
total_param_count: stepResult.clipMetrics?.total_param_count,
|
|
1015
|
+
trainable_param_count: stepResult.paramGroupMetrics?.trainableParamCount ?? null,
|
|
1016
|
+
trainable_groups: stepResult.paramGroupMetrics?.trainableGroups ?? [],
|
|
1017
|
+
frozen_groups: stepResult.paramGroupMetrics?.frozenGroups ?? [],
|
|
1018
|
+
ul_stage: objectiveStage,
|
|
1019
|
+
distill_stage: objectiveDistillStage,
|
|
1020
|
+
lambda: toMetricNumber(
|
|
1021
|
+
stepResult.objectiveMetrics?.lambda,
|
|
1022
|
+
objectiveStage ? toMetricNumber(this.config.training?.ul?.lambda0, null) : null
|
|
1023
|
+
),
|
|
1024
|
+
progress_shard_index: progressSnapshot.shardIndex,
|
|
1025
|
+
progress_shard_count: progressSnapshot.shardCount,
|
|
1026
|
+
progress_step_in_shard: progressSnapshot.stepInShard,
|
|
1027
|
+
progress_steps_in_shard: progressSnapshot.stepsPerShard,
|
|
1028
|
+
progress_global_step: progressSnapshot.globalStep,
|
|
1029
|
+
progress_global_steps: progressSnapshot.globalSteps,
|
|
1030
|
+
progress_percent_complete: progressSnapshot.percentComplete,
|
|
1031
|
+
progress_elapsed_ms: progressSnapshot.elapsedMs,
|
|
1032
|
+
progress_eta_ms: progressSnapshot.etaMs,
|
|
1033
|
+
progress_eta_iso: progressSnapshot.etaIso,
|
|
1034
|
+
telemetry_mode: telemetry.mode,
|
|
1035
|
+
telemetry_window_size: telemetry.windowSize,
|
|
1036
|
+
window_loss_avg: average(lossWindow),
|
|
1037
|
+
window_step_time_ms_avg: average(stepTimeWindow),
|
|
1038
|
+
};
|
|
1039
|
+
collectObjectiveMetrics(entry, stepResult.objectiveMetrics);
|
|
1040
|
+
const anomalies = { nan: 0, inf: 0 };
|
|
1041
|
+
if (telemetry.emitNaNInfCounters) {
|
|
1042
|
+
countNumericAnomaliesFromObject(entry, anomalies);
|
|
1043
|
+
countNumericAnomaliesFromObject(stepResult.objectiveMetrics, anomalies);
|
|
1044
|
+
}
|
|
1045
|
+
entry.nan_count = anomalies.nan;
|
|
1046
|
+
entry.inf_count = anomalies.inf;
|
|
1047
|
+
entry.saturation_count = Number.isInteger(stepResult.clipMetrics?.clipped_event_count)
|
|
1048
|
+
? stepResult.clipMetrics.clipped_event_count
|
|
1049
|
+
: 0;
|
|
1050
|
+
const telemetryAlerts = evaluateTelemetryAlerts(entry, telemetry);
|
|
1051
|
+
if (telemetry.alertsEnabled) {
|
|
1052
|
+
entry.telemetry_alerts = telemetryAlerts;
|
|
1053
|
+
}
|
|
1054
|
+
if (telemetry.failOnAlert && telemetryAlerts.length > 0) {
|
|
1055
|
+
throw new Error(
|
|
1056
|
+
`training telemetry alert(s): ${telemetryAlerts.join(', ')} at step ${entry.step}.`
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
validateTrainingMetricsEntry(entry);
|
|
1060
|
+
metrics.push(entry);
|
|
1061
|
+
if (artifactSession) {
|
|
1062
|
+
await artifactSession.appendStep(entry);
|
|
1063
|
+
}
|
|
1064
|
+
if (
|
|
1065
|
+
checkpointKey
|
|
1066
|
+
&& checkpointInterval !== null
|
|
1067
|
+
&& (checkpointInterval <= 1 || step % checkpointInterval === 0)
|
|
1068
|
+
) {
|
|
1069
|
+
await persistCheckpoint({
|
|
1070
|
+
step,
|
|
1071
|
+
epoch,
|
|
1072
|
+
batch: batchIndex,
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (this.onStep && (logEvery <= 0 || step % logEvery === 0)) {
|
|
1077
|
+
await this.onStep(entry);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
if (maxSteps && step >= maxSteps) {
|
|
1081
|
+
if (artifactSession) {
|
|
1082
|
+
this.lastArtifact = await artifactSession.finalize(metrics);
|
|
1083
|
+
}
|
|
1084
|
+
if (this.onEpoch) {
|
|
1085
|
+
await this.onEpoch({ epoch, steps: batchIndex, loss: meanLoss });
|
|
1086
|
+
}
|
|
1087
|
+
if (checkpointKey) {
|
|
1088
|
+
await persistCheckpoint({
|
|
1089
|
+
step,
|
|
1090
|
+
epoch,
|
|
1091
|
+
batch: batchIndex,
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
return metrics;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
if (this.onEpoch) {
|
|
1099
|
+
const last = metrics[metrics.length - 1];
|
|
1100
|
+
await this.onEpoch({ epoch, steps: batchIndex, loss: last?.total_loss ?? 0 });
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
if (artifactSession) {
|
|
1105
|
+
this.lastArtifact = await artifactSession.finalize(metrics);
|
|
1106
|
+
} else {
|
|
1107
|
+
this.lastArtifact = null;
|
|
1108
|
+
}
|
|
1109
|
+
if (checkpointKey) {
|
|
1110
|
+
const finalEpoch = Math.max(0, epochs - 1);
|
|
1111
|
+
const finalBatch = metrics.length > 0
|
|
1112
|
+
? (metrics[metrics.length - 1]?.batch ?? 0)
|
|
1113
|
+
: 0;
|
|
1114
|
+
await persistCheckpoint({
|
|
1115
|
+
step,
|
|
1116
|
+
epoch: finalEpoch,
|
|
1117
|
+
batch: finalBatch,
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
return metrics;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
async _runStep(model, batch, context = {}) {
|
|
1125
|
+
const lossScale = this.lossScaler.shouldScale() ? this.lossScaler.scale : 1;
|
|
1126
|
+
const options = {
|
|
1127
|
+
crossEntropyLoss: this.lossFn,
|
|
1128
|
+
clipGradients: this.clipFn,
|
|
1129
|
+
optimizer: this.optimizer,
|
|
1130
|
+
trainingObjective: this.trainingObjective,
|
|
1131
|
+
lossScale,
|
|
1132
|
+
stepIndex: context.stepIndex ?? null,
|
|
1133
|
+
epochIndex: context.epoch ?? null,
|
|
1134
|
+
batchIndex: context.batch ?? null,
|
|
1135
|
+
stage1ArtifactContext: context.stage1ArtifactContext ?? null,
|
|
1136
|
+
stageAArtifactContext: context.stageAArtifactContext ?? null,
|
|
1137
|
+
applyClip: false,
|
|
1138
|
+
applyOptimizer: false,
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
const result = await trainStep(model, batch, this.config, options);
|
|
1142
|
+
let grads = result.grads;
|
|
1143
|
+
|
|
1144
|
+
if (this.lossScaler.enabled && this.lossScaler.overflowCheck) {
|
|
1145
|
+
const overflow = await detectOverflow(grads);
|
|
1146
|
+
this.lossScaler.update(overflow);
|
|
1147
|
+
if (overflow) {
|
|
1148
|
+
return {
|
|
1149
|
+
loss: result.loss,
|
|
1150
|
+
forward_ms: result.forward_ms,
|
|
1151
|
+
backward_ms: result.backward_ms,
|
|
1152
|
+
clipMetrics: null,
|
|
1153
|
+
optimizerMetrics: null,
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
} else if (this.lossScaler.enabled) {
|
|
1157
|
+
this.lossScaler.update(false);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
const clipMetrics = await this.clipFn(grads, this.config);
|
|
1161
|
+
const paramGroups = resolveModelParamGroups(model);
|
|
1162
|
+
const freezeMap = this.config.training?.ul?.freeze
|
|
1163
|
+
?? this.config.training?.distill?.freeze
|
|
1164
|
+
?? {};
|
|
1165
|
+
const { trainableGroups, frozenGroups } = selectTrainableParamGroups(paramGroups, freezeMap);
|
|
1166
|
+
const trainableParams = flattenUniqueParams(trainableGroups);
|
|
1167
|
+
const optimizerMetrics = await this.optimizer.step(trainableParams, clipMetrics.clippedGrads, this.config, {
|
|
1168
|
+
trainableGroups: Object.keys(trainableGroups),
|
|
1169
|
+
frozenGroups,
|
|
1170
|
+
allGroups: Object.keys(paramGroups),
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
return {
|
|
1174
|
+
loss: result.loss,
|
|
1175
|
+
forward_ms: result.forward_ms,
|
|
1176
|
+
backward_ms: result.backward_ms,
|
|
1177
|
+
clipMetrics,
|
|
1178
|
+
optimizerMetrics,
|
|
1179
|
+
objectiveName: result.objectiveName,
|
|
1180
|
+
objectiveMetrics: result.objectiveMetrics,
|
|
1181
|
+
paramGroupMetrics: {
|
|
1182
|
+
trainableGroups: Object.keys(trainableGroups),
|
|
1183
|
+
frozenGroups,
|
|
1184
|
+
allGroups: Object.keys(paramGroups),
|
|
1185
|
+
trainableParamCount: trainableParams.length,
|
|
1186
|
+
},
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
export async function runTraining(model, dataset, config, options = {}) {
|
|
1192
|
+
const runner = new TrainingRunner(config, options);
|
|
1193
|
+
return runner.run(model, dataset, options);
|
|
1194
|
+
}
|