Efficient Ternary Weight Embedding Model: Bridging Scalability and Performance

Jiayi Chen, Chen Wu, Shaoqun Zhang, Nan Li, Liangjie Zhang, Qi ZhangarXiv 2024 · DOI

Abstract

Embedding models are foundational to modern information retrieval, yet their reliance on 32-bit floating-point (FP32) weights presents significant challenges for scalability and real-time inference. This paper introduces a novel framework for "ternarizing" these models, reducing weights to a discrete set of three values: $\{-1, 0, +1\}$. By leveraging a self-taught knowledge distillation approach, we demonstrate that ternary-weight models can achieve up to a 13x reduction in storage and a 2.7x speedup in latency while maintaining performance remarkably close to full-precision baselines across diverse NLP and CV tasks.

Introduction

Modern embedding models, such as BERT and Vision Transformers (ViT), are memory-intensive and computationally demanding. While binary quantization (reducing weights to $\{-1, +1\}$) offers extreme efficiency, it often leads to "information collapse" and significant accuracy degradation. Ternary weights introduce a "zero" state, allowing for model sparsity and the preservation of critical representational power. This work addresses the trade-off between scalability and performance by proposing an efficient ternarization pipeline.

Methodology

The proposed framework transforms pre-trained FP32 models into ternary-weight networks through three primary components:

  1. Ternarization Function: A thresholding mechanism maps continuous weights to $\{-1, 0, +1\}$. A tunable parameter, $\beta$, defines the boundaries for these states, allowing for optimized weight distribution.
  2. Self-Distillation: To avoid the high cost of training from scratch, the original FP32 model acts as a "teacher." The ternary "student" model is fine-tuned to minimize the distance between its output embeddings and those of the teacher, ensuring the retention of nuanced semantic information.
  3. Straight-Through Estimator (STE): To overcome the non-differentiable nature of the ternarization function, STE is employed during the backward pass, allowing gradients to update the underlying latent weights.
The self-distillation framework for training ternary-weight models from full-precision teachers.

Experimental Evaluation

The method was evaluated on the MTEB-Chinese benchmark (29 tasks) for text and ImageNet-1k for vision. Baselines included high-performance models like xiaobu-embedding-v2 and stella-base-zh-v2.

Key Insights

  • Implicit Regularization: The "zero" state acts as a form of regularization similar to dropout. Achieving approximately 58% sparsity with $\beta=2$ was found to enhance model robustness.
  • Computational Efficiency: Ternary operations replace complex floating-point multiplications with simple additions and subtractions. This transition significantly reduces energy consumption, as FP32 multiplications are roughly 3.4x more energy-intensive than additions.

Results and Discussion

The ternary models demonstrate a compelling balance of efficiency and accuracy. For text embeddings, the model size was reduced from 1241MB to 159MB (representing a significant reduction in storage footprint) with a 2.7x improvement in inference latency.

Performance comparison between the full-precision baseline and the proposed ternary model across the MTEB-Chinese benchmark.

As shown in the results, the performance gap is minimal. In the majority of tasks, the ternary model remains within 3 points of the full-precision baseline. Furthermore, the proposed method outperformed 4-bit GPTQ quantization in both accuracy and speed. Integration with Approximate Nearest Neighbor (ANN) search libraries like FAISS showed a 60% reduction in embedding generation time without significant loss in retrieval precision.

Conclusion and Future Work

This work proves that ternary quantization, combined with self-distillation, is a viable path for deploying high-performance embedding models on resource-constrained hardware. Future research will focus on optimizing for structured sparsity to better leverage current GPU kernels and exploring automated methods for determining optimal ternarization thresholds.

Summary updated

BibTeX
@misc{chen2024efficient,
  author = {Jiayi Chen and Chen Wu and Shaoqun Zhang and Nan Li and Liangjie Zhang and Qi Zhang},
  title = {{Efficient Ternary Weight Embedding Model: Bridging Scalability and Performance}},
  year = {2024},
  eprint = {2411.15438},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.15438},
}
Figure