Skip to main content

A small tensor-valued autograd engine

Project description

cudagrad

A small tensor-valued autograd engine, inspired by PyTorch and micrograd

Great barracuda photo by James St. John, CC BY 2.0, via Wikimedia Commons

Example

Available on PyPI (pip install cudagrad)

# python -m pip install cudagrad; python ./examples/example.py
import cudagrad as cg

a = cg.Tensor([2, 2], [2.0, 3.0, 4.0, 5.0])
b = cg.Tensor([2, 2], [6.0, 7.0, 8.0, 9.0])
c = cg.Tensor([2, 2], [10.0, 10.0, 10.0, 10.0])
d = cg.Tensor([2, 2], [11.0, 11.0, 11.0, 11.0])
e = ((a @ b) + c) * d
f = e.sum()
f.backward()

print(f.data)  # [2794.0]
print(f.size)  # [1]
print(a.grad)  # [143.0, 187.0, 143.0, 187.0]
print(b.grad)  # [66.0, 66.0, 88.0, 88.0]

WIP! TODO: CUDA operation integration and release on PyPI

Performance

key            setup                   fastest_time            
---------------------------------------------------------------
tiny matmul    import cudagrad as cg;  1.6817973330034873e-06  
tiny matmul    import numpy as np      1.7551545829628593e-06  
tiny matmul    import torch;           5.315409083035774e-06   
tiny backward  import cudagrad as cg;  2.59421900002053e-06    
tiny backward  import torch;           2.302449666702887e-05   
big matmul     import cudagrad as cg;  1.215179824992083       
big matmul     import torch;           0.003011275001335889    

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cudagrad-0.0.46.tar.gz (12.6 kB view details)

Uploaded Source

File details

Details for the file cudagrad-0.0.46.tar.gz.

File metadata

  • Download URL: cudagrad-0.0.46.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for cudagrad-0.0.46.tar.gz
Algorithm Hash digest
SHA256 2f138200ac638b86ab824f9244cf67b89276233e85591c23a5b583253e82574b
MD5 df9b3ff72006ad6c360a5e095263008d
BLAKE2b-256 0e60aab565f5c929cb78d44f096bf12e0faa8791a472260cfd01676517742a4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page