@simulatte/doppler 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +126 -0
- package/README.md +25 -17
- package/package.json +20 -4
- package/src/adapters/adapter-registry.js +12 -1
- package/src/adapters/lora-loader.js +23 -6
- package/src/bridge/extension-client.d.ts +5 -0
- package/src/bridge/extension-client.js +40 -0
- package/src/bridge/index.d.ts +2 -1
- package/src/bridge/index.js +6 -4
- package/src/browser/browser-converter.js +26 -1
- package/src/browser/file-picker.js +6 -0
- package/src/browser/safetensors-parser-browser.js +84 -1
- package/src/browser/shard-io-browser.js +2 -2
- package/src/browser/tensor-source-download.js +8 -2
- package/src/browser/tensor-source-http.d.ts +1 -0
- package/src/browser/tensor-source-http.js +5 -1
- package/src/client/doppler-api.browser.js +20 -4
- package/src/client/doppler-api.js +19 -3
- package/src/client/doppler-provider/generation.js +12 -0
- package/src/client/doppler-provider/model-manager.d.ts +10 -0
- package/src/client/doppler-provider/model-manager.js +91 -19
- package/src/client/doppler-provider/source-runtime.d.ts +2 -1
- package/src/client/doppler-provider/source-runtime.js +132 -13
- package/src/client/doppler-registry.json +8 -7
- package/src/config/backward-registry-loader.js +17 -2
- package/src/config/execution-v0-contract-check.js +113 -15
- package/src/config/kernel-path-contract-check.js +57 -29
- package/src/config/kernel-path-loader.js +5 -36
- package/src/config/kernels/kernel-ref-digests.js +39 -39
- package/src/config/kernels/registry.js +14 -1
- package/src/config/kernels/registry.json +49 -7
- package/src/config/loader.d.ts +1 -1
- package/src/config/loader.js +43 -4
- package/src/config/merge-contract-check.js +59 -4
- package/src/config/merge-helpers.js +128 -7
- package/src/config/merge.d.ts +1 -0
- package/src/config/merge.js +28 -0
- package/src/config/param-validator.js +47 -2
- package/src/config/presets/kernel-paths/{gemma2-q4k-dequant-f32a.json → gemma2-q4k-dequant-f32a-nosubgroups.json} +3 -3
- package/src/config/presets/kernel-paths/gemma3-f16-fused-f32a-online-streamingprefill.json +223 -0
- package/src/config/presets/kernel-paths/{gemma3-q4k-dequant-f32a.json → gemma3-q4k-dequant-f32a-nosubgroups.json} +3 -3
- package/src/config/presets/kernel-paths/registry.json +29 -8
- package/src/config/presets/models/gemma2.json +2 -2
- package/src/config/presets/models/qwen3.json +9 -2
- package/src/config/presets/models/transformer.json +5 -0
- package/src/config/presets/runtime/experiments/bench/gemma3-bench-q4k.json +1 -1
- package/src/config/presets/runtime/experiments/debug/gemma3-debug-q4k.json +1 -1
- package/src/config/presets/runtime/experiments/verify/gemma3-verify.json +1 -1
- package/src/config/presets/runtime/kernels/dequant-f16-q4k.json +6 -13
- package/src/config/presets/runtime/kernels/dequant-f32-q4k.json +6 -13
- package/src/config/presets/runtime/kernels/embeddinggemma-q4k-dequant-f32a.json +37 -0
- package/src/config/presets/runtime/kernels/fused-q4k.json +6 -13
- package/src/config/presets/runtime/kernels/gemma2-q4k-dequant-f16a.json +33 -0
- package/src/config/presets/runtime/kernels/gemma2-q4k-dequant-f32a-nosubgroups.json +33 -0
- package/src/config/presets/runtime/kernels/gemma2-q4k-fused-f32a.json +33 -0
- package/src/config/presets/runtime/kernels/safe-q4k.json +6 -13
- package/src/config/presets/runtime/platform/metal-apple-q4k.json +1 -1
- package/src/config/required-inference-fields-contract-check.js +6 -0
- package/src/config/runtime.js +6 -1
- package/src/config/schema/debug.schema.d.ts +5 -0
- package/src/config/schema/doppler.schema.js +16 -21
- package/src/config/schema/inference-defaults.schema.js +6 -3
- package/src/config/schema/inference.schema.d.ts +9 -0
- package/src/config/schema/kernel-path.schema.d.ts +11 -1
- package/src/config/schema/kernel-thresholds.schema.js +12 -4
- package/src/config/schema/manifest.schema.d.ts +8 -1
- package/src/config/schema/manifest.schema.js +19 -3
- package/src/config/training-defaults.js +30 -22
- package/src/converter/conversion-plan.js +94 -9
- package/src/converter/core.d.ts +7 -0
- package/src/converter/core.js +14 -9
- package/src/converter/execution-v0-manifest.js +4 -1
- package/src/converter/index.d.ts +1 -0
- package/src/converter/index.js +1 -0
- package/src/converter/manifest-inference.js +43 -12
- package/src/converter/parsers/diffusion.js +0 -3
- package/src/converter/quantization-info.js +35 -15
- package/src/converter/rope-config.js +42 -0
- package/src/converter/shard-packer.d.ts +1 -1
- package/src/converter/shard-packer.js +4 -1
- package/src/debug/config.js +123 -11
- package/src/debug/signals.js +7 -1
- package/src/debug/tensor.d.ts +2 -0
- package/src/debug/tensor.js +13 -2
- package/src/distribution/p2p-control-plane.js +52 -12
- package/src/distribution/p2p-observability.js +43 -7
- package/src/distribution/p2p-webrtc-browser.js +20 -0
- package/src/distribution/shard-delivery.js +77 -26
- package/src/formats/gguf/types.js +33 -16
- package/src/formats/rdrr/groups.d.ts +12 -4
- package/src/formats/rdrr/groups.js +3 -6
- package/src/formats/rdrr/parsing.js +39 -2
- package/src/formats/rdrr/types.d.ts +2 -1
- package/src/gpu/command-recorder.js +86 -61
- package/src/gpu/device.d.ts +1 -0
- package/src/gpu/device.js +131 -19
- package/src/gpu/kernel-tuner/benchmarks.js +326 -316
- package/src/gpu/kernel-tuner/cache.js +71 -4
- package/src/gpu/kernel-tuner/tuner.js +22 -4
- package/src/gpu/kernels/attention.js +113 -34
- package/src/gpu/kernels/backward/adam.js +62 -58
- package/src/gpu/kernels/backward/attention_backward.js +257 -169
- package/src/gpu/kernels/backward/conv2d_backward.js +14 -1
- package/src/gpu/kernels/bias_add.wgsl +8 -6
- package/src/gpu/kernels/bias_add_f16.wgsl +8 -5
- package/src/gpu/kernels/cast.js +191 -149
- package/src/gpu/kernels/check-stop.js +33 -44
- package/src/gpu/kernels/conv2d.js +27 -17
- package/src/gpu/kernels/conv2d.wgsl +7 -8
- package/src/gpu/kernels/conv2d_f16.wgsl +7 -8
- package/src/gpu/kernels/cross_entropy_loss.js +21 -15
- package/src/gpu/kernels/depthwise_conv2d.js +37 -26
- package/src/gpu/kernels/depthwise_conv2d.wgsl +6 -9
- package/src/gpu/kernels/depthwise_conv2d_f16.wgsl +6 -9
- package/src/gpu/kernels/dequant.js +178 -126
- package/src/gpu/kernels/energy.d.ts +3 -21
- package/src/gpu/kernels/energy.js +111 -88
- package/src/gpu/kernels/feature-check.js +1 -1
- package/src/gpu/kernels/fused_ffn.js +84 -65
- package/src/gpu/kernels/fused_matmul_residual.js +56 -33
- package/src/gpu/kernels/fused_matmul_rmsnorm.js +62 -45
- package/src/gpu/kernels/gather.js +33 -15
- package/src/gpu/kernels/gelu.js +19 -11
- package/src/gpu/kernels/grouped_pointwise_conv2d.js +34 -23
- package/src/gpu/kernels/grouped_pointwise_conv2d.wgsl +6 -9
- package/src/gpu/kernels/grouped_pointwise_conv2d_f16.wgsl +6 -9
- package/src/gpu/kernels/groupnorm.js +34 -23
- package/src/gpu/kernels/kv-quantize.js +5 -2
- package/src/gpu/kernels/layernorm.js +35 -19
- package/src/gpu/kernels/logit-merge.js +5 -3
- package/src/gpu/kernels/matmul.js +83 -39
- package/src/gpu/kernels/modulate.js +23 -15
- package/src/gpu/kernels/moe.js +221 -175
- package/src/gpu/kernels/pixel_shuffle.js +22 -14
- package/src/gpu/kernels/pixel_shuffle.wgsl +4 -5
- package/src/gpu/kernels/pixel_shuffle_f16.wgsl +4 -5
- package/src/gpu/kernels/relu.js +31 -10
- package/src/gpu/kernels/relu.wgsl +2 -1
- package/src/gpu/kernels/relu_f16.wgsl +2 -1
- package/src/gpu/kernels/repeat_channels.js +25 -17
- package/src/gpu/kernels/repeat_channels.wgsl +4 -5
- package/src/gpu/kernels/repeat_channels_f16.wgsl +4 -5
- package/src/gpu/kernels/residual.js +69 -23
- package/src/gpu/kernels/residual.wgsl +6 -3
- package/src/gpu/kernels/residual_f16.wgsl +2 -1
- package/src/gpu/kernels/residual_f16_vec4.wgsl +2 -1
- package/src/gpu/kernels/residual_vec4.wgsl +2 -1
- package/src/gpu/kernels/rmsnorm.js +96 -28
- package/src/gpu/kernels/rmsnorm.wgsl +14 -6
- package/src/gpu/kernels/rmsnorm_f16.wgsl +10 -2
- package/src/gpu/kernels/rope.d.ts +2 -0
- package/src/gpu/kernels/rope.js +14 -1
- package/src/gpu/kernels/rope.wgsl +56 -40
- package/src/gpu/kernels/sample.js +27 -38
- package/src/gpu/kernels/sana_linear_attention.js +19 -12
- package/src/gpu/kernels/sana_linear_attention_apply.wgsl +4 -5
- package/src/gpu/kernels/sana_linear_attention_apply_f16.wgsl +4 -5
- package/src/gpu/kernels/sana_linear_attention_summary.wgsl +4 -0
- package/src/gpu/kernels/sana_linear_attention_summary_f16.wgsl +4 -0
- package/src/gpu/kernels/scale.js +18 -11
- package/src/gpu/kernels/shader-cache.js +4 -2
- package/src/gpu/kernels/silu.d.ts +1 -0
- package/src/gpu/kernels/silu.js +148 -82
- package/src/gpu/kernels/silu.wgsl +19 -9
- package/src/gpu/kernels/silu_f16.wgsl +19 -9
- package/src/gpu/kernels/softmax.js +44 -25
- package/src/gpu/kernels/split_qkv.js +23 -13
- package/src/gpu/kernels/transpose.js +31 -10
- package/src/gpu/kernels/transpose.wgsl +6 -5
- package/src/gpu/kernels/upsample2d.js +22 -13
- package/src/gpu/kernels/upsample2d.wgsl +6 -9
- package/src/gpu/kernels/upsample2d_f16.wgsl +6 -9
- package/src/gpu/kernels/utils.js +35 -13
- package/src/gpu/partitioned-buffer-pool.js +10 -2
- package/src/gpu/perf-guards.js +2 -9
- package/src/gpu/profiler.js +27 -22
- package/src/gpu/readback-utils.d.ts +16 -0
- package/src/gpu/readback-utils.js +41 -0
- package/src/gpu/submit-tracker.js +13 -0
- package/src/gpu/uniform-cache.d.ts +1 -0
- package/src/gpu/uniform-cache.js +30 -9
- package/src/hotswap/intent-bundle.js +6 -0
- package/src/hotswap/manifest.d.ts +10 -1
- package/src/hotswap/manifest.js +12 -2
- package/src/hotswap/runtime.js +30 -8
- package/src/index-browser.d.ts +44 -0
- package/src/index-browser.js +14 -0
- package/src/inference/browser-harness-contract-helpers.d.ts +5 -0
- package/src/inference/browser-harness-contract-helpers.js +28 -0
- package/src/inference/browser-harness-diffusion-energy-suites.d.ts +2 -0
- package/src/inference/browser-harness-diffusion-energy-suites.js +269 -0
- package/src/inference/browser-harness-model-helpers.d.ts +16 -0
- package/src/inference/browser-harness-model-helpers.js +217 -0
- package/src/inference/browser-harness-report-helpers.d.ts +7 -0
- package/src/inference/browser-harness-report-helpers.js +42 -0
- package/src/inference/browser-harness-runtime-helpers.d.ts +61 -0
- package/src/inference/browser-harness-runtime-helpers.js +415 -0
- package/src/inference/browser-harness-suite-helpers.d.ts +28 -0
- package/src/inference/browser-harness-suite-helpers.js +268 -0
- package/src/inference/browser-harness-text-helpers.d.ts +27 -0
- package/src/inference/browser-harness-text-helpers.js +788 -0
- package/src/inference/browser-harness.d.ts +6 -0
- package/src/inference/browser-harness.js +130 -1950
- package/src/inference/kv-cache/base.js +140 -94
- package/src/inference/kv-cache/tiered.js +5 -3
- package/src/inference/moe-router.js +88 -56
- package/src/inference/multi-model-network.js +5 -3
- package/src/inference/network-evolution.d.ts +11 -2
- package/src/inference/network-evolution.js +20 -21
- package/src/inference/pipelines/context.d.ts +3 -0
- package/src/inference/pipelines/context.js +142 -2
- package/src/inference/pipelines/diffusion/helpers.js +7 -2
- package/src/inference/pipelines/diffusion/pipeline.js +17 -7
- package/src/inference/pipelines/diffusion/sd3-transformer.js +10 -10
- package/src/inference/pipelines/diffusion/text-encoder-gpu.d.ts +5 -0
- package/src/inference/pipelines/diffusion/text-encoder-gpu.js +27 -15
- package/src/inference/pipelines/diffusion/vae.js +3 -7
- package/src/inference/pipelines/energy/pipeline.js +27 -21
- package/src/inference/pipelines/energy/quintel.d.ts +5 -0
- package/src/inference/pipelines/energy/quintel.js +11 -0
- package/src/inference/pipelines/energy-head/row-head-pipeline.js +17 -13
- package/src/inference/pipelines/structured/json-head-pipeline.js +26 -11
- package/src/inference/pipelines/text/attention/projections.js +151 -101
- package/src/inference/pipelines/text/attention/record.js +73 -10
- package/src/inference/pipelines/text/attention/run.js +73 -10
- package/src/inference/pipelines/text/chat-format.js +25 -1
- package/src/inference/pipelines/text/config.d.ts +4 -0
- package/src/inference/pipelines/text/config.js +71 -5
- package/src/inference/pipelines/text/embed.js +2 -8
- package/src/inference/pipelines/text/execution-plan.js +64 -50
- package/src/inference/pipelines/text/execution-v0-contract-helpers.d.ts +59 -0
- package/src/inference/pipelines/text/execution-v0-contract-helpers.js +937 -0
- package/src/inference/pipelines/text/execution-v0-runtime-builders.d.ts +15 -0
- package/src/inference/pipelines/text/execution-v0-runtime-builders.js +279 -0
- package/src/inference/pipelines/text/execution-v0.js +78 -1002
- package/src/inference/pipelines/text/ffn/standard.js +3 -0
- package/src/inference/pipelines/text/generator-steps.d.ts +46 -0
- package/src/inference/pipelines/text/generator-steps.js +298 -207
- package/src/inference/pipelines/text/generator.js +6 -23
- package/src/inference/pipelines/text/init.d.ts +4 -0
- package/src/inference/pipelines/text/init.js +134 -29
- package/src/inference/pipelines/text/kernel-path-auto-select.js +2 -0
- package/src/inference/pipelines/text/kernel-trace.d.ts +2 -0
- package/src/inference/pipelines/text/kernel-trace.js +6 -0
- package/src/inference/pipelines/text/layer.js +14 -9
- package/src/inference/pipelines/text/linear-attention.d.ts +10 -0
- package/src/inference/pipelines/text/linear-attention.js +80 -6
- package/src/inference/pipelines/text/logits/gpu.js +10 -5
- package/src/inference/pipelines/text/logits/index.js +10 -11
- package/src/inference/pipelines/text/logits/utils.d.ts +7 -0
- package/src/inference/pipelines/text/logits/utils.js +9 -0
- package/src/inference/pipelines/text/lora-apply.js +50 -32
- package/src/inference/pipelines/text/model-load.js +279 -104
- package/src/inference/pipelines/text/moe-cache.js +5 -4
- package/src/inference/pipelines/text/moe-cpu-gptoss.js +74 -69
- package/src/inference/pipelines/text/moe-cpu.js +42 -38
- package/src/inference/pipelines/text/moe-gpu.js +110 -86
- package/src/inference/pipelines/text/ops.js +90 -90
- package/src/inference/pipelines/text/probes.js +9 -9
- package/src/inference/pipelines/text/weights.js +17 -7
- package/src/inference/pipelines/text.js +17 -1
- package/src/inference/speculative.d.ts +2 -2
- package/src/inference/speculative.js +4 -18
- package/src/inference/test-harness.d.ts +1 -1
- package/src/inference/test-harness.js +15 -5
- package/src/inference/tokenizer.d.ts +0 -5
- package/src/inference/tokenizer.js +4 -23
- package/src/inference/tokenizers/bpe.js +9 -0
- package/src/inference/tokenizers/bundled.js +176 -33
- package/src/inference/tokenizers/sentencepiece.js +12 -0
- package/src/loader/doppler-loader.js +38 -22
- package/src/loader/dtype-utils.js +3 -44
- package/src/loader/embedding-loader.js +7 -3
- package/src/loader/experts/expert-cache.js +13 -6
- package/src/loader/experts/expert-loader.js +10 -6
- package/src/loader/final-weights-loader.js +8 -4
- package/src/loader/layer-loader.js +2 -1
- package/src/loader/loader-state.js +2 -2
- package/src/loader/memory-monitor.js +8 -0
- package/src/loader/multi-model-loader.d.ts +14 -0
- package/src/loader/multi-model-loader.js +70 -24
- package/src/loader/shard-cache.js +81 -12
- package/src/loader/shard-resolver.js +25 -3
- package/src/loader/tensors/tensor-loader.js +209 -144
- package/src/loader/tensors/tensor-reader.js +76 -19
- package/src/loader/weight-downcast.js +1 -1
- package/src/memory/buffer-pool.d.ts +9 -1
- package/src/memory/buffer-pool.js +109 -44
- package/src/memory/unified-detect.js +1 -1
- package/src/rules/inference/kernel-path.rules.json +24 -8
- package/src/rules/rule-registry.js +25 -1
- package/src/rules/tooling/command-runtime.rules.json +18 -0
- package/src/storage/backends/opfs-store.js +68 -24
- package/src/storage/downloader.js +364 -83
- package/src/storage/index.d.ts +3 -0
- package/src/storage/index.js +3 -0
- package/src/storage/preflight.d.ts +2 -2
- package/src/storage/preflight.js +24 -2
- package/src/storage/quickstart-downloader.js +11 -5
- package/src/storage/registry.js +10 -4
- package/src/storage/reports.js +1 -1
- package/src/storage/shard-manager.d.ts +15 -1
- package/src/storage/shard-manager.js +51 -3
- package/src/storage/source-artifact-store.d.ts +52 -0
- package/src/storage/source-artifact-store.js +234 -0
- package/src/tooling/command-api-constants.d.ts +9 -0
- package/src/tooling/command-api-constants.js +9 -0
- package/src/tooling/command-api-family-normalizers.d.ts +9 -0
- package/src/tooling/command-api-family-normalizers.js +343 -0
- package/src/tooling/command-api-helpers.d.ts +25 -0
- package/src/tooling/command-api-helpers.js +262 -0
- package/src/tooling/command-api.d.ts +27 -1
- package/src/tooling/command-api.js +26 -473
- package/src/tooling/command-envelope.js +4 -1
- package/src/tooling/command-runner-shared.js +52 -18
- package/src/tooling/lean-execution-contract.js +150 -3
- package/src/tooling/node-browser-command-runner.d.ts +4 -0
- package/src/tooling/node-browser-command-runner.js +218 -273
- package/src/tooling/node-command-runner.js +44 -3
- package/src/tooling/node-converter.js +27 -1
- package/src/tooling/node-source-runtime.d.ts +1 -1
- package/src/tooling/node-source-runtime.js +84 -3
- package/src/tooling/node-webgpu.js +30 -105
- package/src/tooling/opfs-cache.js +21 -4
- package/src/tooling/runtime-input-composition.d.ts +38 -0
- package/src/tooling/runtime-input-composition.js +86 -0
- package/src/tooling/source-runtime-bundle.d.ts +40 -5
- package/src/tooling/source-runtime-bundle.js +261 -34
- package/src/tooling/source-runtime-materializer.d.ts +6 -0
- package/src/tooling/source-runtime-materializer.js +93 -0
- package/src/training/attention-backward.js +32 -17
- package/src/training/autograd.js +80 -52
- package/src/training/checkpoint-watch.d.ts +8 -0
- package/src/training/checkpoint-watch.js +139 -0
- package/src/training/checkpoint.d.ts +6 -1
- package/src/training/checkpoint.js +46 -7
- package/src/training/clip.js +2 -1
- package/src/training/datasets/token-batch.js +20 -8
- package/src/training/distillation/artifacts.d.ts +71 -0
- package/src/training/distillation/artifacts.js +132 -0
- package/src/training/distillation/checkpoint-watch.d.ts +10 -0
- package/src/training/distillation/checkpoint-watch.js +58 -0
- package/src/training/distillation/dataset.d.ts +59 -0
- package/src/training/distillation/dataset.js +337 -0
- package/src/training/distillation/eval.d.ts +34 -0
- package/src/training/distillation/eval.js +310 -0
- package/src/training/distillation/index.d.ts +29 -0
- package/src/training/distillation/index.js +29 -0
- package/src/training/distillation/runtime.d.ts +20 -0
- package/src/training/distillation/runtime.js +121 -0
- package/src/training/distillation/scoreboard.d.ts +6 -0
- package/src/training/distillation/scoreboard.js +8 -0
- package/src/training/distillation/stage-a.d.ts +45 -0
- package/src/training/distillation/stage-a.js +338 -0
- package/src/training/distillation/stage-b.d.ts +24 -0
- package/src/training/distillation/stage-b.js +20 -0
- package/src/training/distillation/student-fixture.d.ts +22 -0
- package/src/training/distillation/student-fixture.js +846 -0
- package/src/training/distillation/suite-data.d.ts +45 -0
- package/src/training/distillation/suite-data.js +189 -0
- package/src/training/index.d.ts +10 -0
- package/src/training/index.js +10 -0
- package/src/training/lora-pipeline.d.ts +40 -0
- package/src/training/lora-pipeline.js +793 -0
- package/src/training/lora.js +26 -12
- package/src/training/loss.js +5 -6
- package/src/training/objectives/cross_entropy.js +2 -5
- package/src/training/objectives/distill_kd.js +4 -8
- package/src/training/objectives/distill_triplet.js +4 -8
- package/src/training/objectives/ul_stage2_base.js +4 -8
- package/src/training/operator-artifacts.d.ts +62 -0
- package/src/training/operator-artifacts.js +140 -0
- package/src/training/operator-command.d.ts +5 -0
- package/src/training/operator-command.js +455 -0
- package/src/training/operator-eval.d.ts +48 -0
- package/src/training/operator-eval.js +230 -0
- package/src/training/operator-scoreboard.d.ts +5 -0
- package/src/training/operator-scoreboard.js +44 -0
- package/src/training/optimizer.js +19 -7
- package/src/training/runner.d.ts +52 -0
- package/src/training/runner.js +31 -5
- package/src/training/suite.d.ts +112 -0
- package/src/training/suite.js +24 -984
- package/src/training/tensor-factory.d.ts +9 -0
- package/src/training/tensor-factory.js +13 -0
- package/src/training/trainer.js +3 -5
- package/src/training/ul_dataset.js +3 -5
- package/src/training/workloads.d.ts +164 -0
- package/src/training/workloads.js +530 -0
- package/src/version.js +1 -1
- package/tools/convert-safetensors-node.js +22 -16
- package/tools/doppler-cli.js +179 -63
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LoadedTrainingWorkload } from '../workloads.js';
|
|
2
|
+
|
|
3
|
+
export declare function evaluateDistillationModel(options: {
|
|
4
|
+
loadedWorkload: LoadedTrainingWorkload;
|
|
5
|
+
layout?: Record<string, string> | null;
|
|
6
|
+
stageId: string;
|
|
7
|
+
checkpointId: string;
|
|
8
|
+
checkpointStep: number | null;
|
|
9
|
+
checkpointPath?: string | null;
|
|
10
|
+
distillRuntime: Record<string, unknown>;
|
|
11
|
+
model: Record<string, unknown>;
|
|
12
|
+
evalDatasetId?: string | null;
|
|
13
|
+
configHash?: string | null;
|
|
14
|
+
parentArtifacts?: Array<Record<string, unknown>>;
|
|
15
|
+
}): Promise<Record<string, unknown>[]>;
|
|
16
|
+
|
|
17
|
+
export declare function evaluateDistillationCheckpoint(options: {
|
|
18
|
+
loadedWorkload: LoadedTrainingWorkload;
|
|
19
|
+
checkpointPath: string;
|
|
20
|
+
checkpointId?: string | null;
|
|
21
|
+
checkpointStep?: number | null;
|
|
22
|
+
stageId?: string | null;
|
|
23
|
+
layout?: Record<string, string> | null;
|
|
24
|
+
datasetPath?: string | null;
|
|
25
|
+
stageAArtifact?: string | null;
|
|
26
|
+
stageAArtifactHash?: string | null;
|
|
27
|
+
evalDatasetId?: string | null;
|
|
28
|
+
parentArtifacts?: Array<Record<string, unknown>>;
|
|
29
|
+
}): Promise<Record<string, unknown>[]>;
|
|
30
|
+
|
|
31
|
+
export declare function readDistillCheckpointMarker(markerPath: string): Promise<{
|
|
32
|
+
absolutePath: string;
|
|
33
|
+
marker: Record<string, unknown>;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { loadBackwardRegistry } from '../../config/backward-registry-loader.js';
|
|
5
|
+
import { f16ToF32Array } from '../../inference/kv-cache/types.js';
|
|
6
|
+
import { readBuffer, releaseBuffer } from '../../memory/buffer-pool.js';
|
|
7
|
+
import { AutogradTape } from '../autograd.js';
|
|
8
|
+
import { loadCheckpoint } from '../checkpoint.js';
|
|
9
|
+
import { computeEvalMetrics } from '../operator-eval.js';
|
|
10
|
+
import {
|
|
11
|
+
buildDistillPrompt,
|
|
12
|
+
createDistillRuntimeContext,
|
|
13
|
+
createDistillStudentRuntimeModelFixture,
|
|
14
|
+
resolveDistillDataScope,
|
|
15
|
+
} from '../suite.js';
|
|
16
|
+
import { restoreTrainingCheckpointState } from '../runner.js';
|
|
17
|
+
import { loadCanonicalTranslationDataset } from './dataset.js';
|
|
18
|
+
import { buildDistillArtifactBase, writeDistillEvalReport } from './artifacts.js';
|
|
19
|
+
import { buildDistillationTrainingConfigFromWorkload, resolveInternalDistillStage } from './runtime.js';
|
|
20
|
+
|
|
21
|
+
function toFloat32Array(raw, dtype = 'f32') {
|
|
22
|
+
if (dtype === 'f16') {
|
|
23
|
+
return f16ToF32Array(new Uint16Array(raw));
|
|
24
|
+
}
|
|
25
|
+
return new Float32Array(raw);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolveEvalDatasets(workload, requestedEvalDatasetId = null) {
|
|
29
|
+
const evalDatasets = Array.isArray(workload.evalDatasets) ? workload.evalDatasets : [];
|
|
30
|
+
if (!requestedEvalDatasetId) {
|
|
31
|
+
return evalDatasets;
|
|
32
|
+
}
|
|
33
|
+
return evalDatasets.filter((entry) => entry.id === requestedEvalDatasetId);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function argmax(values) {
|
|
37
|
+
let bestIndex = 0;
|
|
38
|
+
let bestValue = Number.NEGATIVE_INFINITY;
|
|
39
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
40
|
+
const value = Number.isFinite(values[index]) ? values[index] : Number.NEGATIVE_INFINITY;
|
|
41
|
+
if (value > bestValue) {
|
|
42
|
+
bestValue = value;
|
|
43
|
+
bestIndex = index;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return bestIndex;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function releaseTensorLike(value, released) {
|
|
50
|
+
if (!value || typeof value !== 'object') return;
|
|
51
|
+
const buffer = value.buffer;
|
|
52
|
+
if (!buffer || released.has(buffer)) return;
|
|
53
|
+
released.add(buffer);
|
|
54
|
+
releaseBuffer(buffer);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function disposeTapeOutputs(tape, protectedBuffers = new Set()) {
|
|
58
|
+
if (!tape || !Array.isArray(tape.records)) return;
|
|
59
|
+
const released = new Set();
|
|
60
|
+
for (const record of tape.records) {
|
|
61
|
+
const output = record?.output;
|
|
62
|
+
if (!output || typeof output !== 'object') continue;
|
|
63
|
+
if (output.buffer && !protectedBuffers.has(output.buffer)) {
|
|
64
|
+
releaseTensorLike(output, released);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(output)) {
|
|
68
|
+
for (const entry of output) {
|
|
69
|
+
if (entry?.buffer && !protectedBuffers.has(entry.buffer)) {
|
|
70
|
+
releaseTensorLike(entry, released);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function collectProtectedBuffers(model) {
|
|
78
|
+
const protectedBuffers = new Set();
|
|
79
|
+
const groups = typeof model?.paramGroups === 'function'
|
|
80
|
+
? model.paramGroups()
|
|
81
|
+
: {};
|
|
82
|
+
for (const params of Object.values(groups || {})) {
|
|
83
|
+
for (const tensor of Array.isArray(params) ? params : []) {
|
|
84
|
+
if (tensor?.buffer) {
|
|
85
|
+
protectedBuffers.add(tensor.buffer);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return protectedBuffers;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function readLogitsTensor(tensor) {
|
|
93
|
+
const raw = await readBuffer(tensor.buffer);
|
|
94
|
+
return toFloat32Array(raw, tensor.dtype || 'f32');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function greedyDecodeFixture(model, tokenizer, prompt, decodePolicy = {}) {
|
|
98
|
+
const maxTokens = Number.isInteger(decodePolicy?.maxTokens) && decodePolicy.maxTokens > 0
|
|
99
|
+
? decodePolicy.maxTokens
|
|
100
|
+
: null;
|
|
101
|
+
if (!maxTokens) {
|
|
102
|
+
throw new Error('Translation eval requires evalDatasets[].decodePolicy.maxTokens in the workload pack.');
|
|
103
|
+
}
|
|
104
|
+
const stopOnEos = decodePolicy?.stopOnEos !== false;
|
|
105
|
+
const eosToken = tokenizer?.getSpecialTokens?.()?.eos ?? null;
|
|
106
|
+
const protectedBuffers = collectProtectedBuffers(model);
|
|
107
|
+
const generated = [];
|
|
108
|
+
let currentPrompt = prompt;
|
|
109
|
+
for (let step = 0; step < maxTokens; step += 1) {
|
|
110
|
+
const tape = new AutogradTape(loadBackwardRegistry());
|
|
111
|
+
let logits = null;
|
|
112
|
+
try {
|
|
113
|
+
const result = await model.forwardDistill(
|
|
114
|
+
{
|
|
115
|
+
distill: {
|
|
116
|
+
prompts: [currentPrompt],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
tape,
|
|
120
|
+
{ phase: 'anchor' }
|
|
121
|
+
);
|
|
122
|
+
logits = result?.logits || result;
|
|
123
|
+
const values = await readLogitsTensor(logits);
|
|
124
|
+
const tokenId = argmax(values);
|
|
125
|
+
if (stopOnEos && eosToken != null && tokenId === eosToken) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
generated.push(tokenId);
|
|
129
|
+
currentPrompt = `${prompt}${tokenizer.decode(generated, false, false)}`;
|
|
130
|
+
} finally {
|
|
131
|
+
if (logits?.buffer && !protectedBuffers.has(logits.buffer)) {
|
|
132
|
+
releaseBuffer(logits.buffer);
|
|
133
|
+
}
|
|
134
|
+
model.cleanupDistillStep?.();
|
|
135
|
+
disposeTapeOutputs(tape, protectedBuffers);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return tokenizer.decode(generated, true, true);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function flattenMetricSummary(metrics) {
|
|
142
|
+
return {
|
|
143
|
+
bleu: metrics?.bleu?.score ?? null,
|
|
144
|
+
chrf: metrics?.chrf?.score ?? null,
|
|
145
|
+
exact_match: metrics?.exactMatch?.score ?? null,
|
|
146
|
+
accuracy: metrics?.accuracy?.score ?? null,
|
|
147
|
+
primaryMetric: metrics?.primaryMetric || null,
|
|
148
|
+
primaryScore: metrics?.primaryScore ?? null,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function evaluateDistillationModel(options) {
|
|
153
|
+
const loadedWorkload = options.loadedWorkload;
|
|
154
|
+
const workload = loadedWorkload.workload;
|
|
155
|
+
const stageId = options.stageId;
|
|
156
|
+
const checkpointId = options.checkpointId;
|
|
157
|
+
const checkpointStep = options.checkpointStep;
|
|
158
|
+
const distillRuntime = options.distillRuntime;
|
|
159
|
+
const model = options.model;
|
|
160
|
+
if (distillRuntime.studentGraphMode !== 'transformer_full') {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Distillation eval requires studentGraphMode="transformer_full"; got "${distillRuntime.studentGraphMode}".`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const evalDatasets = resolveEvalDatasets(workload, options.evalDatasetId || null);
|
|
166
|
+
if (evalDatasets.length === 0) {
|
|
167
|
+
throw new Error(`No eval datasets resolved for workload "${workload.id}".`);
|
|
168
|
+
}
|
|
169
|
+
const reports = [];
|
|
170
|
+
for (const evalDataset of evalDatasets) {
|
|
171
|
+
if (evalDataset.evalKind !== 'translation') {
|
|
172
|
+
throw new Error(`Distillation eval currently supports translation eval only, got "${evalDataset.evalKind}".`);
|
|
173
|
+
}
|
|
174
|
+
const dataset = await loadCanonicalTranslationDataset(evalDataset.datasetPath, {
|
|
175
|
+
strictPairContract: workload.pipeline.strictPairContract === true,
|
|
176
|
+
sourceLangs: evalDataset.sourceLangs || workload.pipeline.sourceLangs,
|
|
177
|
+
targetLangs: evalDataset.targetLangs || workload.pipeline.targetLangs,
|
|
178
|
+
pairAllowlist: evalDataset.pairAllowlist || workload.pipeline.pairAllowlist,
|
|
179
|
+
});
|
|
180
|
+
const hypotheses = [];
|
|
181
|
+
const references = [];
|
|
182
|
+
const samples = [];
|
|
183
|
+
for (const row of dataset.rows) {
|
|
184
|
+
const prompt = buildDistillPrompt({
|
|
185
|
+
direction: row.pair || (
|
|
186
|
+
row.src_lang && row.tgt_lang
|
|
187
|
+
? `${row.src_lang}->${row.tgt_lang}`
|
|
188
|
+
: 'unknown'
|
|
189
|
+
),
|
|
190
|
+
source: row.source,
|
|
191
|
+
});
|
|
192
|
+
const hypothesis = await greedyDecodeFixture(
|
|
193
|
+
model,
|
|
194
|
+
distillRuntime.studentPipeline.tokenizer,
|
|
195
|
+
prompt,
|
|
196
|
+
evalDataset.decodePolicy || {}
|
|
197
|
+
);
|
|
198
|
+
hypotheses.push(hypothesis);
|
|
199
|
+
references.push(row.target_pos);
|
|
200
|
+
if (samples.length < 5) {
|
|
201
|
+
samples.push({
|
|
202
|
+
row_id: row.row_id,
|
|
203
|
+
source: row.source,
|
|
204
|
+
reference: row.target_pos,
|
|
205
|
+
hypothesis,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const computedMetrics = computeEvalMetrics('translation', hypotheses, references, {});
|
|
210
|
+
const flattened = flattenMetricSummary(computedMetrics);
|
|
211
|
+
const reportPayload = {
|
|
212
|
+
...buildDistillArtifactBase(loadedWorkload, {
|
|
213
|
+
prefix: 'dst_eval',
|
|
214
|
+
artifactType: 'training_eval_report',
|
|
215
|
+
datasetPath: dataset.absolutePath,
|
|
216
|
+
datasetHash: dataset.canonicalHash,
|
|
217
|
+
stage: stageId,
|
|
218
|
+
checkpointStep,
|
|
219
|
+
parentArtifacts: options.parentArtifacts || [],
|
|
220
|
+
configHash: options.configHash || workload.configHash,
|
|
221
|
+
}),
|
|
222
|
+
checkpointId,
|
|
223
|
+
checkpointPath: options.checkpointPath || null,
|
|
224
|
+
evalDatasetId: evalDataset.id,
|
|
225
|
+
evalKind: evalDataset.evalKind,
|
|
226
|
+
metrics: computedMetrics,
|
|
227
|
+
...flattened,
|
|
228
|
+
rowCount: dataset.rowCount,
|
|
229
|
+
sampleRows: samples,
|
|
230
|
+
};
|
|
231
|
+
const reportFile = options.layout
|
|
232
|
+
? await writeDistillEvalReport(options.layout, reportPayload)
|
|
233
|
+
: null;
|
|
234
|
+
reports.push({
|
|
235
|
+
...reportPayload,
|
|
236
|
+
reportPath: reportFile?.path || null,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return reports;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export async function evaluateDistillationCheckpoint(options) {
|
|
243
|
+
const loadedWorkload = options.loadedWorkload;
|
|
244
|
+
const workload = loadedWorkload.workload;
|
|
245
|
+
const stagePlan = workload.pipeline.stagePlan;
|
|
246
|
+
const requestedStageId = String(options.stageId || '').trim();
|
|
247
|
+
const stageEntry = stagePlan.find((entry) => entry.id === requestedStageId)
|
|
248
|
+
|| stagePlan[0];
|
|
249
|
+
if (!stageEntry) {
|
|
250
|
+
throw new Error(`No stage entry resolved for workload "${workload.id}".`);
|
|
251
|
+
}
|
|
252
|
+
const internalStage = resolveInternalDistillStage(stageEntry);
|
|
253
|
+
const checkpointPath = resolve(String(options.checkpointPath));
|
|
254
|
+
const checkpointRecord = await loadCheckpoint(checkpointPath);
|
|
255
|
+
if (!checkpointRecord) {
|
|
256
|
+
throw new Error(`Checkpoint not found: ${checkpointPath}`);
|
|
257
|
+
}
|
|
258
|
+
const configBundle = buildDistillationTrainingConfigFromWorkload(loadedWorkload, stageEntry, {
|
|
259
|
+
datasetPath: options.datasetPath || workload.datasetPath,
|
|
260
|
+
stageAArtifact: options.stageAArtifact || null,
|
|
261
|
+
stageAArtifactHash: options.stageAArtifactHash || null,
|
|
262
|
+
artifactDir: dirname(dirname(checkpointPath)),
|
|
263
|
+
});
|
|
264
|
+
const distillRuntime = await createDistillRuntimeContext({
|
|
265
|
+
teacherModelId: workload.teacherModelId,
|
|
266
|
+
studentModelId: workload.studentModelId,
|
|
267
|
+
trainingStage: internalStage,
|
|
268
|
+
studentGraphMode: workload.pipeline.studentGraphMode,
|
|
269
|
+
}, configBundle.trainingConfig.training);
|
|
270
|
+
let fixture = null;
|
|
271
|
+
try {
|
|
272
|
+
fixture = await createDistillStudentRuntimeModelFixture({
|
|
273
|
+
training: configBundle.trainingConfig.training,
|
|
274
|
+
}, {
|
|
275
|
+
distillRuntime,
|
|
276
|
+
studentGraphMode: workload.pipeline.studentGraphMode,
|
|
277
|
+
});
|
|
278
|
+
await restoreTrainingCheckpointState(
|
|
279
|
+
fixture.model,
|
|
280
|
+
{ getState: () => null, stepCount: 0 },
|
|
281
|
+
checkpointRecord,
|
|
282
|
+
fixture.config
|
|
283
|
+
);
|
|
284
|
+
return evaluateDistillationModel({
|
|
285
|
+
loadedWorkload,
|
|
286
|
+
layout: options.layout || null,
|
|
287
|
+
stageId: stageEntry.id,
|
|
288
|
+
checkpointId: options.checkpointId || 'checkpoint',
|
|
289
|
+
checkpointStep: options.checkpointStep || null,
|
|
290
|
+
checkpointPath,
|
|
291
|
+
distillRuntime,
|
|
292
|
+
model: fixture.model,
|
|
293
|
+
evalDatasetId: options.evalDatasetId || null,
|
|
294
|
+
configHash: configBundle.trainingConfigHash,
|
|
295
|
+
parentArtifacts: options.parentArtifacts || [],
|
|
296
|
+
});
|
|
297
|
+
} finally {
|
|
298
|
+
fixture?.cleanup?.();
|
|
299
|
+
await distillRuntime.cleanup();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export async function readDistillCheckpointMarker(markerPath) {
|
|
304
|
+
const absolutePath = resolve(String(markerPath));
|
|
305
|
+
const raw = await readFile(absolutePath, 'utf8');
|
|
306
|
+
return {
|
|
307
|
+
absolutePath,
|
|
308
|
+
marker: JSON.parse(raw),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export {
|
|
2
|
+
normalizeDistillationPair,
|
|
3
|
+
normalizeTranslationPairRow,
|
|
4
|
+
loadCanonicalTranslationDataset,
|
|
5
|
+
buildFrozenSubset,
|
|
6
|
+
} from './dataset.js';
|
|
7
|
+
export {
|
|
8
|
+
createDistillationRunArtifacts,
|
|
9
|
+
writeDistillStageManifest,
|
|
10
|
+
writeDistillCheckpointMetadata,
|
|
11
|
+
writeDistillCheckpointComplete,
|
|
12
|
+
writeDistillEvalReport,
|
|
13
|
+
writeDistillCompareReport,
|
|
14
|
+
writeDistillQualityGateReport,
|
|
15
|
+
buildDistillArtifactBase,
|
|
16
|
+
} from './artifacts.js';
|
|
17
|
+
export { appendDistillationScoreboardRow } from './scoreboard.js';
|
|
18
|
+
export {
|
|
19
|
+
buildDistillationTrainingConfigFromWorkload,
|
|
20
|
+
resolveInternalDistillStage,
|
|
21
|
+
} from './runtime.js';
|
|
22
|
+
export {
|
|
23
|
+
evaluateDistillationModel,
|
|
24
|
+
evaluateDistillationCheckpoint,
|
|
25
|
+
readDistillCheckpointMarker,
|
|
26
|
+
} from './eval.js';
|
|
27
|
+
export { runDistillationStage, runDistillationStageA } from './stage-a.js';
|
|
28
|
+
export { runDistillationStageB } from './stage-b.js';
|
|
29
|
+
export { watchDistillationCheckpoints } from './checkpoint-watch.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export {
|
|
2
|
+
normalizeDistillationPair,
|
|
3
|
+
normalizeTranslationPairRow,
|
|
4
|
+
loadCanonicalTranslationDataset,
|
|
5
|
+
buildFrozenSubset,
|
|
6
|
+
} from './dataset.js';
|
|
7
|
+
export {
|
|
8
|
+
createDistillationRunArtifacts,
|
|
9
|
+
writeDistillStageManifest,
|
|
10
|
+
writeDistillCheckpointMetadata,
|
|
11
|
+
writeDistillCheckpointComplete,
|
|
12
|
+
writeDistillEvalReport,
|
|
13
|
+
writeDistillCompareReport,
|
|
14
|
+
writeDistillQualityGateReport,
|
|
15
|
+
buildDistillArtifactBase,
|
|
16
|
+
} from './artifacts.js';
|
|
17
|
+
export { appendDistillationScoreboardRow } from './scoreboard.js';
|
|
18
|
+
export {
|
|
19
|
+
buildDistillationTrainingConfigFromWorkload,
|
|
20
|
+
resolveInternalDistillStage,
|
|
21
|
+
} from './runtime.js';
|
|
22
|
+
export {
|
|
23
|
+
evaluateDistillationModel,
|
|
24
|
+
evaluateDistillationCheckpoint,
|
|
25
|
+
readDistillCheckpointMarker,
|
|
26
|
+
} from './eval.js';
|
|
27
|
+
export { runDistillationStage, runDistillationStageA } from './stage-a.js';
|
|
28
|
+
export { runDistillationStageB } from './stage-b.js';
|
|
29
|
+
export { watchDistillationCheckpoints } from './checkpoint-watch.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LoadedTrainingWorkload, DistillStagePlanEntry } from '../workloads.js';
|
|
2
|
+
|
|
3
|
+
export declare function resolveInternalDistillStage(
|
|
4
|
+
stageEntry: DistillStagePlanEntry | Record<string, unknown>
|
|
5
|
+
): 'stage_a' | 'stage_b';
|
|
6
|
+
|
|
7
|
+
export declare function buildDistillationTrainingConfigFromWorkload(
|
|
8
|
+
loadedWorkload: LoadedTrainingWorkload,
|
|
9
|
+
stageEntry: DistillStagePlanEntry | Record<string, unknown>,
|
|
10
|
+
options?: {
|
|
11
|
+
datasetPath?: string | null;
|
|
12
|
+
artifactDir?: string | null;
|
|
13
|
+
stageAArtifact?: string | null;
|
|
14
|
+
stageAArtifactHash?: string | null;
|
|
15
|
+
}
|
|
16
|
+
): {
|
|
17
|
+
internalStage: 'stage_a' | 'stage_b';
|
|
18
|
+
trainingConfig: Record<string, unknown>;
|
|
19
|
+
trainingConfigHash: string;
|
|
20
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createTrainingConfig } from '../../config/training-defaults.js';
|
|
2
|
+
import { sha256Hex } from '../../utils/sha256.js';
|
|
3
|
+
|
|
4
|
+
function stableSortObject(value) {
|
|
5
|
+
if (Array.isArray(value)) {
|
|
6
|
+
return value.map((entry) => stableSortObject(entry));
|
|
7
|
+
}
|
|
8
|
+
if (!value || typeof value !== 'object') {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
const sorted = {};
|
|
12
|
+
for (const key of Object.keys(value).sort()) {
|
|
13
|
+
sorted[key] = stableSortObject(value[key]);
|
|
14
|
+
}
|
|
15
|
+
return sorted;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function stableJson(value) {
|
|
19
|
+
return JSON.stringify(stableSortObject(value));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeStageLabel(value) {
|
|
23
|
+
const normalized = String(value || '').trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
24
|
+
return normalized;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function resolveInternalDistillStage(stageEntry) {
|
|
28
|
+
const trainingStage = normalizeStageLabel(stageEntry?.trainingStage || stageEntry?.id || '');
|
|
29
|
+
const objective = normalizeStageLabel(stageEntry?.objective || '');
|
|
30
|
+
if (trainingStage === 'sft' || objective === 'sft') {
|
|
31
|
+
throw new Error(
|
|
32
|
+
'Distillation workload stage uses "sft", but the current JS distill runner only supports the KD-oriented stage_a contract. Use objective="kd" / trainingStage="stage_a" explicitly.'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (
|
|
36
|
+
trainingStage === 'stage_b'
|
|
37
|
+
|| trainingStage === 'post_sft_distill'
|
|
38
|
+
|| trainingStage === 'post_sft_triplet'
|
|
39
|
+
|| objective === 'triplet'
|
|
40
|
+
) {
|
|
41
|
+
return 'stage_b';
|
|
42
|
+
}
|
|
43
|
+
if (
|
|
44
|
+
trainingStage === 'stage_a'
|
|
45
|
+
|| trainingStage === 'kd'
|
|
46
|
+
|| objective === 'kd'
|
|
47
|
+
|| objective === 'cross_entropy'
|
|
48
|
+
) {
|
|
49
|
+
return 'stage_a';
|
|
50
|
+
}
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Unsupported distillation stage "${stageEntry?.trainingStage || stageEntry?.id || 'unknown'}".`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function buildDistillationTrainingConfigFromWorkload(loadedWorkload, stageEntry, options = {}) {
|
|
57
|
+
const workload = loadedWorkload.workload;
|
|
58
|
+
if (workload.kind !== 'distill') {
|
|
59
|
+
throw new Error('buildDistillationTrainingConfigFromWorkload requires a distill workload.');
|
|
60
|
+
}
|
|
61
|
+
const internalStage = resolveInternalDistillStage(stageEntry);
|
|
62
|
+
const distillTraining = {
|
|
63
|
+
enabled: true,
|
|
64
|
+
stage: internalStage,
|
|
65
|
+
teacherModelId: workload.teacherModelId,
|
|
66
|
+
studentModelId: workload.studentModelId,
|
|
67
|
+
datasetId: workload.datasetId,
|
|
68
|
+
datasetPath: options.datasetPath || workload.datasetPath,
|
|
69
|
+
sourceLangs: workload.pipeline.sourceLangs,
|
|
70
|
+
targetLangs: workload.pipeline.targetLangs,
|
|
71
|
+
pairAllowlist: workload.pipeline.pairAllowlist,
|
|
72
|
+
strictPairContract: workload.pipeline.strictPairContract === true,
|
|
73
|
+
stageAArtifact: options.stageAArtifact || null,
|
|
74
|
+
stageAArtifactHash: options.stageAArtifactHash || null,
|
|
75
|
+
artifactDir: options.artifactDir || null,
|
|
76
|
+
temperature: workload.pipeline.temperature,
|
|
77
|
+
alphaKd: workload.pipeline.alphaKd,
|
|
78
|
+
alphaCe: workload.pipeline.alphaCe,
|
|
79
|
+
tripletMargin: workload.pipeline.tripletMargin,
|
|
80
|
+
studentGraphMode: workload.pipeline.studentGraphMode,
|
|
81
|
+
};
|
|
82
|
+
if (internalStage === 'stage_b') {
|
|
83
|
+
distillTraining.freeze = {
|
|
84
|
+
encoder: true,
|
|
85
|
+
prior: true,
|
|
86
|
+
decoder: true,
|
|
87
|
+
base: false,
|
|
88
|
+
lora: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const trainingConfig = createTrainingConfig({
|
|
92
|
+
training: {
|
|
93
|
+
enabled: true,
|
|
94
|
+
optimizer: {
|
|
95
|
+
type: workload.training.optimizer.type,
|
|
96
|
+
lr: workload.training.optimizer.lr,
|
|
97
|
+
beta1: workload.training.optimizer.beta1,
|
|
98
|
+
beta2: workload.training.optimizer.beta2,
|
|
99
|
+
eps: workload.training.optimizer.eps,
|
|
100
|
+
weightDecay: workload.training.optimizer.weightDecay,
|
|
101
|
+
scheduler: workload.training.optimizer.scheduler,
|
|
102
|
+
},
|
|
103
|
+
gradient: {
|
|
104
|
+
maxNorm: workload.training.gradientClipping.maxNorm,
|
|
105
|
+
},
|
|
106
|
+
precision: workload.training.precision,
|
|
107
|
+
distill: distillTraining,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
internalStage,
|
|
112
|
+
trainingConfig,
|
|
113
|
+
trainingConfigHash: sha256Hex(stableJson({
|
|
114
|
+
workloadConfigHash: workload.configHash,
|
|
115
|
+
stageEntry,
|
|
116
|
+
datasetPath: options.datasetPath || workload.datasetPath,
|
|
117
|
+
stageAArtifact: options.stageAArtifact || null,
|
|
118
|
+
stageAArtifactHash: options.stageAArtifactHash || null,
|
|
119
|
+
})),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function appendDistillationScoreboardRow(
|
|
2
|
+
layout: Record<string, string>,
|
|
3
|
+
stageId: string,
|
|
4
|
+
row: Record<string, unknown>,
|
|
5
|
+
options?: { selectionMetric?: string | null; selectionGoal?: string | null }
|
|
6
|
+
): Promise<{ rowsPath: string; summaryPath: string }>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { appendScoreboardRow } from '../operator-scoreboard.js';
|
|
4
|
+
|
|
5
|
+
export async function appendDistillationScoreboardRow(layout, stageId, row, options = {}) {
|
|
6
|
+
const scoreboardDir = join(layout.scoreboard, String(stageId || 'stage'));
|
|
7
|
+
return appendScoreboardRow(scoreboardDir, row, options);
|
|
8
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { LoadedTrainingWorkload, DistillStagePlanEntry } from '../workloads.js';
|
|
2
|
+
|
|
3
|
+
export declare function runDistillationStage(options: {
|
|
4
|
+
loadedWorkload: LoadedTrainingWorkload;
|
|
5
|
+
stageEntry: DistillStagePlanEntry;
|
|
6
|
+
layout: Record<string, string>;
|
|
7
|
+
datasetPath?: string | null;
|
|
8
|
+
stageAArtifact?: string | null;
|
|
9
|
+
stageAArtifactHash?: string | null;
|
|
10
|
+
legacyArtifactDir?: string | null;
|
|
11
|
+
timestamp?: string | Date | null;
|
|
12
|
+
parentArtifacts?: Array<Record<string, unknown>>;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
stageId: string;
|
|
15
|
+
trainingStage: 'stage_a' | 'stage_b';
|
|
16
|
+
metrics: Record<string, unknown>[];
|
|
17
|
+
checkpointArtifacts: Array<Record<string, unknown>>;
|
|
18
|
+
evalReports: Array<Record<string, unknown>>;
|
|
19
|
+
bestReport: Record<string, unknown> | null;
|
|
20
|
+
stageManifestPath: string;
|
|
21
|
+
legacyArtifact: Record<string, unknown> | null;
|
|
22
|
+
lastCheckpoint: Record<string, unknown> | null;
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
export declare function runDistillationStageA(options: {
|
|
26
|
+
loadedWorkload: LoadedTrainingWorkload;
|
|
27
|
+
stageEntry: DistillStagePlanEntry;
|
|
28
|
+
layout: Record<string, string>;
|
|
29
|
+
datasetPath?: string | null;
|
|
30
|
+
stageAArtifact?: string | null;
|
|
31
|
+
stageAArtifactHash?: string | null;
|
|
32
|
+
legacyArtifactDir?: string | null;
|
|
33
|
+
timestamp?: string | Date | null;
|
|
34
|
+
parentArtifacts?: Array<Record<string, unknown>>;
|
|
35
|
+
}): Promise<{
|
|
36
|
+
stageId: string;
|
|
37
|
+
trainingStage: 'stage_a' | 'stage_b';
|
|
38
|
+
metrics: Record<string, unknown>[];
|
|
39
|
+
checkpointArtifacts: Array<Record<string, unknown>>;
|
|
40
|
+
evalReports: Array<Record<string, unknown>>;
|
|
41
|
+
bestReport: Record<string, unknown> | null;
|
|
42
|
+
stageManifestPath: string;
|
|
43
|
+
legacyArtifact: Record<string, unknown> | null;
|
|
44
|
+
lastCheckpoint: Record<string, unknown> | null;
|
|
45
|
+
}>;
|