NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

VisualCoder: Guiding Large Language Models in Code Execution with Fine-grained Multimodal Chain-of-Thought Reasoning

Cuong Chi Le, Hoang Chau Truong Vinh, Huy Nhat Phan, Dung Duy Le, Tien N. Nguyen, Nghi D. Q. Bui

Large Language Models (LLMs) excel at syntax but often struggle with the dynamic nature of code execution. While they can parse a script, they frequently lose track of variable states during complex loops or follow logically unreachable execution paths. To address this, researchers from FPT Software AI Center, VinUniversity, and UT Dallas have developed VisualCoder. This framework helps Vision-Language Models (VLMs) bridge the gap between static code and dynamic execution using visual Control Flow Graphs (CFGs) and a novel "Reference Mechanism."

The Challenge of Non-Linear Execution

Code is written linearly but executes non-linearly due to branches, loops, and function calls. Traditional approaches using textual CFGs (like Mermaid) often fail to capture structural complexity, and specialized Graph Neural Networks (GNNs) are difficult to integrate into general-purpose LLMs. Even when VLMs are provided with CFG images, they often "hallucinate" by misaligning code lines with graph nodes.

Methodology: Visual CFGs and Grounded Reasoning

VisualCoder introduces two primary innovations to ground model reasoning in the actual execution flow:

  1. Visual CFG Integration: Instead of textual descriptions, the system generates high-resolution images of the code's Control Flow Graph. This leverages the spatial reasoning capabilities of advanced VLMs like Claude 3.5 Sonnet and GPT-4o.
Comparison of source code and its corresponding visual Control Flow Graph (CFG).
  1. The Reference Mechanism: This mechanism instructs the model to explicitly link each line of code it analyzes to a specific node in the CFG (e.g., "Line 5: N += 1 (Node 5 in CFG)"). This explicit mapping ensures the model's internal attention is physically grounded in the correct visual execution path, preventing it from wandering into unreachable code blocks.
Example of fine-grained multimodal Chain-of-Thought (CoT) reasoning identifying a bug.

Evaluation and Benchmarks

The framework was tested across several rigorous benchmarks:

  • CRUXEval: For predicting program inputs and outputs.
  • LiveCodeBench & FixEval: For program repair and fault localization.
  • Defects4J v1.0: A benchmark of 245 real-world Java bugs to test robustness on industrial-scale code.

Key Insights

  • Spatial Reasoning over Text: Visual CFGs consistently outperformed text-based representations. The spatial layout provides an intuitive layer of information for non-linear flows.
  • The Importance of Alignment: Simply providing an image isn't enough; without the Reference Mechanism, models often suffer from cascading errors due to misalignment.
  • Handling Unreachable Code: VisualCoder excels at identifying unreachable branches. While a standard LLM might report an error in an else block that is never executed, VisualCoder uses the CFG to correctly identify the actual error elsewhere.

Results

VisualCoder demonstrated significant performance gains:

  • Fault Localization: Achieved 91.4% accuracy on FixEval (using Claude 3.5 Sonnet), outperforming models without the reference mechanism (86.1%).
  • Program Repair: Boosted InternVL2-26B performance from 2.1% to 10.7%.
  • Real-world Impact: On the Defects4J dataset, VisualCoder identified 12 more real-world bugs than the baseline, improving acc@1 from 47 to 59.

Limitations and Future Directions

The effectiveness of VisualCoder depends on the quality of the generated CFG. Future work will address scalability for massive programs with hundreds of nodes, where VLM resolution might become a bottleneck. Additionally, the researchers suggest exploring other representations like Abstract Syntax Trees (ASTs) for different coding tasks.

VisualCoder marks a significant step toward "embodied" code reasoning, enabling models to navigate code as a structured, visual environment rather than just a sequence of text.

Summary updated

BibTeX
@inproceedings{le2025visualcoder,
  author = {Cuong Chi Le and Hoang Chau Truong Vinh and Huy Nhat Phan and Dung Duy Le and Tien N. Nguyen and Nghi D. Q. Bui},
  title = {{VisualCoder: Guiding Large Language Models in Code Execution with Fine-grained Multimodal Chain-of-Thought Reasoning}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.findings-naacl.370},
}
Figure