@seanhogg/builderforce-memory-engine 2026.10.2 → 2026.10.3
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/dist/evermind/adapt.d.ts +7 -0
- package/dist/evermind/adapt.d.ts.map +1 -1
- package/dist/evermind/adapt.js +1 -1
- package/dist/evermind/adapt.js.map +1 -1
- package/dist/experience/index.d.ts +2 -2
- package/dist/experience/index.d.ts.map +1 -1
- package/dist/experience/index.js.map +1 -1
- package/dist/experience/store.d.ts +19 -1
- package/dist/experience/store.d.ts.map +1 -1
- package/dist/experience/store.js +14 -2
- package/dist/experience/store.js.map +1 -1
- package/dist/experience/types.d.ts +18 -0
- package/dist/experience/types.d.ts.map +1 -1
- package/dist/experience/types.js.map +1 -1
- package/dist/kernels/weight_update.d.ts.map +1 -1
- package/dist/kernels/weight_update.js +12 -0
- package/dist/kernels/weight_update.js.map +1 -1
- package/dist/ml/classical/ewma.d.ts +5 -4
- package/dist/ml/classical/ewma.d.ts.map +1 -1
- package/dist/ml/classical/ewma.js +2 -2
- package/dist/ml/classical/ewma.js.map +1 -1
- package/dist/ml/classical/index.d.ts +2 -2
- package/dist/ml/classical/index.d.ts.map +1 -1
- package/dist/ml/classical/index.js +1 -1
- package/dist/ml/classical/index.js.map +1 -1
- package/dist/ml/classical/knn.d.ts +11 -4
- package/dist/ml/classical/knn.d.ts.map +1 -1
- package/dist/ml/classical/knn.js +26 -6
- package/dist/ml/classical/knn.js.map +1 -1
- package/dist/ml/classical/robust_z.d.ts +9 -3
- package/dist/ml/classical/robust_z.d.ts.map +1 -1
- package/dist/ml/classical/robust_z.js +5 -1
- package/dist/ml/classical/robust_z.js.map +1 -1
- package/dist/ml/head_trainer.d.ts +13 -1
- package/dist/ml/head_trainer.d.ts.map +1 -1
- package/dist/ml/head_trainer.js +47 -10
- package/dist/ml/head_trainer.js.map +1 -1
- package/dist/ml/tasks/experience.d.ts +61 -16
- package/dist/ml/tasks/experience.d.ts.map +1 -1
- package/dist/ml/tasks/experience.js +119 -24
- package/dist/ml/tasks/experience.js.map +1 -1
- package/dist/ml/tasks/run_anomaly.d.ts +26 -9
- package/dist/ml/tasks/run_anomaly.d.ts.map +1 -1
- package/dist/ml/tasks/run_anomaly.js +39 -10
- package/dist/ml/tasks/run_anomaly.js.map +1 -1
- package/dist/ml/train.d.ts +6 -0
- package/dist/ml/train.d.ts.map +1 -1
- package/dist/ml/train.js +19 -11
- package/dist/ml/train.js.map +1 -1
- package/dist/optim/adamw.d.ts +11 -5
- package/dist/optim/adamw.d.ts.map +1 -1
- package/dist/optim/adamw.js +19 -4
- package/dist/optim/adamw.js.map +1 -1
- package/package.json +1 -1
- package/src/evermind/adapt.ts +8 -2
- package/src/experience/index.ts +2 -1
- package/src/experience/store.ts +35 -3
- package/src/experience/types.ts +19 -0
- package/src/kernels/weight_update.ts +12 -0
- package/src/ml/classical/ewma.ts +5 -5
- package/src/ml/classical/index.ts +2 -2
- package/src/ml/classical/knn.ts +25 -6
- package/src/ml/classical/robust_z.ts +15 -5
- package/src/ml/head_trainer.ts +47 -8
- package/src/ml/tasks/experience.ts +148 -28
- package/src/ml/tasks/run_anomaly.ts +41 -10
- package/src/ml/train.ts +31 -12
- package/src/optim/adamw.ts +21 -5
package/src/optim/adamw.ts
CHANGED
|
@@ -138,20 +138,29 @@ export interface AdamWKernelStep {
|
|
|
138
138
|
gradScale?: number;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/** Largest finite f32 — a moment above it would be stored as ±Inf. */
|
|
142
|
+
const F32_MAX = 3.4028234663852886e38;
|
|
143
|
+
|
|
141
144
|
/**
|
|
142
145
|
* One AdamW step over a single parameter tensor — the exact CPU mirror of the
|
|
143
|
-
* `adamw_update` entry point in `WEIGHT_UPDATE_WGSL`, including its
|
|
146
|
+
* `adamw_update` entry point in `WEIGHT_UPDATE_WGSL`, including its safety
|
|
144
147
|
* properties:
|
|
145
148
|
*
|
|
146
|
-
* • the **
|
|
147
|
-
*
|
|
149
|
+
* • the **non-finite gradient skip** — an element whose gradient is NaN/±Inf
|
|
150
|
+
* (or whose new moments would overflow f32) is skipped ENTIRELY: m, v and the
|
|
151
|
+
* weight keep their values (no decay either). Writing the moment first and
|
|
152
|
+
* dropping only the step stored NaN in m/v, and every later step of that
|
|
153
|
+
* element was then NaN too — silently dropped, so the weight froze forever;
|
|
154
|
+
* • the **NaN/Inf step guard** — a non-finite step from finite moments is
|
|
155
|
+
* dropped rather than written into a weight;
|
|
148
156
|
* • the **trust region** — `maxDelta` bounds how far a single step can move a
|
|
149
157
|
* weight, which is what keeps repeated write-through adapts reversible.
|
|
150
158
|
*
|
|
151
159
|
* Decoupled weight decay (`θ * (1 - lr·wd)`), matching the kernel — deliberately
|
|
152
160
|
* NOT the coupled form {@link AdamW} uses for the MoE/EvermindLM trainers.
|
|
153
161
|
*
|
|
154
|
-
* `param`, `m` and `v` are updated in place.
|
|
162
|
+
* `param`, `m` and `v` are updated in place. Returns how many elements were skipped
|
|
163
|
+
* for a non-finite gradient (0 on a healthy step).
|
|
155
164
|
*/
|
|
156
165
|
export function adamwUpdateInPlace(
|
|
157
166
|
param: Float32Array,
|
|
@@ -159,15 +168,21 @@ export function adamwUpdateInPlace(
|
|
|
159
168
|
m: Float32Array,
|
|
160
169
|
v: Float32Array,
|
|
161
170
|
hp: AdamWKernelStep,
|
|
162
|
-
):
|
|
171
|
+
): number {
|
|
163
172
|
const { lr, beta1, beta2, eps, weightDecay, beta1_t, beta2_t, maxDelta } = hp;
|
|
164
173
|
const gradScale = hp.gradScale ?? 1;
|
|
165
174
|
const bc1 = 1 - beta1_t;
|
|
166
175
|
const bc2 = 1 - beta2_t;
|
|
176
|
+
let skipped = 0;
|
|
167
177
|
for (let i = 0; i < param.length; i++) {
|
|
168
178
|
const g = grad[i]! * gradScale;
|
|
169
179
|
const mNew = beta1 * m[i]! + (1 - beta1) * g;
|
|
170
180
|
const vNew = beta2 * v[i]! + (1 - beta2) * g * g;
|
|
181
|
+
// NaN fails every comparison, so this also catches a NaN gradient.
|
|
182
|
+
if (!(Math.abs(mNew) <= F32_MAX && vNew <= F32_MAX)) {
|
|
183
|
+
skipped++;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
171
186
|
m[i] = mNew;
|
|
172
187
|
v[i] = vNew;
|
|
173
188
|
|
|
@@ -177,4 +192,5 @@ export function adamwUpdateInPlace(
|
|
|
177
192
|
|
|
178
193
|
param[i] = param[i]! * (1 - lr * weightDecay) - step;
|
|
179
194
|
}
|
|
195
|
+
return skipped;
|
|
180
196
|
}
|