Large Language Models (LLMs) require substantial computational resources, limiting their deployment on resource-constrained hardware. Ternary LLMs mitigate these demands through weight quantization via ternary values, achieving significant compression often with 50-90% sparsity. However, existing approaches have limitations: methods optimized for ternary weights, such as BitNet, redundant segment reduction (RSR), and its improved version RSR++, do not exploit sparsity structures, while conventional sparse formats neglect ternary characteristics, foregoing dual optimization opportunities. In this paper, we introduce Sparse Segment Reduction (SSR), a ternary matrix multiplication method designed to accelerate the inference of ternary LLMs and general Ternary Weight Networks (TWNs). SSR has a dedicated optimized ternary data format and an algorithm that systematically exploits sparsity patterns through computation trees that scale with the sparsity. SSR provides theoretical gains with asymptotically faster inference than RSR++ for sparsity above 50%, while practical evaluations reveal performance improvements across all sparsity levels. Evaluation results show that SSR achieves 2.1-11.3x speedup over RSR++ on ternary GEMM with 45-95% sparsity. Furthermore, SSR achieves 3.5-6.3x end-to-end speedup and 4.9% of memory saving over RSR++ on the Llama-3 1B model inference.
Figures & tables
Fig. 1 : Pre-processing of the binary matrix W2 and inference with the row vector xj of the input matrix X for L=3 . The length of the reduced permutation sequence equals the number of nonzero patterns in the column blocks: 2 for W2,1 and 1 for W2,2 . Row indices of all-zero rows are deleted and shown in red, while the remaining row indices are shown in blue.
BitNet.cpp
RSR++
SSR
32MNK
log2K2MNK
log2(1−p1)⋅log2K4MN⋅K−1/log2(1−p)
TABLE I : Operation counts of SSR and related works.
Fig. 2 : Execution time of single-thread ternary GEMM (X: 512 × 1024, W: 1024 × 4096, L=6).
Fig. 3 : Execution time of multi-thread ternary GEMM (X: 256 × 1024, W: 1024 × 4096, L=4).
Fig. 4 : Execution time of multi-thread ternary GEMM (X: 512 × 2048, W: 2048 × 8192, L=6).
Fig. 5 : Execution time of one small Llama MLP block (X: 256 × 1024, up_proj: 1024 × 4096, L=6).
After Initialization
During Inference
RSR++
129-146 MB
177-259 MB
SSR
122-124 MB
160-213 MB
TABLE II : Memory usage of one Llama-3 1B MLP block
Fig. 6 : Execution time of one Llama-3 1B MLP block (X: 512 × 2048, up_proj: 2048 × 8192, L=6).
Sparsity
50%
70%
90%
RSR++
36.23 s
36.30 s
36.19 s
SSR
10.49 s
8.80 s
5.71 s
TABLE III : Time-To-First-Token of one Llama-3.1 1B model (Sequence Length = 512)