catniff 0.6.13 → 0.6.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/dist/nn.d.ts CHANGED
@@ -57,6 +57,13 @@ declare class LayerNorm {
57
57
  constructor(normalizedShape: number | number[], eps?: number, elementwiseAffine?: boolean, bias?: boolean, device?: string);
58
58
  forward(input: Tensor): Tensor;
59
59
  }
60
+ declare class RMSNorm {
61
+ weight?: Tensor;
62
+ eps: number;
63
+ normalizedShape: number[];
64
+ constructor(normalizedShape: number | number[], eps?: number, elementwiseAffine?: boolean, device?: string);
65
+ forward(input: Tensor): Tensor;
66
+ }
60
67
  declare class Embedding {
61
68
  weight: Tensor;
62
69
  constructor(numEmbeddings: number, embeddingDim: number, device: string);
@@ -83,6 +90,7 @@ export declare const nn: {
83
90
  GRUCell: typeof GRUCell;
84
91
  LSTMCell: typeof LSTMCell;
85
92
  LayerNorm: typeof LayerNorm;
93
+ RMSNorm: typeof RMSNorm;
86
94
  Embedding: typeof Embedding;
87
95
  MultiheadAttention: typeof MultiheadAttention;
88
96
  state: {
package/dist/nn.js CHANGED
@@ -188,6 +188,42 @@ class LayerNorm {
188
188
  return normalized;
189
189
  }
190
190
  }
191
+ class RMSNorm {
192
+ weight;
193
+ eps;
194
+ normalizedShape;
195
+ constructor(normalizedShape, eps = 1e-5, elementwiseAffine = true, device) {
196
+ this.eps = eps;
197
+ this.normalizedShape = Array.isArray(normalizedShape) ? normalizedShape : [normalizedShape];
198
+ if (this.normalizedShape.length === 0) {
199
+ throw new Error("Normalized shape cannot be empty");
200
+ }
201
+ if (elementwiseAffine) {
202
+ this.weight = core_1.Tensor.ones(this.normalizedShape, { requiresGrad: true, device });
203
+ }
204
+ }
205
+ forward(input) {
206
+ // Normalize over the specified dimensions
207
+ const normalizedDims = this.normalizedShape.length;
208
+ const startDim = input.shape.length - normalizedDims;
209
+ if (startDim < 0) {
210
+ throw new Error("Input does not have enough dims to normalize");
211
+ }
212
+ const dims = [];
213
+ for (let i = 0; i < normalizedDims; i++) {
214
+ if (input.shape[startDim + i] !== this.normalizedShape[i]) {
215
+ throw new Error(`Shape mismatch at dim ${startDim + i}: expected ${this.normalizedShape[i]}, got ${input.shape[startDim + i]}`);
216
+ }
217
+ dims.push(startDim + i);
218
+ }
219
+ let rms = input.square().mean(dims, true).add(this.eps).sqrt();
220
+ let normalized = input.div(rms);
221
+ if (this.weight) {
222
+ normalized = normalized.mul(this.weight);
223
+ }
224
+ return normalized;
225
+ }
226
+ }
191
227
  class Embedding {
192
228
  weight;
193
229
  constructor(numEmbeddings, embeddingDim, device) {
@@ -316,6 +352,7 @@ exports.nn = {
316
352
  GRUCell,
317
353
  LSTMCell,
318
354
  LayerNorm,
355
+ RMSNorm,
319
356
  Embedding,
320
357
  MultiheadAttention,
321
358
  state
package/dist/optim.js CHANGED
@@ -139,7 +139,7 @@ class AdamW extends BaseOptimizer {
139
139
  this.lr = options?.lr || 0.001;
140
140
  this.betas = options?.betas || [0.9, 0.999];
141
141
  this.eps = options?.eps || 1e-8;
142
- this.weightDecay = options?.weightDecay || 0;
142
+ this.weightDecay = options?.weightDecay || 0.01;
143
143
  }
144
144
  step() {
145
145
  this.stepCount++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catniff",
3
- "version": "0.6.13",
3
+ "version": "0.6.15",
4
4
  "description": "A small Torch-like deep learning framework for Javascript",
5
5
  "main": "index.js",
6
6
  "scripts": {