Code Monkey home page Code Monkey logo

toydiff's Introduction

Hi, I'm Alejandro

Data Scientist

aperez aperez alejandrops

  • 🔭 I’m currently working at ETS Factory

  • 👯 I’m looking to collaborate on projects that create a better society using AI

  • 📝 I regularly write articles on my blog and on Quantdare

  • 😄 Pronouns: he / him / his


Python Java LaTeX Jupyter Notebook Ubuntu Visual Studio Code GitLab GitHub

NumPy Pandas Matplotlib PyTorch scikit-learn Keras SciPy

toydiff's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

andrewolal

toydiff's Issues

ENH: add BMM operation

class BatchMatrixMultiplication(BinaryOp):
    def forward(self):
        data_a, data_b = self.get_value()
        # np.stack([a[i] @ b[i] for i in range(a.shape[0])])
        return Tensor(
            np.eisum('ijk, ikz -> ijz', tensor_a, tensor_b),
            parents=self.parents,
            is_leaf=False,
            track_gradient=self.track_gradient,
            parents=self.parents,
            is_leaf=False,
            op_name=self.__repr__(),
        )

    def backward(self, gradient = None):
        data_a, data_b = self.get_value()
        grad_np = gradient.numpy()
        grad_a = np.einsum('ijk, ikz -> ijz', grad_np, np.transpose(data_b.detach().numpy(), (0, 2, 1)))
        grad_b = np.einsum('ijk, ikz -> ijz', np.transpose(data_a, (0, 2, 1)), grad_np)
        self._set_gradients(Tensor(grad_a), Tensor(grad_b))

    def __repr__(self):
        return "BatchMatrixMultiplication(BinaryOp)"

ROADMAP

Prioritary

  • Scalable testing framework. Use fixtures to pass shapes to testing functions
  • Make sure iteration of parameters is okey. It is kinda tricky right now
  • Tests for NN
  • Tests for functional
    • Add more
    • Fix mae and softmax/min float errors when comparing against PyTorch
  • CI/CD:
    • Testing and code checking
    • PyPI upload
    • Sphinx DOCS
  • Fix kaiming initializer
  • Storing and loading weights of a model
  • Shouldn't have to track gradients for the features and labels to optimize model

Desirable

  • Add CHANGELOG
  • Data loading system for the model.
  • Implementation of conv* operations
  • Implementation of recurrent operations
  • Implementation of attention mechanisms
  • Implement more optimizers (Adam, RMSProp, etc)
  • Utilities to load PyTorch weights into toydiff weights
  • Name change (avagrad) and logo
  • Add initializers
  • Context managers to control whether gradients should be computed or not (torch.no_grad vs tf.GradientTape)

Can wait

  • GPU support (PyOpenCL, autoray?)
  • Sphinx docs
  • Consider autoray to allow multiple-backend and lazy execution

speed test

import torch
import perfplot
import numpy as np
import toydiff as tdf


def matmul_torch(t1, t2):
    return torch.matmul(t1, t2)


def matmul_avagrad(t1, t2):
    return tdf.matmul(t1, t2)


def data(n):
    arr = np.random.rand(n, n)
    tensor_t = torch.from_numpy(arr)
    tensor_a = tdf.Tensor(arr)
    
    return tensor_t, tensor_a


perfplot.show(
    setup=lambda n: data(n),
    kernels=[
        lambda tt, ta: matmul_torch(tt, tt),
        lambda tt, ta: matmul_avagrad(ta, ta),
    ],
    labels=["PyTorch", "Avagrad"],
    n_range=[2**k for k in range(14)],
    xlabel="len(a)",
)

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.