QNET lightweight C++ neural network graph library

Neural Network Building Blocks in C++

QNET is a lightweight C++17 neural network graph library for CPU training and inference, actively developed by COS Q Network.

It combines a static computation graph, reverse-mode automatic differentiation, OpenBLAS-backed matrix math, and a focused training stack for building and evaluating neural-network models with a small dependency footprint.

Explore QNET on GitHub

A Small, Explicit Computation Graph

QNET tensor, static graph, autograd, CPU math, and training architecture

QNET stores data in strided Tensor objects and constructs an explicit static Graph of nodes. The graph is built once, then reused across minibatches during training.

Forward execution evaluates the graph, while reverse-mode autograd computes gradients through the same structure. A thread pool supports parallel execution across graph levels.

The CPU math backend uses OpenBLAS GEMM and batched strided matrix multiplication, with SIMD-backed elementwise operations for a focused float-only runtime.

Focused Neural Network Primitives

QNET neural network operations, layers, losses, and optimizers

QNET includes core operations such as matrix multiplication, broadcasting addition, multiplication, ReLU, sigmoid, softmax, convolution, embedding, dropout, and layer normalization.

Its model-building layer provides Linear, Conv2d, Embedding, Dropout, LayerNorm, Sequential, and Model components.

Training workflows support cross-entropy, mean squared error, and binary cross-entropy losses, along with SGD, Adam, and AdamW optimizers.

Training Utilities and Portable Models

QNET training, checkpointing, serialization, and CMake tooling

The training stack includes Dataset, TensorDataset, and DataLoader abstractions for batching and shuffling, plus a Trainer with validation passes, callbacks, early stopping, accuracy metrics, and best-checkpoint restore.

Models can be saved as complete .qnet graphs or parameter-only artifacts. QNET also supports SafeTensors import/export and optimizer-state persistence.

The project uses CMake build and install/export rules, CPack packaging, GitHub Actions CI across Linux, macOS, and Windows, and an optional pybind11 module for selected C++ APIs.

A Deliberately Small CPU-First Library

QNET occupies a focused niche: a self-contained C++17 autograd and neural-network kernel for CPU training and inference, with a static-graph design and a small set of composable primitives.

Optional Python bindings expose selected Tensor, Graph, Node, optimizer, and SafeTensors APIs. An Emscripten helper provides a path toward WebAssembly builds, while the core runtime remains intentionally CPU-first.

QNET is released under the MIT License. Read the full license on GitHub.

Explore QNET

Follow the graph runtime, training utilities, build instructions, serialization formats, and ongoing development in the public repository.

Visit QNET on GitHub