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), this requires the nvcc compiler!

# 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.48.tar.gz (12.6 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for cudagrad-0.0.48.tar.gz
Algorithm Hash digest
SHA256 d14e9bcb9b4506073f30f5d27446f99e7ad162704c2faa0eef807170917f4289
MD5 27e65ab3e1641c4d0430c3cc6c095028
BLAKE2b-256 b32fd9f78b029bdf64520b1b4786b514326e323faf52117943c8a84b31599b72

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