NeuroSymbolicCodeTransformer

A 13.32M-parameter hybrid neuro-symbolic transformer for Python code generation.
Distills knowledge from a 9B reasoning LLM into a compact architecture trainable on 6GB VRAM.

13.32M params 5 custom neurons MoE routing REINFORCE RL RTX 4050 bfloat16

📄 Technical Whitepaper

NeuroSymbolicCodeTransformer: A Neuro-Symbolic Transformer for Code Generation via Knowledge Distillation and REINFORCE Policy Gradient
12 pages — Architecture, Training Pipeline, Experimental Results, Related Work, and Future Directions.

📥 Download PDF

Overview

NeuroSymbolicCodeTransformer uses a three-phase pipeline: (1) a teacher LLM (Ornith 9B, Qwen3.5-based) converts natural language requests into mathematical specifications, (2) a small neuro-symbolic model learns to map those specifications to AST token sequences via supervised learning, and (3) REINFORCE policy-gradient reinforcement learning refines the model using teacher-scored feedback.

The architecture introduces five custom neuron classes — LogicGate, Program, LocalTree, Routing, and Memory — organized into MoE-routed transformer blocks. The entire model occupies only 25.4 MiB of VRAM at bfloat16 precision.

Neuron Architecture

NeuronDimensionsPurposeMechanism
LogicGateNeuron d_model → d_model/2 → d_model Conditional AST nodes (if/else, boolean ops) AND/OR/XOR/NOT with learnable softmax gate weighting
ProgramNeuron d_model → d_model; 5 op chunks Differentiable compute primitives 5 parallel math ops (sum, product, max, min, mean) per chunk
LocalTreeNeuron d_model; kernel=3 Parent-child AST hierarchy Depthwise Conv1d with sigmoid gating
RoutingNeuron d_model → d_model/4 → 4 MoE expert dispatch Mean-pooled → 2-layer MLP → 4-way softmax
MemoryNeuron 32 slots × d_model Long-range dependency memory Attention read + gated soft-update writes

Training Results — Run A

MetricValue
TeacherOrnith 9B (remote LM Studio)
Data generation6/8 examples, ~8 min
Supervised loss8.63 → 8.62 (5 epochs, early stop)
RL best score100.00 / 100
RL average score28.33 / 100 (30 iters, 2 candidates)
Total training time~68 minutes
Model VRAM (bf16)25.4 MiB
Peak training VRAM~500 MiB

Quick Start

git clone https://github.com/DexopT/neuro-symbolic-coder-13M
cd neuro-symbolic-coder-13M
chmod +x setup.sh && ./setup.sh

# Train with remote teacher
python main.py --server http://<lm-studio-ip>:1234 --model ornith-1.0-9b

# Inference
python infer.py --prompt "Write a function to compute fibonacci numbers"

Configuration

ParameterValue
d_model320
Layers5
Heads4
Vocab size5,000
Max sequence512
Memory slots32 per block
Expert count4
Gradient checkpointinguse_reentrant=False