doppler-gpu 0.4.5 → 0.4.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.
Files changed (155) hide show
  1. package/README.md +45 -29
  2. package/assets/doppler-runtime-map.svg +82 -0
  3. package/assets/doppler.svg +1 -3
  4. package/package.json +25 -17
  5. package/src/cli/doppler-quickstart.js +1 -1
  6. package/src/cli/doppler-serve.js +2 -2
  7. package/src/client/doppler-registry.d.ts +19 -0
  8. package/src/client/doppler-registry.js +12 -0
  9. package/src/client/doppler-registry.json +50 -1
  10. package/src/client/runtime/model-session.d.ts +1 -0
  11. package/src/client/runtime/model-session.js +9 -0
  12. package/src/config/conversion/README.md +4 -0
  13. package/src/config/conversion/diffusiongemma/diffusiongemma-26b-a4b-it-q4k-ehf16-af16.json +28 -4
  14. package/src/config/conversion/embeddinggemma/google-embeddinggemma-300m-q4k-ehf16-af32.json +29 -4
  15. package/src/config/conversion/gemma3/gemma-3-1b-it-f16-af32.json +29 -4
  16. package/src/config/conversion/gemma3/gemma-3-1b-it-q4k-ehf16-af32.json +29 -4
  17. package/src/config/conversion/gemma3/gemma-3-270m-it-f16-af32.json +29 -4
  18. package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af16.json +29 -4
  19. package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af32.json +29 -4
  20. package/src/config/conversion/gemma3/translategemma-4b-1b-enes-q4k-ehf16-af32.json +29 -4
  21. package/src/config/conversion/gemma3/translategemma-4b-it-q4k-ehf16-af32.json +29 -4
  22. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af16.json +31 -5
  23. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af32.json +30 -4
  24. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-hq4k-af16.json +30 -4
  25. package/src/config/conversion/gemma4/gemma-4-12b-it-text-w4a16-ct-ehf16-af16.json +30 -4
  26. package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af16.json +30 -5
  27. package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af32.json +29 -4
  28. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af16-int4ple.json +30 -5
  29. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32-int4ple.json +29 -4
  30. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32.json +29 -4
  31. package/src/config/conversion/gemma4/gemma-4-moe-q4k-ehf16-af32.json +29 -4
  32. package/src/config/conversion/gpt-oss-20b-f16-xmxfp4.json +29 -4
  33. package/src/config/conversion/janus/janus-pro-1b-text-q4k-ehaf16.json +29 -4
  34. package/src/config/conversion/lfm2/lfm2.5-1.2b-instruct-q4k-ehf16-af32.json +29 -4
  35. package/src/config/conversion/minicpm/minicpm4-0-5b-f16-af32.json +481 -0
  36. package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +29 -4
  37. package/src/config/conversion/qwen3/qwen-3-5-2b-q4k-ehaf16.json +29 -4
  38. package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-eaf16.json +30 -5
  39. package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-ehaf16.json +29 -4
  40. package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-q4k-ehf16-af32.json +395 -0
  41. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-af32.json +429 -0
  42. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-q4k-ehf16-af32.json +540 -0
  43. package/src/config/execution-contract-check.js +14 -10
  44. package/src/config/merge-contract-check.js +1 -0
  45. package/src/config/merge.js +30 -0
  46. package/src/config/param-validator.d.ts +5 -0
  47. package/src/config/param-validator.js +42 -8
  48. package/src/config/required-inference-fields-contract-check.js +14 -0
  49. package/src/config/schema/debug.schema.d.ts +2 -0
  50. package/src/config/schema/debug.schema.js +1 -0
  51. package/src/config/schema/doppler.schema.d.ts +5 -1
  52. package/src/config/schema/doppler.schema.js +82 -292
  53. package/src/config/schema/inference.schema.d.ts +17 -3
  54. package/src/config/schema/kvcache.schema.d.ts +19 -3
  55. package/src/config/schema/kvcache.schema.js +2 -1
  56. package/src/config/schema/manifest.schema.d.ts +38 -1
  57. package/src/config/schema/manifest.schema.js +18 -0
  58. package/src/config/schema/policy-schema-registry.json +5 -0
  59. package/src/config/source-packages/litert/gemma-4-12b-it.json +20 -1
  60. package/src/config/source-packages/litert/gemma-4-e2b-it.json +20 -1
  61. package/src/config/source-packages/litert/gemma-4-e4b-it.json +21 -1
  62. package/src/config/transforms/execution-graph-transforms.d.ts +6 -0
  63. package/src/config/transforms/execution-graph-transforms.js +8 -0
  64. package/src/converter/conversion-plan.js +2 -0
  65. package/src/converter/parsers/transformer.js +27 -1
  66. package/src/converter/quantization-info.js +16 -4
  67. package/src/converter/rope-config.js +55 -3
  68. package/src/experimental/training/distillation/student-fixture.js +1 -1
  69. package/src/experimental/training/lora-pipeline.js +1 -1
  70. package/src/experimental/training/lora.js +2 -2
  71. package/src/experimental/training/suite.js +1 -1
  72. package/src/gpu/device.js +54 -11
  73. package/src/gpu/kernels/README.md +8 -1
  74. package/src/gpu/kernels/backward/attention_backward.js +8 -0
  75. package/src/gpu/kernels/dequant.d.ts +6 -6
  76. package/src/gpu/kernels/dequant.js +17 -6
  77. package/src/gpu/kernels/linear-attention-core.js +1 -6
  78. package/src/gpu/kernels/matmul-selection.d.ts +2 -2
  79. package/src/gpu/kernels/matmul-selection.js +9 -2
  80. package/src/gpu/kernels/matmul.d.ts +1 -1
  81. package/src/gpu/kernels/matmul.js +63 -9
  82. package/src/gpu/kernels/moe.d.ts +5 -1
  83. package/src/gpu/kernels/moe.js +5 -2
  84. package/src/gpu/kernels/softmax.d.ts +3 -3
  85. package/src/gpu/kernels/softmax.js +9 -2
  86. package/src/gpu/kernels/turboquant-codebook.js +1 -1
  87. package/src/gpu/kernels/types.d.ts +1 -1
  88. package/src/gpu/profiler.js +11 -1
  89. package/src/inference/browser-harness-model-helpers.js +4 -1
  90. package/src/inference/browser-harness-text-helpers.d.ts +28 -0
  91. package/src/inference/browser-harness-text-helpers.js +357 -116
  92. package/src/inference/browser-harness.d.ts +3 -3
  93. package/src/inference/browser-harness.js +266 -11
  94. package/src/inference/fixtures/rerank-semantic-fixtures.json +38 -0
  95. package/src/inference/kv-cache/quantized.js +16 -2
  96. package/src/inference/kv-cache/tiered.js +50 -15
  97. package/src/inference/moe-router.js +38 -7
  98. package/src/inference/pipelines/diffusion/text-encoder-gpu.d.ts +1 -1
  99. package/src/inference/pipelines/diffusion/text-encoder-gpu.js +8 -6
  100. package/src/inference/pipelines/text/config.d.ts +5 -1
  101. package/src/inference/pipelines/text/config.js +135 -112
  102. package/src/inference/pipelines/text/embed.d.ts +1 -0
  103. package/src/inference/pipelines/text/embed.js +39 -12
  104. package/src/inference/pipelines/text/execution-plan.js +8 -2
  105. package/src/inference/pipelines/text/ffn/dense.js +15 -4
  106. package/src/inference/pipelines/text/ffn/moe.js +4 -3
  107. package/src/inference/pipelines/text/ffn/standard.d.ts +2 -1
  108. package/src/inference/pipelines/text/ffn/standard.js +25 -2
  109. package/src/inference/pipelines/text/generator-helpers.js +2 -1
  110. package/src/inference/pipelines/text/generator-runtime.d.ts +6 -2
  111. package/src/inference/pipelines/text/generator-runtime.js +53 -20
  112. package/src/inference/pipelines/text/generator-steps.js +3 -0
  113. package/src/inference/pipelines/text/generator.d.ts +1 -0
  114. package/src/inference/pipelines/text/generator.js +14 -1
  115. package/src/inference/pipelines/text/init-rope.js +54 -6
  116. package/src/inference/pipelines/text/init.js +63 -15
  117. package/src/inference/pipelines/text/layer.js +32 -5
  118. package/src/inference/pipelines/text/linear-attention.js +12 -8
  119. package/src/inference/pipelines/text/logits/gpu.d.ts +1 -1
  120. package/src/inference/pipelines/text/logits/gpu.js +76 -113
  121. package/src/inference/pipelines/text/logits/index.js +44 -87
  122. package/src/inference/pipelines/text/logits/precision-policy.d.ts +11 -0
  123. package/src/inference/pipelines/text/logits/precision-policy.js +103 -0
  124. package/src/inference/pipelines/text/logits/types.d.ts +1 -0
  125. package/src/inference/pipelines/text/logits/utils.d.ts +2 -0
  126. package/src/inference/pipelines/text/logits/utils.js +11 -0
  127. package/src/inference/pipelines/text/lora-apply.js +6 -4
  128. package/src/inference/pipelines/text/moe-cpu.js +25 -0
  129. package/src/inference/pipelines/text/moe-gpu.js +148 -97
  130. package/src/inference/pipelines/text/moe-shape-validator.d.ts +33 -3
  131. package/src/inference/pipelines/text/moe-shape-validator.js +149 -31
  132. package/src/inference/pipelines/text/ops.d.ts +3 -0
  133. package/src/inference/pipelines/text/ops.js +26 -1
  134. package/src/inference/pipelines/text/per-layer-inputs.js +27 -12
  135. package/src/inference/pipelines/text/sampling.js +52 -10
  136. package/src/inference/pipelines/text/weights.js +7 -2
  137. package/src/inference/pipelines/text.js +24 -4
  138. package/src/inference/tokenizers/behavior-flags.js +23 -2
  139. package/src/loader/final-weights-loader.js +12 -1
  140. package/src/loader/tensors/tensor-loader.js +37 -3
  141. package/src/rules/execution-rules-contract-check.js +12 -3
  142. package/src/rules/inference/capability-transforms.rules.json +14 -2
  143. package/src/rules/inference/config.rules.json +26 -2
  144. package/src/rules/inference/dtype.rules.json +12 -5
  145. package/src/rules/inference/execution.rules.json +5 -19
  146. package/src/rules/inference/moe.rules.json +97 -0
  147. package/src/rules/loader/weights.rules.json +1 -0
  148. package/src/tooling/command-api-constants.js +2 -2
  149. package/src/tooling/command-api-family-normalizers.js +2 -1
  150. package/src/tooling/command-api.d.ts +1 -1
  151. package/src/tooling/command-runner-shared.d.ts +1 -1
  152. package/src/tooling/command-runner-shared.js +3 -1
  153. package/src/tooling/node-converter.js +20 -0
  154. package/src/tooling/node-source-runtime.js +5 -1
  155. package/src/version.js +1 -1
