Skip to content

guptaaryan16/micrograd-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micrograd.c

This is a weekend project I did in which I implemented micrograd ( a small autograd engine originally by Karaphaty) in pure C. The idea is to do autodiff using C and learn about the resource constraints and memory management while dealing with ML computations.

How to use

Just use any c compiler (I used GCC) and then run the following command

gcc -o main main.c && ./main

Results

For sample problem, where


Problem: 

a = 2
b = 3
c = 4
d = 5

out = (d*exp(a*b)) + c

for which we got,

a = [value=2.000000, grad=742.065796]
b = [value=3.000000, grad=742.065796]
c = [value=4.000000, grad=1.000000]
d = [value=5.000000, grad=148.413162]
out = [value=746.065796, grad=1.000000]

Some learnings

For the project, I really looked at functional programming in C, and then I compared the results with pytorch and original micrograd. This small project helped me learn some good things about the minimalist C and how we can build really complex systems using pretty simple code. Btw it is pretty hard to debug C but can be really easy once u start printing stuff and using Valgrind.

Licence

I used concepts of the original micrograd project and wrote a custom implementation. It is MIT Licensed and you can use it however you like.

Thanks

Thanks for reading this project.

About

Custom functional implementation of micrograd

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages