Skip to main content

A lightweight neural-network library built on JAX

Project description

JAXFlow Logo

PyPI version License Build Status Coverage Status

JAXFlow

A lightweight neural-network library built on JAX – pure-functional, multi-device-ready, and flexible enough for both research and production.


🚀 Features

Built from scratch with ❤️ and powered by JAX, JAXFlow began as a deep dive into how libraries like Keras and scikit-learn work under the hood—and evolved into a full-featured framework for high-performance deep learning and machine learning.

  • Modular Model API Build networks using Sequential, subclassed Models, or pure-layer stacks.
  • Multi-Device Execution Fully compatible with jit, vmap, pmap, and pjit via PyTree-aware design.
  • Layer Collection Dense, Conv, BatchNorm, Dropout, Flatten, Embedding, and custom Layer subclasses.
  • Train-Eval Pipelines model.compile() + fit() for simplicity, or write your own training loop for advanced control.
  • Optimizers & Schedulers Integrated with Optax, supports SGD, Adam, RMSProp, and more.
  • Losses & Metrics MSE, CrossEntropy, F1Score, Precision, Recall, Accuracy, etc. via streaming metric classes.
  • Callbacks & Checkpoints EarlyStopping, ModelCheckpoint, LearningRateScheduler, and Orbax-powered save/load.
  • Pre-built Models Includes ResNet, MLP, Transformer, and composable Blocks.
  • Lazy Imports Top-level jaxflow is fast to import; deep components load on demand.

📦 Installation

pip install jaxflow

Note:

Requires JAX with CPU/GPU/TPU support.

pip install "jax[cuda]>=0.6.0" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html

Or simply use:

pip install --upgrade jaxflow[GPU]   # for CUDA support
pip install --upgrade jaxflow[tpu]   # for TPU support

Python ≥3.9 required.


🎉 Quickstart

JAXFlow models can be defined in two main styles:

1. Subclassing Model

import jaxflow as jf
from jaxflow.models import Model
from jaxflow.layers import Conv2D, MaxPooling2D, Dense
from jaxflow.initializers import GlorotUniform, Zeros

class CNN(Model):
    def __init__(self, num_classes: int = 10, name: str = "MyCNN"):
        super().__init__(name=name)
        self.conv1 = Conv2D(filters=32, kernel_size=(3,3), activation=jf.activations.relu, kernel_initializer=GlorotUniform, bias_initializer=Zeros, padding='SAME')
        self.pool1 = MaxPooling2D(pool_size=(2,2))
        self.conv2 = Conv2D(filters=64, kernel_size=(3,3), activation=jf.activations.relu, kernel_initializer=GlorotUniform, bias_initializer=Zeros, padding='SAME')
        self.pool2 = MaxPooling2D(pool_size=(2,2))
        self.flatten = jf.layers.GlobalAveragePooling2D()
        self.dense1 = Dense(units=64, activation=jf.activations.relu, kernel_initializer=GlorotUniform, bias_initializer=Zeros)
        self.outputs = Dense(units=num_classes, activation=jf.activations.softmax, kernel_initializer=GlorotUniform, bias_initializer=Zeros)

    def call(self, inputs, training: bool = False):
        x = self.conv1(inputs, training=training)
        x = self.pool1(x, training=training)
        x = self.conv2(x, training=training)
        x = self.pool2(x, training=training)
        x = self.flatten(x)
        x = self.dense1(x, training=training)
        return self.outputs(x, training=training)

2. Using the .add() Method (Sequential-style API)

import jaxflow as jf
from jaxflow.models import Model
from jaxflow.layers import Conv2D, MaxPooling2D, Dense
from jaxflow.initializers import GlorotUniform, Zeros
from jaxflow.optimizers import Adam
from jaxflow.losses import SparseCategoricalCrossentropy

model = Model()
model.add(Conv2D(filters=32, kernel_size=(3,3), activation=jf.activations.relu, kernel_initializer=GlorotUniform, bias_initializer=Zeros, padding='SAME'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(filters=64, kernel_size=(3,3), activation=jf.activations.relu, kernel_initializer=GlorotUniform, bias_initializer=Zeros, padding='SAME'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(jf.layers.GlobalAveragePooling2D())
model.add(Dense(units=64, activation=jf.activations.relu, kernel_initializer=GlorotUniform, bias_initializer=Zeros))
model.add(Dense(units=10, activation=jf.activations.softmax, kernel_initializer=GlorotUniform, bias_initializer=Zeros))

model.build(input_shape=(None, 28, 28, 1))
model.compile(optimizer=Adam(0.001), loss_fn=SparseCategoricalCrossentropy())
model.fit(x_train, y_train, epochs=5, batch_size=64, validation_split=0.1)

📖 Documentation

Whether you're exploring JAX, need scalable training tools, or just love building things—check it out and let us know what you think!


🛠️ Structure

jaxflow/
├── core/           # Variable management, RNG scopes
├── gradient/       # Autograd and custom gradients
├── activations/    # relu, gelu, swiglu, ...
├── initializers/   # he_normal, glorot_uniform, ...
├── layers/         # Conv2D, Dense, LayerNorm, ...
├── losses/         # mse, cross_entropy, ...
├── optimizers/     # Optax integration
├── callbacks/      # EarlyStopping, Logger, Checkpointing
├── metrics/        # Precision, Recall, Accuracy, ...
├── models/         # Sequential, ResNet, Transformer
└── regularizers/   # Dropout, L2, ...

🚧 Coming Soon

  • Transformer layer with attention
  • Callback system (EarlyStopping, ModelCheckpoint, etc.)
  • Model saving/loading
  • Classical ML models (SVM, Logistic Regression, KNN, Random Forest)

📄 License

JAXFlow is distributed under the Apache-2.0 License. See LICENSE for full details.


With JAXFlow, keep your research code clean, fast, and scalable.

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

jaxflow-0.1.3.dev0.tar.gz (54.3 kB view details)

Uploaded Source

Built Distribution

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

jaxflow-0.1.3.dev0-py3-none-any.whl (71.4 kB view details)

Uploaded Python 3

File details

Details for the file jaxflow-0.1.3.dev0.tar.gz.

File metadata

  • Download URL: jaxflow-0.1.3.dev0.tar.gz
  • Upload date:
  • Size: 54.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jaxflow-0.1.3.dev0.tar.gz
Algorithm Hash digest
SHA256 9fc6a3fe406e55ee6e7334f7da398ba78302f01f8242e8b192a7f2684c220951
MD5 e1dc0a1040466122c660c6150c05d2dc
BLAKE2b-256 b4d91088d26da1ecaf7d97132392a537309a84486fc3aaeb80184844e20c4dce

See more details on using hashes here.

Provenance

The following attestation bundles were made for jaxflow-0.1.3.dev0.tar.gz:

Publisher: python-publish.yml on mthd98/JAXFlow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jaxflow-0.1.3.dev0-py3-none-any.whl.

File metadata

  • Download URL: jaxflow-0.1.3.dev0-py3-none-any.whl
  • Upload date:
  • Size: 71.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jaxflow-0.1.3.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe5578c688510142544d5da9898a258d85c8afd64f474229174c148f17c2a5d4
MD5 028d5233551fbb9b159ee1fbdf17147b
BLAKE2b-256 3c212ec7c5482cf26c5ebf5440eeee3a125222faa0674020bc837e996b1133e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for jaxflow-0.1.3.dev0-py3-none-any.whl:

Publisher: python-publish.yml on mthd98/JAXFlow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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