Papers
Topics
Authors
Recent
Search
2000 character limit reached

RaggedShard: Flexible Tensor Sharding

Updated 3 July 2026
  • RaggedShard is a structure-aware sharding scheme that partitions tensors into atomic, contiguous blocks to preserve alignment and enable efficient computation.
  • It employs a global shard planner with heuristic and ILP-inspired methods to balance device buffer sizes while minimizing padding and communication overhead.
  • Integration with PyTorch SPMD supports block-wise quantization and matrix-aware optimizers, resulting in improved throughput, memory efficiency, and scalability.

RaggedShard is a flexible, structure-aware sharding scheme for distributed tensor storage and communication, introduced in veScale-FSDP to address the limitations of traditional element- and row-wise sharding formats in large-scale deep learning. Its core innovation is treating each tensor as a sequence of atomic, contiguous memory blocks of arbitrary shape—enabling efficient, alignment-preserving assignment of these blocks to devices. RaggedShard supports complex training paradigms, such as block-wise quantization and matrix-aware optimizers, achieving superior throughput, memory efficiency, and scaling relative to established Fully Sharded Data Parallel (FSDP) approaches (Wang et al., 25 Feb 2026).

1. Motivation and Design Principles

Traditional FSDP and ZeRO-based systems are constrained by element- or row-wise sharding, leading to misalignments and inefficiencies when deploying block-structured computations. For example, 32×32 block-wise quantization and full-matrix optimizers like Shampoo or Muon require tensor subdivisions that do not conform to fixed-grain sharding, forcing manual data realignment or runtime overhead due to padding and bespoke collectives.

RaggedShard is designed to:

  • Divide tensors into atomic, fixed-size blocks (shape B\mathbf B), each indivisible for the purposes of sharding.
  • Allow arbitrary mapping of these atomic blocks to devices via a function f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\} for mm GPUs.
  • Preserve contiguous layout of blocks within tensor storage, with any required padding restricted to inter-tensor regions in communication buffers.
  • Compose cleanly with existing DTensor placements (Replicate, Shard(dim)), enabling orthogonal parallelism strategies.

These principles enable exact block alignment for quantization, full-matrix operations, and irregular sparsity layouts inherent in Mixture-of-Experts (MoE) models.

2. Data Layout and Mapping

Let a tensor tt of shape DtNd\mathbf D_t \in \mathbb N^d be partitioned into blocks of shape BtNd\mathbf B_t \in \mathbb N^d. The number of blocks per dimension is

Ut(i)=Dt(i)/Bt(i),U_t(i) = \lceil D_t(i)/B_t(i) \rceil,

and the total number of blocks is Ut=i=0d1Ut(i)U_t = \prod_{i=0}^{d-1} U_t(i). Each block is indexed as u=(u0,,ud1)\mathbf u = (u_0,\dots,u_{d-1}), 0ui<Ut(i)0 \le u_i < U_t(i).

The offset of block f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}0 in flat storage is

f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}1

and its size in elements is f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}2.

Device assignment is defined by f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}3, with each GPU f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}4 storing its contiguous blocks:

f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}5

This data layout ensures all computation and quantization within a block are local, with no further communication needed for atomic block operations.

3. Structure-Aware Shard Planning

The global sharding problem—finding an assignment of blocks to GPUs that (a) respects block atomicity, (b) equalizes per-device buffer size f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}6, and (c) avoids partial blocks or padding at shard boundaries—is NP-hard by reduction from Partition.

An ILP formulation (not used at runtime) minimizes f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}7 and determines offsets f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}8:

  • f:{blocks of T}{0,,m1}f: \{\text{blocks of }T\} \to \{0,\dots,m-1\}9, mm0,
  • Non-overlapping intervals mm1,
  • For every device boundary mm2, either mm3 is outside mm4 or aligned on a block boundary: mm5.

veScale-FSDP implements a polynomial-time heuristic:

  • Sort tensors (e.g., by block size).
  • Binary search for minimal mm6 over multiples of least common multiples (l.c.m.) of block sizes.
  • Use dynamic programming in CheckValidShard(S) to verify feasibility in mm7.
  • Overall complexity is mm8.

Simplified pseudocode:

Ut(i)=Dt(i)/Bt(i),U_t(i) = \lceil D_t(i)/B_t(i) \rceil,4 Where mm9 is the element count, tt0 block size, and tt1 the set of tensors.

4. Integration with FSDP and Runtime Mechanics

