doppler-gpu 0.4.10 → 0.4.14

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 (131) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +40 -1
  3. package/models/catalog.json +637 -32
  4. package/package.json +24 -3
  5. package/src/client/doppler-registry.js +6 -0
  6. package/src/client/doppler-registry.json +135 -13
  7. package/src/client/runtime/lora.d.ts +10 -0
  8. package/src/client/runtime/lora.js +69 -0
  9. package/src/client/runtime/model-manager.js +6 -167
  10. package/src/client/runtime/model-session.d.ts +3 -1
  11. package/src/client/runtime/model-session.js +6 -0
  12. package/src/client/wrap-pipeline-handle.js +7 -0
  13. package/src/config/conversion/amplify/amplify-120m-f16-af32.json +516 -0
  14. package/src/config/conversion/esm/esm2-t12-35m-ur50d-f32-af32.json +571 -0
  15. package/src/config/conversion/esmc/esmc-300m-f32-af32.json +342 -0
  16. package/src/config/conversion/nucleotide-transformer/nucleotide-transformer-v2-50m-f32-af32.json +388 -0
  17. package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +3 -2
  18. package/src/config/kernels/kernel-ref-digests.js +2 -1
  19. package/src/config/kernels/registry.json +73 -11
  20. package/src/config/merge.js +24 -0
  21. package/src/config/required-inference-fields-contract-check.js +2 -0
  22. package/src/config/schema/adapter.schema.d.ts +6 -1
  23. package/src/config/schema/adapter.schema.js +5 -0
  24. package/src/config/schema/converter.schema.d.ts +7 -0
  25. package/src/config/schema/converter.schema.js +15 -0
  26. package/src/config/schema/inference.schema.d.ts +8 -0
  27. package/src/config/schema/manifest.schema.d.ts +32 -1
  28. package/src/config/schema/manifest.schema.js +26 -0
  29. package/src/converter/conversion-plan.js +15 -1
  30. package/src/converter/core.js +5 -4
  31. package/src/converter/source-tensor-rules.d.ts +50 -0
  32. package/src/converter/source-tensor-rules.js +180 -0
  33. package/src/converter/source-tokenizer.d.ts +45 -0
  34. package/src/converter/source-tokenizer.js +155 -0
  35. package/src/experimental/adapters/artifact-contract.d.ts +83 -0
  36. package/src/experimental/adapters/artifact-contract.js +254 -0
  37. package/src/experimental/adapters/index.d.ts +25 -0
  38. package/src/experimental/adapters/index.js +12 -0
  39. package/src/experimental/adapters/lora-loader.js +24 -4
  40. package/src/experimental/bridge/trainer-artifact-bridge.d.ts +2 -1
  41. package/src/experimental/bridge/trainer-artifact-bridge.js +35 -13
  42. package/src/experimental/training/artifacts.d.ts +160 -0
  43. package/src/experimental/training/attention-backward.d.ts +64 -0
  44. package/src/experimental/training/attention-forward.d.ts +22 -0
  45. package/src/experimental/training/attention-forward.js +82 -0
  46. package/src/experimental/training/autograd.d.ts +76 -0
  47. package/src/experimental/training/checkpoint.d.ts +36 -0
  48. package/src/experimental/training/clip.d.ts +9 -0
  49. package/src/experimental/training/dataloader.d.ts +8 -0
  50. package/src/experimental/training/distillation/student-fixture.js +1 -0
  51. package/src/experimental/training/export.d.ts +41 -0
  52. package/src/experimental/training/lora-pipeline.d.ts +186 -0
  53. package/src/experimental/training/lora-pipeline.js +5 -0
  54. package/src/experimental/training/lora.d.ts +20 -0
  55. package/src/experimental/training/lora.js +4 -3
  56. package/src/experimental/training/loss-scaling.d.ts +21 -0
  57. package/src/experimental/training/loss.d.ts +10 -0
  58. package/src/experimental/training/native-qwen-lora.d.ts +106 -0
  59. package/src/experimental/training/native-qwen-lora.js +449 -0
  60. package/src/experimental/training/objectives/base.d.ts +58 -0
  61. package/src/experimental/training/optimizer.d.ts +22 -0
  62. package/src/experimental/training/optimizer.js +1 -0
  63. package/src/experimental/training/runner.d.ts +249 -0
  64. package/src/experimental/training/trainer.d.ts +89 -0
  65. package/src/experimental/training/workloads.d.ts +205 -0
  66. package/src/gpu/kernels/backward/adam.d.ts +1 -0
  67. package/src/gpu/kernels/backward/adam.js +6 -2
  68. package/src/gpu/kernels/backward/adam.wgsl +3 -2
  69. package/src/gpu/kernels/backward/matmul_backward_q4k.wgsl +90 -0
  70. package/src/gpu/kernels/backward/utils.js +18 -4
  71. package/src/inference/pipelines/text/attention/attn-config.js +2 -0
  72. package/src/inference/pipelines/text/attention/projections.js +161 -24
  73. package/src/inference/pipelines/text/attention/record.js +67 -9
  74. package/src/inference/pipelines/text/attention/run.js +60 -7
  75. package/src/inference/pipelines/text/attention/types.js +18 -9
  76. package/src/inference/pipelines/text/config.d.ts +5 -0
  77. package/src/inference/pipelines/text/config.js +91 -0
  78. package/src/inference/pipelines/text/ffn/dense.js +205 -2
  79. package/src/inference/pipelines/text/ffn/standard.js +50 -3
  80. package/src/inference/pipelines/text/generator-helpers.js +11 -1
  81. package/src/inference/pipelines/text/generator-runtime.js +63 -15
  82. package/src/inference/pipelines/text/generator-steps.js +3 -1
  83. package/src/inference/pipelines/text/generator.d.ts +5 -1
  84. package/src/inference/pipelines/text/generator.js +196 -3
  85. package/src/inference/pipelines/text/init-qkv-fusion.js +85 -1
  86. package/src/inference/pipelines/text/init.d.ts +2 -0
  87. package/src/inference/pipelines/text/init.js +2 -0
  88. package/src/inference/pipelines/text/layer.js +6 -0
  89. package/src/inference/pipelines/text/linear-attention.d.ts +2 -0
  90. package/src/inference/pipelines/text/linear-attention.js +77 -6
  91. package/src/inference/pipelines/text/logits/cpu.d.ts +6 -0
  92. package/src/inference/pipelines/text/logits/cpu.js +22 -0
  93. package/src/inference/pipelines/text/logits/index.d.ts +1 -1
  94. package/src/inference/pipelines/text/logits/index.js +85 -11
  95. package/src/inference/pipelines/text/logits/types.d.ts +4 -0
  96. package/src/inference/pipelines/text/lora-types.d.ts +6 -1
  97. package/src/inference/pipelines/text/lora-types.js +5 -0
  98. package/src/inference/pipelines/text/ops.js +33 -0
  99. package/src/inference/pipelines/text/types.d.ts +66 -0
  100. package/src/inference/pipelines/text/weights.d.ts +10 -0
  101. package/src/inference/pipelines/text/weights.js +33 -1
  102. package/src/inference/pipelines/text.d.ts +9 -2
  103. package/src/inference/pipelines/text.js +116 -0
  104. package/src/inference/tokenizers/behavior-flags.js +5 -1
  105. package/src/inference/tokenizers/bundled.js +99 -8
  106. package/src/loader/doppler-loader.d.ts +2 -0
  107. package/src/loader/doppler-loader.js +9 -0
  108. package/src/loader/final-weights-loader.d.ts +8 -0
  109. package/src/loader/final-weights-loader.js +42 -0
  110. package/src/loader/layer-loader.d.ts +6 -0
  111. package/src/loader/layer-loader.js +102 -3
  112. package/src/loader/loader-types.d.ts +15 -2
  113. package/src/models/diffusiongemma.js +1 -1
  114. package/src/models/embeddinggemma.js +1 -1
  115. package/src/models/gemma3.js +1 -1
  116. package/src/models/gemma4.js +1 -1
  117. package/src/models/qwen3.js +1 -1
  118. package/src/tooling/hf-registry-utils.js +1 -1
  119. package/src/tooling/node-browser-command-runner.d.ts +16 -0
  120. package/src/tooling/node-browser-command-runner.js +1 -1
  121. package/src/tooling/node-converter.js +33 -1
  122. package/src/tooling/node-webgpu.js +85 -2
  123. package/src/training-browser.d.ts +19 -0
  124. package/src/training-browser.js +13 -0
  125. package/src/training.d.ts +137 -0
  126. package/src/training.js +219 -0
  127. package/src/version.js +1 -1
  128. package/tests/kernels/browser/kernel-suite.js +9 -1
  129. package/tests/kernels/browser/test-page.js +4 -2
  130. package/tests/kernels/reference/adam.js +4 -2
  131. package/NOTICE +0 -5
