Skip to content

Eventually building a tinygrad or micrograd like neural net engine in rust (mostly for educational purposes)

Notifications You must be signed in to change notification settings

Miraj98/tinygrad-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example

use tinygrad_rust::tensor::{Tensor, ops::binary_ops::BinaryOps, Tensor};

fn main() {
  let x = Tensor::randn((2, 2), Some(true)); // requires_grad = Some(true)
  let y = Tensor::randn((2, 2), Some(true));
  let z = y.matmul(&x).sum();
  z.backward();
  
  println!("{:#?}", x.grad().as_ref().unwrap()); // dz/dx
  println!("{:#?}", y.grad().as_ref().unwrap()); // dz/dy
}

Same example in torch

import torch
x = torch.rand(2, 2, requires_grad=True)
y = torch.rand(2, 2, requires_grad=True)
z = y.matmul(x).sum()
z.backward()

print(x.grad)  # dz/dx
print(y.grad)  # dz/dy

About

Eventually building a tinygrad or micrograd like neural net engine in rust (mostly for educational purposes)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages