Verify Distributed Deep Learning Model Implementation Refinement with Iterative Relation Inference

Zhanghan Wang, Ding Ding, Hang Zhu, Haibin Lin, Aurojit Panda · DOI

Introduction

Modern deep learning models, such as Llama-3 and GPT, have grown to sizes that far exceed the memory capacity of a single GPU. Consequently, developers must employ complex distribution strategies, including Tensor Parallelism (TP), Pipeline Parallelism (PP), and Sequence Parallelism (SP). This involves manually transforming a sequential model specification ($G_s$) into a distributed implementation ($G_d$) by inserting communication kernels (e.g., All-Reduce, Reduce-Scatter) and data sharding operations.

This transformation process is highly error-prone. Subtle bugs—such as incorrect scaling factors, padding offsets, or weight matrix sharding—can lead to models that "run" but produce slightly incorrect gradients. These "silent" bugs degrade performance and are notoriously difficult to debug using traditional methods.

Methodology: GraphGuard

To address these challenges, we present GraphGuard, a static analysis tool designed to verify that a distributed implementation correctly refines its sequential specification.

Model Refinement and Clean Relations

GraphGuard defines correctness through the lens of Model Refinement: an implementation $G_d$ is considered correct if the outputs of the sequential model $G_s$ can be reconstructed from $G_d$ using only "clean" operations. Clean operations are restricted to simple rearrangements (slicing, concatenation) or basic reductions (sums), ensuring that the implementation does not introduce unintended mathematical deviations.

Sequential vs. Distributed Graph Refinement

Iterative Relation Inference

A key innovation in GraphGuard is Iterative Relation Inference. Rather than attempting to prove the equivalence of two massive graphs simultaneously—a computationally prohibitive task—GraphGuard processes the sequential model operator-by-operator in topological order.

Iterative Relation Inference Process

By verifying that each individual operator's output in $G_s$ can be mapped to a corresponding set of tensors in $G_d$, the verification complexity scales linearly with the number of operators. This approach also provides actionable localization: if a proof fails, GraphGuard identifies the exact operator where the discrepancy originated.

Equality Saturation and Graph Capture

GraphGuard utilizes the egg library for Equality Saturation (EGraphs) to perform symbolic rewriting. It attempts to rewrite the distributed implementation's tensors to match the sequential model's expected outputs. To integrate with existing PyTorch workflows, GraphGuard leverages TorchDynamo to extract computation graphs directly from source code.

Evaluation and Results

GraphGuard was evaluated on state-of-the-art architectures (GPT, Llama-3, Qwen2) and frameworks (Megatron-LM, vLLM, and internal Bytedance systems).

  • Efficiency: The tool is remarkably fast, verifying a single layer of complex LLMs in 6 to 167 seconds.
  • Scalability: Verification time grows linearly with model complexity and remains practical as the degree of parallelism increases.
  • Bug Discovery: GraphGuard successfully identified 6 real-world bugs, including incorrect RoPE offsets and mismatched padding in Mixture of Experts (MoE) models. One notable catch was a missing $1/T$ scaling factor for auxiliary loss in MoE training, a bug that traditional unit tests often miss.
  • Soundness: The tool is sound; a successful verification guarantees a correct refinement. While theoretically incomplete (potential false alarms), no false alarms were encountered during production model evaluations.

Conclusion and Future Work

GraphGuard provides a scalable, automated way to ensure the correctness of distributed model implementations. While currently limited by TorchDynamo's handling of certain low-level optimizations (like contiguous buffer management) and requiring manual lemmas for custom kernels, it represents a significant step forward in AI systems reliability. Future work will focus on expanding graph capture capabilities and automating lemma generation for specialized kernels.

Summary updated

BibTeX
@inproceedings{wang2026verify,
  author = {Zhanghan Wang and Ding Ding and Hang Zhu and Haibin Lin and Aurojit Panda},
  title = {{Verify Distributed Deep Learning Model Implementation Refinement with Iterative Relation Inference}},
  booktitle = {ASPLOS},
  year = {2026},
  doi = {10.1145/3779212.3790178},
}
Figure