Less is More: Learning Graph Tasks with Just LLMs

Sola Shirai, Kavitha Srinivas, Julian Dolby, Michael Katz, Horst Samulowitz, Shirin SohrabiarXiv 2025 · DOI

Introduction

Reasoning over graph structures—such as social networks, knowledge bases, or code dependencies—remains a significant challenge for Large Language Models (LLMs). Current research typically follows one of two paths: serialization, where the graph is converted into a textual description, or hybrid architectures, which utilize a Graph Neural Network (GNN) to inject specialized "graph tokens" into the LLM's latent space. While hybrid models aim for efficiency, they often struggle with generalization. This paper investigates whether a standard LLM can learn the underlying logic of graph algorithms through text-based fine-tuning alone.

Methodology

The study evaluates four distinct approaches using a Phi4-Mini (4B) model to determine the most effective way to infuse graph reasoning capabilities:

  1. LoRA: Fine-tuning the LLM's weights on textual graph descriptions.
  2. P-Tuning: Learning continuous "soft prompt" embeddings while keeping the LLM frozen.
  3. Graph Tokens: Employing a Relational Transformer (GNN) to generate embeddings from an adjacency matrix.
  4. Graph Tokens + Text: A hybrid approach combining GNN embeddings with textual descriptions.
The four architectural approaches evaluated: LoRA, P-Tuning, Graph Tokens, and a hybrid Graph Tokens + Text model.

A critical component of the training is Instructive Chain-of-Thought (CoT). Rather than providing simple answers, the training data includes deterministic execution traces (e.g., Python-like queue states for BFS). The models were trained on four foundational tasks: Node Count, Node Degree, DFS, and BFS.

Experimental Setup

The researchers generated synthetic graphs ranging from 20 to 100 nodes across seven structural models (e.g., Erdos-Rényi, Barabási–Albert). Evaluation extended beyond these parameters to include:

  • Out-of-Distribution (OOD) Size: Graphs with up to 280 nodes.
  • OOD Structure: Trees and Cycle graphs.
  • OOD Tasks: Edge Existence, Shortest Path, and Cycle Check.
  • Real-world Benchmarks: PrOntoQA (logical reasoning) and LC-QuAD 2.0 (Knowledge Graph QA).

Results and Discussion

The experimental results highlight several key findings:

The Superiority of LoRA

Pure text-based fine-tuning via LoRA emerged as the clear winner. While GNN-based "Graph Tokens" are more token-efficient, they proved brittle when encountering larger graphs or novel structures. In contrast, LoRA achieved nearly 100% accuracy on in-distribution tasks.

Generalization and Scalability

One of the most significant findings is the model's ability to generalize to larger graph sizes. As shown in the performance metrics for Depth-First Search (DFS) on cycle graphs, the LoRA-tuned model maintains high accuracy even as the number of nodes doubles beyond the training distribution.

Accuracy vs. Number of Nodes for the Cycle Graph DFS task. LoRA (red) maintains near-perfect accuracy even as graph size increases, significantly outperforming GNN-based token methods.

The Role of Chain-of-Thought

Instructive CoT was found to be non-negotiable. Without these execution traces, models—particularly P-Tuning and Graph Token variants—failed even on basic tasks like node degree counting. This suggests that the "recipe" of the algorithm is more important than the raw structural data.

Downstream Impact

The graph-tuned LoRA model demonstrated remarkable transferability to logical reasoning. On the PrOntoQA benchmark, it reached 99.8% accuracy (up from 47% for the base model) by reframing logical assertions as graph reachability problems.

Conclusion

This research demonstrates that specialized neural encoders are not strictly necessary for graph reasoning. Small LLMs can master complex graph algorithms and generalize to unseen structures through LoRA fine-tuning and instructive CoT. While challenges remain—such as the "stopping problem" in cycle detection and token efficiency for massive graphs—text-based fine-tuning provides a robust and surprisingly scalable path forward for graph-aware AI.

Summary updated

BibTeX
@misc{shirai2025less,
  author = {Sola Shirai and Kavitha Srinivas and Julian Dolby and Michael Katz and Horst Samulowitz and Shirin Sohrabi},
  title = {{Less is More: Learning Graph Tasks with Just LLMs}},
  year = {2025},
  eprint = {2508.10115},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.10115},
}
Figure