Skip to content

GraphMend: Code Transformations for Fixing Graph Breaks in PyTorch 2

Sep 2025 · arXiv.org · Vol abs/2509.16248 · 1 citation · 68 references
Computer Science

TL;DR

Results demonstrate that semantics-aware source-level analysis and transformation are effective complements to PyTorch's dynamic JIT compilation pipeline, substantially improving both usability and performance.

Abstract

This paper presents GraphMend, a compiler technique that automatically fixes FX graph breaks in PyTorch 2 programs. Although PyTorch 2 introduced TorchDynamo and TorchInductor to enable just-in-time graph compilation, certain code patterns still cause graph breaks that force execution to fall back to Python eager mode, introducing costly CPU-GPU synchronization and reducing optimization opportunities. Our investigation of 195 Hugging Face models reveals that 13.8% of models exhibit graph breaks. GraphMend automatically eliminates fixable breaks through source-level program analysis and transformations. It analyzes AST-level program structure to identify graph-break patterns and applies transformations only when their semantic preservation can be statically established. These transformations enable PyTorch to capture larger, uninterrupted FX graphs without manual refactoring by developers. We evaluate GraphMend on all 27 models found to exhibit graph breaks in our investigation. GraphMend eliminates 107 of 147 graph breaks (73%), fully fixing all breaks in 21 models. In our experiments on NVIDIA GPUs, GraphMend achieves up to 26x cold-start speedup, 5x on average, and up to 1.39x steady-state forward pass speedup. These results demonstrate that semantics-aware source-level analysis and transformation are effective complements to PyTorch's dynamic JIT compilation pipeline, substantially improving both usability and performance.

View source

Similar papers

CG-Diff: Organizing Code Changes Around Call Graphs

Tools for code review present code changes file-by-file. We argue that, oftentimes, changes can be better organized around a call graph of the changed code. From an empirical study of GitHub pull requests (PRs) in-the-wild, we find that (1) in around 40% of the PRs, more than half of the changed functions (and methods)...

Bimal Gyawali, Devamardeep Hayatpur, N. Polikarpova · 0 citations
Book Open access Oct 2026

Order-Aware State Elimination for Algebraic Program Analysis

Algebraic program analysis (APA) constructs path expressions from a control-flow graph and interprets them in a semantic algebra. Existing work has shown that graph structure, decompositions, and fill-reducing orderings affect APA cost, but does not choose the next state online as elimination evolves. Such methods cann...

Bo-Xuan Zheng · 0 citations
Sep 2026

Dynamic Conformance Testing of WebGPU Through Specification-Driven Mutation

LANTERN, a specification-guided dynamic conformance testing framework that mutates CTS tests using constraints extracted from the WebGPU specification, is introduced, demonstrating that syntactically seeded, semantics-aware mutation of conformance tests provides a way to uncover browser bugs during WebGPU testing.

Mahya Samdaliri, Zhi-Hao Yao, Kasthuri Jayarajah · 0 citations
Preprint Oct 2026

Pattern-Guided Graph Synthesis for Suppressing Known Defects in DL Compiler Fuzzing

Fuzzing is effective at finding bugs in deep learning (DL) compilers, but existing fuzzers repeatedly trigger faults they have already uncovered. Current fuzzers diversify the generated programs, and downstream tools deduplicate bug reports post hoc, but neither stops a fuzzer from generating programs that re-trigger k...

Qiong Feng, Xiao-Tian Ma, Di Cui et al. · 0 citations
Book Open access Nov 2026

EvoFuzz: IR-Aware Fuzzing for JIT Compilers through the Lens of Node Evolution

JIT compilers are core components of modern language virtual machines, and their bugs can crash the VM or silently miscompile programs. Modern JIT compilers perform multiple rounds of optimizations on graph-based intermediate representation (IR), where each round modifies, transforms, or eliminates IR nodes (referred t...

Jin-Ze Si, Yu-Chen Sun, Ming-Yu Wu et al. · 0 citations
Open access Oct 2026

BCaLLM: Call Graph-Guided Python Breaking Change Detection with Large Language Models

Software libraries frequently evolve, introducing breaking changes that disrupt client applications. Existing detection approaches primarily target static programming languages or focus on syntactic changes, leaving behavioral breaking changes in dynamic languages such as Python underexplored. This task is particularly...

Wei Cheng, Chen Shen, Huan Zhang et al. · 0 citations

Related blog posts

MIT News · Artificial Intelligence Nov 17, 2026

Learning the language of machine learning

By studying the computational foundations of language learning, Associate Professor Jacob Andreas builds intelligent systems that can communicate effectively with humans.

Microsoft Research Blog Nov 16, 2026

TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient

AI coding agents are increasingly help developers fix bugs and build features largely on their own, but every interaction with their models consumes tokens. In each session, an agent sends instructions, tool descriptions, and session history to its model. Most efforts to reduce this cost focus on individual tasks. Yet developers return to the same […] The post TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient appeared first on Microsoft Research.

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.