doppler-gpu 0.4.15 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/package.json +25 -2
- package/src/cli/doppler-cli.js +253 -94
- package/src/cli/runtime-profiles.js +3 -7
- package/src/client/doppler-api.d.ts +28 -0
- package/src/client/doppler-api.js +2 -0
- package/src/client/inspection.d.ts +122 -0
- package/src/client/inspection.js +343 -0
- package/src/client/runtime/index.d.ts +54 -0
- package/src/client/runtime/index.js +190 -18
- package/src/client/runtime/model-manager.d.ts +0 -4
- package/src/client/runtime/model-manager.js +0 -28
- package/src/client/runtime/model-session.d.ts +48 -1
- package/src/client/runtime/model-session.js +149 -30
- package/src/client/runtime/model-source.d.ts +10 -1
- package/src/client/runtime/scoped-session.d.ts +117 -0
- package/src/client/runtime/scoped-session.js +257 -0
- package/src/client/runtime/types.d.ts +0 -1
- package/src/client/runtime/types.js +0 -1
- package/src/config/evidence/boundary-evidence-policy.json +54 -0
- package/src/config/evidence/source-intake-policy.json +122 -0
- package/src/config/inspection/observation-policies.json +80 -0
- package/src/config/param-validator.js +21 -36
- package/src/config/runtime/compute/f16-activations.json +1 -0
- package/src/config/runtime/compute/f16-batched.json +1 -0
- package/src/config/runtime/default.json +1 -0
- package/src/config/runtime/diagnostics/debug-logits.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-alt.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k-batched.json +1 -0
- package/src/config/runtime/experiments/bench/gemma3-bench-q4k.json +1 -0
- package/src/config/runtime/experiments/bench/gemma4-bench-q4k.json +1 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-alt.json +1 -0
- package/src/config/runtime/experiments/bench/qwen3-bench-q4k-batched.json +1 -0
- package/src/config/runtime/experiments/debug/gemma3-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/debug/gemma3-debug-q4k.json +1 -3
- package/src/config/runtime/experiments/debug/gemma4-e2b-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/debug/qwen35-browser-diagnose-q4k.json +1 -1
- package/src/config/runtime/experiments/verify/gemma3-verify.json +1 -3
- package/src/config/runtime/experiments/verify/gemma4-e2b-verify.json +1 -3
- package/src/config/runtime/experiments/verify/lfm2-verify.json +1 -3
- package/src/config/runtime/experiments/verify/translategemma-verify.json +1 -3
- package/src/config/runtime/model/gemma2-debug.json +1 -0
- package/src/config/runtime/model/gemma2-pipeline-debug.json +1 -0
- package/src/config/runtime/model/gemma2-pipeline.json +1 -0
- package/src/config/runtime/model/gemma3-layer-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-layer-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-layer3-boundary-probe.json +1 -0
- package/src/config/runtime/model/qwen3-5-linear-attn-debug.json +1 -0
- package/src/config/runtime/optimization-candidates/registry.json +5 -0
- package/src/config/runtime/platform/metal-apple-q4k.json +1 -0
- package/src/config/runtime/profiles/default.json +1 -0
- package/src/config/runtime/profiles/diffusiongemma-26b-a4b-throughput.json +1 -0
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-overlapped-probe.json +1 -0
- package/src/config/runtime/profiles/gemma3-270m-q4k-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-b4.json +1 -3
- package/src/config/runtime/profiles/gemma4-12b-rdrr-safe-single.json +1 -3
- package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-baseline-probe.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-probe.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-fused-rmsnorm-test.json +1 -0
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-baseline-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-f16a-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-reference-export.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-int4ple-retain-q4k-probe.json +1 -5
- package/src/config/runtime/profiles/gemma4-e2b-low-memory.json +1 -0
- package/src/config/runtime/profiles/gemma4-e2b-prefill-profile.json +1 -3
- package/src/config/runtime/profiles/gemma4-e2b-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/low-memory.json +1 -0
- package/src/config/runtime/profiles/production.json +1 -3
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-attn128-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-maxbatch64-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-normed-ffn-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-overlap-ringtokens1-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-parity.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-sequential-candidate.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-0-8b-prefill-profile.json +1 -3
- package/src/config/runtime/profiles/qwen-3-5-0-8b-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-2b-f16-primary-throughput.json +1 -5
- package/src/config/runtime/profiles/qwen-3-5-2b-metal-parity.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-2b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-5-9b-metal-correctness.json +1 -0
- package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-stability.json +1 -3
- package/src/config/runtime/profiles/qwen-3-embedding-0-6b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-stability.json +1 -0
- package/src/config/runtime/profiles/qwen-3-reranker-0-6b-metal-throughput.json +1 -0
- package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +1 -5
- package/src/config/runtime/profiles/rerank-stability.json +1 -3
- package/src/config/runtime/profiles/rerank-throughput.json +1 -3
- package/src/config/runtime/profiles/simulation.json +1 -3
- package/src/config/runtime/profiles/throughput.json +1 -3
- package/src/config/runtime/profiles/trace-layers.json +1 -3
- package/src/config/runtime/profiles/translategemma-1b-nativekd2-q4k-rdna3-throughput-probe.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous-prod.json +1 -0
- package/src/config/runtime/profiles/turboquant-contiguous.json +1 -0
- package/src/config/runtime/profiles/turboquant.json +1 -0
- package/src/config/runtime/profiles/vector-stability.json +1 -3
- package/src/config/runtime/profiles/vector-throughput.json +1 -0
- package/src/config/runtime/profiles/verbose-trace.json +1 -3
- package/src/config/runtime/tiers/gemma4-128gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-16gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-24gb.json +1 -0
- package/src/config/runtime/tiers/gemma4-32gb.json +1 -0
- package/src/config/schema/benchmark.schema.d.ts +7 -0
- package/src/config/schema/benchmark.schema.js +5 -0
- package/src/config/schema/index.d.ts +8 -16
- package/src/config/schema/index.js +5 -8
- package/src/config/schema/kernel-thresholds.schema.d.ts +0 -12
- package/src/config/schema/kernel-thresholds.schema.js +0 -12
- package/src/config/schema/kernel-warmup.schema.d.ts +1 -3
- package/src/config/schema/kernel-warmup.schema.js +0 -1
- package/src/config/schema/runtime-profile.schema.d.ts +24 -0
- package/src/config/schema/runtime-profile.schema.js +92 -0
- package/src/config/schema/shared-runtime.schema.d.ts +1 -4
- package/src/config/schema/shared-runtime.schema.js +0 -2
- package/src/config/schema/tooling.schema.d.ts +8 -5
- package/src/config/schema/tooling.schema.js +3 -2
- package/src/debug/tensor.d.ts +2 -0
- package/src/debug/tensor.js +21 -2
- package/src/gpu/command-recorder.d.ts +5 -0
- package/src/gpu/command-recorder.js +17 -0
- package/src/gpu/kernel-runtime.js +2 -10
- package/src/gpu/kernels/index.d.ts +0 -2
- package/src/gpu/kernels/index.js +0 -2
- package/src/gpu/kernels/kernel-prewarm.d.ts +3 -0
- package/src/gpu/kernels/kernel-prewarm.js +60 -0
- package/src/gpu/kernels/utils.d.ts +2 -4
- package/src/gpu/kernels/utils.js +2 -4
- package/src/index.d.ts +13 -1
- package/src/index.js +7 -1
- package/src/inference/browser-harness-model-helpers.js +4 -0
- package/src/inference/browser-harness-runtime-helpers.js +25 -10
- package/src/inference/browser-harness-text-helpers.js +4 -1
- package/src/inference/browser-harness.d.ts +4 -0
- package/src/inference/browser-harness.js +91 -4
- package/src/inference/observation-context.d.ts +22 -0
- package/src/inference/observation-context.js +41 -0
- package/src/inference/pipelines/text/attention/attn-config.js +1 -1
- package/src/inference/pipelines/text/attention/executor-immediate.js +42 -0
- package/src/inference/pipelines/text/attention/executor-recorded.js +29 -0
- package/src/inference/pipelines/text/attention/index.js +7 -0
- package/src/inference/pipelines/text/attention/interpreter.js +1334 -0
- package/src/inference/pipelines/text/attention/plan.d.ts +36 -0
- package/src/inference/pipelines/text/attention/plan.js +328 -0
- package/src/inference/pipelines/text/attention/receipt.js +60 -0
- package/src/inference/pipelines/text/attention/record.js +8 -1278
- package/src/inference/pipelines/text/attention/run.js +8 -1386
- package/src/inference/pipelines/text/generator-decode-policy.js +4 -1
- package/src/inference/pipelines/text/generator-helpers.js +2 -0
- package/src/inference/pipelines/text/generator-steps.js +32 -15
- package/src/inference/pipelines/text/generator.js +10 -5
- package/src/inference/pipelines/text/init.d.ts +3 -0
- package/src/inference/pipelines/text/layer-plan-gpu.js +2 -0
- package/src/inference/pipelines/text/layer.js +2 -0
- package/src/inference/pipelines/text/model-load.d.ts +0 -1
- package/src/inference/pipelines/text/model-load.js +2 -11
- package/src/inference/pipelines/text/probes.js +10 -0
- package/src/inference/pipelines/text/resolved-runtime-session.d.ts +56 -0
- package/src/inference/pipelines/text/resolved-runtime-session.js +175 -0
- package/src/inference/pipelines/text/state.d.ts +6 -0
- package/src/inference/pipelines/text/state.js +3 -0
- package/src/inference/pipelines/text/types.d.ts +6 -0
- package/src/inference/pipelines/text.js +16 -1
- package/src/inference/refactor-receipt.d.ts +49 -0
- package/src/inference/refactor-receipt.js +188 -0
- package/src/inference/resource-scope.d.ts +33 -0
- package/src/inference/resource-scope.js +168 -0
- package/src/inference/test-harness.d.ts +3 -0
- package/src/inference/test-harness.js +1 -0
- package/src/storage/model-cache.d.ts +53 -0
- package/src/storage/model-cache.js +550 -0
- package/src/tooling/boundary-evidence.d.ts +51 -0
- package/src/tooling/boundary-evidence.js +408 -0
- package/src/tooling/browser-command-runner.js +4 -4
- package/src/tooling/command-context.d.ts +25 -0
- package/src/tooling/command-context.js +53 -0
- package/src/tooling/command-runner-shared.js +22 -5
- package/src/tooling/demo-receipts.d.ts +56 -0
- package/src/tooling/demo-receipts.js +113 -0
- package/src/tooling/diagnose-runner.js +2 -2
- package/src/tooling/execution-cost-ledger.d.ts +21 -0
- package/src/tooling/execution-cost-ledger.js +199 -0
- package/src/tooling/node-command-runner.js +2 -2
- package/src/tooling/opfs-cache.d.ts +11 -49
- package/src/tooling/opfs-cache.js +4 -510
- package/src/tooling/precision-replay-math.d.ts +42 -0
- package/src/tooling/precision-replay-math.js +174 -0
- package/src/tooling/program-bundle-parity.d.ts +3 -0
- package/src/tooling/program-bundle-parity.js +8 -0
- package/src/tooling/program-bundle.d.ts +1 -52
- package/src/tooling/program-bundle.js +0 -139
- package/src/tooling/registered-variant-calibration.d.ts +24 -0
- package/src/tooling/registered-variant-calibration.js +286 -0
- package/src/tooling/runtime-input-composition.js +105 -53
- package/src/tooling/runtime-intent.js +41 -0
- package/src/tooling/runtime-optimization-index.d.ts +6 -0
- package/src/tooling/runtime-optimization-index.js +72 -0
- package/src/tooling/runtime-optimization.d.ts +47 -6
- package/src/tooling/runtime-optimization.js +559 -40
- package/src/tooling/source-intake.d.ts +49 -0
- package/src/tooling/source-intake.js +414 -0
- package/src/tooling-exports/evidence.d.ts +34 -0
- package/src/tooling-exports/evidence.js +34 -0
- package/src/tooling-exports/runtime.d.ts +7 -0
- package/src/tooling-exports/runtime.js +7 -0
- package/src/tooling-exports.d.ts +11 -0
- package/src/tooling-exports.js +6 -3
- package/src/tooling-exports.shared.d.ts +32 -0
- package/src/tooling-exports.shared.js +31 -0
- package/src/version.js +1 -1
- package/src/config/schema/tuner.schema.d.ts +0 -39
- package/src/config/schema/tuner.schema.js +0 -13
- package/src/gpu/kernel-tuner/benchmarks.js +0 -902
- package/src/gpu/kernel-tuner/cache.js +0 -145
- package/src/gpu/kernel-tuner/index.js +0 -38
- package/src/gpu/kernel-tuner/tuner.js +0 -247
- package/src/gpu/kernel-tuner.js +0 -12
- package/src/gpu/kernels/kernel-tuning.d.ts +0 -42
- package/src/gpu/kernels/kernel-tuning.js +0 -158
- package/src/gpu/profiler.js +0 -382
- package/src/inference/pipelines/text/attention/output-gate-fusion.js +0 -37
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export const DEMO_CONTRACT_RECEIPT_SCHEMA = 'doppler.demo-contract-receipt/v1';
|
|
2
|
+
export const DEMO_HARDWARE_RECEIPT_SCHEMA = 'doppler.demo-hardware-receipt/v1';
|
|
3
|
+
|
|
4
|
+
const CONTRACT_EXECUTION_CLASSES = new Set([
|
|
5
|
+
'mocked-contract',
|
|
6
|
+
'software-webgpu',
|
|
7
|
+
'hardware-webgpu',
|
|
8
|
+
]);
|
|
9
|
+
const HARDWARE_EXECUTION_CLASSES = new Set([
|
|
10
|
+
'software-webgpu',
|
|
11
|
+
'hardware-webgpu',
|
|
12
|
+
]);
|
|
13
|
+
const DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
14
|
+
|
|
15
|
+
function assertObject(value, label) {
|
|
16
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
17
|
+
throw new Error(`${label} must be an object.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function assertDigest(value, label) {
|
|
22
|
+
if (!DIGEST_PATTERN.test(String(value ?? ''))) {
|
|
23
|
+
throw new Error(`${label} must be a sha256 digest.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function assertBooleanFields(value, fields, label) {
|
|
28
|
+
assertObject(value, label);
|
|
29
|
+
for (const field of fields) {
|
|
30
|
+
if (typeof value[field] !== 'boolean') {
|
|
31
|
+
throw new Error(`${label}.${field} must be boolean.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function assertGeneration(value, label) {
|
|
37
|
+
assertObject(value, label);
|
|
38
|
+
if (typeof value.outputText !== 'string') {
|
|
39
|
+
throw new Error(`${label}.outputText must be a string.`);
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(value.tokenIds) || value.tokenIds.some((id) => !Number.isInteger(id) || id < 0)) {
|
|
42
|
+
throw new Error(`${label}.tokenIds must contain non-negative integers.`);
|
|
43
|
+
}
|
|
44
|
+
assertDigest(value.transcriptHash, `${label}.transcriptHash`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function validateDemoContractReceipt(receipt) {
|
|
48
|
+
assertObject(receipt, 'demo contract receipt');
|
|
49
|
+
if (receipt.schema !== DEMO_CONTRACT_RECEIPT_SCHEMA) {
|
|
50
|
+
throw new Error(`Demo contract receipt schema must be ${DEMO_CONTRACT_RECEIPT_SCHEMA}.`);
|
|
51
|
+
}
|
|
52
|
+
if (receipt.status !== 'passed' && receipt.status !== 'failed') {
|
|
53
|
+
throw new Error('Demo contract receipt status must be passed or failed.');
|
|
54
|
+
}
|
|
55
|
+
if (!CONTRACT_EXECUTION_CLASSES.has(receipt.executionClass)) {
|
|
56
|
+
throw new Error('Demo contract receipt executionClass is invalid.');
|
|
57
|
+
}
|
|
58
|
+
if (receipt.entrypoint !== '/demo/index.html') {
|
|
59
|
+
throw new Error('Demo contract receipt must exercise /demo/index.html.');
|
|
60
|
+
}
|
|
61
|
+
assertBooleanFields(
|
|
62
|
+
receipt.journey,
|
|
63
|
+
['catalogRendered', 'modelSelected', 'modelLoaded', 'generationCompleted'],
|
|
64
|
+
'demo contract receipt journey'
|
|
65
|
+
);
|
|
66
|
+
assertDigest(receipt.shellManifestDigest, 'demo contract receipt shellManifestDigest');
|
|
67
|
+
if (!Array.isArray(receipt.fatalConsoleErrors)) {
|
|
68
|
+
throw new Error('Demo contract receipt fatalConsoleErrors must be an array.');
|
|
69
|
+
}
|
|
70
|
+
return receipt;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function validateDemoHardwareReceipt(receipt) {
|
|
74
|
+
assertObject(receipt, 'demo hardware receipt');
|
|
75
|
+
if (receipt.schema !== DEMO_HARDWARE_RECEIPT_SCHEMA) {
|
|
76
|
+
throw new Error(`Demo hardware receipt schema must be ${DEMO_HARDWARE_RECEIPT_SCHEMA}.`);
|
|
77
|
+
}
|
|
78
|
+
if (!['passed', 'failed'].includes(receipt.status)) {
|
|
79
|
+
throw new Error('Demo hardware receipt status is invalid.');
|
|
80
|
+
}
|
|
81
|
+
if (!HARDWARE_EXECUTION_CLASSES.has(receipt.executionClass)) {
|
|
82
|
+
throw new Error('Demo hardware receipt cannot claim a mocked execution class.');
|
|
83
|
+
}
|
|
84
|
+
assertObject(receipt.browser, 'demo hardware receipt browser');
|
|
85
|
+
assertObject(receipt.adapter, 'demo hardware receipt adapter');
|
|
86
|
+
assertObject(receipt.artifact, 'demo hardware receipt artifact');
|
|
87
|
+
assertDigest(receipt.artifact.manifestHash, 'demo hardware receipt artifact.manifestHash');
|
|
88
|
+
assertGeneration(receipt.online, 'demo hardware receipt online');
|
|
89
|
+
assertGeneration(receipt.offline, 'demo hardware receipt offline');
|
|
90
|
+
assertBooleanFields(
|
|
91
|
+
receipt.lifecycle,
|
|
92
|
+
[
|
|
93
|
+
'allPagesClosed',
|
|
94
|
+
'networkDisabled',
|
|
95
|
+
'persistentCacheRestored',
|
|
96
|
+
'upgradeChecked',
|
|
97
|
+
'partialCacheFailureChecked',
|
|
98
|
+
],
|
|
99
|
+
'demo hardware receipt lifecycle'
|
|
100
|
+
);
|
|
101
|
+
assertObject(receipt.fingerprint, 'demo hardware receipt fingerprint');
|
|
102
|
+
if (receipt.status === 'passed') {
|
|
103
|
+
for (const [field, value] of Object.entries(receipt.lifecycle)) {
|
|
104
|
+
if (value !== true) {
|
|
105
|
+
throw new Error(`Passed demo hardware receipt requires lifecycle.${field}=true.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (receipt.online.transcriptHash !== receipt.offline.transcriptHash) {
|
|
109
|
+
throw new Error('Passed demo hardware receipt requires identical online/offline transcripts.');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return receipt;
|
|
113
|
+
}
|
|
@@ -62,8 +62,8 @@ async function loadRuntimeModules() {
|
|
|
62
62
|
function createRuntimeBridge(modules) {
|
|
63
63
|
return {
|
|
64
64
|
loadRuntimeConfigFromRef,
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
loadRuntimeProfile: modules.harness.loadRuntimeProfile,
|
|
66
|
+
loadRuntimeConfigFromUrl: modules.harness.loadRuntimeConfigFromUrl,
|
|
67
67
|
getRuntimeConfig: modules.runtime.getRuntimeConfig,
|
|
68
68
|
setRuntimeConfig: modules.runtime.setRuntimeConfig,
|
|
69
69
|
resetRuntimeConfig: modules.runtime.resetRuntimeConfig,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const TOKEN_COST_LEDGER_SCHEMA: 'doppler.token-cost-ledger/v1';
|
|
2
|
+
|
|
3
|
+
export declare function isExecutionObservationRequested(
|
|
4
|
+
runtimeConfig: Record<string, unknown>
|
|
5
|
+
): boolean;
|
|
6
|
+
|
|
7
|
+
export declare function buildTokenCostLedger(options: {
|
|
8
|
+
metrics: Record<string, unknown>;
|
|
9
|
+
identity?: Record<string, unknown>;
|
|
10
|
+
device?: Record<string, unknown> | null;
|
|
11
|
+
browser?: Record<string, unknown> | null;
|
|
12
|
+
}): Record<string, unknown>;
|
|
13
|
+
|
|
14
|
+
export declare function classifyTokenCostLedger(
|
|
15
|
+
ledger: Record<string, unknown>,
|
|
16
|
+
policy: Record<string, unknown>
|
|
17
|
+
): {
|
|
18
|
+
dominantWall: string;
|
|
19
|
+
classifiedGpuMs: Array<{ wall: string; gpuMs: number }>;
|
|
20
|
+
prescribedExperiments: string[];
|
|
21
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { computeCanonicalSha256 } from '../utils/canonical-hash.js';
|
|
2
|
+
|
|
3
|
+
export const TOKEN_COST_LEDGER_SCHEMA = 'doppler.token-cost-ledger/v1';
|
|
4
|
+
|
|
5
|
+
export function isExecutionObservationRequested(runtimeConfig) {
|
|
6
|
+
return runtimeConfig?.shared?.benchmark?.run?.executionObserver?.enabled === true
|
|
7
|
+
|| runtimeConfig?.shared?.debug?.profiler?.enabled === true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function finiteOrNull(value) {
|
|
11
|
+
return Number.isFinite(value) ? Number(value) : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function aggregateOperations(profileSteps) {
|
|
15
|
+
const operations = new Map();
|
|
16
|
+
for (const step of profileSteps) {
|
|
17
|
+
const dispatches = step.recorderStats?.dispatches ?? [];
|
|
18
|
+
const dispatchesByLabel = new Map();
|
|
19
|
+
for (const dispatch of dispatches) {
|
|
20
|
+
const aggregate = dispatchesByLabel.get(dispatch.label) ?? {
|
|
21
|
+
count: 0,
|
|
22
|
+
knownWorkgroups: 0,
|
|
23
|
+
workgroups: 0,
|
|
24
|
+
};
|
|
25
|
+
aggregate.count += 1;
|
|
26
|
+
if (Array.isArray(dispatch.workgroups)) {
|
|
27
|
+
aggregate.knownWorkgroups += 1;
|
|
28
|
+
aggregate.workgroups += dispatch.workgroups.reduce(
|
|
29
|
+
(product, dimension) => product * dimension,
|
|
30
|
+
1
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
dispatchesByLabel.set(dispatch.label, aggregate);
|
|
34
|
+
}
|
|
35
|
+
for (const [label, dispatch] of dispatchesByLabel) {
|
|
36
|
+
const current = operations.get(label) ?? {
|
|
37
|
+
label,
|
|
38
|
+
gpuMs: 0,
|
|
39
|
+
hasGpuTiming: false,
|
|
40
|
+
dispatches: 0,
|
|
41
|
+
knownDispatchGeometry: 0,
|
|
42
|
+
workgroups: 0,
|
|
43
|
+
};
|
|
44
|
+
current.dispatches += dispatch.count;
|
|
45
|
+
current.knownDispatchGeometry += dispatch.knownWorkgroups;
|
|
46
|
+
current.workgroups += dispatch.workgroups;
|
|
47
|
+
operations.set(label, current);
|
|
48
|
+
}
|
|
49
|
+
for (const [label, gpuMs] of Object.entries(step.timings ?? {})) {
|
|
50
|
+
const current = operations.get(label) ?? {
|
|
51
|
+
label,
|
|
52
|
+
gpuMs: 0,
|
|
53
|
+
hasGpuTiming: false,
|
|
54
|
+
dispatches: 0,
|
|
55
|
+
knownDispatchGeometry: 0,
|
|
56
|
+
workgroups: 0,
|
|
57
|
+
};
|
|
58
|
+
current.gpuMs += Number(gpuMs);
|
|
59
|
+
current.hasGpuTiming = true;
|
|
60
|
+
const dispatch = dispatchesByLabel.get(label);
|
|
61
|
+
if (!dispatch) {
|
|
62
|
+
current.dispatches += step.recorderStats?.opLabelCounts?.[label] ?? 0;
|
|
63
|
+
}
|
|
64
|
+
operations.set(label, current);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Array.from(operations.values())
|
|
68
|
+
.map(({ hasGpuTiming, ...operation }) => ({
|
|
69
|
+
...operation,
|
|
70
|
+
gpuMs: hasGpuTiming ? operation.gpuMs : null,
|
|
71
|
+
}))
|
|
72
|
+
.sort((left, right) => (
|
|
73
|
+
(right.gpuMs ?? 0) - (left.gpuMs ?? 0) || left.label.localeCompare(right.label)
|
|
74
|
+
));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function buildPhase(name, wallMs, profileSteps) {
|
|
78
|
+
const steps = Array.isArray(profileSteps) ? profileSteps : [];
|
|
79
|
+
const operations = aggregateOperations(steps);
|
|
80
|
+
const attributedGpuMs = operations.reduce(
|
|
81
|
+
(sum, operation) => sum + (operation.gpuMs ?? 0),
|
|
82
|
+
0
|
|
83
|
+
);
|
|
84
|
+
const hasTimestampEvidence = operations.some((operation) => operation.gpuMs !== null);
|
|
85
|
+
const dispatches = operations.reduce((sum, operation) => sum + operation.dispatches, 0);
|
|
86
|
+
const knownDispatchGeometry = operations.reduce(
|
|
87
|
+
(sum, operation) => sum + operation.knownDispatchGeometry,
|
|
88
|
+
0
|
|
89
|
+
);
|
|
90
|
+
const phaseWallMs = finiteOrNull(wallMs);
|
|
91
|
+
return {
|
|
92
|
+
phase: name,
|
|
93
|
+
measurementSource: hasTimestampEvidence
|
|
94
|
+
? 'gpu-timestamp-query'
|
|
95
|
+
: 'cpu-wall-estimate',
|
|
96
|
+
wallMs: phaseWallMs,
|
|
97
|
+
attributedGpuMs: hasTimestampEvidence ? attributedGpuMs : null,
|
|
98
|
+
unattributedWallMs: hasTimestampEvidence && phaseWallMs !== null
|
|
99
|
+
? Math.max(0, phaseWallMs - attributedGpuMs)
|
|
100
|
+
: null,
|
|
101
|
+
timestampCoverageRatio: hasTimestampEvidence && phaseWallMs > 0
|
|
102
|
+
? Math.min(1, attributedGpuMs / phaseWallMs)
|
|
103
|
+
: null,
|
|
104
|
+
overlapSemantics:
|
|
105
|
+
'Operation GPU timestamps are additive pass durations. They are not asserted to equal wall time.',
|
|
106
|
+
operations,
|
|
107
|
+
dispatches,
|
|
108
|
+
dispatchGeometryCoverage: dispatches > 0 ? knownDispatchGeometry / dispatches : null,
|
|
109
|
+
commandBufferSubmissions: steps.length,
|
|
110
|
+
observerReadbacks: hasTimestampEvidence ? steps.length : 0,
|
|
111
|
+
executionReadbacks: {
|
|
112
|
+
value: null,
|
|
113
|
+
status: 'not-attributed-by-observer',
|
|
114
|
+
},
|
|
115
|
+
estimatedBytesMoved: {
|
|
116
|
+
value: null,
|
|
117
|
+
unit: 'bytes',
|
|
118
|
+
status: 'unavailable',
|
|
119
|
+
semantics: 'estimated-not-measured',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function buildTokenCostLedger({
|
|
125
|
+
metrics,
|
|
126
|
+
identity,
|
|
127
|
+
device,
|
|
128
|
+
browser,
|
|
129
|
+
}) {
|
|
130
|
+
const phases = [
|
|
131
|
+
buildPhase('prefill', metrics?.prefillMs, metrics?.prefillProfileSteps),
|
|
132
|
+
buildPhase('decode', metrics?.decodeMs, metrics?.decodeProfileSteps),
|
|
133
|
+
];
|
|
134
|
+
const selectedVariants = {
|
|
135
|
+
kernelPathId: metrics?.kernelPathId ?? null,
|
|
136
|
+
kernelPathSource: metrics?.kernelPathSource ?? null,
|
|
137
|
+
executionPlan: metrics?.executionPlan ?? null,
|
|
138
|
+
};
|
|
139
|
+
const dominantOperation = phases
|
|
140
|
+
.flatMap((phase) => phase.operations.map((operation) => ({
|
|
141
|
+
phase: phase.phase,
|
|
142
|
+
label: operation.label,
|
|
143
|
+
gpuMs: operation.gpuMs,
|
|
144
|
+
})))
|
|
145
|
+
.filter((operation) => operation.gpuMs !== null)
|
|
146
|
+
.sort((left, right) => right.gpuMs - left.gpuMs)[0] ?? null;
|
|
147
|
+
const core = {
|
|
148
|
+
schema: TOKEN_COST_LEDGER_SCHEMA,
|
|
149
|
+
identity: {
|
|
150
|
+
artifactDigest: identity?.artifactDigest ?? null,
|
|
151
|
+
manifestDigest: identity?.manifestDigest ?? null,
|
|
152
|
+
executionGraphDigest: identity?.executionGraphDigest ?? null,
|
|
153
|
+
runtimeConfigDigest: identity?.runtimeConfigDigest ?? null,
|
|
154
|
+
kernelSetDigest: identity?.kernelSetDigest ?? null,
|
|
155
|
+
wrapperDigest: identity?.wrapperDigest ?? null,
|
|
156
|
+
browserDigest: identity?.browserDigest ?? (
|
|
157
|
+
browser ? computeCanonicalSha256(browser) : null
|
|
158
|
+
),
|
|
159
|
+
adapterDigest: identity?.adapterDigest ?? (
|
|
160
|
+
device ? computeCanonicalSha256(device) : null
|
|
161
|
+
),
|
|
162
|
+
},
|
|
163
|
+
device: device ?? null,
|
|
164
|
+
browser: browser ?? null,
|
|
165
|
+
phases,
|
|
166
|
+
selectedVariants,
|
|
167
|
+
rejectedOrFallbackVariants: metrics?.rejectedOrFallbackVariants ?? [],
|
|
168
|
+
dominantOperation,
|
|
169
|
+
};
|
|
170
|
+
return { ...core, digest: computeCanonicalSha256(core) };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function classifyTokenCostLedger(ledger, policy) {
|
|
174
|
+
if (policy?.schema !== 'doppler.token-cost-classifier-policy/v1') {
|
|
175
|
+
throw new Error('token cost ledger: classifier policy v1 is required');
|
|
176
|
+
}
|
|
177
|
+
const totals = Object.fromEntries(policy.walls.map((wall) => [wall.id, 0]));
|
|
178
|
+
for (const phase of ledger.phases ?? []) {
|
|
179
|
+
for (const operation of phase.operations ?? []) {
|
|
180
|
+
const wall = policy.walls.find((candidate) => (
|
|
181
|
+
candidate.patterns.some((pattern) => new RegExp(pattern, 'i').test(operation.label))
|
|
182
|
+
));
|
|
183
|
+
if (wall) totals[wall.id] += operation.gpuMs;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const classified = Object.entries(totals)
|
|
187
|
+
.map(([wall, gpuMs]) => ({ wall, gpuMs }))
|
|
188
|
+
.sort((left, right) => right.gpuMs - left.gpuMs);
|
|
189
|
+
const dominant = classified[0]?.gpuMs > 0 ? classified[0] : {
|
|
190
|
+
wall: 'unclassified',
|
|
191
|
+
gpuMs: 0,
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
dominantWall: dominant.wall,
|
|
195
|
+
classifiedGpuMs: classified,
|
|
196
|
+
prescribedExperiments:
|
|
197
|
+
policy.walls.find((wall) => wall.id === dominant.wall)?.experiments ?? [],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -203,8 +203,8 @@ export async function runNodeCommand(commandRequest, options = {}) {
|
|
|
203
203
|
const modules = await loadRuntimeModules();
|
|
204
204
|
const runtimeBridge = {
|
|
205
205
|
loadRuntimeConfigFromRef,
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
loadRuntimeProfile: modules.harness.loadRuntimeProfile,
|
|
207
|
+
loadRuntimeConfigFromUrl: modules.harness.loadRuntimeConfigFromUrl,
|
|
208
208
|
getRuntimeConfig: modules.runtime.getRuntimeConfig,
|
|
209
209
|
setRuntimeConfig: modules.runtime.setRuntimeConfig,
|
|
210
210
|
resetRuntimeConfig: modules.runtime.resetRuntimeConfig,
|
|
@@ -1,49 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
message?: string;
|
|
13
|
-
percent?: number;
|
|
14
|
-
totalBytes?: number;
|
|
15
|
-
downloadedBytes?: number;
|
|
16
|
-
totalShards?: number;
|
|
17
|
-
completedShards?: number;
|
|
18
|
-
speed?: number;
|
|
19
|
-
speedFormatted?: string;
|
|
20
|
-
totalFormatted?: string;
|
|
21
|
-
downloadedFormatted?: string;
|
|
22
|
-
eta?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface CachedModelSourceResult extends EnsureModelCachedResult {
|
|
26
|
-
manifest: Record<string, unknown>;
|
|
27
|
-
manifestText: string;
|
|
28
|
-
manifestHash: string;
|
|
29
|
-
storageContext: Record<string, unknown>;
|
|
30
|
-
storageBackend: 'opfs';
|
|
31
|
-
totalBytes: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface EnsureModelCachedSourceOptions {
|
|
35
|
-
expectedManifestHash?: string | { hex?: string; hash?: string; digest?: string };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export declare function ensureModelCached(
|
|
39
|
-
modelId: string,
|
|
40
|
-
modelBaseUrl: string,
|
|
41
|
-
onProgress?: ((progress: CacheProgressEvent) => void) | null
|
|
42
|
-
): Promise<EnsureModelCachedResult>;
|
|
43
|
-
|
|
44
|
-
export declare function ensureModelCachedSource(
|
|
45
|
-
modelId: string,
|
|
46
|
-
modelBaseUrl: string,
|
|
47
|
-
onProgress?: ((progress: CacheProgressEvent) => void) | null,
|
|
48
|
-
options?: EnsureModelCachedSourceOptions
|
|
49
|
-
): Promise<CachedModelSourceResult>;
|
|
1
|
+
export {
|
|
2
|
+
ensureModelCached,
|
|
3
|
+
ensureModelCachedSource,
|
|
4
|
+
} from '../storage/model-cache.js';
|
|
5
|
+
|
|
6
|
+
export type {
|
|
7
|
+
CacheProgressEvent,
|
|
8
|
+
CachedModelSourceResult,
|
|
9
|
+
EnsureModelCachedResult,
|
|
10
|
+
EnsureModelCachedSourceOptions,
|
|
11
|
+
} from '../storage/model-cache.js';
|