GraphMend: Code Transformations for Fixing Graph Breaks in PyTorch 2

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Kashmira, Savini, Dantanarayana, Jayanaka, Sathiyalogeswaran, Thamirawaran, Flautner, Krisztian, Tang, Lingjia, Mars, Jason
Format: Preprint
Veröffentlicht: 2025
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866918476129501184
author Kashmira, Savini
Dantanarayana, Jayanaka
Sathiyalogeswaran, Thamirawaran
Flautner, Krisztian
Tang, Lingjia
Mars, Jason
author_facet Kashmira, Savini
Dantanarayana, Jayanaka
Sathiyalogeswaran, Thamirawaran
Flautner, Krisztian
Tang, Lingjia
Mars, Jason
contents This paper presents GRAPHMEND, a high-level compiler technique that eliminates FX graph breaks in PyTorch 2 programs. Although PyTorch 2 introduced TorchDynamo and TorchInductor to enable just-in-time graph compilation, unresolved dynamic control flow and unsupported Python constructs often fragment models into multiple FX graphs. These fragments force frequent fallbacks to eager mode, introduce costly CPU-to-GPU synchronizations, and reduce optimization opportunities. GRAPHMEND addresses this limitation by analyzing and transforming source code before execution. Built on the Jaseci compilation framework, GRAPHMEND introduces two code transformations that remove graph breaks due to dynamic control flow and Python side effects. This design allows PyTorch's compilation pipeline to capture larger, uninterrupted FX graphs without requiring manual refactoring by developers. Evaluation across eight Hugging Face models shows that GRAPHMEND removes graph breaks due to dynamic control flow and Python side effects, reducing the break count to 0 in 6 models and reducing it from 5 to 2 in another model. On NVIDIA RTX 3090 and A40 GPUs, GRAPHMEND achieves up to 75% latency reductions and up to 8% higher end-to-end throughput. These results demonstrate that high-level code transformation is an effective complement to PyTorch's dynamic JIT compilation pipeline, substantially improving both usability and performance.
format Preprint
id arxiv_https___arxiv_org_abs_2509_16248
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle GraphMend: Code Transformations for Fixing Graph Breaks in PyTorch 2
Kashmira, Savini
Dantanarayana, Jayanaka
Sathiyalogeswaran, Thamirawaran
Flautner, Krisztian
Tang, Lingjia
Mars, Jason
Programming Languages
Machine Learning
Software Engineering
This paper presents GRAPHMEND, a high-level compiler technique that eliminates FX graph breaks in PyTorch 2 programs. Although PyTorch 2 introduced TorchDynamo and TorchInductor to enable just-in-time graph compilation, unresolved dynamic control flow and unsupported Python constructs often fragment models into multiple FX graphs. These fragments force frequent fallbacks to eager mode, introduce costly CPU-to-GPU synchronizations, and reduce optimization opportunities. GRAPHMEND addresses this limitation by analyzing and transforming source code before execution. Built on the Jaseci compilation framework, GRAPHMEND introduces two code transformations that remove graph breaks due to dynamic control flow and Python side effects. This design allows PyTorch's compilation pipeline to capture larger, uninterrupted FX graphs without requiring manual refactoring by developers. Evaluation across eight Hugging Face models shows that GRAPHMEND removes graph breaks due to dynamic control flow and Python side effects, reducing the break count to 0 in 6 models and reducing it from 5 to 2 in another model. On NVIDIA RTX 3090 and A40 GPUs, GRAPHMEND achieves up to 75% latency reductions and up to 8% higher end-to-end throughput. These results demonstrate that high-level code transformation is an effective complement to PyTorch's dynamic JIT compilation pipeline, substantially improving both usability and performance.
title GraphMend: Code Transformations for Fixing Graph Breaks in PyTorch 2
topic Programming Languages
Machine Learning
Software Engineering
url https://arxiv.org/abs/2509.16248