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.
Just use any c compiler (I used GCC) and then run the following command
gcc -o main main.c && ./main
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]
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.
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 for reading this project.