doppler-gpu 0.4.14 → 0.4.15

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 CHANGED
@@ -8,6 +8,15 @@ docs so the `0.1.x` line has one conventional npm-visible history surface.
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.4.15] - 2026-07-24
12
+
13
+ ### Added
14
+
15
+ - Added `generateWithEvidence()` to loaded model handles. The browser-safe
16
+ result binds generated token IDs, transcript, resolved generation config,
17
+ runtime profile, WebGPU backend identity, and execution-plan identity with
18
+ canonical SHA-256 hashes.
19
+
11
20
  ## [0.4.14] - 2026-07-19
12
21
 
13
22
  ### Added
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <img src="assets/doppler-logo.svg" alt="doppler" width="190" />
3
+ </p>
4
+
1
5
  # doppler-gpu
2
6
 
3
7
  [![Build](https://img.shields.io/github/actions/workflow/status/clocksmith/doppler/check-green.yml?branch=main&label=build)](https://github.com/clocksmith/doppler/actions/workflows/check-green.yml)
@@ -6,15 +10,16 @@
6
10
  [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/clocksmith/doppler/pulls)
7
11
 
8
12
  Doppler turns inference engineering into a verifiable search problem. Optimizers
9
- edit RDRR manifests, execution plans, and kernels; parity and benchmark gates
13
+ edit JSON manifests, execution plans, and WGSL kernels; parity and benchmark gates
10
14
  accept or reject each candidate against correctness and speed.
11
15
 
12
- Today engineers use these contracts and gates to tune a JavaScript/WGSL WebGPU
16
+ These contracts and gates are used by operators to tune a configurable and pure JavaScript and WGSL sourced WebGPU
13
17
  runtime for supported
14
18
  [RDRR artifacts](https://github.com/clocksmith/doppler/blob/main/docs/rdrr-format.md)
15
- in browser and Node. Doppler runs text generation, embeddings, and reranking
16
- locally, with CLI and OpenAI-compatible server entry points. Bun WebGPU support
17
- is experimental.
19
+ in browser, Node, and Bun. Doppler runs text generation, embeddings, and reranking
20
+ locally, with CLI and OpenAI-compatible server entry points.
21
+
22
+ **Read this first:** [getting started](https://github.com/clocksmith/doppler/blob/main/docs/getting-started.md) → [Root API](https://github.com/clocksmith/doppler/blob/main/docs/api/root.md) → [open source evidence](https://github.com/clocksmith/doppler/blob/main/docs/model-competition-scoreboard.md)
18
23
 
19
24
  **[Try the live demo](https://d4da.com/doppler)** | **[npm](https://www.npmjs.com/package/doppler-gpu)** | **[docs](https://github.com/clocksmith/doppler/blob/main/docs/INDEX.md)**
20
25
 
@@ -30,16 +35,16 @@ Doppler classifies artifacts by what they consume and produce. This is
30
35
  separate from lineage (`family`), runtime implementation (`modelType`), and
31
36
  artifact-size tier.
32
37
 
33
- | Type | Input → output | Runtime-verified / cataloged | Representative lanes |
34
- | --- | --- | --- | --- |
35
- | Text generators | text → text | 12 / 14 | gemma-3-1b-it-q4k-ehf16-af32<br>gemma-3-270m-it-f16-af32<br>gemma-3-270m-it-q4k-ehf16-af32<br>+11 more |
36
- | Multimodal generators | audio + image + text → text | 3 / 3 | gemma-4-e2b-it-q4k-ehf16-af16-int4ple<br>gemma-4-e2b-it-q4k-ehf16-af32<br>gemma-4-e2b-it-q4k-ehf16-af32-int4ple |
37
- | Diffusion language models | text → text | 0 / 1 | diffusiongemma-26b-a4b-it-q4k-ehf16-af16 |
38
- | Translation specialists | text → text | 2 / 2 | translategemma-4b-1b-enes-q4k-ehf16-af32<br>translategemma-4b-it-q4k-ehf16-af32 |
39
- | Language embedders | text → pooled-embedding | 2 / 2 | google-embeddinggemma-300m-q4k-ehf16-af32<br>qwen-3-embedding-0-6b-q4k-ehf16-af32 |
40
- | Rerankers | text-pair → relevance-score | 2 / 2 | qwen-3-reranker-0-6b-f16-af32<br>qwen-3-reranker-0-6b-q4k-ehf16-af32 |
41
- | Protein encoders | protein-sequence → pooled-embedding + token-embedding + token-logits | 3 / 3 | amplify-120m-f16-af32<br>esm2-t12-35m-ur50d-f32-af32<br>esmc-300m-f32-af32 |
42
- | Nucleotide encoders | dna-sequence → pooled-embedding + token-embedding | 1 / 1 | nucleotide-transformer-v2-50m-f32-af32 |
38
+ | Type | Verified / Cataloged | What it does |
39
+ | --- | --- | --- |
40
+ | Text generators | 12 / 14 | `text → text` |
41
+ | Multimodal generators | 3 / 3 | `audio + image + text → text` |
42
+ | Diffusion language models | 0 / 1 | `text → text` |
43
+ | Translation specialists | 2 / 2 | `text → text` |
44
+ | Language embedders | 2 / 2 | `text → embedding` |
45
+ | Rerankers | 2 / 2 | `text-pair → relevance-score` |
46
+ | Protein encoders | 3 / 3 | `sequence → embedding + token outputs` |
47
+ | Nucleotide encoders | 1 / 1 | `dna-seq → embedding` |
43
48
 
44
49
  The [full model-support matrix](https://github.com/clocksmith/doppler/blob/main/docs/model-support-matrix.md)
45
50
  lists every lane and its lifecycle evidence. Classification says what an
@@ -49,22 +54,29 @@ modality.
49
54
 
50
55
  <!-- model-type-clusters:end -->
51
56
 
52
- ## Supported LoRA adapters (PEFT)
57
+ ## LoRA: runtime loading and training
53
58
 
54
- Doppler supports runtime loading and hot-swapping of LoRA adapters (in SafeTensors format) bound to specific base models.
59
+ Doppler supports:
55
60
 
56
- | Adapter ID | Base Model ID | HF Repository | Lifecycle & Purpose |
57
- | --- | --- | --- | --- |
58
- | `doppler-wgsl-qwen35-9b-v12-external20-seed11` | `qwen-3-5-9b-f16-af32` | [clocksmith/lora](https://huggingface.co/clocksmith/lora/blob/5662f8f7e3dbcf1e2ec353b5a04d0d4f2f5254ce/adapters/seed11/adapter_model.safetensors) | Preserved portable adapter (v12) |
59
- | `doppler-wgsl-qwen35-9b-v12-external20-seed29` | `qwen-3-5-9b-f16-af32` | [clocksmith/lora](https://huggingface.co/clocksmith/lora/blob/5662f8f7e3dbcf1e2ec353b5a04d0d4f2f5254ce/adapters/seed29/adapter_model.safetensors) | Candidate adapter for repair validation (v12) |
60
- | `doppler-wgsl-qwen35-9b-v12-external20-seed47` | `qwen-3-5-9b-f16-af32` | [clocksmith/lora](https://huggingface.co/clocksmith/lora/blob/5662f8f7e3dbcf1e2ec353b5a04d0d4f2f5254ce/adapters/seed47/adapter_model.safetensors) | Preserved portable adapter (v12) |
61
+ - SafeTensors LoRA loading and hot-swap at runtime.
62
+ - Experimental SFT/LoRA training in Node, Bun, and browser via `doppler-gpu/training`.
63
+ - Native packed-Q4K LoRA for `qwen-3-5-0-8b-q4k-ehaf16` in `webgpu_native` (frozen base, LoRA A/B updates only).
64
+ - External backends for other packed-Q4K training targets.
61
65
 
62
- Active adapters are registered in [models/adapters/catalog.json](models/adapters/catalog.json). See the [LoRA Format specification](docs/lora-format.md) for details on the adapter manifest schema.
66
+ ```bash
67
+ npx doppler-gpu lora --config ./workload.json --surface node
68
+ ```
69
+
70
+ Active adapters are registered in [models/adapters/catalog.json](models/adapters/catalog.json).
71
+ The training API, workload schema, and adapter families live in the
72
+ [LoRA Format specification](docs/lora-format.md),
73
+ [Training handbook](docs/training-handbook.md), and [Training API](docs/api/training.md).
63
74
 
64
75
  ## Evidence
65
76
 
66
- Doppler has higher steady-state inference throughput than Transformers.js in each
67
- of the comparable browser WebGPU results indexed below.
77
+ Doppler has higher steady-state inference throughput than Transformers.js in
78
+ accepted, throughput-comparable browser WebGPU comparisons indexed below where
79
+ the throughput gate passes.
68
80
 
69
81
  ![Metal and Vulkan browser WebGPU throughput distributions](https://raw.githubusercontent.com/clocksmith/doppler/main/assets/doppler-webgpu-evidence.svg)
70
82
 
@@ -77,33 +89,29 @@ receipt, and the [methodology](https://github.com/clocksmith/doppler/blob/main/d
77
89
 
78
90
  ## Why these lanes are faster
79
91
 
80
- Doppler authors the WGSL path and pins it in RDRR. Runtime profiles pin session
81
- cadence. The measured wins come from different mechanisms in different phases:
92
+ Doppler speedups come from specific, explicit runtime changes:
82
93
 
83
- | Lever | Affected phase | Measured receipt |
84
- | --- | --- | --- |
85
- | Fused Q4_K projection and FFN work removes separate dispatches | Text decode | [Qwen 3.5 0.8B Metal](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/compare_20260709T154633.json) |
86
- | Fixed `head_dim=128` attention avoids the generic prefill path | Retrieval attention | [embedding](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/embedding_compare_qwen-3-embedding-0-6b-q4k-ehf16-af32_20260709T180853.json), [reranking](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/rerank_compare_qwen-3-reranker-0-6b-q4k-ehf16-af32_20260709T192830.json) |
87
- | Batch-four decode amortizes one readback across four tokens | Submit and map waits | [Qwen 3.5 2B Vulkan](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/compare_20260707T161623.json) |
88
- | INT4-PLE and Q4_K layouts lower projection traffic | Text decode | [Gemma 4 Vulkan](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/compare_20260707T170557.json) |
94
+ - **Fusion:** projection + FFN path reductions reduce kernel count.
95
+ - **Attention/layout tuning:** lowers prefill overhead.
96
+ - **Batched decode:** amortizes readback overhead.
97
+ - **Packed kernels:** Q4_K + INT4-PLE reduce projection traffic.
89
98
 
90
- The Gemma 4 comparison uses its declared product-format output policy. It does
91
- not claim exact greedy token parity.
99
+ Evidence receipts:
92
100
 
93
- Parity and comparable benchmark gates decide what is retained. The
94
- [challenger framework](https://github.com/clocksmith/doppler/blob/main/docs/local-gpu-challenger-framework.md)
95
- records accepted and rejected trials, and each verdict's receipt binds it to a
96
- model, profile, workload, and device; the
97
- [negative-results findings](https://github.com/clocksmith/doppler/blob/main/docs/developer-guides/16-kernel-performance-optimization.md#what-we-ruled-out)
98
- keep the dead ends.
101
+ - [Qwen 3.5 0.8B (Metal)](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/compare_20260709T154633.json)
102
+ - [Qwen embedding + rerank](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/embedding_compare_qwen-3-embedding-0-6b-q4k-ehf16-af32_20260709T180853.json), [Qwen rerank](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/rerank_compare_qwen-3-reranker-0-6b-q4k-ehf16-af32_20260709T192830.json)
103
+ - [Qwen 3.5 2B (Vulkan)](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/compare_20260707T161623.json)
104
+ - [Gemma 4 (Vulkan)](https://github.com/clocksmith/doppler/blob/main/benchmarks/vendors/results/compare_20260707T170557.json)
105
+
106
+ Retention is gated: a lane moves forward only when both parity and benchmark
107
+ receipts pass in the
108
+ [challenger framework](https://github.com/clocksmith/doppler/blob/main/docs/local-gpu-challenger-framework.md).
99
109
 
100
110
  ### Long-term direction
101
111
 
102
- Humans run this loop today. The WGSL-distillation workload is experimental.
103
- Automated kernel generation and autotuning are directions, not shipped product
104
- paths. Doppler aims to reduce the manual steps between a new checkpoint or GPU
105
- and a verified runtime lane. Automated proposals will face the same parity and
106
- benchmark gates.
112
+ Humans run this loop today. WGSL-distillation is experimental.
113
+ Automation in kernel generation/autotuning is a roadmap item, not shipped yet.
114
+ New checkpoints and GPUs still go through the same parity and benchmark gate flow.
107
115
 
108
116
  ## How it works
109
117
 
@@ -209,8 +217,22 @@ for await (const token of model.generate('Describe WebGPU briefly')) {
209
217
 
210
218
  // One-shot
211
219
  const text = await model.generateText('Explain WebGPU in one sentence');
220
+
221
+ // One-shot with a hash-bound execution receipt
222
+ const evidence = await model.generateWithEvidence('Explain WebGPU in one sentence', {
223
+ maxTokens: 64,
224
+ temperature: 0,
225
+ });
226
+ console.log(evidence.outputText, evidence.transcriptHash);
227
+
228
+ await model.unload();
212
229
  ```
213
230
 
231
+ `generateWithEvidence()` returns the text and token IDs together with canonical
232
+ SHA-256 hashes for the transcript, resolved generation config, runtime profile,
233
+ WebGPU backend, and execution-plan identity. The receipt records what ran; it
234
+ does not by itself establish output correctness.
235
+
214
236
  ### OpenAI-compatible server
215
237
 
216
238
  ```bash
@@ -232,12 +254,12 @@ Registry IDs resolve to hosted RDRR artifacts from `clocksmith/rdrr` by default.
232
254
 
233
255
  ## Start here
234
256
 
235
- | Reader | Entry points |
236
- | --- | --- |
237
- | Application developers | [Getting started](https://github.com/clocksmith/doppler/blob/main/docs/getting-started.md), [Root API](https://github.com/clocksmith/doppler/blob/main/docs/api/root.md), and the [OpenAI-compatible server](#openai-compatible-server) |
238
- | Model integrators | [RDRR format](https://github.com/clocksmith/doppler/blob/main/docs/rdrr-format.md), [model support](https://github.com/clocksmith/doppler/blob/main/docs/model-support-matrix.md), and [Program Bundles](https://github.com/clocksmith/doppler/blob/main/docs/integration/program-bundle.md) |
239
- | Runtime and kernel engineers | [Architecture](https://github.com/clocksmith/doppler/blob/main/docs/architecture.md), [kernel optimization](https://github.com/clocksmith/doppler/blob/main/docs/developer-guides/16-kernel-performance-optimization.md), and the [challenger framework](https://github.com/clocksmith/doppler/blob/main/docs/local-gpu-challenger-framework.md) |
240
- | Evidence reviewers | [Competition scoreboard](https://github.com/clocksmith/doppler/blob/main/docs/model-competition-scoreboard.md), [benchmark methodology](https://github.com/clocksmith/doppler/blob/main/docs/benchmark-methodology.md), and [release matrix](https://github.com/clocksmith/doppler/blob/main/docs/release-matrix.md) |
257
+ ### Pick a path
258
+
259
+ - **Application builders:** start with [getting started](https://github.com/clocksmith/doppler/blob/main/docs/getting-started.md), [Root API](https://github.com/clocksmith/doppler/blob/main/docs/api/root.md), and the [OpenAI-compatible server](#openai-compatible-server).
260
+ - **Integrators:** use the [RDRR format](https://github.com/clocksmith/doppler/blob/main/docs/rdrr-format.md), [support matrix](https://github.com/clocksmith/doppler/blob/main/docs/model-support-matrix.md), and [Program Bundles](https://github.com/clocksmith/doppler/blob/main/docs/integration/program-bundle.md).
261
+ - **Kernel/inference engineers:** follow [architecture](https://github.com/clocksmith/doppler/blob/main/docs/architecture.md), [performance optimization](https://github.com/clocksmith/doppler/blob/main/docs/developer-guides/16-kernel-performance-optimization.md), and the [challenger framework](https://github.com/clocksmith/doppler/blob/main/docs/local-gpu-challenger-framework.md).
262
+ - **Evidence reviewers:** review the [scoreboard](https://github.com/clocksmith/doppler/blob/main/docs/model-competition-scoreboard.md), [methodology](https://github.com/clocksmith/doppler/blob/main/docs/benchmark-methodology.md), and [release matrix](https://github.com/clocksmith/doppler/blob/main/docs/release-matrix.md).
241
263
 
242
264
  The [docs index](https://github.com/clocksmith/doppler/blob/main/docs/INDEX.md)
243
265
  owns the complete model, subsystem, API, architecture, and operator inventory.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doppler-gpu",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "description": "Browser-native WebGPU inference engine for local intent and inference loops",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -2,12 +2,79 @@ import type { InferencePipeline, KVCacheSnapshot, PromptInput } from '../../infe
2
2
  import type { ChatMessage } from '../../inference/pipelines/text/chat-format.js';
3
3
  import type { GenerateOptions } from '../../generation/index.js';
4
4
  import type { RDRRManifest } from '../../formats/rdrr/index.js';
5
- import type { LogitsStepResult, PrefillResult, SequenceEncodeOptions, SequenceEncodeResult } from '../../inference/pipelines/text/types.d.ts';
5
+ import type { LogitsStepResult, PipelineStats, PrefillResult, SequenceEncodeOptions, SequenceEncodeResult } from '../../inference/pipelines/text/types.d.ts';
6
6
  import type { LoRAManifest } from './types.js';
7
7
  import type { LoRALoadOptions } from './lora.js';
8
8
 
9
9
  export type DopplerGenerateOptions = Omit<GenerateOptions, 'stopTokens'>;
10
10
 
11
+ export interface DopplerGenerationConfigEvidence {
12
+ maxTokens: number;
13
+ temperature: number;
14
+ topP: number;
15
+ topK: number;
16
+ repetitionPenalty: number;
17
+ repetitionPenaltyWindow: number;
18
+ greedyThreshold: number;
19
+ suppressSpecialTokens: boolean;
20
+ suppressSpecialLikeTokens: boolean;
21
+ suppressTokenIds: number[];
22
+ stopSequences: string[];
23
+ useChatTemplate: boolean;
24
+ useSpeculative: boolean;
25
+ seed: number | null;
26
+ }
27
+
28
+ export interface DopplerGenerationBackendIdentity {
29
+ backend: 'webgpu';
30
+ adapter: {
31
+ vendor: string | null;
32
+ architecture: string | null;
33
+ device: string | null;
34
+ description: string | null;
35
+ };
36
+ hasF16: boolean;
37
+ hasSubgroups: boolean;
38
+ maxBufferSize: number;
39
+ deviceEpoch: number;
40
+ kernelPathId: string | null;
41
+ kernelPathSource: string | null;
42
+ executionPlanId: string | null;
43
+ activationDtype: string | null;
44
+ }
45
+
46
+ export interface DopplerGenerationEvidence {
47
+ schema: 'doppler_generation_evidence/v1';
48
+ outputText: string;
49
+ tokenIds: number[];
50
+ transcript: {
51
+ schema: 'doppler_generation_transcript/v1';
52
+ outputText: string;
53
+ tokenIds: number[];
54
+ };
55
+ transcriptHash: string;
56
+ generationConfig: DopplerGenerationConfigEvidence;
57
+ generationConfigHash: string;
58
+ runtimeProfile: {
59
+ schema: 'doppler_runtime_profile/v1';
60
+ runtime: {
61
+ package: 'doppler-gpu';
62
+ version: string;
63
+ surface: 'node' | 'browser';
64
+ };
65
+ model: {
66
+ modelId: string | null;
67
+ manifestHash: string | null;
68
+ activeAdapter: string | null;
69
+ };
70
+ backendIdentity: DopplerGenerationBackendIdentity;
71
+ };
72
+ runtimeProfileHash: string;
73
+ backendIdentity: DopplerGenerationBackendIdentity;
74
+ backendIdentityHash: string;
75
+ stats: PipelineStats | null;
76
+ }
77
+
11
78
  export interface DopplerChatResponse {
12
79
  content: string;
13
80
  usage: {
@@ -20,6 +87,7 @@ export interface DopplerChatResponse {
20
87
  export interface DopplerModelHandle {
21
88
  generate(prompt: string, options?: DopplerGenerateOptions): AsyncGenerator<string, void, void>;
22
89
  generateText(prompt: string, options?: DopplerGenerateOptions): Promise<string>;
90
+ generateWithEvidence(prompt: string, options?: DopplerGenerateOptions): Promise<DopplerGenerationEvidence>;
23
91
  chat(messages: ChatMessage[], options?: DopplerGenerateOptions): AsyncGenerator<string, void, void>;
24
92
  chatText(messages: ChatMessage[], options?: DopplerGenerateOptions): Promise<DopplerChatResponse>;
25
93
  encodeSequence(sequence: string, options?: SequenceEncodeOptions): Promise<SequenceEncodeResult>;
@@ -1,5 +1,8 @@
1
1
  import { getKernelCapabilities } from '../../gpu/device.js';
2
2
  import { formatChatMessages } from '../../inference/pipelines/text/chat-format.js';
3
+ import { resolveSamplingConfig } from '../../inference/pipelines/text/sampling-config.js';
4
+ import { DOPPLER_VERSION } from '../../version.js';
5
+ import { isNodeRuntime } from '../../utils/runtime-env.js';
3
6
  import {
4
7
  activateLoRAFromTrainingOutputForPipeline,
5
8
  getActiveLoRAForPipeline,
@@ -58,6 +61,208 @@ async function collectText(iterable) {
58
61
  return output;
59
62
  }
60
63
 
64
+ const GENERATION_EVIDENCE_SCHEMA = 'doppler_generation_evidence/v1';
65
+ const GENERATION_TRANSCRIPT_SCHEMA = 'doppler_generation_transcript/v1';
66
+ const RUNTIME_PROFILE_SCHEMA = 'doppler_runtime_profile/v1';
67
+
68
+ function canonicalizeEvidence(value) {
69
+ if (value === null || typeof value === 'boolean' || typeof value === 'string') {
70
+ return JSON.stringify(value);
71
+ }
72
+ if (typeof value === 'number') {
73
+ if (!Number.isFinite(value)) {
74
+ throw new Error('Doppler generation evidence cannot hash non-finite numbers.');
75
+ }
76
+ return JSON.stringify(value);
77
+ }
78
+ if (Array.isArray(value)) {
79
+ return `[${value.map((entry) => canonicalizeEvidence(entry)).join(',')}]`;
80
+ }
81
+ if (value && typeof value === 'object') {
82
+ const entries = Object.keys(value)
83
+ .sort()
84
+ .map((key) => `${JSON.stringify(key)}:${canonicalizeEvidence(value[key])}`);
85
+ return `{${entries.join(',')}}`;
86
+ }
87
+ throw new Error(`Doppler generation evidence cannot hash ${typeof value} values.`);
88
+ }
89
+
90
+ function bytesToHex(bytes) {
91
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
92
+ }
93
+
94
+ async function hashEvidenceValue(value) {
95
+ if (!globalThis.crypto?.subtle) {
96
+ throw new Error('Doppler generation evidence requires Web Crypto SHA-256 support.');
97
+ }
98
+ const bytes = new TextEncoder().encode(canonicalizeEvidence(value));
99
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', bytes);
100
+ return `sha256:${bytesToHex(new Uint8Array(digest))}`;
101
+ }
102
+
103
+ function cleanEvidenceString(value) {
104
+ const text = String(value ?? '').trim();
105
+ return text || null;
106
+ }
107
+
108
+ function buildAdapterIdentity(deviceInfo = {}) {
109
+ return {
110
+ vendor: cleanEvidenceString(deviceInfo.vendor),
111
+ architecture: cleanEvidenceString(deviceInfo.architecture),
112
+ device: cleanEvidenceString(deviceInfo.device),
113
+ description: cleanEvidenceString(deviceInfo.description),
114
+ };
115
+ }
116
+
117
+ function buildGenerationBackendIdentity({
118
+ deviceInfo = null,
119
+ kernelCapabilities = null,
120
+ stats = null,
121
+ } = {}) {
122
+ const capabilities = kernelCapabilities && typeof kernelCapabilities === 'object'
123
+ ? kernelCapabilities
124
+ : {};
125
+ const adapter = deviceInfo && typeof deviceInfo === 'object'
126
+ ? deviceInfo
127
+ : (capabilities.adapterInfo || {});
128
+ const executionPlan = stats?.executionPlan || null;
129
+ const finalPlanId = executionPlan?.finalActivePlanId
130
+ || executionPlan?.activePlanIdAtStart
131
+ || null;
132
+ const primaryPlan = executionPlan?.primary || null;
133
+ const fallbackPlan = executionPlan?.fallback || null;
134
+ const finalPlan = finalPlanId && fallbackPlan?.id === finalPlanId
135
+ ? fallbackPlan
136
+ : primaryPlan;
137
+ return {
138
+ backend: 'webgpu',
139
+ adapter: buildAdapterIdentity(adapter),
140
+ hasF16: capabilities.hasF16 === true,
141
+ hasSubgroups: capabilities.hasSubgroups === true,
142
+ maxBufferSize: Number(capabilities.maxBufferSize || 0),
143
+ deviceEpoch: Number(capabilities.deviceEpoch || 0),
144
+ kernelPathId: cleanEvidenceString(stats?.kernelPathId || finalPlan?.kernelPathId),
145
+ kernelPathSource: cleanEvidenceString(stats?.kernelPathSource || finalPlan?.kernelPathSource),
146
+ executionPlanId: cleanEvidenceString(finalPlanId),
147
+ activationDtype: cleanEvidenceString(finalPlan?.activationDtype),
148
+ };
149
+ }
150
+
151
+ async function buildGenerationEvidence({
152
+ outputText,
153
+ tokenIds,
154
+ generationConfig,
155
+ modelId,
156
+ manifestHash,
157
+ activeAdapter,
158
+ backendIdentity,
159
+ stats,
160
+ } = {}) {
161
+ if (typeof outputText !== 'string') {
162
+ throw new Error('Doppler generation evidence requires outputText.');
163
+ }
164
+ if (!Array.isArray(tokenIds) || tokenIds.some((tokenId) => !Number.isInteger(tokenId) || tokenId < 0)) {
165
+ throw new Error('Doppler generation evidence requires non-negative integer tokenIds.');
166
+ }
167
+ const transcript = {
168
+ schema: GENERATION_TRANSCRIPT_SCHEMA,
169
+ outputText,
170
+ tokenIds: [...tokenIds],
171
+ };
172
+ const generationConfigHash = await hashEvidenceValue(generationConfig);
173
+ const transcriptHash = await hashEvidenceValue(transcript);
174
+ const backendIdentityHash = await hashEvidenceValue(backendIdentity);
175
+ const runtimeProfile = {
176
+ schema: RUNTIME_PROFILE_SCHEMA,
177
+ runtime: {
178
+ package: 'doppler-gpu',
179
+ version: DOPPLER_VERSION,
180
+ surface: isNodeRuntime() ? 'node' : 'browser',
181
+ },
182
+ model: {
183
+ modelId: cleanEvidenceString(modelId),
184
+ manifestHash: cleanEvidenceString(manifestHash),
185
+ activeAdapter: cleanEvidenceString(activeAdapter),
186
+ },
187
+ backendIdentity,
188
+ };
189
+ const runtimeProfileHash = await hashEvidenceValue(runtimeProfile);
190
+ return {
191
+ schema: GENERATION_EVIDENCE_SCHEMA,
192
+ outputText,
193
+ tokenIds: [...tokenIds],
194
+ transcript,
195
+ transcriptHash,
196
+ generationConfig,
197
+ generationConfigHash,
198
+ runtimeProfile,
199
+ runtimeProfileHash,
200
+ backendIdentity,
201
+ backendIdentityHash,
202
+ stats: stats && typeof stats === 'object' ? stats : null,
203
+ };
204
+ }
205
+
206
+ function resolveUseChatTemplate(pipeline, options) {
207
+ if (typeof options.useChatTemplate === 'boolean') {
208
+ return options.useChatTemplate;
209
+ }
210
+ const runtimeValue = pipeline?.runtimeConfig?.inference?.chatTemplate?.enabled;
211
+ if (typeof runtimeValue === 'boolean') {
212
+ return runtimeValue;
213
+ }
214
+ const modelValue = pipeline?.modelConfig?.chatTemplateEnabled;
215
+ return typeof modelValue === 'boolean' ? modelValue : false;
216
+ }
217
+
218
+ function resolveGenerationConfigEvidence(pipeline, options) {
219
+ const runtimeConfig = pipeline?.runtimeConfig;
220
+ const generation = runtimeConfig?.inference?.generation;
221
+ if (!generation || typeof generation !== 'object' || Array.isArray(generation)) {
222
+ throw new Error('Loaded Doppler pipeline does not expose resolved generation config.');
223
+ }
224
+ const maxTokens = options.maxTokens ?? generation.maxTokens;
225
+ if (!Number.isInteger(maxTokens) || maxTokens <= 0) {
226
+ throw new Error('Resolved Doppler generation maxTokens must be a positive integer.');
227
+ }
228
+ const sampling = resolveSamplingConfig(options, runtimeConfig);
229
+ const stopSequences = options.stopSequences ?? [];
230
+ if (!Array.isArray(stopSequences) || stopSequences.some((value) => typeof value !== 'string')) {
231
+ throw new Error('Resolved Doppler stopSequences must be an array of strings.');
232
+ }
233
+ const useSpeculative = options.useSpeculative ?? generation.useSpeculative;
234
+ if (typeof useSpeculative !== 'boolean') {
235
+ throw new Error('Resolved Doppler useSpeculative must be a boolean.');
236
+ }
237
+ const seed = options.seed ?? null;
238
+ if (seed !== null && (!Number.isFinite(seed) || seed < 0)) {
239
+ throw new Error('Resolved Doppler seed must be null or a non-negative number.');
240
+ }
241
+ return {
242
+ maxTokens,
243
+ temperature: sampling.temperature,
244
+ topP: sampling.topP,
245
+ topK: sampling.topK,
246
+ repetitionPenalty: sampling.repetitionPenalty,
247
+ repetitionPenaltyWindow: sampling.repetitionPenaltyWindow,
248
+ greedyThreshold: sampling.greedyThreshold,
249
+ suppressSpecialTokens: sampling.suppressSpecialTokens,
250
+ suppressSpecialLikeTokens: sampling.suppressSpecialLikeTokens,
251
+ suppressTokenIds: [...sampling.suppressTokenIds],
252
+ stopSequences: [...stopSequences],
253
+ useChatTemplate: resolveUseChatTemplate(pipeline, options),
254
+ useSpeculative,
255
+ seed,
256
+ };
257
+ }
258
+
259
+ function decodeGeneratedTokens(pipeline, tokenIds) {
260
+ if (!pipeline?.tokenizer || typeof pipeline.tokenizer.decode !== 'function') {
261
+ throw new Error('Loaded Doppler pipeline does not expose tokenizer.decode().');
262
+ }
263
+ return String(pipeline.tokenizer.decode(tokenIds, true, false));
264
+ }
265
+
61
266
  export function createModelHandle(pipeline, resolved) {
62
267
  return {
63
268
  generate(prompt, options = {}) {
@@ -68,6 +273,32 @@ export function createModelHandle(pipeline, resolved) {
68
273
  assertSupportedGenerationOptions(options);
69
274
  return collectText(pipeline.generate(prompt, options));
70
275
  },
276
+ async generateWithEvidence(prompt, options = {}) {
277
+ assertSupportedGenerationOptions(options);
278
+ const generationConfig = resolveGenerationConfigEvidence(pipeline, options);
279
+ const result = await pipeline.generateTokenIds(prompt, options);
280
+ const tokenIds = Array.from(result?.tokenIds || [], Number);
281
+ const outputText = decodeGeneratedTokens(pipeline, tokenIds);
282
+ const stats = result?.stats || pipeline.getStats?.() || null;
283
+ const kernelCapabilities = typeof pipeline.getKernelCapabilities === 'function'
284
+ ? pipeline.getKernelCapabilities()
285
+ : getKernelCapabilities();
286
+ const backendIdentity = buildGenerationBackendIdentity({
287
+ deviceInfo: kernelCapabilities?.adapterInfo || null,
288
+ kernelCapabilities,
289
+ stats,
290
+ });
291
+ return buildGenerationEvidence({
292
+ outputText,
293
+ tokenIds,
294
+ generationConfig,
295
+ modelId: resolved.modelId,
296
+ manifestHash: resolved.manifestHash || null,
297
+ activeAdapter: getActiveLoRAForPipeline(pipeline),
298
+ backendIdentity,
299
+ stats,
300
+ });
301
+ },
71
302
  chat(messages, options = {}) {
72
303
  assertSupportedGenerationOptions(options);
73
304
  return pipeline.generate(messages, options);
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const DOPPLER_VERSION = '0.4.14';
1
+ export const DOPPLER_VERSION = '0.4.15';
2
2
  export const DOPPLER_PROVIDER_VERSION = DOPPLER_VERSION;