newnet β Neural Network Engine from Scratch in C++
A minimal, educational neural network library built from scratch in C++17.
No dependencies. One compile command. Multi-threaded CPU backend designed to be swapped to SYCL/AdaptiveCpp for cross-vendor GPU support.
Quick Start
git clone https://huggingface.co/notRaphael/newnet
cd newnet
g++ -std=c++17 -O2 -pthread -o newnet main.cpp
./newnet
Architecture
newnet/
βββ core/
β βββ tensor.hpp β Tensor class (data + grad + shape)
β βββ backend.hpp β All math ops (matmul, relu, sigmoid, etc.)
β Swap THIS file for SYCL/GPU backend.
βββ layers/
β βββ layer.hpp β Abstract base class
β βββ dense.hpp β Fully connected layer (forward + backward)
βββ graph/
β βββ graph.hpp β Sequential model (chains layers)
β βββ optimizer.hpp β SGD optimizer
βββ loss/
β βββ loss.hpp β MSE loss
βββ main.cpp β XOR training example with progress bar
Design Principles
- Loose coupling: Backend is one file. Swap it for SYCL/AdaptiveCpp without touching neural network code.
- No dependencies: Compiles with plain g++. No cmake, no libraries.
- Every line readable: Written for humans learning how NNs work internally.
- Hardcoded derivatives: Each layer knows its own gradient formula. No autograd, no symbolic math.
Backend Abstraction
The core/backend.hpp file contains ALL math operations:
matmul(multi-threaded)relu_forward/relu_backwardsigmoid_forward/sigmoid_backwardtranspose,add,scale,sum_columns
To port to GPU: replace this ONE file with SYCL kernels. Everything else stays the same.
Roadmap
- Tensor class
- Dense layer with forward/backward
- SGD optimizer
- MSE loss
- XOR training (proof of concept)
- MNIST training
- Skip connections (ResNet-style)
- Conv2D layer
- Adam optimizer
- L-BFGS (second-order optimizer)
- SYCL/AdaptiveCpp backend
- Vision Transformer
Papers & References
- Backpropagation: Rumelhart et al., 1986
- Xavier initialization: Glorot & Bengio, 2010
- Adam: Kingma & Ba, 2014
- ResNet skip connections: He et al., 2015
License
MIT
Generated by ML Intern
This model repository was generated by ML Intern, an agent for machine learning research and development on the Hugging Face Hub.
- Try ML Intern: https://smolagents-ml-intern.hf.space
- Source code: https://github.com/huggingface/ml-intern
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "notRaphael/newnet"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
For non-causal architectures, replace AutoModelForCausalLM with the appropriate AutoModel class.
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support