Skip to content

This repo contains custom NN model written from scratch in python. It also checks performance & results against pytorch lib.

Notifications You must be signed in to change notification settings

karthikeyanrathore/multilayer-perceptron-torch-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multilayer-perceptron-torch-test

Testing custom MLP model written from scratch in python in < 200 loc against pytorch library.

forward / backward propagation comparison against pytorch

In mlp/mlp_value.py

>>> from mlp.mlp_value import Value
>>> x = Value(-4.0)
>>> z = 2 * x + 2 + x
>>> q = z.tanh() + z * x
>>> h = (z * z).tanh()
>>> y = h + q + q * x
>>> y.backward()
>>> x.gradient
104.99999992992078
>>> y.data
-116.00000001236691

In Pytorch

>>> import torch
>>> x = torch.Tensor([-4.0]).double() # 64-bit
>>> x.requires_grad = True
>>> z = 2 * x + 2 + x
>>> q = z.tanh() + z * x
>>> h = (z * z).tanh()
>>> y = h + q + q * x
>>> y.backward()
>>> x.grad.item()
104.99999992992078
>>> y.data
tensor([-116.0000], dtype=torch.float64)

build and run mlp_test.py

docker-compose build; \
docker-compose run custom-mlp-model

testing in local

can't docker-compose as it requires torch package.

export TORCH_TESTING=1;pwd test; coverage run -m pytest

TODO

About

This repo contains custom NN model written from scratch in python. It also checks performance & results against pytorch lib.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published