catgrad
You like category theory? You like tinygrad? You love catgrad! ❤️
catgrad is a bit different: instead of using autograd to train, you compile your model's reverse pass into static code. This means your training loop can run without needing a deep learning framework (not even catgrad!)
Here is a linear model in catgrad:
model = layers.linear(BATCH_TYPE, INPUT_TYPE, OUTPUT_TYPE)
catgrad can compile this model...
CompiledModel, _, _ = compile_model(model, layers.sgd(learning_rate), layers.mse)
... into static code like this...
class CompiledModel:
backend: ArrayBackend
def predict(self, x1, x0):
x2 = x0 @ x1
return [x2]
def step(self, x0, x1, x9):
x4, x10 = (x0, x0)
x11, x12 = (x1, x1)
x16 = self.backend.constant(0.0001, Dtype.float32)
# ... snip ...
x18 = x17 * x5
x2 = x10 - x18
return [x2]
... so you can train your model by just iterating step; no autograd needed:
for i in range(0, NUM_ITER):
p = step(p, x, y)
Catgrad doesn't just compile to Python: I'm working on support for other targets like C++ (ggml), CUDA, FPGAs, and more!
Catgrad uses reverse derivatives and open hypergraphs to transform a model into its backwards pass. For details, see this paper.
Install
pip install catgrad
Examples
Train simple MLPs for the iris dataset:
./data/get-iris-data.sh
python3 -m examples.iris (linear|simple|dense|hidden)
Compilation Targets
Target backends we plan to support soon:
Metadata
Release files for catgrad 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| catgrad-0.2.2.tar.gz | 18.4 kB | Without provenance | Details for catgrad-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| catgrad-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for catgrad-0.2.2-py3-none-any.whl |
Total release size: 45.2 kB
Release files / catgrad-0.2.2.tar.gz
| Download URL | catgrad-0.2.2.tar.gz |
|---|---|
| Size | 18.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4beb40aec2a3b1cfcb1a0ecb58113c580c0d02c058ade653429f61405d61a32
|
|
BLAKE2b-256 checksum How to use checksums |
0283cdba62d35a5784799b95f7042e20373a2203827445fb777b6cf0a7829008
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / catgrad-0.2.2-py3-none-any.whl
| Download URL | catgrad-0.2.2-py3-none-any.whl |
|---|---|
| Size | 26.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6730743f0f779256af6e5d0dcc9a0fd99dfb6c2b091aaa37d20cacf976ac7934
|
|
BLAKE2b-256 checksum How to use checksums |
262d9bc79e499653e8863e6c2e3a89d382e179002cb7bf19cb3a427a3bde83af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for catgrad 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.