RaggedShard operates as a new placement for DTensor, natively supported in PyTorch SPMD environments:

  • Initialization: Modules are wrapped as FullyShardedDataParallel(..., sharding=RaggedShard(...)). The system plans global buffer sizes and offsets, then allocates a tt2 DBuffer and sets up zero-copy slicing for local shards.
  • Forward pass: Prior to execution, FSDP invokes DBuffer.all_gather(parameters), converting placements from RaggedShard(Shard) to RaggedShard(Replicate). This enables a single, large NCCL AllGather operation.
  • Backward pass: Following gradient computation, DBuffer.reduce_scatter(gradients) performs a unified NCCL ReduceScatter to revert to RaggedShard(Shard) format, followed by local optimizer steps.

This unified buffer strategy eliminates per-tensor padding, redundant copying, and inefficient collective sizes.

5. Enabling Block-Wise Quantization and Matrix-Aware Optimizers

RaggedShard enables precise block-level control required by structure-aware training components:

  • Block-wise 8-bit Adam: Given a quantization tile size (e.g., tt3), each block is assigned locally, with quantization and scaling factors computed entirely on-device, removing the need for cross-device scale factor gathering or manual padding.
  • Matrix-aware optimizers (e.g., Muon): RaggedShard allows all blocks of a 2D tensor to reside on a root GPU tt4. Operations such as Newton–Schulz iterations for full-matrix preconditioning proceed entirely locally. Redistribute operations handle block collection and broadcast, abstracted away by DTensor and RaggedShard logic, eliminating manual intervention and custom communication code.

6. Performance and Scaling Characteristics

Performance and efficiency metrics for RaggedShard in veScale-FSDP include:

  • Communication Volume:

tt5

elements communicated for all-gather and reduce-scatter, where tt6 is total parameter elements, tt7 number of devices, and tt8 aggregate padding (tt9 of DtNd\mathbf D_t \in \mathbb N^d0 in practice).

  • Memory Overhead per GPU:

DtNd\mathbf D_t \in \mathbb N^d1

much improved compared to up to DtNd\mathbf D_t \in \mathbb N^d2 padding in fixed-sharding.

  • Throughput Model:

DtNd\mathbf D_t \in \mathbb N^d3

Communication reduction proportional to DtNd\mathbf D_t \in \mathbb N^d4 increases DtNd\mathbf D_t \in \mathbb N^d5 by DtNd\mathbf D_t \in \mathbb N^d6.

  • Empirical observations:
    • Throughput for DtNd\mathbf D_t \in \mathbb N^d7B–DtNd\mathbf D_t \in \mathbb N^d8B parameter LLMs at DtNd\mathbf D_t \in \mathbb N^d9K GPUs is BtNd\mathbf B_t \in \mathbb N^d0 higher than DeepSpeed/ZeRO-3 and PyTorch FSDP, BtNd\mathbf B_t \in \mathbb N^d1 higher on MoE models.
    • Memory consumption is BtNd\mathbf B_t \in \mathbb N^d2 lower per-GPU than all baselines.
    • Padding is BtNd\mathbf B_t \in \mathbb N^d3 for typical BtNd\mathbf B_t \in \mathbb N^d4 or BtNd\mathbf B_t \in \mathbb N^d5 blocks.
    • Planner overhead is BtNd\mathbf B_t \in \mathbb N^d6 seconds for hundreds of tensors on thousands of GPUs.
    • Scaling demonstrated up to BtNd\mathbf B_t \in \mathbb N^d7 GPUs with near-linear weak and strong scaling.
    • Model scaling: MFU for BtNd\mathbf B_t \in \mathbb N^d8T parameters on BtNd\mathbf B_t \in \mathbb N^d9K GPUs remains around Ut(i)=Dt(i)/Bt(i),U_t(i) = \lceil D_t(i)/B_t(i) \rceil,0–Ut(i)=Dt(i)/Bt(i),U_t(i) = \lceil D_t(i)/B_t(i) \rceil,1.

7. Significance and Influence

RaggedShard provides a uniform, block-aware sharding abstraction, underpinned by a provably near-optimal planner and high-performance DBuffer primitive. It furnishes structure-aware training methods—block quantization, full-matrix preconditioners, and sparse MoE layouts—with consistent, boundary-aligned semantics and high runtime efficiency. Block-wise quantized Adam and matrix-aware Muon optimizers converge identically to data-parallel (DDP) baselines, but execute at Ut(i)=Dt(i)/Bt(i),U_t(i) = \lceil D_t(i)/B_t(i) \rceil,2–Ut(i)=Dt(i)/Bt(i),U_t(i) = \lceil D_t(i)/B_t(i) \rceil,3 of full-precision throughput without code changes.

By decoupling atomic block sharding from rigid element/row constraints, RaggedShard eliminates manual boundary checks and padding overhead, substantially outperforming fixed-grain formats on both communication and memory metrics, particularly as model and system scales increase (Wang et al., 25 Feb 2026).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to RaggedShard.