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.
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.
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 | Dimensions | Purpose | Mechanism |
|---|---|---|---|
| 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 |
| Metric | Value |
|---|---|
| Teacher | Ornith 9B (remote LM Studio) |
| Data generation | 6/8 examples, ~8 min |
| Supervised loss | 8.63 → 8.62 (5 epochs, early stop) |
| RL best score | 100.00 / 100 |
| RL average score | 28.33 / 100 (30 iters, 2 candidates) |
| Total training time | ~68 minutes |
| Model VRAM (bf16) | 25.4 MiB |
| Peak training VRAM | ~500 MiB |
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"
| Parameter | Value |
|---|---|
| d_model | 320 |
| Layers | 5 |
| Heads | 4 |
| Vocab size | 5,000 |
| Max sequence | 512 |
| Memory slots | 32 per block |
| Expert count | 4 |
| Gradient checkpointing | use_reentrant=False |