BladeDISC++: Memory Optimizations Based On Symbolic Shape

Xiulong Yuan, Xu Yan, Wenting Shen, Xiafei Qiu, Ang Wang, Jie Zhang, Yong Li, Wei LinarXiv 2024

Abstract

Recent deep learning workloads exhibit dynamic characteristics, leading to the rising adoption of dynamic shape compilers. These compilers can generate efficient kernels for dynamic shape graphs characterized by a fixed graph topology and uncertain tensor shapes. However, memory optimization, although particularly crucial in this large model era, remains relatively underexplored for dynamic shape graphs. The fundamental challenge lies in the lack of precise tensor shapes which are essential in conventional methods such as operation scheduling (op scheduling) and rematerialization. To address this challenge, we propose op scheduling and rematerialization approaches based on symbolic shapes and developed BladeDISC++. Besides, since rematerialization decisions cannot be made solely at compile time when tensor shapes are unknown, BladeDISC++ employs a compilation-runtime combined strategy to optimally address shape dynamics. Evaluations indicate that BladeDISC++ effectively reduces memory usage for dynamic shape graphs, achieving memory consumption comparable to optimizations using precise shapes, thereby promoting the broader adoption of dynamic shape compilers.

Introduction

Modern deep learning workloads, particularly Large Language Models (LLMs), frequently encounter dynamic characteristics such as variable sequence lengths. To manage this variability, dynamic shape compilers have become standard. While these compilers excel at generating optimized kernels for uncertain shapes, they often struggle with memory optimization.

Traditional memory-saving techniques, such as operation (op) scheduling and rematerialization, rely on precise knowledge of tensor sizes to determine execution order or eviction candidates. In a dynamic environment, this information is unavailable at compile-time. Consequently, existing dynamic compilers often suffer from excessive memory consumption or Out-Of-Memory (OOM) errors that static compilers—which use fixed, padded shapes—can avoid.

Methodology

BladeDISC++ addresses the "unknown shape" challenge through a three-pronged approach centered on symbolic reasoning and a hybrid execution model.

BladeDISC++ system architecture illustrating the split between compile-time symbolic analysis and runtime decision making.
  1. Symbolic Shape Graph Analysis: Instead of treating shapes as opaque variables, the compiler extracts algebraic relationships between dimensions (e.g., recording that a reshape operation maintains a specific ratio between dimensions). This builds a global graph of symbolic dependencies.
  2. Symbolic Op Scheduling: BladeDISC++ calculates memory impact using symbolic expressions (SymbolicExpr). By performing algebraic comparisons, the compiler can mathematically prove that one execution order is more memory-efficient than another, even without concrete values.
  3. Hybrid Rematerialization: To handle runtime unpredictability, BladeDISC++ decouples the "how" from the "when." At compile-time, it identifies potential eviction candidates and pre-generates recomputation subgraphs. At runtime, the system monitors actual memory pressure and triggers these pre-compiled branches only when necessary.

Experimental Evaluation

The system was evaluated using a modified Llama-2-1b model (4 layers) fine-tuned on the CodeAlpaca-20K dataset. This dataset contains code samples with text lengths ranging from 100 to 3,000 characters, providing a robust test for dynamic shape handling. The performance of BladeDISC++ was compared against standard dynamic shape training and static shape training (which uses padding).

Results and Discussion

The experimental results demonstrate that BladeDISC++ effectively bridges the gap between dynamic flexibility and static efficiency.

Performance comparison across different batch sizes, highlighting BladeDISC++'s ability to avoid OOM and match static memory efficiency.
  • OOM Prevention: While standard dynamic compilers failed with OOM errors at batch sizes of 16 and 18, BladeDISC++ successfully completed the workloads.
  • Memory Parity: BladeDISC++ achieved memory consumption nearly identical to static shape training. For instance, at a batch size of 14, it utilized 35.76 GiB, matching the 35.75 GiB required by the static version.
  • Throughput Advantages: By eliminating the "padding tax" associated with static compilers, BladeDISC++ achieved higher throughput. At batch size 14, it processed 5749 tokens/sec compared to 5242 tokens/sec for the static baseline.

These results suggest that algebraic comparison is a sufficient proxy for concrete size knowledge in optimization. Furthermore, by decoupling recomputation logic from the decision to execute it, the system successfully manages the unpredictability of dynamic shapes.

Conclusion and Future Work

BladeDISC++ demonstrates that symbolic shape analysis can bring the memory efficiency of static compilers to dynamic workloads without the overhead of padding. While highly effective, the system currently relies on heuristics for runtime eviction decisions and may encounter complex graphs where symbolic expressions are difficult to compare algebraically. Future work will explore more sophisticated cost-benefit models for runtime rematerialization and extend symbolic optimization to memory pooling and fragmentation reduction.

Summary updated

BibTeX
@misc{yuan2024bladedisc,
  author = {Xiulong Yuan and Xu Yan and Wenting Shen and Xiafei Qiu and Ang Wang and Jie Zhang and Yong Li and Wei Lin},
  title = {{BladeDISC++: Memory Optimizations Based On Symbolic Shape}},
  year = {2024},
  eprint = {2412.16985},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.16985},
}
Figure