@simulatte/doppler 0.1.6 → 0.1.8
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 +145 -0
- package/README.md +16 -23
- package/package.json +30 -32
- 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 +31 -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 +5 -20
- 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.d.ts +5 -0
- package/src/config/kernel-path-loader.js +18 -36
- package/src/config/kernels/kernel-ref-digests.js +1 -1
- package/src/config/kernels/registry.js +14 -1
- package/src/config/kernels/registry.json +81 -5
- package/src/config/loader.d.ts +1 -1
- package/src/config/loader.js +15 -2
- package/src/config/merge-contract-check.js +66 -4
- package/src/config/merge-helpers.js +128 -7
- package/src/config/merge.d.ts +1 -0
- package/src/config/merge.js +10 -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/gemma3-q4k-dequant-f32w-f32a-online.json +56 -0
- package/src/config/presets/kernel-paths/lfm2-q4k-dequant-f32a-nosubgroups.json +61 -0
- package/src/config/presets/kernel-paths/registry.json +43 -8
- package/src/config/presets/models/gemma2.json +3 -2
- package/src/config/presets/models/gemma3.json +2 -0
- package/src/config/presets/models/qwen3.json +4 -3
- package/src/config/presets/models/qwen3_5.json +16 -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/model/qwen3-5-layer-probe.json +52 -0
- package/src/config/presets/runtime/model/qwen3-5-linear-attn-debug.json +90 -0
- package/src/config/presets/runtime/platform/metal-apple-q4k.json +1 -1
- package/src/config/runtime.js +6 -1
- package/src/config/schema/conversion.schema.d.ts +1 -0
- 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 +3 -3
- package/src/config/schema/kernel-path.schema.d.ts +5 -1
- package/src/config/schema/kernel-thresholds.schema.js +12 -4
- package/src/config/schema/manifest.schema.d.ts +3 -2
- package/src/config/schema/manifest.schema.js +17 -4
- package/src/config/schema/storage.schema.js +1 -1
- package/src/config/training-defaults.js +30 -22
- package/src/converter/conversion-plan.js +104 -11
- package/src/converter/core.d.ts +7 -0
- package/src/converter/core.js +16 -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 +50 -29
- package/src/converter/parsers/diffusion.js +0 -3
- package/src/converter/parsers/transformer.js +4 -0
- package/src/converter/quantization-info.js +40 -16
- package/src/converter/quantizer.js +19 -12
- package/src/converter/rope-config.js +8 -6
- package/src/converter/shard-packer.d.ts +1 -1
- package/src/converter/shard-packer.js +4 -1
- package/src/converter/tokenizer-utils.d.ts +1 -0
- package/src/converter/tokenizer-utils.js +4 -1
- package/src/debug/config.js +123 -11
- package/src/debug/reference/hf_qwen35_linear_attn_debug.py +268 -0
- 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 +83 -27
- 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.d.ts +4 -0
- package/src/formats/rdrr/parsing.js +53 -3
- 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 +73 -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 +15 -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/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/cross_entropy_loss.js +21 -15
- package/src/gpu/kernels/depthwise_conv2d.js +36 -26
- 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 +33 -23
- package/src/gpu/kernels/groupnorm.js +34 -23
- package/src/gpu/kernels/index.d.ts +8 -0
- package/src/gpu/kernels/index.js +6 -0
- 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-selection.js +47 -4
- package/src/gpu/kernels/matmul.d.ts +2 -0
- package/src/gpu/kernels/matmul.js +59 -40
- 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/relu.js +18 -10
- package/src/gpu/kernels/repeat_channels.js +25 -17
- package/src/gpu/kernels/residual.js +37 -27
- package/src/gpu/kernels/rmsnorm.js +66 -43
- package/src/gpu/kernels/rope.js +3 -0
- package/src/gpu/kernels/sample.js +27 -38
- package/src/gpu/kernels/sana_linear_attention.js +18 -10
- package/src/gpu/kernels/scale.js +18 -11
- package/src/gpu/kernels/shader-cache.js +4 -2
- package/src/gpu/kernels/silu.js +120 -72
- package/src/gpu/kernels/softmax.js +44 -25
- package/src/gpu/kernels/split_qg.d.ts +50 -0
- package/src/gpu/kernels/split_qg.js +46 -0
- package/src/gpu/kernels/split_qg.wgsl +58 -0
- package/src/gpu/kernels/split_qg_f16.wgsl +62 -0
- package/src/gpu/kernels/split_qkv.js +23 -13
- package/src/gpu/kernels/transpose.js +18 -10
- package/src/gpu/kernels/transpose.wgsl +5 -3
- package/src/gpu/kernels/upsample2d.js +21 -13
- package/src/gpu/kernels/utils.js +20 -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/gpu/weight-buffer.d.ts +1 -1
- package/src/gpu/weight-buffer.js +1 -1
- 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 +8 -0
- package/src/inference/browser-harness.js +149 -1996
- 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 +10 -2
- package/src/inference/pipelines/diffusion/pipeline.js +2 -1
- package/src/inference/pipelines/diffusion/sd3-transformer.js +10 -10
- package/src/inference/pipelines/diffusion/text-encoder-gpu.js +8 -2
- 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/output-projection.d.ts +12 -0
- package/src/inference/pipelines/text/attention/output-projection.js +8 -0
- package/src/inference/pipelines/text/attention/projections.d.ts +10 -1
- package/src/inference/pipelines/text/attention/projections.js +192 -112
- package/src/inference/pipelines/text/attention/record.js +77 -14
- package/src/inference/pipelines/text/attention/run.js +112 -14
- package/src/inference/pipelines/text/config.js +17 -4
- package/src/inference/pipelines/text/embed.js +2 -8
- package/src/inference/pipelines/text/execution-plan.js +46 -23
- 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 +62 -1013
- package/src/inference/pipelines/text/generator-runtime.js +5 -0
- package/src/inference/pipelines/text/generator-steps.d.ts +52 -0
- package/src/inference/pipelines/text/generator-steps.js +340 -221
- package/src/inference/pipelines/text/generator.js +56 -40
- package/src/inference/pipelines/text/init.d.ts +13 -0
- package/src/inference/pipelines/text/init.js +94 -25
- 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 +4 -9
- package/src/inference/pipelines/text/linear-attention.d.ts +15 -0
- package/src/inference/pipelines/text/linear-attention.js +113 -9
- package/src/inference/pipelines/text/logits/gpu.js +12 -7
- package/src/inference/pipelines/text/logits/index.d.ts +6 -1
- package/src/inference/pipelines/text/logits/index.js +13 -12
- 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 +282 -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/sampling.js +52 -6
- package/src/inference/pipelines/text/weights.js +17 -7
- package/src/inference/pipelines/text.js +13 -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 +17 -7
- 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 +20 -0
- 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 +10 -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 +84 -14
- package/src/loader/shard-resolver.js +25 -3
- package/src/loader/tensors/tensor-loader.js +214 -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/dtype.rules.json +5 -0
- package/src/rules/inference/kernel-path.rules.json +24 -8
- package/src/rules/kernels/split-qg.rules.json +6 -0
- package/src/rules/rule-registry.js +27 -1
- package/src/storage/backends/opfs-store.js +68 -24
- package/src/storage/downloader.js +365 -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 +55 -6
- 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.js +16 -602
- package/src/tooling/command-envelope.js +4 -1
- package/src/tooling/command-runner-shared.js +52 -18
- package/src/tooling/conversion-config-materializer.js +3 -5
- package/src/tooling/lean-execution-contract.js +150 -3
- package/src/tooling/node-browser-command-runner.js +161 -271
- package/src/tooling/node-command-runner.js +29 -3
- package/src/tooling/node-converter.js +30 -1
- package/src/tooling/node-source-runtime.d.ts +1 -1
- package/src/tooling/node-source-runtime.js +120 -3
- package/src/tooling/node-webgpu.js +24 -21
- 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 +2 -1
- package/src/training/checkpoint-watch.js +39 -6
- package/src/training/checkpoint.js +40 -11
- package/src/training/clip.js +2 -1
- package/src/training/datasets/token-batch.js +20 -8
- package/src/training/distillation/checkpoint-watch.js +1 -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/lora-pipeline.js +4 -7
- 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-command.js +2 -0
- package/src/training/optimizer.js +19 -7
- package/src/training/runner.js +2 -1
- package/src/training/suite.js +18 -978
- 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.js +70 -79
- package/src/types/model.d.ts +5 -0
- package/src/version.js +1 -1
- package/tools/convert-safetensors-node.js +22 -16
- package/tools/doppler-cli.js +50 -26
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DISTILL_ACTION_SET,
|
|
3
|
+
LORA_ACTION_SET,
|
|
4
|
+
TRAINING_COMMAND_SCHEMA_VERSION,
|
|
5
|
+
VERIFY_SUITES,
|
|
6
|
+
} from './command-api-constants.js';
|
|
7
|
+
import {
|
|
8
|
+
asOptionalAction,
|
|
9
|
+
asOptionalBoolean,
|
|
10
|
+
asOptionalForceResumeReason,
|
|
11
|
+
asOptionalObject,
|
|
12
|
+
asOptionalPositiveInteger,
|
|
13
|
+
asOptionalString,
|
|
14
|
+
asOptionalStringArray,
|
|
15
|
+
asOptionalTrainingStage,
|
|
16
|
+
assertForbiddenConfigChainField,
|
|
17
|
+
assertForbiddenObjectField,
|
|
18
|
+
assertForbiddenStringField,
|
|
19
|
+
assertModelId,
|
|
20
|
+
createCommandRequestBase,
|
|
21
|
+
resolveCommandRuntimeContract,
|
|
22
|
+
resolveSuiteForCommand,
|
|
23
|
+
} from './command-api-helpers.js';
|
|
24
|
+
|
|
25
|
+
function normalizeConvertExecution(value) {
|
|
26
|
+
const execution = asOptionalObject(value, 'convertPayload.execution');
|
|
27
|
+
if (!execution) return null;
|
|
28
|
+
|
|
29
|
+
const workerCountPolicy = asOptionalString(
|
|
30
|
+
execution.workerCountPolicy,
|
|
31
|
+
'convertPayload.execution.workerCountPolicy'
|
|
32
|
+
);
|
|
33
|
+
if (workerCountPolicy && workerCountPolicy !== 'cap' && workerCountPolicy !== 'error') {
|
|
34
|
+
throw new Error(
|
|
35
|
+
'tooling command: convertPayload.execution.workerCountPolicy must be "cap" or "error" when provided.'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...execution,
|
|
41
|
+
workers: asOptionalPositiveInteger(
|
|
42
|
+
execution.workers,
|
|
43
|
+
'convertPayload.execution.workers'
|
|
44
|
+
),
|
|
45
|
+
workerCountPolicy,
|
|
46
|
+
maxInFlightJobs: asOptionalPositiveInteger(
|
|
47
|
+
execution.maxInFlightJobs,
|
|
48
|
+
'convertPayload.execution.maxInFlightJobs'
|
|
49
|
+
),
|
|
50
|
+
rowChunkRows: asOptionalPositiveInteger(
|
|
51
|
+
execution.rowChunkRows,
|
|
52
|
+
'convertPayload.execution.rowChunkRows'
|
|
53
|
+
),
|
|
54
|
+
rowChunkMinTensorBytes: asOptionalPositiveInteger(
|
|
55
|
+
execution.rowChunkMinTensorBytes,
|
|
56
|
+
'convertPayload.execution.rowChunkMinTensorBytes'
|
|
57
|
+
),
|
|
58
|
+
useGpuCast: asOptionalBoolean(
|
|
59
|
+
execution.useGpuCast,
|
|
60
|
+
'convertPayload.execution.useGpuCast'
|
|
61
|
+
),
|
|
62
|
+
gpuCastMinTensorBytes: asOptionalPositiveInteger(
|
|
63
|
+
execution.gpuCastMinTensorBytes,
|
|
64
|
+
'convertPayload.execution.gpuCastMinTensorBytes'
|
|
65
|
+
),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function normalizeConvertPayload(value) {
|
|
70
|
+
const payload = asOptionalObject(value, 'convertPayload');
|
|
71
|
+
if (!payload) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
'tooling command: convert requires convertPayload.converterConfig.'
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const converterConfig = asOptionalObject(
|
|
77
|
+
payload.converterConfig,
|
|
78
|
+
'convertPayload.converterConfig'
|
|
79
|
+
);
|
|
80
|
+
if (!converterConfig) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
'tooling command: convert requires convertPayload.converterConfig.'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
...payload,
|
|
87
|
+
converterConfig,
|
|
88
|
+
execution: normalizeConvertExecution(payload.execution),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function normalizeConvert(raw) {
|
|
93
|
+
const inputDir = asOptionalString(raw.inputDir, 'inputDir');
|
|
94
|
+
const outputDir = asOptionalString(raw.outputDir, 'outputDir');
|
|
95
|
+
const modelId = asOptionalString(raw.modelId, 'modelId');
|
|
96
|
+
const payload = normalizeConvertPayload(raw.convertPayload);
|
|
97
|
+
|
|
98
|
+
if (!inputDir) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
'tooling command: convert requires inputDir.'
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (modelId) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
'tooling command: convert does not accept modelId. Set convertPayload.converterConfig.output.modelBaseId.'
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
assertForbiddenStringField(raw, 'runtimePreset', 'convert');
|
|
109
|
+
assertForbiddenStringField(raw, 'runtimeConfigUrl', 'convert');
|
|
110
|
+
assertForbiddenObjectField(raw, 'runtimeConfig', 'convert');
|
|
111
|
+
assertForbiddenConfigChainField(raw, 'convert');
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
...createCommandRequestBase(raw, 'convert'),
|
|
115
|
+
inputDir,
|
|
116
|
+
outputDir,
|
|
117
|
+
convertPayload: payload,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function normalizeTrainingOperatorCommand(raw, command) {
|
|
122
|
+
assertForbiddenConfigChainField(raw, command);
|
|
123
|
+
const allowedActions = command === 'distill' ? DISTILL_ACTION_SET : LORA_ACTION_SET;
|
|
124
|
+
const action = asOptionalAction(raw.action, 'action', allowedActions);
|
|
125
|
+
if (!action) {
|
|
126
|
+
throw new Error(`tooling command: ${command} requires action.`);
|
|
127
|
+
}
|
|
128
|
+
const workloadPath = asOptionalString(raw.workloadPath, 'workloadPath');
|
|
129
|
+
const runRoot = asOptionalString(raw.runRoot, 'runRoot');
|
|
130
|
+
const checkpointPath = asOptionalString(raw.checkpointPath, 'checkpointPath');
|
|
131
|
+
const checkpointId = asOptionalString(raw.checkpointId, 'checkpointId');
|
|
132
|
+
const checkpointStep = asOptionalPositiveInteger(raw.checkpointStep, 'checkpointStep');
|
|
133
|
+
const stageId = asOptionalString(raw.stageId, 'stageId');
|
|
134
|
+
const stageArtifact = asOptionalString(raw.stageArtifact, 'stageArtifact');
|
|
135
|
+
const subsetManifest = asOptionalString(raw.subsetManifest, 'subsetManifest');
|
|
136
|
+
const evalDatasetId = asOptionalString(raw.evalDatasetId, 'evalDatasetId');
|
|
137
|
+
const pollIntervalMs = asOptionalPositiveInteger(raw.pollIntervalMs, 'pollIntervalMs');
|
|
138
|
+
const stopWhenIdle = asOptionalBoolean(raw.stopWhenIdle, 'stopWhenIdle');
|
|
139
|
+
if (!workloadPath && !runRoot) {
|
|
140
|
+
throw new Error(`tooling command: ${command} requires workloadPath or runRoot.`);
|
|
141
|
+
}
|
|
142
|
+
if ((action === 'eval' || action === 'export') && !checkpointPath && !runRoot) {
|
|
143
|
+
throw new Error(`tooling command: ${command} ${action} requires checkpointPath or runRoot.`);
|
|
144
|
+
}
|
|
145
|
+
if (action === 'watch' && !runRoot) {
|
|
146
|
+
throw new Error(`tooling command: ${command} watch requires runRoot.`);
|
|
147
|
+
}
|
|
148
|
+
if ((action === 'compare' || action === 'quality-gate') && !runRoot) {
|
|
149
|
+
throw new Error(`tooling command: ${command} ${action} requires runRoot.`);
|
|
150
|
+
}
|
|
151
|
+
if (command === 'distill' && action === 'stage-b' && !stageArtifact && !runRoot) {
|
|
152
|
+
throw new Error('tooling command: distill stage-b requires stageArtifact or runRoot.');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
...createCommandRequestBase(raw, command),
|
|
157
|
+
action,
|
|
158
|
+
workloadType: 'training',
|
|
159
|
+
modelUrl: null,
|
|
160
|
+
workloadPath,
|
|
161
|
+
runRoot,
|
|
162
|
+
checkpointPath,
|
|
163
|
+
checkpointId,
|
|
164
|
+
checkpointStep,
|
|
165
|
+
stageId,
|
|
166
|
+
stageArtifact,
|
|
167
|
+
subsetManifest,
|
|
168
|
+
evalDatasetId,
|
|
169
|
+
pollIntervalMs,
|
|
170
|
+
stopWhenIdle,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function normalizeSuiteCommand(raw, command) {
|
|
175
|
+
assertForbiddenConfigChainField(raw, command);
|
|
176
|
+
const runtimeContract = resolveCommandRuntimeContract(command);
|
|
177
|
+
const suite = resolveSuiteForCommand(raw, command, runtimeContract);
|
|
178
|
+
if (!runtimeContract.suite && !VERIFY_SUITES.includes(suite)) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`tooling command: "${command}" suite must be one of ${VERIFY_SUITES.join(', ')}.`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const modelUrl = asOptionalString(raw.modelUrl, 'modelUrl');
|
|
185
|
+
const trainingTests = asOptionalStringArray(raw.trainingTests, 'trainingTests');
|
|
186
|
+
const trainingStage = asOptionalTrainingStage(raw.trainingStage, 'trainingStage');
|
|
187
|
+
const trainingConfig = asOptionalObject(raw.trainingConfig, 'trainingConfig');
|
|
188
|
+
const stage1Artifact = asOptionalString(raw.stage1Artifact, 'stage1Artifact');
|
|
189
|
+
const stage1ArtifactHash = asOptionalString(raw.stage1ArtifactHash, 'stage1ArtifactHash');
|
|
190
|
+
const ulArtifactDir = asOptionalString(raw.ulArtifactDir, 'ulArtifactDir');
|
|
191
|
+
const stageAArtifact = asOptionalString(raw.stageAArtifact, 'stageAArtifact');
|
|
192
|
+
const stageAArtifactHash = asOptionalString(raw.stageAArtifactHash, 'stageAArtifactHash');
|
|
193
|
+
const distillArtifactDir = asOptionalString(raw.distillArtifactDir, 'distillArtifactDir');
|
|
194
|
+
const teacherModelId = asOptionalString(raw.teacherModelId, 'teacherModelId');
|
|
195
|
+
const studentModelId = asOptionalString(raw.studentModelId, 'studentModelId');
|
|
196
|
+
const distillDatasetId = asOptionalString(raw.distillDatasetId, 'distillDatasetId');
|
|
197
|
+
const distillDatasetPath = asOptionalString(raw.distillDatasetPath, 'distillDatasetPath');
|
|
198
|
+
const distillLanguagePair = asOptionalString(raw.distillLanguagePair, 'distillLanguagePair');
|
|
199
|
+
const distillSourceLangs = asOptionalStringArray(raw.distillSourceLangs, 'distillSourceLangs');
|
|
200
|
+
const distillTargetLangs = asOptionalStringArray(raw.distillTargetLangs, 'distillTargetLangs');
|
|
201
|
+
const distillPairAllowlist = asOptionalStringArray(raw.distillPairAllowlist, 'distillPairAllowlist');
|
|
202
|
+
const strictPairContract = asOptionalBoolean(raw.strictPairContract, 'strictPairContract');
|
|
203
|
+
const distillShardIndex = asOptionalPositiveInteger(raw.distillShardIndex, 'distillShardIndex');
|
|
204
|
+
const distillShardCount = asOptionalPositiveInteger(raw.distillShardCount, 'distillShardCount');
|
|
205
|
+
const resumeFrom = asOptionalString(raw.resumeFrom, 'resumeFrom');
|
|
206
|
+
const forceResume = asOptionalBoolean(raw.forceResume, 'forceResume');
|
|
207
|
+
const forceResumeReason = asOptionalForceResumeReason(raw.forceResumeReason, 'forceResumeReason');
|
|
208
|
+
const forceResumeSource = asOptionalString(raw.forceResumeSource, 'forceResumeSource');
|
|
209
|
+
const checkpointOperator = asOptionalString(raw.checkpointOperator, 'checkpointOperator');
|
|
210
|
+
const trainingSchemaVersionInput = asOptionalPositiveInteger(
|
|
211
|
+
raw.trainingSchemaVersion,
|
|
212
|
+
'trainingSchemaVersion'
|
|
213
|
+
);
|
|
214
|
+
const trainingBenchSteps = asOptionalPositiveInteger(raw.trainingBenchSteps, 'trainingBenchSteps');
|
|
215
|
+
const checkpointEvery = asOptionalPositiveInteger(raw.checkpointEvery, 'checkpointEvery');
|
|
216
|
+
const workloadType = asOptionalString(raw.workloadType, 'workloadType');
|
|
217
|
+
const isTrainingBenchWorkload = command === 'bench' && suite === 'bench' && workloadType === 'training';
|
|
218
|
+
const allowsTrainingFields = suite === 'training' || isTrainingBenchWorkload;
|
|
219
|
+
if (!allowsTrainingFields && (
|
|
220
|
+
trainingTests
|
|
221
|
+
|| trainingStage
|
|
222
|
+
|| trainingConfig
|
|
223
|
+
|| stage1Artifact
|
|
224
|
+
|| stage1ArtifactHash
|
|
225
|
+
|| ulArtifactDir
|
|
226
|
+
|| stageAArtifact
|
|
227
|
+
|| stageAArtifactHash
|
|
228
|
+
|| distillArtifactDir
|
|
229
|
+
|| teacherModelId
|
|
230
|
+
|| studentModelId
|
|
231
|
+
|| distillDatasetId
|
|
232
|
+
|| distillDatasetPath
|
|
233
|
+
|| distillLanguagePair
|
|
234
|
+
|| distillSourceLangs
|
|
235
|
+
|| distillTargetLangs
|
|
236
|
+
|| distillPairAllowlist
|
|
237
|
+
|| strictPairContract !== null
|
|
238
|
+
|| distillShardIndex
|
|
239
|
+
|| distillShardCount
|
|
240
|
+
|| resumeFrom
|
|
241
|
+
|| forceResume !== null
|
|
242
|
+
|| forceResumeReason
|
|
243
|
+
|| forceResumeSource
|
|
244
|
+
|| checkpointOperator
|
|
245
|
+
|| trainingSchemaVersionInput
|
|
246
|
+
|| trainingBenchSteps
|
|
247
|
+
|| checkpointEvery
|
|
248
|
+
)) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
'tooling command: training-only fields require suite="training" or bench workloadType="training".'
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (forceResumeReason && forceResume !== true) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
'tooling command: forceResumeReason requires forceResume=true.'
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
if (forceResumeSource && forceResume !== true) {
|
|
259
|
+
throw new Error(
|
|
260
|
+
'tooling command: forceResumeSource requires forceResume=true.'
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
if (checkpointOperator && forceResume !== true) {
|
|
264
|
+
throw new Error(
|
|
265
|
+
'tooling command: checkpointOperator requires forceResume=true.'
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
const trainingSchemaVersion = allowsTrainingFields
|
|
269
|
+
? (trainingSchemaVersionInput ?? TRAINING_COMMAND_SCHEMA_VERSION)
|
|
270
|
+
: null;
|
|
271
|
+
if (trainingSchemaVersionInput != null && trainingSchemaVersionInput !== TRAINING_COMMAND_SCHEMA_VERSION) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`tooling command: trainingSchemaVersion must be ${TRAINING_COMMAND_SCHEMA_VERSION}.`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
if (
|
|
277
|
+
distillShardIndex != null
|
|
278
|
+
&& distillShardCount != null
|
|
279
|
+
&& distillShardIndex > distillShardCount
|
|
280
|
+
) {
|
|
281
|
+
throw new Error('tooling command: distillShardIndex must be <= distillShardCount.');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const requiresModel = suite !== 'kernels' && !isTrainingBenchWorkload;
|
|
285
|
+
const hasTrainingSource = allowsTrainingFields && (
|
|
286
|
+
!!modelUrl
|
|
287
|
+
|| !!trainingStage
|
|
288
|
+
|| !!stage1Artifact
|
|
289
|
+
|| !!stageAArtifact
|
|
290
|
+
|| !!trainingConfig?.ul?.stage
|
|
291
|
+
|| !!trainingConfig?.distill?.stage
|
|
292
|
+
|| !!trainingConfig?.dataset
|
|
293
|
+
|| !!trainingConfig?.distill?.datasetId
|
|
294
|
+
|| !!trainingConfig?.distill?.datasetPath
|
|
295
|
+
|| !!teacherModelId
|
|
296
|
+
|| !!studentModelId
|
|
297
|
+
|| !!distillDatasetPath
|
|
298
|
+
);
|
|
299
|
+
const modelId = (requiresModel && !hasTrainingSource)
|
|
300
|
+
? assertModelId(raw.modelId, command, suite)
|
|
301
|
+
: asOptionalString(raw.modelId, 'modelId');
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
...createCommandRequestBase(raw, command),
|
|
305
|
+
suite,
|
|
306
|
+
intent: runtimeContract.intent,
|
|
307
|
+
modelId,
|
|
308
|
+
trainingTests,
|
|
309
|
+
trainingStage,
|
|
310
|
+
trainingConfig,
|
|
311
|
+
stage1Artifact,
|
|
312
|
+
stage1ArtifactHash,
|
|
313
|
+
ulArtifactDir,
|
|
314
|
+
stageAArtifact,
|
|
315
|
+
stageAArtifactHash,
|
|
316
|
+
distillArtifactDir,
|
|
317
|
+
teacherModelId,
|
|
318
|
+
studentModelId,
|
|
319
|
+
distillDatasetId,
|
|
320
|
+
distillDatasetPath,
|
|
321
|
+
distillLanguagePair,
|
|
322
|
+
distillSourceLangs,
|
|
323
|
+
distillTargetLangs,
|
|
324
|
+
distillPairAllowlist,
|
|
325
|
+
strictPairContract: allowsTrainingFields ? strictPairContract : null,
|
|
326
|
+
distillShardIndex,
|
|
327
|
+
distillShardCount,
|
|
328
|
+
resumeFrom,
|
|
329
|
+
forceResume: allowsTrainingFields
|
|
330
|
+
? (forceResume == null ? null : forceResume === true)
|
|
331
|
+
: null,
|
|
332
|
+
forceResumeReason: allowsTrainingFields ? forceResumeReason : null,
|
|
333
|
+
forceResumeSource: allowsTrainingFields ? forceResumeSource : null,
|
|
334
|
+
checkpointOperator: allowsTrainingFields ? checkpointOperator : null,
|
|
335
|
+
trainingSchemaVersion,
|
|
336
|
+
trainingBenchSteps,
|
|
337
|
+
checkpointEvery: allowsTrainingFields ? checkpointEvery : null,
|
|
338
|
+
workloadType,
|
|
339
|
+
modelUrl,
|
|
340
|
+
captureOutput: asOptionalBoolean(raw.captureOutput, 'captureOutput') ?? false,
|
|
341
|
+
keepPipeline: asOptionalBoolean(raw.keepPipeline, 'keepPipeline') ?? false,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function asOptionalString(value: unknown, label: string): string | null;
|
|
2
|
+
export declare function asOptionalBoolean(value: unknown, label: string): boolean | null;
|
|
3
|
+
export declare function asOptionalObject(value: unknown, label: string): Record<string, unknown> | null;
|
|
4
|
+
export declare function asOptionalStringArray(value: unknown, label: string): string[] | null;
|
|
5
|
+
export declare function asOptionalPositiveInteger(value: unknown, label: string): number | null;
|
|
6
|
+
export declare function asOptionalTrainingStage(value: unknown, label: string): string | null;
|
|
7
|
+
export declare function asOptionalForceResumeReason(value: unknown, label: string): string | null;
|
|
8
|
+
export declare function asOptionalAction(value: unknown, label: string, allowed: string[]): string | null;
|
|
9
|
+
export declare function assertCommand(value: unknown): string;
|
|
10
|
+
export declare function resolveCommandRuntimeContract(command: string): { suite: string | null; intent: string | null };
|
|
11
|
+
export declare function asOptionalCacheMode(value: unknown, label: string): 'cold' | 'warm' | null;
|
|
12
|
+
export declare function asOptionalLoadMode(value: unknown, label: string): 'opfs' | 'http' | 'memory' | null;
|
|
13
|
+
export declare function assertModelId(value: unknown, command: string, suite: string): string;
|
|
14
|
+
export declare function assertForbiddenStringField(raw: Record<string, unknown>, fieldName: string, command: string): void;
|
|
15
|
+
export declare function assertForbiddenObjectField(raw: Record<string, unknown>, fieldName: string, command: string): void;
|
|
16
|
+
export declare function assertForbiddenConfigChainField(raw: Record<string, unknown>, command: string): void;
|
|
17
|
+
export declare function resolveSuiteForCommand(
|
|
18
|
+
raw: Record<string, unknown>,
|
|
19
|
+
command: string,
|
|
20
|
+
runtimeContract: { suite: string | null; intent: string | null }
|
|
21
|
+
): string;
|
|
22
|
+
export declare function createCommandRequestBase(
|
|
23
|
+
raw: Record<string, unknown>,
|
|
24
|
+
command: string
|
|
25
|
+
): Record<string, unknown>;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { isPlainObject } from '../utils/plain-object.js';
|
|
2
|
+
import { selectRuleValue } from '../rules/rule-registry.js';
|
|
3
|
+
import {
|
|
4
|
+
TOOLING_COMMAND_SET,
|
|
5
|
+
TOOLING_INTENT_SET,
|
|
6
|
+
TOOLING_SUITE_SET,
|
|
7
|
+
TRAINING_STAGE_SET,
|
|
8
|
+
} from './command-api-constants.js';
|
|
9
|
+
|
|
10
|
+
export function asOptionalString(value, label) {
|
|
11
|
+
if (value === undefined || value === null || value === '') return null;
|
|
12
|
+
if (typeof value !== 'string') {
|
|
13
|
+
throw new Error(`tooling command: ${label} must be a string when provided.`);
|
|
14
|
+
}
|
|
15
|
+
const trimmed = value.trim();
|
|
16
|
+
return trimmed || null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function asOptionalBoolean(value, label) {
|
|
20
|
+
if (value === undefined || value === null) return null;
|
|
21
|
+
if (typeof value !== 'boolean') {
|
|
22
|
+
throw new Error(`tooling command: ${label} must be a boolean when provided.`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function asOptionalObject(value, label) {
|
|
28
|
+
if (value === undefined || value === null) return null;
|
|
29
|
+
if (!isPlainObject(value)) {
|
|
30
|
+
throw new Error(`tooling command: ${label} must be an object when provided.`);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function asOptionalStringArray(value, label) {
|
|
36
|
+
if (value === undefined || value === null) return null;
|
|
37
|
+
if (!Array.isArray(value)) {
|
|
38
|
+
throw new Error(`tooling command: ${label} must be an array of strings when provided.`);
|
|
39
|
+
}
|
|
40
|
+
const normalized = value.map((entry, index) => {
|
|
41
|
+
if (typeof entry !== 'string') {
|
|
42
|
+
throw new Error(`tooling command: ${label}[${index}] must be a string.`);
|
|
43
|
+
}
|
|
44
|
+
const trimmed = entry.trim();
|
|
45
|
+
if (!trimmed) {
|
|
46
|
+
throw new Error(`tooling command: ${label}[${index}] must not be empty.`);
|
|
47
|
+
}
|
|
48
|
+
return trimmed;
|
|
49
|
+
});
|
|
50
|
+
return normalized.length > 0 ? normalized : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function asOptionalPositiveInteger(value, label) {
|
|
54
|
+
if (value === undefined || value === null || value === '') return null;
|
|
55
|
+
const parsed = Number(value);
|
|
56
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
57
|
+
throw new Error(`tooling command: ${label} must be a positive integer when provided.`);
|
|
58
|
+
}
|
|
59
|
+
return parsed;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function asOptionalTrainingStage(value, label) {
|
|
63
|
+
const stage = asOptionalString(value, label);
|
|
64
|
+
if (!stage) return null;
|
|
65
|
+
if (!TRAINING_STAGE_SET.includes(stage)) {
|
|
66
|
+
throw new Error(`tooling command: ${label} must be one of ${TRAINING_STAGE_SET.join(', ')}.`);
|
|
67
|
+
}
|
|
68
|
+
return stage;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function asOptionalForceResumeReason(value, label) {
|
|
72
|
+
const reason = asOptionalString(value, label);
|
|
73
|
+
if (!reason) return null;
|
|
74
|
+
return reason;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function asOptionalAction(value, label, allowed) {
|
|
78
|
+
const action = asOptionalString(value, label);
|
|
79
|
+
if (!action) return null;
|
|
80
|
+
if (!allowed.includes(action)) {
|
|
81
|
+
throw new Error(`tooling command: ${label} must be one of ${allowed.join(', ')}.`);
|
|
82
|
+
}
|
|
83
|
+
return action;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function assertCommand(value) {
|
|
87
|
+
const command = asOptionalString(value, 'command');
|
|
88
|
+
if (!command) {
|
|
89
|
+
throw new Error('tooling command: command is required.');
|
|
90
|
+
}
|
|
91
|
+
if (!TOOLING_COMMAND_SET.includes(command)) {
|
|
92
|
+
throw new Error(`tooling command: unsupported command "${command}".`);
|
|
93
|
+
}
|
|
94
|
+
return command;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function resolveCommandRuntimeContract(command) {
|
|
98
|
+
const runtimeContract = selectRuleValue('tooling', 'commandRuntime', 'runtimeContract', { command });
|
|
99
|
+
if (!isPlainObject(runtimeContract)) {
|
|
100
|
+
throw new Error(`tooling command: missing runtime contract metadata for "${command}".`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const suite = runtimeContract.suite == null
|
|
104
|
+
? null
|
|
105
|
+
: asOptionalString(runtimeContract.suite, `runtime contract suite for "${command}"`);
|
|
106
|
+
if (suite && !TOOLING_SUITE_SET.includes(suite)) {
|
|
107
|
+
throw new Error(`tooling command: runtime contract suite "${suite}" is not supported.`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const intent = runtimeContract.intent == null
|
|
111
|
+
? null
|
|
112
|
+
: asOptionalString(runtimeContract.intent, `runtime contract intent for "${command}"`);
|
|
113
|
+
if (intent && !TOOLING_INTENT_SET.includes(intent)) {
|
|
114
|
+
throw new Error(`tooling command: runtime contract intent "${intent}" is not supported.`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
suite,
|
|
119
|
+
intent,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function asOptionalCacheMode(value, label) {
|
|
124
|
+
const cacheMode = asOptionalString(value, label);
|
|
125
|
+
if (!cacheMode) return null;
|
|
126
|
+
if (cacheMode !== 'cold' && cacheMode !== 'warm') {
|
|
127
|
+
throw new Error(`${label} must be "cold" or "warm"`);
|
|
128
|
+
}
|
|
129
|
+
return cacheMode;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function asOptionalLoadMode(value, label) {
|
|
133
|
+
const loadMode = asOptionalString(value, label);
|
|
134
|
+
if (!loadMode) return null;
|
|
135
|
+
if (loadMode !== 'opfs' && loadMode !== 'http' && loadMode !== 'memory') {
|
|
136
|
+
throw new Error(`${label} must be "opfs", "http", or "memory"`);
|
|
137
|
+
}
|
|
138
|
+
return loadMode;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function assertModelId(value, command, suite) {
|
|
142
|
+
const modelId = asOptionalString(value, 'modelId');
|
|
143
|
+
if (!modelId) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`tooling command: modelId is required for command "${command}" (suite "${suite}").`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return modelId;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function assertForbiddenStringField(raw, fieldName, command) {
|
|
152
|
+
const value = asOptionalString(raw[fieldName], fieldName);
|
|
153
|
+
if (value) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`tooling command: ${command} does not accept ${fieldName}.`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function assertForbiddenObjectField(raw, fieldName, command) {
|
|
161
|
+
const value = asOptionalObject(raw[fieldName], fieldName);
|
|
162
|
+
if (value) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`tooling command: ${command} does not accept ${fieldName}.`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function assertForbiddenConfigChainField(raw, command) {
|
|
170
|
+
const value = asOptionalStringArray(raw.configChain, 'configChain');
|
|
171
|
+
if (value) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`tooling command: ${command} does not accept configChain. ` +
|
|
174
|
+
'configChain is only supported by harness/browser-manifest runtime composition.'
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function resolveSuiteForCommand(raw, command, runtimeContract) {
|
|
180
|
+
const inputSuite = asOptionalString(raw.suite, 'suite');
|
|
181
|
+
if (runtimeContract.suite) {
|
|
182
|
+
if (inputSuite && inputSuite !== runtimeContract.suite) {
|
|
183
|
+
throw new Error(
|
|
184
|
+
`tooling command: "${command}" requires suite "${runtimeContract.suite}" and does not accept "${inputSuite}".`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
return runtimeContract.suite;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const suite = inputSuite;
|
|
191
|
+
if (!suite) {
|
|
192
|
+
throw new Error(`tooling command: suite is required for "${command}".`);
|
|
193
|
+
}
|
|
194
|
+
if (!TOOLING_SUITE_SET.includes(suite)) {
|
|
195
|
+
throw new Error(`tooling command: unsupported suite "${suite}".`);
|
|
196
|
+
}
|
|
197
|
+
return suite;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function createCommandRequestBase(raw, command) {
|
|
201
|
+
return {
|
|
202
|
+
command,
|
|
203
|
+
suite: null,
|
|
204
|
+
intent: null,
|
|
205
|
+
action: null,
|
|
206
|
+
modelId: null,
|
|
207
|
+
trainingTests: null,
|
|
208
|
+
trainingStage: null,
|
|
209
|
+
trainingConfig: null,
|
|
210
|
+
stage1Artifact: null,
|
|
211
|
+
stage1ArtifactHash: null,
|
|
212
|
+
ulArtifactDir: null,
|
|
213
|
+
stageAArtifact: null,
|
|
214
|
+
stageAArtifactHash: null,
|
|
215
|
+
distillArtifactDir: null,
|
|
216
|
+
teacherModelId: null,
|
|
217
|
+
studentModelId: null,
|
|
218
|
+
distillDatasetId: null,
|
|
219
|
+
distillDatasetPath: null,
|
|
220
|
+
distillLanguagePair: null,
|
|
221
|
+
distillSourceLangs: null,
|
|
222
|
+
distillTargetLangs: null,
|
|
223
|
+
distillPairAllowlist: null,
|
|
224
|
+
strictPairContract: null,
|
|
225
|
+
distillShardIndex: null,
|
|
226
|
+
distillShardCount: null,
|
|
227
|
+
resumeFrom: null,
|
|
228
|
+
forceResume: null,
|
|
229
|
+
forceResumeReason: null,
|
|
230
|
+
forceResumeSource: null,
|
|
231
|
+
checkpointOperator: null,
|
|
232
|
+
trainingSchemaVersion: null,
|
|
233
|
+
trainingBenchSteps: null,
|
|
234
|
+
checkpointEvery: null,
|
|
235
|
+
workloadType: asOptionalString(raw.workloadType, 'workloadType'),
|
|
236
|
+
modelUrl: asOptionalString(raw.modelUrl, 'modelUrl'),
|
|
237
|
+
cacheMode: asOptionalCacheMode(raw.cacheMode, 'cacheMode'),
|
|
238
|
+
loadMode: asOptionalLoadMode(raw.loadMode, 'loadMode'),
|
|
239
|
+
runtimePreset: asOptionalString(raw.runtimePreset, 'runtimePreset'),
|
|
240
|
+
runtimeConfigUrl: asOptionalString(raw.runtimeConfigUrl, 'runtimeConfigUrl'),
|
|
241
|
+
runtimeConfig: asOptionalObject(raw.runtimeConfig, 'runtimeConfig'),
|
|
242
|
+
inputDir: null,
|
|
243
|
+
outputDir: null,
|
|
244
|
+
convertPayload: null,
|
|
245
|
+
workloadPath: null,
|
|
246
|
+
runRoot: null,
|
|
247
|
+
checkpointPath: null,
|
|
248
|
+
checkpointId: null,
|
|
249
|
+
checkpointStep: null,
|
|
250
|
+
stageId: null,
|
|
251
|
+
stageArtifact: null,
|
|
252
|
+
subsetManifest: null,
|
|
253
|
+
evalDatasetId: null,
|
|
254
|
+
pollIntervalMs: null,
|
|
255
|
+
stopWhenIdle: null,
|
|
256
|
+
captureOutput: false,
|
|
257
|
+
keepPipeline: false,
|
|
258
|
+
report: asOptionalObject(raw.report, 'report'),
|
|
259
|
+
timestamp: raw.timestamp ?? null,
|
|
260
|
+
searchParams: raw.searchParams ?? null,
|
|
261
|
+
};
|
|
262
|
+
}
|