Learning to Shard: RL for Co-optimizing the Parallelism Degrees and Per-operator Sharding Dimensions in Distributed LLM Inference

Ruokai Yin, Sattwik Deb Mishra, Xuan Zuo, Hokchhay Tann, Preyas Shah, Apala GuhaarXiv 2025 · DOI

Abstract

Deploying trillion-parameter Large Language Models (LLMs) requires sophisticated distributed computing strategies. Current approaches often rely on static heuristics that optimize high-level parallelism and low-level operator sharding independently. We present "Learn to Shard," the first reinforcement learning (RL) framework to co-optimize these layers. By navigating a combinatorial search space of over $10^9$ configurations, our agent achieves up to a 3.5× throughput boost over standard search methods and outperforms hand-tuned industry heuristics on massive Mixture-of-Experts (MoE) models.

Introduction

The scale of modern LLMs necessitates splitting workloads across thousands of accelerators. Traditionally, systems like Megatron-LM use heuristics to determine coarse-grained strategies (Tensor, Pipeline, and Expert Parallelism) and fine-grained strategies (operator-level sharding). However, as hardware and models evolve, these "rules of thumb" become suboptimal. The search space for an ideal configuration is too vast for exhaustive search, leading to significant performance gaps in large-scale deployments.

The Learn to Shard Framework

The core of our approach is an RL-based agent that jointly optimizes parallelism degrees ($a_{TP}, a_{EP}, a_{PP}$), batch sizes, and per-operator sharding dimensions.

The Learn to Shard RL framework, featuring an elite history queue and a transformer-based policy for strategy generation.

The framework employs several key components:

  • Elite-Context Policy: A transformer-based policy utilizes an "elite history buffer" of top-performing strategies to guide the search, enabling the agent to recognize structural patterns in successful configurations.
  • PPO Training: The agent is trained via Proximal Policy Optimization to maximize throughput rewards derived from a high-fidelity performance simulator.
  • Confidence-Based Early Exit: To optimize the search budget, the agent can exit early when high confidence is reached, allowing for restarts that explore new regions of the search space while retaining historical knowledge.

Experimental Evaluation

We evaluated Learn to Shard using a roofline-based simulator validated against Megatron-LM. Tests were conducted on synthetic Mixture-of-Experts (MoE) models with 1.2T and 1.6T parameters, simulating clusters of up to 24,000 NVIDIA H100 GPUs across various context lengths.

Results and Insights

Our RL agent consistently discovered non-intuitive strategies that human experts often overlook. For instance, while standard heuristics favor All-Reduce operations, the agent identified scenarios where sharding on the "hidden" dimension of an MLP—necessitating an All-Gather—yielded superior performance under specific interconnect constraints.

Throughput performance of Learn to Shard compared to Megatron-LM and other search baselines on 1.2T and 1.6T MoE models.

Key performance metrics include:

  • Superior Throughput: Learn to Shard achieved up to 3.5× higher throughput than Simulated Annealing (SA) and Random Walk (RW) baselines.
  • Outperforming Industry Standards: The framework surpassed the strong Megatron-LM heuristic by up to 1.06×. In large-scale H100 clusters, a 6% improvement translates to substantial cost savings and increased serving capacity.
  • Search Efficiency: Optimal strategies were typically identified in under 10 minutes.

Conclusion and Future Work

Learn to Shard demonstrates that co-optimizing parallelism and sharding through RL can unlock significant performance gains in LLM inference. Future work will expand the search space to include 2-D and 3-D tensor parallelism, as well as explicit sequence parallelism for varying context lengths. Additionally, real-world deployment of these non-standard communication patterns will require further kernel-level engineering.

Summary updated

BibTeX
@misc{yin2025learning,
  author = {Ruokai Yin and Sattwik Deb Mishra and Xuan Zuo and Hokchhay Tann and Preyas Shah and Apala Guha},
  title = {{Learning to Shard: RL for Co-optimizing the Parallelism Degrees and Per-operator Sharding Dimensions in Distributed LLM Inference}},
  year = {2025},
  eprint = {2509.00217},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.00217},
}
Figure