@@ -1,4 +1,3 @@
1
- import { log as debugLog } from '../debug/index.js';
2
1
  import { readBuffer } from '../memory/buffer-pool.js';
3
2
  import { CAPTURE_LEVELS, createDefaultCaptureConfig } from '../debug/capture-policy.js';
4
3
  import { selectRuleValue } from '../rules/rule-registry.js';
@@ -8,47 +7,12 @@ import { cloneJsonValue } from '../utils/clone-json.js';
8
7
  import { sha256BytesHex } from '../utils/sha256.js';
9
8
  import { resolvePromptInput } from './pipelines/text/generator-prefill-helpers.js';
10
9
 
11
- const DEFAULT_SAMPLING_DEFAULTS = Object.freeze({
12
- temperature: 1.0,
13
- topP: 0.95,
14
- topK: 50,
15
- repetitionPenalty: 1.1,
16
- greedyThreshold: 0.01,
17
- repetitionPenaltyWindow: 100,
18
- });
19
-
20
- const DEFAULT_HARNESS_PROMPT = 'The color of the sky is';
21
- const DEFAULT_RUNTIME_PLACEHOLDER_PROMPT = 'Hello from Doppler.';
22
- const DEFAULT_QWEN_PROMPT = Object.freeze({
23
- messages: Object.freeze([
24
- Object.freeze({
25
- role: 'user',
26
- content: 'Answer in one short sentence: What color is the sky on a clear day?',
27
- }),
28
- ]),
29
- });
30
- const DEFAULT_TRANSLATEGEMMA_PROMPT = Object.freeze({
31
- messages: Object.freeze([
32
- Object.freeze({
33
- role: 'user',
34
- content: Object.freeze([
35
- Object.freeze({
36
- type: 'text',
37
- source_lang_code: 'en',
38
- target_lang_code: 'fr',
39
- text: 'Hello world.',
40
- }),
41
- ]),
42
- }),
43
- ]),
44
- });
45
10
  const DEFAULT_IMAGE_TRANSCRIPTION_PROMPT = 'Describe the image in one short sentence.';
