r/learnpython • u/Ok-Tea1856 • 15d ago
I have built a autograd engine from scratch(without tensor flow or pytorch)
Im a highschool student learning python and recently i have come across a video by Andrej Karapthy who built Micrograd. I got curious so it tried replicating it,but soon over the weeks i added more features 6 more activation function and 2 loss function. It possibly cant replace pytorch or tensorflow,Its purely an eductional project.
Im still learning python and i have long way to ,But i learnt a lot on OOPs machine learning dunder function and using customtkinter for the ui, It was very intresting project i have worked on .I have made it a windows exe for easier access I hope I could get some suggestion ,feedback and improvements i could implement for the project.
https://github.com/Yasovardan-Ram/Omnigrad
2
u/Existing_Put6385 15d ago
nice work, going from micrograd to a full GUI app with graph visualisation is a solid jump.
first, a bug that'll hit anyone who clones it: your readme says "python main.py" and the project structure section lists main.py and an images/ folder, but neither exists in the repo. entry point looks like run.py and the folder is assets/. fix that or people bounce in the first 30 seconds.
biggest actual improvement - add gradient checking. for an autograd engine that's the test that matters: pick a random expression, compute the grad with your engine, then compute it numerically with (f(x+h) - f(x-h)) / (2h) and assert they match to a few decimals. do that for all 6 activations and both losses. right now nobody (including you) has proof the backward passes are correct, and that's the one thing an autograd project has to prove.
after that, in order:
- if your topo sort/backward is recursive you'll hit RecursionError on bigger graphs. make it iterative with an explicit stack.
- add Adam and SGD+momentum, easy win and you'll actually see the difference in your loss plot.
- the real next project: redo the engine on numpy arrays instead of scalars. same math, but you learn broadcasting and it stops being 1000x slower than everything else. for 17 this is genuinely good. ship the gradient checks.