cwenzi/neuroflow-cpp
1
NeuroFlow C++ LLM
NeuroFlow is a memory-augmented causal language model implemented entirely in C++17, featuring a three-brain architecture (SN/ECN/DMN) inspired by cognitive neuroscience. Designed for efficient training and inference on consumer GPUs.
Model Architecture
Three-Brain Architecture
- SN (Sensory Network): Input encoding and feature extraction
- ECN (Executive Control Network): Core reasoning and processing layers
- DMN (Default Mode Network): Memory-augmented association and retrieval
Files
Source Code
The full C++ source is included under src/ and include/ directories:
- Core:
tensor.hpp/cpp,model.hpp/cpp,tokenizer.hpp/cpp - Architecture:
causal_lm.hpp/cpp,generative_model.hpp/cpp,networks.hpp - Training:
train_lm.hpp/cpp,train_v2.cpp,sft_train.cpp,dpo_train.cpp - CUDA:
cuda_context.hpp/cpp,cuda_kernels.hpp,tensor_ops.cpp - Optimizers:
adamw.hpp/cpp,scheduler.hpp/cpp,grad_scaler.hpp/cpp
Build & Train
Prerequisites
- CMake ≥ 3.15
- C++17 compiler (GCC ≥ 9, MSVC 2019+)
- CUDA Toolkit ≥ 11.4 (optional, for GPU training)
- BLAS (OpenBLAS recommended)
Build
# CPU only
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
# With CUDA
mkdir build_cuda && cd build_cuda
cmake .. -DNEUROFLOW_USE_CUDA=ON -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)Train
./build_cuda/neuroflow_train_v2 \
--config configs/config_distill.json \
--data data/distill_train.txt \
--output output \
--epochs 20 \
--batch-size 64 \
--lr 0.0003 \
--use-cuda --adamTraining Scripts
Key Python scripts in scripts/:
train_distill.py— Knowledge distillation training pipelinepreprocess_distill.py— Data preprocessing for distillationdeploy_dsw.sh— One-click deployment for Alibaba Cloud DSW (A10 GPU)train_optimized.sh— Optimized multi-stage training
License
Apache 2.0
