cogforge-engine 1.0.4__tar.gz → 1.0.5__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cogforge-engine
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: A custom autograd engine and Transformer block built from scratch.
5
5
  Project-URL: Homepage, https://github.com/avikmjd2/cogforge
6
6
  Author-email: Avik Majumder <avikmjd2@gmail.com>
@@ -387,10 +387,10 @@ class Tensor:
387
387
  flat, idx, rows = p.reshape(N, -1), target_ids.reshape(N), backend.np.arange(N)
388
388
  loss = cls(-backend.np.log(backend.np.clip(flat[rows, idx], 1e-15, 1.0)).sum() / N, children=(scores,))
389
389
  def _backward():
390
+ # g = p.reshape(N, -1).copy()
390
391
  g = p.reshape(N, -1)
391
- g[rows, idx] -= 1.0
392
- coef = numpy.float32(float(loss.grad) / N)
393
- _iadd_scaled(scores.grad, g.reshape(scores.shape), coef)
392
+ g[rows, idx] -= 1.0 # (softmax - onehot)
393
+ scores.grad += (g.reshape(scores.shape) / N) * loss.grad
394
394
  loss._backwards = _backward
395
395
  return loss
396
396
 
@@ -403,7 +403,8 @@ class Tensor:
403
403
  def _backward():
404
404
  g = p.reshape(N, -1)
405
405
  g[rows, idx] -= 1.0
406
- _iadd_scaled(scores.grad, g.reshape(scores.shape), backend.np.float32(loss.grad / N))
406
+ coef = numpy.float32(float(loss.grad) / N)
407
+ _iadd_scaled(scores.grad, g.reshape(scores.shape), coef)
407
408
  loss._backwards = _backward
408
409
  return loss
409
410
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cogforge-engine"
7
- version = "1.0.4"
7
+ version = "1.0.5"
8
8
  authors = [
9
9
  { name="Avik Majumder", email="avikmjd2@gmail.com" },
10
10
  ]
File without changes