46
11
  const DEFAULT_IMAGE_TRANSCRIPTION_SOFT_TOKEN_BUDGET = 70;
47
- const DEFAULT_HARNESS_MAX_TOKENS = 32;
48
12
  const EMBEDDING_PREVIEW_LENGTH = 16;
49
13
  const GENERATION_TOKEN_DIAGNOSTIC_LIMIT = 32;
50
14
  const DECODE_RECORD_TOP_OP_LIMIT = 20;
51
- let defaultsWarningEmitted = false;
15
+ const RERANK_SCORE_POLICIES = new Set(['logit_difference', 'true_logit']);
52
16
 
53
17
  export function normalizeDecodeRecordOpLabels(value) {
54
18
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
@@ -355,54 +319,18 @@ export async function captureKvCacheByteProof(pipeline, enabled) {
355
319
  };
356
320
  }
357
321
 
358
- function hasPromptInput(value) {
359
- return (typeof value === 'string' && value.trim().length > 0)
360
- || (Array.isArray(value) && value.length > 0)
361
- || isStructuredPromptInput(value);
362
- }
363
-
364
- function warnIfUsingDefaults(runtimeConfig, runOverrides = null) {
365
- if (defaultsWarningEmitted) return;
366
- const promptOverride = runtimeConfig?.inference?.prompt;
367
- const hasPrompt = hasPromptInput(runOverrides?.prompt)
368
- || hasPromptInput(promptOverride);
369
- const hasRuntimeSampling = isPlainObject(runtimeConfig?.inference?.sampling)
370
- && Object.keys(runtimeConfig.inference.sampling).length > 0;
371
- const hasRunSampling = isPlainObject(runOverrides?.sampling)
372
- && Object.keys(runOverrides.sampling).length > 0;
373
- const hasSampling = hasRuntimeSampling || hasRunSampling;
374
- const hasMaxTokens = Number.isFinite(runOverrides?.maxTokens)
375
- || Number.isFinite(runtimeConfig?.inference?.generation?.maxTokens);
376
- if (hasPrompt && hasSampling && hasMaxTokens) return;
377
- defaultsWarningEmitted = true;
378
- const missingFields = [];
379
- const defaults = [];
380
- if (!hasPrompt) {
381
- missingFields.push('prompt');
382
- defaults.push(` prompt: "${DEFAULT_HARNESS_PROMPT}"`);
383
- }
384
- if (!hasMaxTokens) {
385
- missingFields.push('generation.maxTokens');
386
- defaults.push(` maxTokens: ${DEFAULT_HARNESS_MAX_TOKENS}`);
387
- }
388
- if (!hasSampling) {
389
- missingFields.push('sampling');
390
- defaults.push(` temperature: ${DEFAULT_SAMPLING_DEFAULTS.temperature}`);
391
- defaults.push(` topK: ${DEFAULT_SAMPLING_DEFAULTS.topK}`);
392
- defaults.push(` topP: ${DEFAULT_SAMPLING_DEFAULTS.topP}`);
393
- }
394
- debugLog.warn('Harness',
395
- `Running with default inference parameters for missing fields: ${missingFields.join(', ')}.\n`
396
- + defaults.join('\n')
397
- + '\n Provide explicit runtime.inference.sampling and generation.maxTokens if you want harness-stable settings.'
398
- );
399
- }
400
322
  const embeddingSemanticFixtureAsset = await loadJson(
401
323
  './fixtures/embedding-semantic-fixtures.json',
402
324
  import.meta.url,
403
325
  'Failed to load embedding semantic fixtures'
404
326
  );
