Merge pull request #43 from lucasdelimanogueira/tmp

add example training
This commit is contained in:
lucasdelimanogueira 2024-05-10 02:01:40 -03:00 committed by GitHub
commit 4e5173597c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 184 additions and 1 deletions

177
examples/train.ipynb Normal file

File diff suppressed because one or more lines are too long

2
install.sh Executable file
View file

@ -0,0 +1,2 @@
cd build
make

View file

@ -27,7 +27,9 @@ class ElementwiseMulBackward:
self.input = [x, y]
def backward(self, gradient):
return [gradient * self.input[1], gradient * self.input[0]]
x = self.input[0]
y = self.input[1]
return [y * gradient, x * gradient]
class MatmulBackward:
def __init__(self, x, y):

View file

@ -179,6 +179,8 @@ class Tensor:
self.grad_fn = None
def __getitem__(self, indices):
if isinstance(indices, int):
indices = [indices]
if len(indices) != self.ndim:
raise ValueError("Number of indices must match the number of dimensions")