@seanhogg/builderforce-memory-engine 2026.10.2 → 2026.10.22

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 (68) hide show
  1. package/dist/evermind/adapt.d.ts +7 -0
  2. package/dist/evermind/adapt.d.ts.map +1 -1
  3. package/dist/evermind/adapt.js +1 -1
  4. package/dist/evermind/adapt.js.map +1 -1
  5. package/dist/experience/index.d.ts +2 -2
  6. package/dist/experience/index.d.ts.map +1 -1
  7. package/dist/experience/index.js.map +1 -1
  8. package/dist/experience/store.d.ts +19 -1
  9. package/dist/experience/store.d.ts.map +1 -1
  10. package/dist/experience/store.js +14 -2
  11. package/dist/experience/store.js.map +1 -1
  12. package/dist/experience/types.d.ts +18 -0
  13. package/dist/experience/types.d.ts.map +1 -1
  14. package/dist/experience/types.js.map +1 -1
  15. package/dist/kernels/weight_update.d.ts.map +1 -1
  16. package/dist/kernels/weight_update.js +12 -0
  17. package/dist/kernels/weight_update.js.map +1 -1
  18. package/dist/ml/classical/ewma.d.ts +5 -4
  19. package/dist/ml/classical/ewma.d.ts.map +1 -1
  20. package/dist/ml/classical/ewma.js +2 -2
  21. package/dist/ml/classical/ewma.js.map +1 -1
  22. package/dist/ml/classical/index.d.ts +2 -2
  23. package/dist/ml/classical/index.d.ts.map +1 -1
  24. package/dist/ml/classical/index.js +1 -1
  25. package/dist/ml/classical/index.js.map +1 -1
  26. package/dist/ml/classical/knn.d.ts +11 -4
  27. package/dist/ml/classical/knn.d.ts.map +1 -1
  28. package/dist/ml/classical/knn.js +26 -6
  29. package/dist/ml/classical/knn.js.map +1 -1
  30. package/dist/ml/classical/robust_z.d.ts +9 -3
  31. package/dist/ml/classical/robust_z.d.ts.map +1 -1
  32. package/dist/ml/classical/robust_z.js +5 -1
  33. package/dist/ml/classical/robust_z.js.map +1 -1
  34. package/dist/ml/head_trainer.d.ts +13 -1
  35. package/dist/ml/head_trainer.d.ts.map +1 -1
  36. package/dist/ml/head_trainer.js +47 -10
  37. package/dist/ml/head_trainer.js.map +1 -1
  38. package/dist/ml/tasks/experience.d.ts +61 -16
  39. package/dist/ml/tasks/experience.d.ts.map +1 -1
  40. package/dist/ml/tasks/experience.js +119 -24
  41. package/dist/ml/tasks/experience.js.map +1 -1
  42. package/dist/ml/tasks/run_anomaly.d.ts +26 -9
  43. package/dist/ml/tasks/run_anomaly.d.ts.map +1 -1
  44. package/dist/ml/tasks/run_anomaly.js +39 -10
  45. package/dist/ml/tasks/run_anomaly.js.map +1 -1
  46. package/dist/ml/train.d.ts +6 -0
  47. package/dist/ml/train.d.ts.map +1 -1
  48. package/dist/ml/train.js +19 -11
  49. package/dist/ml/train.js.map +1 -1
  50. package/dist/optim/adamw.d.ts +11 -5
  51. package/dist/optim/adamw.d.ts.map +1 -1
  52. package/dist/optim/adamw.js +19 -4
  53. package/dist/optim/adamw.js.map +1 -1
  54. package/package.json +1 -1
  55. package/src/evermind/adapt.ts +8 -2
  56. package/src/experience/index.ts +2 -1
  57. package/src/experience/store.ts +35 -3
  58. package/src/experience/types.ts +19 -0
  59. package/src/kernels/weight_update.ts +12 -0
  60. package/src/ml/classical/ewma.ts +5 -5
  61. package/src/ml/classical/index.ts +2 -2
  62. package/src/ml/classical/knn.ts +25 -6
  63. package/src/ml/classical/robust_z.ts +15 -5
  64. package/src/ml/head_trainer.ts +47 -8
  65. package/src/ml/tasks/experience.ts +148 -28
  66. package/src/ml/tasks/run_anomaly.ts +41 -10
  67. package/src/ml/train.ts +31 -12
  68. package/src/optim/adamw.ts +21 -5
@@ -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 two safety
146
+ * `adamw_update` entry point in `WEIGHT_UPDATE_WGSL`, including its safety
144
147
  * properties:
145
148
  *
146
- * • the **NaN/Inf guard** — a non-finite step is dropped rather than written
147
- * into a weight, so one bad gradient cannot permanently poison the model;
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
- ): void {
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
  }