A Tensor module that allows a deep learning framework to switch seamlessly between different engines.
Project description
Overview
AnyGrad is a simple tensor library that makes it easy to perform forward and backward passes. It uses a high-performance C++ backend together with a user-friendly Python frontend. You can change the backend easily and simply.
Note: currently version
0.0.1does not support any engine. But in the future, the integrations of engines likenumpy,pytorchetc. will come and you can use them for anything from Tensor operation to high-level transformer training.
Installation
Install the library from PyPI:
pip install anygrad
If you'd like to work on the code:
git clone https://github.com/Ruhaan838/AnyGrad.git
./setup.sh
Getting Started
Creating a Tensor
Create tensors by importing the library and instantiating Tensor. By default, gradients are not tracked unless you enable them:
import anygrad
# A tensor that does not calculate gradients
a = anygrad.Tensor([1, 2, 3])
# A tensor with gradient tracking enabled
b = anygrad.Tensor([2, 3, 4], requires_grad=True)
# A tensor with a specific data type (float64)
c = anygrad.Tensor([2, 3, 4], dtype=anygrad.float64)
Other datatypes:
anygrad.int32
anygrad.int64
anygrad.bool
Arithmetic Operations
Element-wise Operations
Perform calculations on tensors element by element:
d = a + b # addition
d = a * d # multiplication
d = d / 10 # division
e = d - 10 # subtraction
Matrix Multiplication
You can multiply matrices in two ways:
# Using the @ operator:
a = anygrad.ones((1, 2, 3), requires_grad=True)
b = anygrad.ones((2, 3, 4), requires_grad=True)
c = a @ b # tensor of shape (2, 2, 4)
# Or using the function:
c = anygrad.matmul(a, b)
Gradient Calculation
AnyGrad automatically computes gradients, which you can access after running the backward pass:
a = anygrad.Tensor([1, 2, 3], requires_grad=True)
b = anygrad.Tensor([2, 3, 4], requires_grad=True)
c = a * b
result = c.sum()
result.backward()
print(a.grad)
print(b.grad)
Contributing
Contributions are welcome! Whether you want to improve performance or enhance the documentation, please open an issue or submit a pull request.
License
This project is licensed under the terms outlined in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anygrad-0.0.3.tar.gz.
File metadata
- Download URL: anygrad-0.0.3.tar.gz
- Upload date:
- Size: 31.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d81b42ce00725ee022e61a57b593004067e621ad1b74f718b74bd6e668745092
|
|
| MD5 |
a4957afff64f2ffb07a88aa6df5e5df8
|
|
| BLAKE2b-256 |
c70de659325c5ff8a13b5c0133b8619e1b4f9ebde55711240bb474963b6463a9
|
File details
Details for the file anygrad-0.0.3-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: anygrad-0.0.3-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 308.5 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5ac2570441e3feced9805a2dcc61705e6c3139c3e840bc1e80fbc97ff5c9bdd
|
|
| MD5 |
67c292c3cf54aaf6d388a541c354fb6a
|
|
| BLAKE2b-256 |
b1270d22c951040a7c32b5998befab9af9b16a232c889c60dd5f9d3bfb603e68
|
File details
Details for the file anygrad-0.0.3-cp313-cp313-macosx_10_14_universal2.whl.
File metadata
- Download URL: anygrad-0.0.3-cp313-cp313-macosx_10_14_universal2.whl
- Upload date:
- Size: 784.8 kB
- Tags: CPython 3.13, macOS 10.14+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2930ddadfd13ed101dc8a1d224697522cc4047058761a00849f9e195391ed9ae
|
|
| MD5 |
6477a9525e9df1fb126b978f05e07e74
|
|
| BLAKE2b-256 |
29b269844dcd775b0ea40f3d032107b96cf59f05653b8e98d546f20f88d00599
|