Algorithmic Language Models with Neurally Compiled Libraries

Lucas Saldyt, Subbarao Kambhampati · DOI

Introduction

Despite their transformative impact, Large Language Models (LLMs) often struggle with "true" algorithmic reasoning. When tasked with sorting a list or executing complex planning, these models frequently rely on statistical patterns—or "shortcuts"—found in their training data rather than executing the underlying logic. This limitation stems from two primary factors: the mathematical constraints of the Transformer architecture (upper-bounded by the complexity class $TC^0$) and the tendency of gradient descent to favor memorization over generalized algorithm induction.

To address this, researchers have developed a method to augment LLMs with an internal "differentiable computer." By integrating a library of pre-compiled, symbolic programs directly into the neural architecture, the model can move beyond statistical approximations toward robust, sequential reasoning.

Overview of the LLaMA-based system augmented with a differentiable program library.

The Differentiable Register Machine

The core of this approach involves augmenting a model, such as LLaMA 3.2, with a Differentiable Register Machine (DRM). Rather than training the model to learn an algorithm like sorting from scratch through raw text examples, the researchers "neurally compile" known symbolic algorithms into the model's weights.

Key Components

  • The Library ($\Lambda$): A collection of differentiable programs (e.g., insertion sort, Fibonacci) and primitive arithmetic operations.
  • Neural Compilation: A technique that transforms symbolic code into neural network parameters, ensuring the network executes the exact logic of the original program.
  • The call Instruction: A novel addition that allows the model to jump between different sub-programs, enabling the composition of complex behaviors from simpler modules.
  • Differentiable Memory & Registers: Utilizing softmax-based "superposition" to read and write data, the entire system remains end-to-end trainable via backpropagation.

Implementation: Lookup Tables vs. Circuits

A critical design choice in building these libraries is how to implement basic operations like arithmetic. The researchers compared two distinct methods:

  1. Lookup Tables: These are fast and easy for the model to learn but are memory-intensive and do not scale well to large numerical ranges.
  2. Differentiable Circuits: These are logic gates constructed from differentiable operators. While they scale significantly better, they are notoriously difficult to train from scratch.
Comparison of test accuracy over epochs for lookup tables versus differentiable circuits.

As shown in the experimental results, Lookup Tables allow the model to reach 100% accuracy almost immediately, whereas Differentiable Circuits struggle to converge. This led to a "bootstrapping" insight: models can be trained to use simple lookup tables first to master the "parsing" of natural language into symbolic inputs, before swapping the backend for a more complex, generalized logic circuit.

Experimental Results and Insights

The system was evaluated on several algorithmic hurdles using synthetic datasets:

  • Modular Arithmetic: A fine-tuned LLaMA 3.2 1B model achieved 100% accuracy on modular arithmetic tasks (e.g., "Add 3 and 4 mod 128") within just 4 to 9 epochs. This demonstrates that the LLM can successfully learn to map natural language prompts into the specific one-hot encodings required by the internal computer.
  • Character Sorting: On tasks requiring the sorting of 8- to 12-character strings, the model achieved 33-36% accuracy. While modest, this represents a significant step in end-to-end supervised learning through the 42-instruction-long loops required for insertion sort.
  • Recursion Depth: The authors successfully trained models to handle recursive depths of up to 6 (roughly 48 interpreter steps). However, they noted that deeper recursions introduce significant gradient noise, creating a "threshold" for trainability.

Challenges and Future Directions

While promising, the integration of symbolic libraries and neural networks faces several hurdles. Numerical instability is a primary concern; the "superposition" of states in a differentiable computer can lead to "fuzzy" values that accumulate error over sequential steps, resulting in vanishing or exploding gradients. Furthermore, there is a fundamental tension between the LLM's fluid internal representations and the rigid requirements of a symbolic library.

Future work aims to explore massively parallel differentiable computers, which may be more naturally compatible with the Transformer's processing style. Additionally, the researchers hope to further investigate compositionality—the model's ability to synthesize entirely new programs by composing multiple library functions on the fly.

Summary updated

BibTeX
@inproceedings{saldyt2024algorithmic,
  author = {Lucas Saldyt and Subbarao Kambhampati},
  title = {{Algorithmic Language Models with Neurally Compiled Libraries}},
  booktitle = {Sys2-Reasoning @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=W77TygnBN5},
}
Figure