Skip to main content

Dynamic neural networks and function transformations in Python + Mojo

Project description

alt text

Nabla is an open-source Scientific Computing library in Python, featuring:

  • Multidimensional array computation with strong GPU acceleration
  • JAX-like composable function transformations: grad, vmap, jit, and other automatic differentiation tools
  • Deep integration with the MAX compiler and custom Mojo kernels

For tutorials and API reference, visit: nablaml.com 🤗

Installation

pip install nabla-ml

Quick Start

The most simple, but fully functional Neural Network training setup:

import nabla as nb

# Defines MLP forward pass and loss.
def loss_fn(params, x, y):
    for i in range(0, len(params) - 2, 2):
        x = nb.relu(x @ params[i] + params[i + 1])
    predictions = x @ params[-2] + params[-1]
    return nb.mean((predictions - y) ** 2)

# JIT-compiled training step via SGD
@nb.jit(auto_device=True)
def train_step(params, x, y, lr):
    loss, grads = nb.value_and_grad(loss_fn)(params, x, y)
    return loss, [p - g * lr for p, g in zip(params, grads)]

# Setup network (hyper)parameters.
LAYERS = [1, 32, 64, 32, 1]
params = [p for i in range(len(LAYERS) - 1) for p in (nb.glorot_uniform((LAYERS[i], LAYERS[i + 1])), nb.zeros((1, LAYERS[i + 1])),)]

# Run training loop.
x, y = nb.rand((256, 1)), nb.rand((256, 1))
for i in range(1001):
    loss, params = train_step(params, x, y, 0.01)
    if i % 100 == 0: print(i, loss.to_numpy())

For Developers

  1. Clone the repository
  2. Create a virtual environment (recommended)
  3. Install dependencies
git clone https://github.com/nabla-ml/nabla.git
cd nabla

python3 -m venv venv
source venv/bin/activate

pip install -r requirements-dev.txt
pip install -e ".[dev]"

Repository Structure

nabla/
├── nabla/                     # Core Python library
│   ├── core/                  # Array class and MAX compiler integration
│   ├── nn/                    # Neural network modules and models
│   ├── ops/                   # Mathematical operations (binary, unary, linalg, etc.)
│   ├── transforms/            # Function transformations (vmap, grad, jit, etc.)
│   └── utils/                 # Utilities (formatting, types, MAX-interop, etc.)
├── tests/                     # Comprehensive test suite
├── tutorials/                 # Notebooks on Nabla usage for ML tasks
└── examples/                  # Example scripts for common use cases

Contributing

Contributions welcome! Discuss significant changes in Issues first. Submit PRs for bugs, docs, and smaller features.

License

Nabla is licensed under the Apache-2.0 license.


Thank you for checking out Nabla!

Development Status PyPI version Python 3.12+ License: Apache 2.0

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

nabla_ml-25.8311355.tar.gz (102.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nabla_ml-25.8311355-py3-none-any.whl (134.0 kB view details)

Uploaded Python 3

File details

Details for the file nabla_ml-25.8311355.tar.gz.

File metadata

  • Download URL: nabla_ml-25.8311355.tar.gz
  • Upload date:
  • Size: 102.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for nabla_ml-25.8311355.tar.gz
Algorithm Hash digest
SHA256 ec57696af20e6aad29c6b08ddf7499c33b4dbaac7ce42b5acc32acdec533afaa
MD5 f2542d50c11d03a1bc202e49de123aed
BLAKE2b-256 76255d6fef62adc5aefd414bc71526ec3dc0aaea91032aa77c69a6bbb1083643

See more details on using hashes here.

File details

Details for the file nabla_ml-25.8311355-py3-none-any.whl.

File metadata

  • Download URL: nabla_ml-25.8311355-py3-none-any.whl
  • Upload date:
  • Size: 134.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for nabla_ml-25.8311355-py3-none-any.whl
Algorithm Hash digest
SHA256 61dc61ea3ea30916b4cab410d0c57db150f0e279000089b2e849effdda63b4d7
MD5 8c1002e161821148332247995ba60114
BLAKE2b-256 808511bddb689c913987adf32b1d249c7ad8c8f5598beb57f4c1c8add8e1eb1d

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