Code Monkey home page Code Monkey logo

Comments (5)

coreylowman avatar coreylowman commented on May 13, 2024

rust code for benching:

use dfdx::prelude::*;
use rand::{prelude::StdRng, SeedableRng};
use rand_distr::StandardNormal;
use std::time::{Duration, Instant};

fn main() {
    let mut rng = StdRng::seed_from_u64(0);

    let mut l: Linear<512, 256> = Default::default();
    l.randomize(&mut rng, &StandardNormal);

    let mut opt = Adam::default();

    const N: usize = 10000;
    let mut total = Duration::default();
    for _ in 0..N {
        let x: Tensor2D<32, 512> = Tensor2D::randn(&mut rng);
        let y = l.forward(x.traced());
        let loss = y.square().mean();
        let start = Instant::now();
        let gradients = loss.backward();
        opt.update(&mut l, gradients);
        total += start.elapsed();
    }
    println!("{:?} batch per s", N as f32 / total.as_secs_f32());
}

from dfdx.

coreylowman avatar coreylowman commented on May 13, 2024

Python code for benching:

from datetime import datetime, timedelta
import torch

torch.manual_seed(0)

l = torch.nn.Linear(512, 256)
opt = torch.optim.Adam(l.parameters())

total = timedelta()
N = 10000
for _ in range(N):
    x = torch.randn(32, 512)
    y = l(x)
    loss = y.square().mean()
    start = datetime.now()
    opt.zero_grad()
    loss.backward()
    opt.step()
    total += datetime.now() - start

print(N / total.total_seconds())

from dfdx.

coreylowman avatar coreylowman commented on May 13, 2024

Use https://crates.io/crates/criterion

from dfdx.

coreylowman avatar coreylowman commented on May 13, 2024

Both dfdx version and torch version should use flush to zero (#60)

from dfdx.

coreylowman avatar coreylowman commented on May 13, 2024

Closing - might do in future, but this will continue to be ad-hoc for now

from dfdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.