405
327
 
328
+ const rerankSemanticFixtureAsset = await loadJson(
329
+ './fixtures/rerank-semantic-fixtures.json',
330
+ import.meta.url,
331
+ 'Failed to load rerank semantic fixtures'
332
+ );
333
+
406
334
  function asText(value) {
407
335
  if (typeof value !== 'string') return null;
408
336
  const trimmed = value.trim();
@@ -482,6 +410,59 @@ function normalizeThroughputCorpus(corpus) {
482
410
  return normalized.length > 0 ? normalized : null;
483
411
  }
484
412
 
413
+ function normalizeRerankCases(cases) {
414
+ if (!Array.isArray(cases)) return null;
415
+ const normalized = [];
416
+ for (let i = 0; i < cases.length; i++) {
417
+ const entry = cases[i];
418
+ if (!entry || typeof entry !== 'object') continue;
419
+
420
+ const query = asText(entry.query);
421
+ const positive = asText(entry.positive);
422
+ const negative = asText(entry.negative);
423
+ if (!query || !positive || !negative) {
424
+ continue;
425
+ }
426
+ normalized.push({
427
+ id: asText(entry.id) ?? `rerank-${i + 1}`,
428
+ query,
429
+ positive,
430
+ negative,
431
+ });
432
+ }
433
+ return normalized.length > 0 ? normalized : null;
434
+ }
435
+
436
+ function resolveDefaultRerankSemanticFixtures() {
437
+ const defaults = rerankSemanticFixtureAsset?.defaults;
438
+ if (!isPlainObject(defaults)) {
439
+ throw new Error('Rerank semantic fixture asset must define defaults.');
440
+ }
441
+
442
+ const cases = normalizeRerankCases(defaults.cases);
443
+ if (!cases) {
444
+ throw new Error('Rerank semantic fixture asset must define cases.');
445
+ }
446
+ if (!Number.isFinite(defaults.minPairAcc)) {
447
+ throw new Error('Rerank semantic fixture asset must define minPairAcc.');
448
+ }
449
+ if (!Number.isFinite(defaults.minScoreMargin)) {
450
+ throw new Error('Rerank semantic fixture asset must define minScoreMargin.');
451
+ }
452
+
453
+ return {
454
+ cases,
455
+ minPairAcc: Math.max(0, Math.min(1, Number(defaults.minPairAcc))),
456
+ minScoreMargin: Number(defaults.minScoreMargin),
457
+ };
458
+ }
459
+
460
+ const DEFAULT_RERANK_SEMANTIC_FIXTURES = resolveDefaultRerankSemanticFixtures();
461
+
462
+ export function getDefaultRerankSemanticFixtures() {
463
+ return cloneJsonValue(DEFAULT_RERANK_SEMANTIC_FIXTURES);
464
+ }
465
+
485
466
  function resolveDefaultEmbeddingSemanticFixtures() {
486
467
  const defaults = embeddingSemanticFixtureAsset?.defaults;
487
468
  if (!isPlainObject(defaults)) {
@@ -565,12 +546,13 @@ function resolveEmbeddingSemanticFixtures(runtimeConfig, options = null) {
565
546
  function resolveEmbeddingSemanticStyle(pipeline) {
566
547
  const manifest = pipeline?.manifest ?? null;
567
548
  const style = selectRuleValue('inference', 'config', 'embeddingSemanticStyle', {
568
- modelId: String(manifest?.modelId ?? '').toLowerCase(),
549
+ modelType: String(manifest?.modelType ?? '').toLowerCase(),
569
550
  manifestModelType: String(
570
551
  manifest?.config?.model_type
571
552
  ?? manifest?.config?.text_config?.model_type
572
553
  ?? ''
573
554
  ).toLowerCase(),
555
+ sourceCheckpointId: String(manifest?.artifactIdentity?.sourceCheckpointId ?? ''),
574
556
  });
575
557
  if (typeof style === 'string' && style.length > 0) {
576
558
  return style;
@@ -587,6 +569,12 @@ function formatEmbeddingSemanticText(text, kind, style) {
587
569
  return `title: None | text: ${text}`;
588
570
  }
589
571
  }
572
+ if (style === 'qwen3_embedding') {
573
+ if (kind === 'query') {
574
+ return `Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: ${text}`;
575
+ }
576
+ return text;
577
+ }
590
578
  return text;
591
579
  }
592
580
 
@@ -595,7 +583,290 @@ export function resolvePrompt(runtimeConfig) {
595
583
  if (typeof runtimePrompt === 'string' && runtimePrompt.trim()) {
596
584
  return runtimePrompt.trim();
597
585
  }
598
- return DEFAULT_HARNESS_PROMPT;
586
+ throw new Error('Harness embedding requires explicit runtime.inference.prompt.');
587
+ }
588
+
589
+ function assertRerankTokenId(value, label) {
590
+ const tokenId = Number(value);
591
+ if (!Number.isInteger(tokenId) || tokenId < 0) {
592
+ throw new Error(`Manifest rerank config requires non-negative integer ${label}.`);
593
+ }
594
+ return tokenId;
595
+ }
596
+
597
+ function assertRerankText(value, label, preserve = false) {
598
+ if (typeof value !== 'string') {
599
+ throw new Error(`Manifest rerank config requires non-empty ${label}.`);
600
+ }
601
+ const text = value.trim();
602
+ if (!text) {
603
+ throw new Error(`Manifest rerank config requires non-empty ${label}.`);
604
+ }
605
+ return preserve ? value : text;
606
+ }
607
+
608
+ export function resolveRerankScoringConfig(pipeline) {
609
+ const config = pipeline?.manifest?.inference?.rerank;
610
+ if (!isPlainObject(config)) {
611
+ throw new Error('Rerank workload requires manifest.inference.rerank scoring config.');
612
+ }
613
+ const format = assertRerankText(config.format, 'format');
614
+ if (format !== 'qwen3_yes_no_logit') {
615
+ throw new Error(`Unsupported rerank scoring format "${format}".`);
616
+ }
617
+ const trueTokenId = assertRerankTokenId(config.trueTokenId, 'trueTokenId');
618
+ const falseTokenId = assertRerankTokenId(config.falseTokenId, 'falseTokenId');
619
+ if (trueTokenId === falseTokenId) {
620
+ throw new Error('Manifest rerank config trueTokenId and falseTokenId must be distinct.');
621
+ }
622
+ const score = assertRerankText(config.score, 'score');
623
+ if (!RERANK_SCORE_POLICIES.has(score)) {
624
+ throw new Error(`Unsupported rerank score policy "${score}".`);
625
+ }
626
+ const probability = assertRerankText(config.probability, 'probability');
627
+ if (probability !== 'sigmoid') {
628
+ throw new Error(`Unsupported rerank probability policy "${probability}".`);
629
+ }
630
+ return {
631
+ format,
632
+ instruction: assertRerankText(config.instruction, 'instruction'),
633
+ inputTemplate: assertRerankText(config.inputTemplate, 'inputTemplate', true),
634
+ prefix: assertRerankText(config.prefix, 'prefix', true),
635
+ suffix: assertRerankText(config.suffix, 'suffix', true),
636
+ trueToken: assertRerankText(config.trueToken, 'trueToken'),
637
+ trueTokenId,
638
+ falseToken: assertRerankText(config.falseToken, 'falseToken'),
639
+ falseTokenId,
640
+ score,
641
+ probability,
642
+ };
643
+ }
644
+
645
+ function replaceRerankTemplate(template, values) {
646
+ let output = template;
647
+ for (const [key, value] of Object.entries(values)) {
648
+ const placeholder = `{${key}}`;
649
+ if (!output.includes(placeholder)) {
650
+ throw new Error(`Manifest rerank inputTemplate is missing ${placeholder}.`);
651
+ }
652
+ output = output.split(placeholder).join(value);
653
+ }
654
+ return output;
655
+ }
656
+
657
+ export function formatRerankPrompt(query, document, scoringConfig) {
658
+ const instruction = assertRerankText(scoringConfig?.instruction, 'instruction');
659
+ const normalizedQuery = assertRerankText(query, 'query');
660
+ const normalizedDocument = assertRerankText(document, 'document');
661
+ const input = replaceRerankTemplate(
662
+ assertRerankText(scoringConfig?.inputTemplate, 'inputTemplate', true),
663
+ {
664
+ instruction,
665
+ query: normalizedQuery,
666
+ document: normalizedDocument,
667
+ }
668
+ );
669
+ return `${assertRerankText(scoringConfig?.prefix, 'prefix', true)}${input}${assertRerankText(scoringConfig?.suffix, 'suffix', true)}`;
670
+ }
671
+
672
+ function sigmoid(value) {
673
+ return 1 / (1 + Math.exp(-value));
674
+ }
675
+
676
+ function computeRerankScore(scoringConfig, trueLogit, falseLogit) {
677
+ if (scoringConfig.score === 'logit_difference') {
678
+ return trueLogit - falseLogit;
679
+ }
680
+ if (scoringConfig.score === 'true_logit') {
681
+ return trueLogit;
682
+ }
683
+ throw new Error(`Unsupported rerank score policy "${scoringConfig.score}".`);
684
+ }
685
+
686
+ function assertLogitsVector(value) {
687
+ if (!ArrayBuffer.isView(value) && !Array.isArray(value)) {
688
+ throw new Error('Rerank prefillWithLogits result must include a logits vector.');
689
+ }
690
+ return value;
691
+ }
692
+
693
+ export async function scoreRerankDocument(pipeline, query, document, scoringConfig = null) {
694
+ if (!pipeline || typeof pipeline.prefillWithLogits !== 'function') {
695
+ throw new Error('Rerank workload requires pipeline.prefillWithLogits().');
696
+ }
697
+ const config = scoringConfig ?? resolveRerankScoringConfig(pipeline);
698
+ const prompt = formatRerankPrompt(query, document, config);
699
+ pipeline.reset?.();
700
+ const result = await pipeline.prefillWithLogits(prompt, { useChatTemplate: false });
701
+ const logits = assertLogitsVector(result?.logits);
702
+ const trueLogit = Number(logits[config.trueTokenId]);
703
+ const falseLogit = Number(logits[config.falseTokenId]);
704
+ if (!Number.isFinite(trueLogit) || !Number.isFinite(falseLogit)) {
705
+ throw new Error(
706
+ `Rerank logits missing finite yes/no scores at token IDs ${config.trueTokenId}/${config.falseTokenId}.`
707
+ );
708
+ }
709
+ const score = computeRerankScore(config, trueLogit, falseLogit);
710
+ const probability = sigmoid(score);
711
+ return {
712
+ query,
713
+ document,
714
+ prompt,
715
+ tokenCount: Number.isFinite(result?.tokens?.length) ? result.tokens.length : 0,
716
+ score,
717
+ probability,
718
+ trueLogit,
719
+ falseLogit,
720
+ trueTokenId: config.trueTokenId,
721
+ falseTokenId: config.falseTokenId,
722
+ };
723
+ }
724
+
725
+ function resolveRerankInput(runtimeConfig, runOverrides = null) {
726
+ const source = isPlainObject(runOverrides?.rerank)
727
+ ? runOverrides.rerank
728
+ : runtimeConfig?.inference?.rerank;
729
+ if (!isPlainObject(source)) {
730
+ throw new Error('Harness rerank requires explicit runtime.inference.rerank.');
731
+ }
732
+ const query = asText(source.query);
733
+ if (!query) {
734
+ throw new Error('Harness rerank requires non-empty runtime.inference.rerank.query.');
735
+ }
736
+ const documents = Array.isArray(source.documents)
737
+ ? source.documents.map(asText).filter(Boolean)
738
+ : [];
739
+ if (documents.length === 0) {
740
+ throw new Error('Harness rerank requires non-empty runtime.inference.rerank.documents.');
741
+ }
742
+ return { query, documents };
743
+ }
744
+
745
+ function summarizeRerankScores(scores) {
746
+ const sorted = [...scores].sort((a, b) => {
747
+ const scoreDelta = b.score - a.score;
748
+ return scoreDelta !== 0 ? scoreDelta : a.index - b.index;
749
+ });
750
+ return {
751
+ ranking: sorted.map((entry, rank) => ({
752
+ rank: rank + 1,
753
+ index: entry.index,
754
+ document: entry.document,
755
+ score: Number(entry.score.toFixed(6)),
756
+ probability: Number(entry.probability.toFixed(6)),
757
+ trueLogit: Number(entry.trueLogit.toFixed(6)),
758
+ falseLogit: Number(entry.falseLogit.toFixed(6)),
759
+ tokenCount: entry.tokenCount,
760
+ })),
761
+ top: sorted[0] ?? null,
762
+ };
763
+ }
764
+
765
+ export async function runRerank(pipeline, runtimeConfig, runOverrides = null) {
766
+ const input = resolveRerankInput(runtimeConfig, runOverrides);
767
+ const config = resolveRerankScoringConfig(pipeline);
768
+ const start = performance.now();
769
+ const scores = [];
770
+ for (let i = 0; i < input.documents.length; i++) {
771
+ const scored = await scoreRerankDocument(
772
+ pipeline,
773
+ input.query,
774
+ input.documents[i],
775
+ config
776
+ );
777
+ scores.push({
778
+ index: i,
779
+ ...scored,
780
+ });
781
+ }
782
+ const summary = summarizeRerankScores(scores);
783
+ return {
784
+ query: input.query,
785
+ documents: input.documents,
786
+ documentCount: input.documents.length,
787
+ scores,
788
+ ranking: summary.ranking,
789
+ topDocument: summary.top
790
+ ? {
791
+ index: summary.top.index,
792
+ document: summary.top.document,
793
+ score: summary.top.score,
794
+ probability: summary.top.probability,
795
+ }
796
+ : null,
797
+ durationMs: Math.max(1, performance.now() - start),
798
+ };
799
+ }
800
+
801
+ function resolveRerankSemanticFixtures(runtimeConfig, options = null) {
802
+ const overrides = isPlainObject(options?.rerankSemantic)
803
+ ? options.rerankSemantic
804
+ : null;
805
+ const runtimeOverrides = runtimeConfig?.shared?.benchmark?.run?.rerankSemantic;
806
+ const source = overrides ?? (isPlainObject(runtimeOverrides) ? runtimeOverrides : null);
807
+ const cases = normalizeRerankCases(source?.cases)
808
+ ?? DEFAULT_RERANK_SEMANTIC_FIXTURES.cases;
809
+ const minPairAcc = Number.isFinite(source?.minPairAcc)
810
+ ? Math.max(0, Math.min(1, Number(source.minPairAcc)))
811
+ : DEFAULT_RERANK_SEMANTIC_FIXTURES.minPairAcc;
812
+ const minScoreMargin = Number.isFinite(source?.minScoreMargin)
813
+ ? Number(source.minScoreMargin)
814
+ : DEFAULT_RERANK_SEMANTIC_FIXTURES.minScoreMargin;
815
+ return {
816
+ cases,
817
+ minPairAcc,
818
+ minScoreMargin,
819
+ };
820
+ }
821
+
822
+ export async function runRerankSemanticChecks(pipeline, options = null) {
823
+ const fixture = resolveRerankSemanticFixtures(pipeline?.runtimeConfig ?? {}, options);
824
+ const config = resolveRerankScoringConfig(pipeline);
825
+ const start = performance.now();
826
+ const pairs = [];
827
+ let pairPassed = 0;
828
+ for (const testCase of fixture.cases) {
829
+ const positive = await scoreRerankDocument(
830
+ pipeline,
831
+ testCase.query,
832
+ testCase.positive,
833
+ config
834
+ );
835
+ const negative = await scoreRerankDocument(
836
+ pipeline,
837
+ testCase.query,
838
+ testCase.negative,
839
+ config
840
+ );
841
+ const margin = positive.score - negative.score;
842
+ const passed = Number.isFinite(margin) && margin > fixture.minScoreMargin;
843
+ if (passed) pairPassed++;
844
+ pairs.push({
845
+ id: testCase.id,
846
+ query: testCase.query,
847
+ positive: testCase.positive,
848
+ negative: testCase.negative,
849
+ passed,
850
+ positiveScore: Number(positive.score.toFixed(6)),
851
+ negativeScore: Number(negative.score.toFixed(6)),
852
+ positiveProbability: Number(positive.probability.toFixed(6)),
853
+ negativeProbability: Number(negative.probability.toFixed(6)),
854
+ margin: Number.isFinite(margin) ? Number(margin.toFixed(6)) : null,
855
+ });
856
+ }
857
+ const pairAcc = pairs.length > 0 ? pairPassed / pairs.length : 0;
858
+ const passed = pairAcc >= fixture.minPairAcc;
859
+ return {
860
+ passed,
861
+ pairAcc,
862
+ pairPassed,
863
+ pairTotal: pairs.length,
864
+ minPairAcc: Number(fixture.minPairAcc.toFixed(4)),
865
+ minScoreMargin: Number(fixture.minScoreMargin.toFixed(4)),
866
+ failedCaseIds: pairs.filter((item) => !item.passed).map((item) => item.id),
867
+ pairs,
868
+ durationMs: Math.max(1, performance.now() - start),
869
+ };
599
870
  }
600
871
 
601
872
  function isStructuredPromptInput(value) {
@@ -624,26 +895,6 @@ function resolvePromptTemplateType(source) {
624
895
  return asText(source?.manifest?.inference?.chatTemplate?.type);
625
896
  }
626
897
 
627
- function buildDefaultGenerationPrompt(templateType) {
628
- if (templateType === 'qwen') {
629
- return clonePromptInput(DEFAULT_QWEN_PROMPT);
630
- }
631
- if (templateType === 'translategemma') {
632
- return clonePromptInput(DEFAULT_TRANSLATEGEMMA_PROMPT);
633
- }
634
- return DEFAULT_HARNESS_PROMPT;
635
- }
636
-
637
- function shouldPreferModelDefaultPrompt(runtimePrompt, templateType) {
638
- if (templateType !== 'translategemma' && templateType !== 'qwen') {
639
- return false;
640
- }
641
- if (typeof runtimePrompt !== 'string') {
642
- return false;
643
- }
644
- return runtimePrompt.trim() === DEFAULT_RUNTIME_PLACEHOLDER_PROMPT;
645
- }
646
-
647
898
  function assertPromptContract(runtimePrompt, templateType, source = 'runtime.inference.prompt') {
648
899
  if (templateType !== 'translategemma') {
649
900
  return;
@@ -652,10 +903,6 @@ function assertPromptContract(runtimePrompt, templateType, source = 'runtime.inf
652
903
  return;
653
904
  }
654
905
  if (typeof runtimePrompt === 'string') {
655
- const trimmed = runtimePrompt.trim();
656
- if (!trimmed || trimmed === DEFAULT_RUNTIME_PLACEHOLDER_PROMPT) {
657
- return;
658
- }
659
906
  throw new Error(
660
907
  `TranslateGemma harness prompt contract violation: ${source} must be ` +
661
908
  '{ messages: [...] } with source_lang_code/target_lang_code blocks, not a plain string.'
@@ -671,7 +918,7 @@ function assertPromptContract(runtimePrompt, templateType, source = 'runtime.inf
671
918
 
672
919
  function describePromptInput(promptInput) {
673
920
  if (typeof promptInput === 'string') {
674
- return promptInput.trim() || DEFAULT_HARNESS_PROMPT;
921
+ return promptInput.trim() || '[empty prompt]';
675
922
  }
676
923
  if (isPlainObject(promptInput?.image) && typeof promptInput?.prompt === 'string') {
677
924
  const width = Number.isFinite(promptInput.image.width) ? promptInput.image.width : '?';
@@ -924,9 +1171,6 @@ function resolveGenerationPromptInput(runtimeConfig, runOverrides = null, source
924
1171
 
925
1172
  const runtimePrompt = runtimeConfig?.inference?.prompt;
926
1173
  assertPromptContract(runtimePrompt, templateType, 'runtimeConfig.inference.prompt');
927
- if (shouldPreferModelDefaultPrompt(runtimePrompt, templateType)) {
928
- return buildDefaultGenerationPrompt(templateType);
929
- }
930
1174
  if (typeof runtimePrompt === 'string' && runtimePrompt.trim()) {
931
1175
  return runtimePrompt;
932
1176
  }
@@ -934,15 +1178,15 @@ function resolveGenerationPromptInput(runtimeConfig, runOverrides = null, source
934
1178
  return clonePromptInput(runtimePrompt);
935
1179
  }
936
1180
 
937
- return buildDefaultGenerationPrompt(templateType);
1181
+ throw new Error('Harness generation requires explicit runOverrides.prompt or runtime.inference.prompt.');
938
1182
  }
939
1183
 
940
1184
  function resolveMaxTokens(runtimeConfig) {
941
1185
  const runtimeMax = runtimeConfig?.inference?.generation?.maxTokens;
942
- if (Number.isFinite(runtimeMax)) {
943
- return Math.max(1, Math.floor(runtimeMax));
1186
+ if (Number.isFinite(runtimeMax) && runtimeMax > 0) {
1187
+ return Math.floor(runtimeMax);
944
1188
  }
945
- return DEFAULT_HARNESS_MAX_TOKENS;
1189
+ throw new Error('Harness generation requires explicit runtime.inference.generation.maxTokens.');
946
1190
  }
947
1191
 
948
1192
  function resolveAutomaticGenerationDiagnostics(runtimeConfig, runOverrides = null) {
@@ -1545,7 +1789,6 @@ export function isCoherentOutput(tokens, output) {
1545
1789
  }
1546
1790
 
1547
1791
  export async function runGeneration(pipeline, runtimeConfig, runOverrides = null) {
1548
- warnIfUsingDefaults(runtimeConfig, runOverrides);
1549
1792
  const tokens = [];
1550
1793
  const tokenIds = [];
1551
1794
  const tokenRecords = [];
@@ -1558,7 +1801,6 @@ export async function runGeneration(pipeline, runtimeConfig, runOverrides = null
1558
1801
  ? Math.max(1, Math.floor(runOverrides.maxTokens))
1559
1802
  : resolveMaxTokens(runtimeConfig);
1560
1803
  const sampling = {
1561
- ...DEFAULT_SAMPLING_DEFAULTS,
1562
1804
  ...(runtimeConfig.inference?.sampling || {}),
1563
1805
  ...(isPlainObject(runOverrides?.sampling) ? runOverrides.sampling : {}),
1564
1806
  };
@@ -1706,7 +1948,6 @@ export async function runTextInference(pipeline, runtimeConfig, runOverrides = n
1706
1948
  }
1707
1949
 
1708
1950
  export async function runEmbedding(pipeline, runtimeConfig, runOverrides = null) {
1709
- warnIfUsingDefaults(runtimeConfig);
1710
1951
  const prompt = typeof runOverrides?.prompt === 'string' && runOverrides.prompt.trim()
1711
1952
  ? runOverrides.prompt.trim()
1712
1953
  : resolvePrompt(runtimeConfig);
@@ -19,8 +19,8 @@ export interface RuntimeConfigLoadOptions {
19
19
  }
20
20
 
21
21
  export type BrowserHarnessMode = 'verify' | 'debug' | 'bench';
22
- export type BrowserWorkload = 'kernels' | 'inference' | 'embedding' | 'training' | 'diffusion' | 'energy';
23
- export type BrowserSuite = 'kernels' | 'inference' | 'embedding' | 'training' | 'bench' | 'debug' | 'diffusion' | 'energy';
22
+ export type BrowserWorkload = 'kernels' | 'inference' | 'embedding' | 'rerank' | 'training' | 'diffusion' | 'energy';
23
+ export type BrowserSuite = 'kernels' | 'inference' | 'embedding' | 'rerank' | 'training' | 'bench' | 'debug' | 'diffusion' | 'energy';
24
24
 
25
25
  export interface SuiteTestResult {
26
26
  name: string;
@@ -64,7 +64,7 @@ export interface BrowserSuiteOptions extends InferenceHarnessOptions {
64
64
  suite?: BrowserSuite;
65
65
  command?: string;
66
66
  surface?: string;
67
- expectedModelType?: 'embedding';
67
+ expectedModelType?: 'embedding' | 'rerank';
68
68
  modelUrl?: string;
69
69
  modelId?: string;
70
70
  workloadType?: string;