Partially Shared Query-Key for Lightweight Language Models

Kai Yang, Vahid Partovi Nia, Boxing Chen, Masoud AsgharianWorkshops @ NeurIPS 2024

TL;DR

This paper introduces "partial parameter sharing" for the query and key weight matrices in Transformer models, aiming to create more efficient lightweight language models. They found that sharing these matrices up to 95% still maintains strong performance while mitigating overfitting, offering a practical way to balance model complexity and effectiveness for resource-constrained devices.

What Problem Does This Paper Address?

The field of Natural Language Processing (NLP) has seen incredible advancements with large language models (LLMs). However, these models are computationally expensive and require significant memory, making them impractical for deployment on devices with limited resources, like smartphones or edge devices. Lightweight language models, such as TinyBERT, aim to address this by reducing parameter size and computational demands. A key component of these models is the Transformer's attention mechanism, which relies on query (Q), key (K), and value (V) matrices. While some research has explored full parameter sharing between Q and K to reduce parameters, this paper argues that it oversimplifies the attention mechanism, leading to degraded performance and an inability to capture crucial directional dependencies in language. The problem, therefore, is how to achieve the benefits of parameter sharing (reduced complexity, less overfitting) without sacrificing the nuanced directional understanding that distinct Q and K matrices provide.

Methods

The core innovation presented is partial parameter sharing between the query (Q) and key (K) weight matrices within the Transformer's self-attention mechanism. Instead of having entirely separate Q and K matrices, or sharing them completely, the authors propose a method where a significant portion of their weights are shared.

Specifically, they define Q and K as: $Q = XW_Q$ $K = XW_K$

Where $W_Q$ and $W_K$ are the weight matrices. Partial sharing implies that $W_Q$ and $W_K$ are not identical but share a common underlying structure or a substantial overlap. The paper mentions that this approach can be interpreted as applying a low-rank approximation to the query and key matrices, drawing parallels to techniques like LoRA (Low-Rank Adaptation). This method aims to reduce the dimensionality and parameter count associated with Q and K, thereby simplifying the model architecture and improving efficiency. The key idea is to balance the benefits of shared parameters with the need for distinct representations to capture directional dependencies.

Datasets

The paper uses two character-level text datasets for their experiments:

  • Tiny Shakespeare: A dataset derived from Shakespeare's works.
  • Oxford American Essays: A dataset comprising a collection of American essays.

Both datasets were split into training and validation sets with a 90/10 ratio. Characters were tokenized into integers representing their unique occurrences. The model was trained to predict the next character in a sequence.

Key Insights and Ideas

  • Full Q-K sharing is detrimental: The paper strongly suggests that completely sharing query and key matrices leads to a "fully-quadratic attention matrix" that oversimplifies directional dependencies, degrades pre-training loss, and ultimately reduces model effectiveness.
  • Partial sharing strikes a balance: The core insight is that partial parameter sharing offers a sweet spot. It significantly reduces model complexity and memory usage, similar to full sharing, but crucially, it preserves the ability to capture directional relationships in language.
  • Overfitting mitigation: Partial sharing was found to be particularly effective at mitigating overfitting, especially when training on limited data. This is a significant advantage for lightweight models that are often deployed in such scenarios.
  • High sharing levels are viable: Surprisingly, the authors found that performance remained comparable to fully separate Q and K vectors even with a high degree of parameter sharing (up to 95%). This suggests that the model can tolerate a substantial amount of shared parameters without a significant performance hit.

Key Results

The experiments demonstrated that:

  • Full parameter sharing resulted in higher cross-entropy loss during both training and validation compared to other configurations, indicating degraded performance.
  • Partial parameter sharing performed similarly to models with entirely separate query and key vectors.
  • Even with 90% and 95% parameter sharing, the performance remained comparable to the original setting with fully separate query and key vectors.
  • Partial sharing was observed to mitigate overfitting effects after a certain number of training iterations, suggesting its benefit for model stability and generalization.

Limitations and Future Work

Limitations: * The paper focuses on character-level text data and lightweight Transformer architectures (specifically mentioning a multi-head attention mechanism with 6 heads and 6 Transformer layers). The generalizability to other model sizes, architectures, or tokenization schemes is not explicitly discussed. * While the paper shows that high degrees of sharing (90-95%) are viable, it doesn't explore the absolute upper limit or the precise point where performance might start to degrade significantly.

Future Work: * The authors suggest exploring varying the degree of parameter sharing across different Transformer layers. * They also propose assessing the impact of this partial sharing strategy on a broader range of NLP tasks. * Further research could investigate the optimal balance between shared and distinct parameters for different model sizes and datasets.

Summary updated

BibTeX
@inproceedings{yang2024partially,
  author = {Kai Yang and Vahid Partovi Nia and Boxing Chen and Masoud Asgharian},
  title = {{Partially Shared Query-Key for Lightweight Language Models}},
  booktitle = {Workshops @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=PJ6j15kOvW},
}
Figure