Skip to main content

A C++ neural network engine with Python bindings, designed for educational performance optimization.

Project description

abovo logo


docs tests pypi OpenSSF Scorecard downloads

NN-ab-ovo (abovo) is a neural network engine written in C++ with Python bindings, designed to teach systems-level ML optimizations like threading, cache efficiency, hardware acceleration, and quantization.


Features

  • C++ backend with modular layers and training pipeline
  • Python API via pybind11 bindings (pip install abovo)
  • Optimizations: SIMD, OpenMP multithreading, cache blocking
  • Post-training quantization (PTQ) and quantization-aware training (QAT) (FP32 → INT8)
  • Profiling support (Valgrind, cache misses, instruction counts)

Installation

pip install abovo

Requires a C++17-compatible compiler and OpenMP support.

Example (XOR)

from abovo import Sequential, DenseLayer, Matrix, ActivationType, LossType

X = Matrix(4, 2)
X[0, 0] = 0; X[0, 1] = 0
X[1, 0] = 0; X[1, 1] = 1
X[2, 0] = 1; X[2, 1] = 0
X[3, 0] = 1; X[3, 1] = 1

y = Matrix(4, 1)
y[0, 0] = 0
y[1, 0] = 1
y[2, 0] = 1
y[3, 0] = 0

model = Sequential()
model.add(DenseLayer(2, 4, ActivationType.RELU))
model.add(DenseLayer(4, 1, ActivationType.SIGMOID))
model.train(X, y, epochs=100, batch_size=1, learning_rate=0.1, loss_type=LossType.MSE)

Build (C++ Only)

You can either build natively or in Docker. Note the provided Dockerfile runs valgrind, so adjust as needed to run the correct binary. Recommended on Apple Silicon for x86 builds.

Native Build (Mac/Linux):

make
./NN-ab-ovo

Docker (x86_64 emulation):

docker build -t nn-ab-ovo .
docker run --rm nn-ab-ovo

Make sure the MNIST dataset files (train-images.idx3-ubyte, train-labels.idx1-ubyte, etc.) are in the project root or mounted into the Docker container.

Datasets

  • XOR: Validates non-linear separability
  • MNIST: Handwritten digit classification

Optimizations

Optimization experiments are documented in the GitHub repository under optimizations.md, including:

  • Naive vs. blocked matrix multiplication
  • Compiler flag benchmarking
  • L1/L2 cache miss analysis (Valgrind)
  • OpenMP and SIMD speedups
  • Timing analysis with std::chrono

These experiments help evaluate system-level performance, guide improvements for training/inference, and validate optimizations available to the community.

Project Structure

The GitHub repository features the following project structure:

  • Matrix.hpp / Matrix.cpp: Core matrix operations and linear algebra utilities.
  • DenseLayer.hpp / DenseLayer.cpp: Fully connected layer with forward and backward pass.
  • Activation.hpp / Activation.cpp: Support for activation functions (e.g., ReLU, LeakyReLU, Sigmoid).
  • Loss.hpp: Interface for loss functions (e.g., MSE, CrossEntropy).
  • Sequential.hpp / Sequential.cpp: High-level container for layer sequencing and model training.
  • tests: Directory containing runnable code on specific datasets.

The engine is modular: activation functions, loss functions, and layers are easily swappable for flexibility and experimentation.

Documentation

Read the full docs at: https://nn-ab-ovo.readthedocs.io/.

Why “ab ovo”?

"From the egg" — the library was built from the ground up, with performance and pedagogy in mind.

Future Work

  • Switch Design Pattern for Activation + Loss
  • Switch Matrix class to use size_t + Refactor
  • More comprehensive Softmax implementation
  • Continue with optimizations
  • Add support for convolutional layers
  • Implement GPU acceleration (Metal or CUDA)
  • LLVMs?

Disclaimer

NN-ab-ovo (abovo) is an independent open-source project and is not affiliated with or endorsed by any company or organization.

License

MIT License

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

abovo-0.1.3.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

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

abovo-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (154.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file abovo-0.1.3.tar.gz.

File metadata

  • Download URL: abovo-0.1.3.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for abovo-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f2c4a6837d0708f40718a42668143a28aca0a260b15114b98ee725851a7929b9
MD5 db0ea9fdeff00fd5f11ddd4f03db1710
BLAKE2b-256 609da07f335149848950624c15ed7762746990dbd9a16e2e8095ff2e9c3b3cc5

See more details on using hashes here.

File details

Details for the file abovo-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for abovo-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee79fc5502946aff3560a785cd0594f7dfce0497e510df37d5e40161efb2de96
MD5 1b9386c39c53dfd8d9f8149a265074ec
BLAKE2b-256 93f28332a0660c1f835db05e6161eb923d55c0fd730a9425cbbe698c88d895ae

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