TL;DR
The authors introduce GRAPHGYM, a semi-automatic framework that constructs complex, multi-dimensional graph reasoning benchmarks to rigorously test Large Language Models (LLMs). By evaluating models across unified text- and code-based environments with graphs scaling up to 10,000 nodes, GRAPHGYM exposes critical bottlenecks in LLM reasoning, particularly showing how models fail when shifting from textbook algorithms to open-ended, composite problems.
What Problem Does This Paper Address?
Graph reasoning is an ideal testbed for LLMs: it avoids data leakage (since graphs can be programmatically randomized) and naturally tests long-context capabilities. However, existing benchmarks suffer from three major flaws:
- Low Data Complexity: They rely on small graphs, single-step tasks, and explicit graph-theoretic terms.
- Library Exploitation: In code-based settings, models often bypass actual algorithmic reasoning by simply invoking mature Python libraries like
NetworkXto solve classical problems perfectly. - Isolated Evaluation Modes: Benchmarks evaluate either text-based or code-based reasoning in isolation, failing to provide a unified picture of internal reasoning versus external tool usage.
GRAPHGYM addresses these gaps by systematically expanding benchmark coverage across five dimensions: Graph Size, Task Complexity, Task Description, Graph Loading, and Task Source.
Methods
GRAPHGYM utilizes an LLM-based data generator (DeepSeek-V3) structured into a five-stage semi-automatic pipeline, blending automated scaling with targeted human quality control:
- Task Composition & Graph Generation: Combines atomic "seed" tasks using seven composition patterns (e.g., sequential, constrained, hierarchical) and generates code to scale graphs from 10 to 10,000 nodes.
- Solver Generation & Label Annotation: The LLM generates Python solver code to compute ground-truth labels. Human annotators validate these solvers against functional test cases to ensure perfect label accuracy.
- Task Description & Question Generation: Generates both explicit (formal) and implicit (real-world narrative) problem descriptions, alongside inline and file-based graph-loading scripts.
- Evaluation Script Generation: Creates task-specific, type-aware evaluation scripts capable of parsing heterogeneous outputs (Booleans, lists, dictionaries).
- Quality Validation & Filtering: An LLM judge filters out low-quality tasks based on clarity, suitability, naturalness, and uniqueness.
Datasets
The authors construct the GRAPHGYM benchmark, featuring 202 composite tasks and up to 4,198 canonical evaluation instances. The dataset is built from a diverse pool of 100 seed tasks: 40 classical graph algorithms (e.g., shortest path, biconnectivity) and 60 open-ended problems sourced from online assessment (OA) platforms like LeetCode.
Key Insights and Ideas
- The Graph-Extraction Bottleneck: When graph data is serialized directly into the prompt (inline loading), performance collapses on large graphs. The average graph-extraction accuracy is only 54.5%. Models spend too much context and compute parsing the structure rather than solving the problem.
- File-Based Loading as a Decoupler: Providing a local file path (file-based loading) decouples graph size from prompt length. This shifts the burden to offline code execution, allowing models to remain highly robust even at 10,000 nodes.
- The "Cheating" Nature of Classical Tasks: Strong models achieve near-perfect scores on classical graph tasks at small scales because they can easily invoke pre-existing libraries. Online assessment (OA) style tasks force custom logic and reveal true performance gaps.
- Brittleness of Graph Fine-Tuning: Models fine-tuned specifically for graph tasks (e.g., GCoder, GraphWiz) suffer from severe out-of-distribution generalization issues and frequently hallucinate non-existent library APIs (e.g.,
nx.minimum_height_trees).
Key Results
- Graph Size Scaling: Under the coding-inline setting, average Exact Match (EM) scores drop precipitously from 77.9% (10 nodes) to 14.2% (10,000 nodes). Conversely, coding-file reasoning drops more gracefully from 77.7% to 46.3%.
- Compositionality Cost: Moving from a single seed task (combo size 1) to a deeply chained task (combo size 4) reduces model performance by an average of 20 percentage points.
- Code vs. Text: Code-based reasoning consistently outperforms text-based reasoning across all graph sizes and complexities, highlighting the advantage of delegating execution to an external Python interpreter.
- Top Models: Advanced models like
o4-miniandDeepSeek-V3.2lead the pack, but even they struggle significantly when implicit descriptions are combined with high composition depths.
Limitations and Future Work
The framework's effectiveness is bound to the capabilities of its underlying backbone LLM; weaker local models may struggle to reliably generate valid tasks and solvers during the construction phase. Additionally, GRAPHGYM is currently optimized strictly for evaluation rather than model fine-tuning. The authors suggest that future work should focus on developing more robust Retrieval-Augmented Generation (RAG) methods that help models better adapt to custom constraints and open algorithm designs.
Summary updated