@@ -29,6 +29,19 @@ export const COLUMBO_QWEN_ADAPTER_PARITY_CHECKS = Object.freeze([
29
29
  'browser_capability_evaluation',
30
30
  ]);
31
31
 
32
+ export const TINKER_PEFT_BROWSER_ADAPTER_PARITY_CHECKS = Object.freeze([
33
+ 'source_artifact_byte_identity',
34
+ 'tokenizer_and_prompt_identity',
35
+ 'architecture_and_conversion_lineage',
36
+ 'evaluation_input_identity',
37
+ 'tinker_checkpoint_vs_peft_reference',
38
+ 'peft_reference_vs_doppler_f16',
39
+ 'doppler_f16_vs_quantized_browser',
40
+ 'gamma_sealed_task_gain',
41
+ 'gamma_retention_floor',
42
+ 'browser_capability_evaluation',
43
+ ]);
44
+
32
45
  const SHA256_PATTERN = /^[0-9a-f]{64}$/;
33
46
  const FILE_ROLES_BY_KIND = Object.freeze({
34
47
  [TRAINER_ARTIFACT_KIND_FULL_CHECKPOINT]: Object.freeze([
@@ -44,9 +57,22 @@ const FILE_ROLES_BY_KIND = Object.freeze({
44
57
  'training_report',
45
58
  ]),
46
59
  });
47
- const PARITY_CHECKS_BY_PROFILE = Object.freeze({
48
- translation_full_checkpoint: TRANSLATION_FULL_CHECKPOINT_PARITY_CHECKS,
49
- columbo_qwen_adapter: COLUMBO_QWEN_ADAPTER_PARITY_CHECKS,
60
+ const PARITY_PROFILES = Object.freeze({
61
+ translation_full_checkpoint: Object.freeze({
62
+ artifactKind: TRAINER_ARTIFACT_KIND_FULL_CHECKPOINT,
63
+ selectionAuthority: 'clocksmith/gamma',
64
+ requiredChecks: TRANSLATION_FULL_CHECKPOINT_PARITY_CHECKS,
65
+ }),
66
+ columbo_qwen_adapter: Object.freeze({
67
+ artifactKind: TRAINER_ARTIFACT_KIND_PEFT_ADAPTER,
68
+ selectionAuthority: 'clocksmith/columbo',
69
+ requiredChecks: COLUMBO_QWEN_ADAPTER_PARITY_CHECKS,
70
+ }),
71
+ tinker_peft_browser_adapter: Object.freeze({
72
+ artifactKind: TRAINER_ARTIFACT_KIND_PEFT_ADAPTER,
73
+ selectionAuthority: 'clocksmith/gamma',
74
+ requiredChecks: TINKER_PEFT_BROWSER_ADAPTER_PARITY_CHECKS,
75
+ }),
50
76
  });
51
77
 
52
78
  function stableJson(value) {
@@ -181,18 +207,16 @@ function normalizeParity(parity, artifactKind) {
181
207
  throw new Error('trainer artifact bridge: parity must be an object.');
182
208
  }
183
209
  const profile = requireText(parity.profile, 'parity.profile');
184
- const canonicalChecks = PARITY_CHECKS_BY_PROFILE[profile];
185
- if (!canonicalChecks) {
210
+ const profileContract = PARITY_PROFILES[profile];
211
+ if (!profileContract) {
186
212
  throw new Error(`trainer artifact bridge: unsupported parity profile "${profile}".`);
187
213
  }
188
- const expectedProfile = artifactKind === TRAINER_ARTIFACT_KIND_FULL_CHECKPOINT
189
- ? 'translation_full_checkpoint'
190
- : 'columbo_qwen_adapter';
191
- if (profile !== expectedProfile) {
214
+ if (profileContract.artifactKind !== artifactKind) {
192
215
  throw new Error(
193
- `trainer artifact bridge: artifact kind "${artifactKind}" requires parity profile "${expectedProfile}".`
216
+ `trainer artifact bridge: parity profile "${profile}" does not support artifact kind "${artifactKind}".`
194
217
  );
195
218
  }
219
+ const canonicalChecks = profileContract.requiredChecks;
196
220
  const requiredChecks = Array.isArray(parity.requiredChecks) ? parity.requiredChecks : [];
197
221
  if (stableJson(requiredChecks) !== stableJson(canonicalChecks)) {
198
222
  throw new Error(`trainer artifact bridge: parity.requiredChecks must match profile "${profile}".`);
@@ -435,9 +459,7 @@ export function assertTrainerArtifactCandidateEntry(descriptor) {
435
459
  if (normalized.selection.status !== 'selected' || !normalized.selection.receipt) {
436
460
  throw new Error('trainer artifact bridge: candidate entry denied; selection receipt is required.');
437
461
  }
438
- const expectedAuthority = normalized.artifact.kind === TRAINER_ARTIFACT_KIND_FULL_CHECKPOINT
439
- ? 'clocksmith/gamma'
440
- : 'clocksmith/columbo';
462
+ const expectedAuthority = PARITY_PROFILES[normalized.parity.profile].selectionAuthority;
441
463
  if (normalized.selection.authority !== expectedAuthority) {
442
464
  throw new Error(
443
465
  `trainer artifact bridge: candidate entry denied; selection authority must be "${expectedAuthority}".`
@@ -0,0 +1,160 @@
1
+ import type { TrainingConfigSchema } from '../../config/training-defaults.d.ts';
2
+ import type { DistillTrainingStage } from '../../config/schema/distill-training.schema.js';
3
+ import type { UlTrainingStage } from '../../config/schema/ul-training.schema.js';
4
+
5
+ export interface UlTrainingContract {
6
+ enabled: boolean;
7
+ stage: UlTrainingStage | null;
8
+ artifactDir: string | null;
9
+ stage1Artifact: string | null;
10
+ stage1ArtifactHash: string | null;
11
+ }
12
+
13
+ export interface DistillTrainingContract {
14
+ enabled: boolean;
15
+ stage: DistillTrainingStage | null;
16
+ artifactDir: string | null;
17
+ stageAArtifact: string | null;
18
+ stageAArtifactHash: string | null;
19
+ teacherModelId: string | null;
20
+ studentModelId: string | null;
21
+ datasetId: string | null;
22
+ datasetPath: string | null;
23
+ languagePair: string | null;
24
+ allowHintFallback: boolean;
25
+ }
26
+
27
+ export interface UlArtifactFinalizeResult {
28
+ kind: 'ul';
29
+ stage: UlTrainingStage;
30
+ runDir: string;
31
+ metricsPath: string;
32
+ manifestPath: string;
33
+ manifestHash: string;
34
+ manifestContentHash: string;
35
+ manifestFileHash: string;
36
+ stage1Dependency: {
37
+ path: string;
38
+ hash: string;
39
+ manifestHash: string | null;
40
+ } | null;
41
+ }
42
+
43
+ export interface DistillArtifactFinalizeResult {
44
+ kind: 'distill';
45
+ stage: DistillTrainingStage;
46
+ runDir: string;
47
+ metricsPath: string;
48
+ manifestPath: string;
49
+ manifestHash: string;
50
+ manifestContentHash: string;
51
+ manifestFileHash: string;
52
+ stageADependency: {
53
+ path: string;
54
+ hash: string;
55
+ manifestHash: string | null;
56
+ metricsHash: string;
57
+ metricsSummary: {
58
+ stepCount: number;
59
+ kdCount: number;
60
+ tripletCount: number;
61
+ kdMean: number | null;
62
+ tripletMean: number | null;
63
+ totalLossMean: number | null;
64
+ };
65
+ } | null;
66
+ }
67
+
68
+ export interface UlArtifactSession {
69
+ appendStep(entry: Record<string, unknown>): Promise<void>;
70
+ finalize(stepMetrics: Record<string, unknown>[]): Promise<UlArtifactFinalizeResult>;
71
+ }
72
+
73
+ export interface DistillArtifactSession {
74
+ appendStep(entry: Record<string, unknown>): Promise<void>;
75
+ finalize(stepMetrics: Record<string, unknown>[]): Promise<DistillArtifactFinalizeResult>;
76
+ }
77
+
78
+ export interface CreateUlArtifactSessionOptions {
79
+ config: TrainingConfigSchema;
80
+ stage: UlTrainingStage;
81
+ runOptions?: Record<string, unknown>;
82
+ }
83
+
84
+ export interface CreateDistillArtifactSessionOptions {
85
+ config: TrainingConfigSchema;
86
+ stage: DistillTrainingStage;
87
+ runOptions?: Record<string, unknown>;
88
+ }
89
+
90
+ export interface Stage1ArtifactContext {
91
+ manifestPath: string;
92
+ manifestHash: string;
93
+ ulContractHash: string | null;
94
+ latentDataset: {
95
+ path: string;
96
+ hash: string;
97
+ count: number;
98
+ summary: {
99
+ lambdaMean: number;
100
+ noisyStdMean: number;
101
+ cleanStdMean: number;
102
+ noiseStdMean: number;
103
+ scheduleMaxStep: number;
104
+ vectorCount: number;
105
+ };
106
+ entries: Record<string, unknown>[];
107
+ };
108
+ }
109
+
110
+ export interface StageAArtifactContext {
111
+ manifestPath: string;
112
+ manifestHash: string;
113
+ distillContractHash: string | null;
114
+ metrics: {
115
+ path: string;
116
+ hash: string;
117
+ count: number;
118
+ summary: {
119
+ stepCount: number;
120
+ kdCount: number;
121
+ tripletCount: number;
122
+ kdMean: number | null;
123
+ tripletMean: number | null;
124
+ totalLossMean: number | null;
125
+ };
126
+ entries: Record<string, unknown>[];
127
+ };
128
+ metricsSummary: {
129
+ stepCount: number;
130
+ kdCount: number;
131
+ tripletCount: number;
132
+ kdMean: number | null;
133
+ tripletMean: number | null;
134
+ totalLossMean: number | null;
135
+ };
136
+ }
137
+
138
+ export declare function resolveUlTrainingContract(
139
+ ulConfig: TrainingConfigSchema['training']['ul'] | null | undefined
140
+ ): UlTrainingContract;
141
+
142
+ export declare function resolveDistillTrainingContract(
143
+ distillConfig: TrainingConfigSchema['training']['distill'] | null | undefined
144
+ ): DistillTrainingContract;
145
+
146
+ export declare function createUlArtifactSession(
147
+ options: CreateUlArtifactSessionOptions
148
+ ): Promise<UlArtifactSession | null>;
149
+
150
+ export declare function createDistillArtifactSession(
151
+ options: CreateDistillArtifactSessionOptions
152
+ ): Promise<DistillArtifactSession | null>;
153
+
154
+ export declare function resolveStage1ArtifactContext(
155
+ config: TrainingConfigSchema
156
+ ): Promise<Stage1ArtifactContext | null>;
157
+
158
+ export declare function resolveStageAArtifactContext(
159
+ config: TrainingConfigSchema
160
+ ): Promise<StageAArtifactContext | null>;
@@ -0,0 +1,64 @@
1
+ import type { Tensor } from '../../gpu/tensor.js';
2
+
3
+ export interface AttentionBackwardOptions {
4
+ seqLen: number;
5
+ numHeads: number;
6
+ numKVHeads?: number;
7
+ headDim: number;
8
+ scale?: number;
9
+ causal?: boolean;
10
+ }
11
+
12
+ export interface AttentionGeometry {
13
+ seqLen: number;
14
+ numHeads: number;
15
+ numKVHeads: number;
16
+ headDim: number;
17
+ headsPerKV: number;
18
+ scale: number;
19
+ causal: boolean;
20
+ }
21
+
22
+ export interface AttentionBackwardResult {
23
+ gradQ: Tensor;
24
+ gradK: Tensor;
25
+ gradV: Tensor;
26
+ geometry: AttentionGeometry;
27
+ }
28
+
29
+ export interface AttentionBackwardDataResult {
30
+ dQ: Float32Array;
31
+ dK: Float32Array;
32
+ dV: Float32Array;
33
+ geometry: AttentionGeometry;
34
+ }
35
+
36
+ export declare function computeAttentionSoftmaxData(
37
+ qData: Float32Array,
38
+ kData: Float32Array,
39
+ options: AttentionBackwardOptions
40
+ ): Float32Array;
41
+
42
+ export declare function computeAttentionBackwardData(
43
+ qData: Float32Array,
44
+ kData: Float32Array,
45
+ vData: Float32Array,
46
+ softmaxData: Float32Array,
47
+ gradOutputData: Float32Array,
48
+ options: AttentionBackwardOptions
49
+ ): AttentionBackwardDataResult;
50
+
51
+ export declare function buildAttentionSoftmaxCache(
52
+ q: Tensor,
53
+ k: Tensor,
54
+ options: AttentionBackwardOptions
55
+ ): Promise<Tensor>;
56
+
57
+ export declare function attentionBackwardCpu(
58
+ q: Tensor,
59
+ k: Tensor,
60
+ v: Tensor,
61
+ softmax: Tensor | null,
62
+ gradOutput: Tensor,
63
+ options: AttentionBackwardOptions
64
+ ): Promise<AttentionBackwardResult>;
@@ -0,0 +1,22 @@
1
+ import type { TrainingConfigSchema } from '../../config/training-defaults.d.ts';
2
+ import type { Tensor } from '../../gpu/tensor.js';
3
+
4
+ export declare function recordAttentionForward(
5
+ q: Tensor,
6
+ k: Tensor,
7
+ v: Tensor,
8
+ config: TrainingConfigSchema,
9
+ tape: unknown,
10
+ options?: {
11
+ seqLen?: number;
12
+ numHeads?: number;
13
+ numKVHeads?: number;
14
+ headDim?: number;
15
+ scale?: number;
16
+ causal?: boolean;
17
+ startPos?: number;
18
+ attnSoftcap?: number;
19
+ slidingWindow?: number;
20
+ kvLen?: number;
21
+ }
22
+ ): Promise<{ output: Tensor; softmax: Tensor | null }>;
@@ -0,0 +1,82 @@
1
+ import { runAttention } from '../../gpu/kernels/index.js';
2
+ import { buildAttentionSoftmaxCache } from './attention-backward.js';
3
+ import { OpType } from './autograd.js';
4
+
5
+ export async function recordAttentionForward(
6
+ q,
7
+ k,
8
+ v,
9
+ config,
10
+ tape,
11
+ options = {}
12
+ ) {
13
+ if (!tape || typeof tape.record !== 'function') {
14
+ throw new Error('recordAttentionForward requires an autograd tape');
15
+ }
16
+
17
+ const {
18
+ seqLen,
19
+ numHeads,
20
+ numKVHeads = numHeads,
21
+ headDim,
22
+ scale,
23
+ causal = true,
24
+ startPos = 0,
25
+ attnSoftcap = 0,
26
+ slidingWindow = 0,
27
+ kvLen = seqLen,
28
+ } = options;
29
+
30
+ if (!seqLen || !numHeads || !headDim) {
31
+ throw new Error('recordAttentionForward requires seqLen, numHeads, and headDim');
32
+ }
33
+
34
+ const resolvedScale = scale ?? 1.0 / Math.sqrt(headDim);
35
+ const recomputeForward = Boolean(config?.training?.attention?.recomputeForward);
36
+ const softmax = recomputeForward
37
+ ? null
38
+ : await buildAttentionSoftmaxCache(q, k, {
39
+ seqLen,
40
+ numHeads,
41
+ headDim,
42
+ scale: resolvedScale,
43
+ causal,
44
+ });
45
+
46
+ const attentionOptions = {
47
+ seqLen,
48
+ kvLen,
49
+ numHeads,
50
+ numKVHeads,
51
+ headDim,
52
+ scale: resolvedScale,
53
+ causal,
54
+ startPos,
55
+ attnSoftcap,
56
+ slidingWindow,
57
+ };
58
+
59
+ const output = await tape.record(
60
+ OpType.ATTENTION,
61
+ (inputQ, inputK, inputV) => runAttention(
62
+ inputQ,
63
+ inputK,
64
+ inputV,
65
+ null,
66
+ numHeads,
67
+ headDim,
68
+ attentionOptions
69
+ ),
70
+ [q, k, v, softmax],
71
+ {
72
+ seqLen,
73
+ numHeads,
74
+ headDim,
75
+ scale: resolvedScale,
76
+ causal,
77
+ recomputeForward,
78
+ }
79
+ );
80
+
81
+ return { output, softmax };
82
+ }
@@ -0,0 +1,76 @@
1
+ import type { Tensor } from '../../gpu/tensor.js';
2
+ import type { BackwardRegistrySchema } from '../../config/schema/backward-registry.schema.js';
3
+
4
+ export const OpType: {
5
+ EMBED: 'embed';
6
+ MATMUL: 'matmul';
7
+ RMSNORM: 'rmsnorm';
8
+ RESIDUAL_ADD: 'residual_add';
9
+ RESHAPE: 'reshape';
10
+ ROW_SLICE: 'row_slice';
11
+ LAYERNORM: 'layernorm';
12
+ ATTENTION: 'attention';
13
+ SOFTMAX: 'softmax';
14
+ ROPE: 'rope';
15
+ SILU: 'silu';
16
+ SILU_ROWSPLIT: 'silu_rowsplit';
17
+ SILU_GATED: 'silu_gated';
18
+ GELU: 'gelu';
19
+ SCALE: 'scale';
20
+ CROSS_ENTROPY: 'cross_entropy';
21
+ BIAS_ADD: 'bias_add';
22
+ UPSAMPLE2D: 'upsample2d';
23
+ PIXEL_SHUFFLE: 'pixel_shuffle';
24
+ GROUPNORM: 'groupnorm';
25
+ CONV2D: 'conv2d';
26
+ };
27
+
28
+ export declare function resolveMatmulBackwardOptions<T extends Record<string, unknown> = Record<string, unknown>>(
29
+ options?: T
30
+ ): T & {
31
+ computeGradInput: boolean;
32
+ computeGradWeight: boolean;
33
+ };
34
+
35
+ export declare function computeSiluGatedBackwardValues(
36
+ gate: ArrayLike<number>,
37
+ up: ArrayLike<number>,
38
+ gradOutput: ArrayLike<number>,
39
+ swigluLimit?: number
40
+ ): {
41
+ gradGate: Float32Array;
42
+ gradUp: Float32Array;
43
+ };
44
+
45
+ export interface AutogradRecord {
46
+ op: string;
47
+ inputs: Tensor[];
48
+ output: Tensor;
49
+ options?: Record<string, unknown>;
50
+ }
51
+
52
+ export interface BackwardSeed {
53
+ tensor: Tensor;
54
+ grad: Tensor;
55
+ }
56
+
57
+ export type BackwardSeedInput =
58
+ | Tensor
59
+ | Map<Tensor, Tensor>
60
+ | BackwardSeed[]
61
+ | { seeds: BackwardSeed[] };
62
+
63
+ export declare class AutogradTape {
64
+ constructor(registry: BackwardRegistrySchema);
65
+ registry: BackwardRegistrySchema;
66
+ records: AutogradRecord[];
67
+ watch<T extends Tensor>(tensor: T): T;
68
+ record(
69
+ op: string,
70
+ fn: (...args: Tensor[]) => Promise<Tensor>,
71
+ inputs: Tensor[],
72
+ options?: Record<string, unknown>
73
+ ): Promise<Tensor>;
74
+ backward(gradOutput: BackwardSeedInput): Promise<Map<Tensor, Tensor>>;
75
+ reset(): void;
76
+ }
@@ -0,0 +1,36 @@
1
+ export interface CheckpointStoreOptions {
2
+ dbName?: string;
3
+ storeName?: string;
4
+ version?: number;
5
+ nodeDir?: string;
6
+ configHash?: string;
7
+ datasetHash?: string;
8
+ tokenizerHash?: string;
9
+ optimizerHash?: string;
10
+ runtimeProfileId?: string;
11
+ kernelPathId?: string;
12
+ environmentMetadata?: unknown;
13
+ buildProvenance?: Record<string, unknown> | null;
14
+ priorCheckpointHash?: string;
15
+ expectedMetadata?: Record<string, unknown>;
16
+ forceResume?: boolean;
17
+ forceResumeReason?: string;
18
+ forceResumeSource?: string;
19
+ forceResumeOperator?: string | null;
20
+ }
21
+
22
+ export declare function saveCheckpoint(
23
+ key: string,
24
+ data: unknown,
25
+ options?: CheckpointStoreOptions
26
+ ): Promise<{
27
+ key: string;
28
+ path: string | null;
29
+ metadata: Record<string, unknown>;
30
+ data: unknown;
31
+ }>;
32
+
33
+ export declare function loadCheckpoint(
34
+ key: string,
35
+ options?: CheckpointStoreOptions
36
+ ): Promise<unknown | null>;
@@ -0,0 +1,9 @@
1
+ import type { TrainingConfigSchema } from '../../config/training-defaults.d.ts';
2
+ import type { Tensor } from '../../gpu/tensor.js';
3
+
4
+ import type { ClipMetrics } from './trainer.d.ts';
5
+
6
+ export declare function clipGradients(
7
+ grads: Map<Tensor, Tensor>,
8
+ config: TrainingConfigSchema
9
+ ): Promise<ClipMetrics>;
@@ -0,0 +1,8 @@
1
+ export declare class DataLoader<T> {
2
+ constructor(dataset: T[], batchSize: number, shuffle?: boolean);
3
+ dataset: T[];
4
+ batchSize: number;
5
+ shuffle: boolean;
6
+ collate(batch: T[]): T[] | unknown;
7
+ batches(): AsyncGenerator<T[] | unknown, void, void>;
8
+ }
@@ -186,6 +186,7 @@ function createTransformerLoraAdapters(config, dims) {
186
186
  outDim: shape.outDim,
187
187
  rank: config.rank,
188
188
  alpha: config.alpha,
189
+ dtype: 'f32',
189
190
  });
190
191
  }
191
192
  return adapters;
@@ -0,0 +1,41 @@
1
+ import type { AdapterManifest } from '../adapters/adapter-manifest.js';
2
+ import type { LoRAModuleName } from '../../inference/pipelines/text/lora-types.js';
3
+ import type { Tensor } from '../../gpu/tensor.js';
4
+
5
+ export interface LoRAExportTensor {
6
+ name: string;
7
+ tensor: Tensor | Float32Array | GPUBuffer;
8
+ shape?: [number, number];
9
+ dtype?: 'f16' | 'f32';
10
+ }
11
+
12
+ export interface LoRAExportOptions {
13
+ id: string;
14
+ name: string;
15
+ baseModel: string;
16
+ rank: number;
17
+ alpha: number;
18
+ targetModules: LoRAModuleName[];
19
+ version?: string;
20
+ description?: string;
21
+ metadata?: Record<string, unknown>;
22
+ tensors: LoRAExportTensor[];
23
+ format?: 'base64' | 'array';
24
+ weightsFormat?: 'json' | 'safetensors';
25
+ weightsPath?: string;
26
+ pretty?: boolean;
27
+ }
28
+
29
+ export interface LoRAExportResult {
30
+ manifest: AdapterManifest;
31
+ json: string;
32
+ weights?: ArrayBuffer;
33
+ weightsSha256?: string;
34
+ weightsPath?: string;
35
+ }
36
+
37
+ export declare function serializeLoRASafetensors(
38
+ tensors: Array<{ name: string; shape: [number, number]; data: Float32Array | number[] }>
39
+ ): ArrayBuffer;
40
+
41
+ export declare function exportLoRAAdapter(options: LoRAExportOptions): Promise<LoRAExportResult>;