EdgeShard: Efficient LLM Inference via Collaborative Edge Computing

Mingjin Zhang, Xiaoming Shen, Jiannong Cao, Zeyang Cui, Shan JiangIEEE Internet of Things Journal 2024

TL;DR

This paper introduces EdgeShard, a novel framework for running large language models (LLMs) efficiently on distributed edge devices and cloud servers. By intelligently partitioning LLM models and allocating them across heterogeneous devices, EdgeShard significantly reduces inference latency and increases throughput, overcoming the limitations of traditional cloud-based LLM deployment.

What Problem Does This Paper Address?

Large Language Models (LLMs) have revolutionized natural language processing, but their massive scale (billions of parameters) makes them computationally intensive and memory-hungry. This typically forces them to run on powerful cloud servers, leading to several critical issues:

  • High Latency: Sending data to and from the cloud introduces significant delays, making LLMs unsuitable for real-time applications like robotics or interactive systems.
  • Bandwidth Costs: Transmitting large amounts of data to cloud data centers incurs substantial network costs.
  • Privacy Concerns: Sensitive data processed by LLMs in the cloud raises privacy and security issues for users and organizations.

While edge computing offers a solution by bringing computation closer to data sources, existing approaches face challenges. Model quantization can reduce LLM size but often sacrifices accuracy. Cloud-edge collaboration methods, while promising, can suffer from unstable network connections between edge devices and the cloud. This paper aims to bridge this gap by enabling efficient, collaborative LLM inference across a network of diverse edge devices and cloud resources.

Methods

EdgeShard proposes a general framework for collaborative LLM inference, built upon three core stages:

  1. Offline Profiling: This initial step gathers crucial information about the network and devices. It profiles the execution time of each LLM layer on different devices, the memory consumption of each layer, and the available bandwidth between devices. This profiling is done once and provides the foundation for optimization.
  2. Scheduling Optimization: This is the core of EdgeShard's innovation. It formulates a joint device selection and model partition problem. The goal is to determine which subset of devices to use, how to partition the LLM model into shards (layers or groups of layers), and which device should host each shard. This optimization is performed using dynamic programming to minimize inference latency or maximize throughput, considering device memory constraints, network bandwidth, and privacy requirements (e.g., keeping the first layer on a designated source node).
  3. Online Collaborative Inference: Once the optimal deployment strategy is determined, the selected devices execute the LLM collaboratively. The framework supports two inference modes:
  4. Sequential Inference: Devices process their assigned model shards sequentially, passing the output to the next device in line. This is suitable for single-user scenarios.
  5. Pipeline Parallel Inference: This strategy aims to improve resource utilization by overlapping computation and communication. It splits input data into micro-batches and processes them in a pipelined fashion, reducing device idle time. The paper also introduces an "EdgeShard-No-bubbles" variant that further minimizes idle time by allowing immediate token generation without waiting for all micro-batches in an iteration to complete.

Datasets

The paper uses the WikiText-2 dataset from HuggingFace for evaluating LLM inference performance. They extract samples with an input token length of 32 and generate 96 tokens for their experiments.

Key Insights and Ideas

  • Heterogeneity is Key: Unlike cloud-centric approaches that assume homogeneous hardware (e.g., multiple identical GPUs), EdgeShard explicitly leverages the diverse computational capabilities and memory capacities of edge devices and cloud servers.
  • Dynamic Partitioning Outperforms Static: The dynamic programming approach for model partitioning and device selection is crucial. It allows EdgeShard to adapt to varying network conditions and device availability, leading to better performance than fixed or evenly distributed strategies.
  • Bandwidth Matters, But Not Always: While increased bandwidth generally improves collaborative inference, the paper shows that beyond a certain point (around 10Mbps in their experiments), computation time becomes the bottleneck, and further bandwidth increases yield diminishing returns.
  • Edge-Solo vs. Collaboration: For smaller models or when bandwidth is severely limited (e.g., 1Mbps), running the LLM locally on a single capable edge device (Edge-Solo) can sometimes outperform collaborative methods due to high communication overhead. However, for larger models or better network conditions, collaboration offers significant advantages.
  • "No-Bubbles" Pipeline is Better: The proposed "EdgeShard-No-bubbles" pipeline execution strategy significantly reduces device idle time, leading to higher throughput compared to traditional pipelined approaches.

Key Results

EdgeShard demonstrates substantial improvements over baseline methods:

  • Latency Reduction: Up to 50% latency reduction compared to baseline methods. For Llama2-7B, EdgeShard achieved 75.88ms latency, which is about 1.85x faster than Edge-Solo and Cloud-Edge-Opt, and about 3x faster than Cloud-Edge-Even.
  • Throughput Improvement: Up to 2x throughput improvement. For Llama2-7B, EdgeShard achieved 52.45 tokens/second, around 2.2 times larger than Edge-Solo and Cloud-Edge-Opt, and about 7 times larger than Cloud-Edge-Even.
  • Handling Large Models: EdgeShard successfully deploys and runs the Llama2-70B model, which is too large for single-device deployment (requiring ~280GB), achieving 1.25 tokens/second.
  • Bandwidth Sensitivity: Collaborative methods show latency reduction with increasing bandwidth, but the gains plateau. EdgeShard-No-bubbles showed significant throughput improvements (e.g., ~6.96 tokens/sec for Llama2-7B) over EdgeShard-bubble.

Limitations and Future Work

  • Incentive Mechanisms: The paper acknowledges that in scenarios where devices belong to different stakeholders, incentive mechanisms are needed to encourage resource sharing for collaborative inference.
  • Batch Size Optimization: The current dynamic programming algorithm does not explicitly consider batch size, which influences memory usage and throughput. Future work could incorporate batch size awareness for further optimization.
  • Privacy: While the framework aims to improve privacy by keeping data local, more advanced privacy-preserving techniques could be explored.
  • Dynamic Network Conditions: The current optimization is based on pre-profiled network conditions. Adapting to highly dynamic or unpredictable network changes in real-time could be a future research direction.

Summary updated

BibTeX
@article{zhang2024edgeshard,
  author = {Mingjin Zhang and Xiaoming Shen and Jiannong Cao and Zeyang Cui and Shan Jiang},
  title = {{EdgeShard: Efficient LLM Inference via Collaborative Edge Computing}},
  journal = {IEEE Internet of Things Journal},
  year = {2024},
}
Figure