MicroTensorGrad 1.0.0__tar.gz → 1.0.2__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: MicroTensorGrad
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: A Tensor Based autograd engine used to train neural network based models
5
5
  Author-email: Guettara Mohamed Amine <guettaraamine2@gmail.com>
6
6
  License: MIT
@@ -22,6 +22,8 @@ A Tensor Based autograd engine used to train neural network based models.
22
22
  - **Tensor-Based Autograd:** Automatic differentiation engine operating directly on Tensors.
23
23
  - **Neural Network Training:** Built specifically to construct, backpropagate through, and train neural network architectures.
24
24
 
25
+ For more informations and guide, visit : https://github.com/Lberdy/MircoTensorGrad
26
+
25
27
  ## Installation
26
28
 
27
29
  ```bash
@@ -7,6 +7,8 @@ A Tensor Based autograd engine used to train neural network based models.
7
7
  - **Tensor-Based Autograd:** Automatic differentiation engine operating directly on Tensors.
8
8
  - **Neural Network Training:** Built specifically to construct, backpropagate through, and train neural network architectures.
9
9
 
10
+ For more informations and guide, visit : https://github.com/Lberdy/MircoTensorGrad
11
+
10
12
  ## Installation
11
13
 
12
14
  ```bash
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "MicroTensorGrad"
7
- version = "1.0.0"
7
+ version = "1.0.2"
8
8
  description = "A Tensor Based autograd engine used to train neural network based models"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -5,14 +5,16 @@ class MicroTensor:
5
5
  self.array = np_array
6
6
  self.grad = 0
7
7
  self.backward_ = lambda : None
8
+
9
+ def zero_grad(self):
10
+ self.grad = 0
8
11
 
9
12
  def __matmul__(self, other):
10
- # print(f"self array shape transpose: {self.array.transpose((0, 2, 1)).shape}, other array shape : {other.array.shape}")
11
13
  out = MicroTensor(self.array.T@other.array)
12
14
 
13
15
  def backward():
14
- self.grad = (out.grad@other.array.transpose(0, 2, 1)).transpose(0, 2, 1)
15
- other.grad = self.array@out.grad
16
+ self.grad += (out.grad@other.array.transpose(0, 2, 1)).transpose(0, 2, 1)
17
+ other.grad += self.array@out.grad
16
18
 
17
19
  out.backward_ = backward
18
20
 
@@ -33,8 +35,7 @@ class MicroTensor:
33
35
  out = MicroTensor(np.where(self.array < 0, 0, self.array))
34
36
 
35
37
  def backward():
36
- self.grad += np.where(out.grad < 0, 0, 1)*out.grad
37
-
38
+ self.grad += np.where(out.array < 0, 0, 1)*out.grad
38
39
 
39
40
  out.backward_ = backward
40
41
 
@@ -44,7 +45,7 @@ class MicroTensor:
44
45
  out = MicroTensor(np.tanh(self.array))
45
46
 
46
47
  def backward():
47
- self.grad += (1 - np.tanh(self.array))*out.grad
48
+ self.grad += (1 - np.tanh(self.array)**2)*out.grad
48
49
 
49
50
  out.backward_ = backward
50
51
 
@@ -63,8 +64,9 @@ class MicroTensor:
63
64
  return out
64
65
 
65
66
  def Softmax(self):
66
- e_x = np.exp(self.array)
67
- return e_x / np.sum(e_x, axis=1, keepdims=True)
67
+ epsilon = 1e-8
68
+ e_x = np.exp(self.array - np.max(self.array, axis=1, keepdims=True))
69
+ return e_x / (np.sum(e_x, axis=1, keepdims=True) + epsilon)
68
70
 
69
71
  def CrossEntopyLoss(self, Y : np.ndarray):
70
72
  out = MicroTensor(np.mean(-np.sum(Y*np.log(self.Softmax()), axis=1), axis=0))
@@ -1,7 +1,7 @@
1
1
  import numpy as np
2
- from Engine import MicroTensor
2
+ from .Engine import MicroTensor
3
3
  from typing import Literal
4
- from Optimizers import Optimizer
4
+ from .Optimizers import Optimizer
5
5
 
6
6
  def HE_Initialization(in_ : int, out_ : int):
7
7
  return np.random.normal(loc=0, scale=np.sqrt(2/in_), size=(in_, out_))
@@ -73,6 +73,11 @@ class MLP:
73
73
  "optimize" : False
74
74
  }
75
75
  )
76
+
77
+ def zero_grad(self):
78
+ for step in self.steps:
79
+ if step["optimize"]:
80
+ step["content"].zero_grad()
76
81
 
77
82
  def update(self):
78
83
  self.optimizer.update(self.steps)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MicroTensorGrad
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: A Tensor Based autograd engine used to train neural network based models
5
5
  Author-email: Guettara Mohamed Amine <guettaraamine2@gmail.com>
6
6
  License: MIT
@@ -22,6 +22,8 @@ A Tensor Based autograd engine used to train neural network based models.
22
22
  - **Tensor-Based Autograd:** Automatic differentiation engine operating directly on Tensors.
23
23
  - **Neural Network Training:** Built specifically to construct, backpropagate through, and train neural network architectures.
24
24
 
25
+ For more informations and guide, visit : https://github.com/Lberdy/MircoTensorGrad
26
+
25
27
  ## Installation
26
28
 
27
29
  ```bash
File without changes