Abstract
Large Language Models (LLMs) have shown proficiency in various tasks, but their ability to perform multi-step logical reasoning on explicit structures like graphs remains a subject of debate. This paper discusses the Multistep Algorithmic reAsoning Benchmark (MAGMA), introduced by researchers at UCLA. MAGMA evaluates LLMs on their ability to execute classical graph algorithms step-by-step rather than just providing a final answer. The study finds that while frontier models like GPT-4o struggle with complex graph logic, smaller models fine-tuned on intermediate reasoning steps can significantly outperform them, highlighting the importance of internal state tracking for robust algorithmic reasoning.
Introduction
While LLMs have mastered creative writing and basic coding, they often encounter difficulties with multi-step logical reasoning, particularly when dealing with explicit structures like graphs. Most current evaluations of "graph reasoning" are oversimplified, providing a graph and asking for a final answer (e.g., "What is the shortest path?"). This "flattened" approach ignores the algorithmic journey, failing to capture whether a model truly understands the logic or is simply making a statistical guess.
The MAGMA Benchmark
To address these limitations, the Multistep Algorithmic reAsoning Benchmark (MAGMA) was developed. Adapted from the CLRS benchmark, MAGMA converts classical graph algorithms into a natural language format suitable for LLMs. The benchmark includes five fundamental algorithms: Breadth-First Search (BFS), Depth-First Search (DFS), Dijkstra’s, Floyd-Warshall, and Prim’s algorithm.
The researchers tested three primary prompting and training strategies:
- Input-Output (IO): The traditional approach where the model is given a graph and asked for the final result.
- Intermediate Steps (IS): The model is prompted to produce the state of the algorithm at every logical step.
- Intermediate Steps with Hints (ISH): Similar to IS, but the prompt includes additional internal state variables (like predecessor pointers) to guide the model.
Key Insights and Results
The evaluation compared state-of-the-art closed models (GPT-4o) against fine-tuned open-source models (Llama-3-8B and Mistral-7B). Several key findings emerged:
- Specialized Reasoning vs. Scale: Fine-tuned 7B or 8B parameter models vastly outperformed massive frontier models like GPT-4o on specific algorithmic tasks. For instance, on the complex Floyd-Warshall algorithm, GPT-4o’s zero-shot accuracy was near zero for larger graphs, while fine-tuned smaller models maintained functional reasoning.
- The Scaffold Effect: Fine-tuning on intermediate steps significantly improves final answer accuracy. These steps act as a logical scaffold, grounding the model in the graph's actual structure and reducing hallucinations of non-existent nodes or edges.
- The Hint Paradox: Surprisingly, adding more detailed hints (ISH) sometimes decreased performance compared to using only intermediate steps (IS). This suggests that LLMs are highly sensitive to extraneous information, which can clutter the context and distract from core logic.
Conclusion
The MAGMA benchmark demonstrates that "showing your work" through intermediate steps is essential for LLMs to perform complex graph reasoning. While raw scale provides general-purpose capabilities, specialized fine-tuning on algorithmic trajectories allows smaller models to achieve superior performance on structured logical tasks. Future research will focus on scaling these findings to more diverse graph types and exploring the transferability of these reasoning skills to other scientific and engineering domains.
Summary updated