| --- |
| tags: |
| - ml-intern |
| --- |
| # 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 |
|
|
| ```bash |
| 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 |
|
|
| 1. **Loose coupling**: Backend is one file. Swap it for SYCL/AdaptiveCpp without touching neural network code. |
| 2. **No dependencies**: Compiles with plain g++. No cmake, no libraries. |
| 3. **Every line readable**: Written for humans learning how NNs work internally. |
| 4. **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_backward` |
| - `sigmoid_forward` / `sigmoid_backward` |
| - `transpose`, `add`, `scale`, `sum_columns` |
|
|
| To port to GPU: replace this ONE file with SYCL kernels. Everything else stays the same. |
|
|
| ## Roadmap |
|
|
| - [x] Tensor class |
| - [x] Dense layer with forward/backward |
| - [x] SGD optimizer |
| - [x] MSE loss |
| - [x] 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 |
|
|
| <!-- ml-intern-provenance --> |
| ## Generated by ML Intern |
|
|
| This model repository was generated by [ML Intern](https://github.com/huggingface/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 |
|
|
| ```python |
| 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. |
|
|