Enhancing Learned Knowledge in LoRA Adapters Through Efficient Contrastive Decoding on Ascend NPUs

Morgan Lindsay Heisler, Linzi Xing, Ge Shi, Hanieh Sadri, Gursimran Singh, Weiwei Zhang, Tao Ye, Ying Xiong, Yong Zhang, Zhenan Fan · DOI

TL;DR

Low-Rank Adaptation (LoRA) is a go-to method for efficiently fine-tuning Large Language Models (LLMs), but standard decoding strategies often let the base model's biases drown out the adapter's specialized knowledge. To fix this, researchers introduced Contrastive LoRA Decoding (CoLD), a framework that amplifies task-specific signals by contrasting the LoRA-adapted model against its base model. By pairing this algorithmic tweak with a custom-designed kernel for Huawei’s Ascend NPUs, the team achieved up to a 5.54% boost in accuracy while simultaneously slashing end-to-end latency by 28%.

What Problem Does This Paper Address?

When deploying LLMs in production, full-parameter fine-tuning is often too resource-intensive. LoRA offers a lightweight alternative by freezing the base model and training small, low-rank adapter matrices. However, during generation, standard decoding methods like greedy search tend to favor high-probability, generic tokens inherent to the massive base model. This "base model bias" frequently overrides the nuanced, task-specific knowledge the LoRA adapter was supposed to introduce, leading to generic or incorrect outputs on complex reasoning tasks.

While vanilla Contrastive Decoding (CD) can mitigate this by contrasting a large "expert" model against a smaller "amateur" model, applying it directly to LoRA introduces severe bottlenecks:

  1. Computational & Memory Overhead: Standard CD requires loading and running two distinct models simultaneously.
  2. Hardware Incompatibility: Unlike GPUs, which enjoy mature multi-model serving libraries like Punica, Neural Processing Units (NPUs) lack off-the-shelf, optimized kernels for handling dynamic, batched multi-LoRA operations efficiently.

Methods

The authors introduce Contrastive LoRA Decoding (CoLD), which elegantly re-frames the contrastive setup: the LoRA-adapted model acts as the expert, and the frozen base model alone serves as the amateur.

Figure 1: Contrastive LoRA Decoding Framework on Huawei Cloud Service: In practice, contrastive decoding (a) operates through the contrastive interaction between a small amateur model and a large expert model, typically selected from the same model family. Our proposed CoLD (b) formulates the LoRA adapter, combined with the base language model, as the expert model, while the base language model alone serves as the amateur model.

The Scoring Mechanism

At each decoding step, CoLD refines token selection using two key steps:

  1. Expert Adapter’s $\alpha$-Mask: A dynamic threshold filters out tokens whose expert logits fall below a certain proportion ($\alpha$) of the maximum score, ensuring the model only considers highly confident predictions.
  2. Base Model’s Contrastive Penalty ($\eta$): The base model's logits are scaled and subtracted from the expert's logits. This penalizes generic, high-frequency tokens favored by the base model, allowing the adapter's specialized knowledge to shine through.

NPU Kernel Optimization

To make CoLD viable for real-time cloud deployment, the authors developed a custom Batched Gather Matrix-Vector Multiplication (BGMV) kernel tailored specifically for the asynchronous, pipeline-driven architecture of Huawei Ascend NPUs.

  • BGMV-Shrink (Down-projection): Implements software pipelining to allow the NPU's scalar unit to fetch the next memory tile while the vector unit processes the current one, eliminating hardware stalls during horizontal sum reductions.
  • BGMV-Expand (Up-projection): Duplicates inputs to match the NPU's SIMD vector width and fuses the final addition back into the base model's results, dramatically reducing memory round-trips.

Datasets

The framework was evaluated across three distinct task domains using Llama-2 7B and Microsoft Phi-2:

  • GSM8K (Grade-School Math 8K): 8,000 multi-step algebraic word problems used to evaluate multi-step mathematical reasoning.
  • ViGGO: A dataset consisting of over 25,000 instances of structured graph data paired with conversational descriptions, used to evaluate structured data-to-text generation.
  • CSQA (Commonsense Question Answering): 12,247 multiple-choice questions testing everyday reasoning and general world knowledge.

Key Insights and Ideas

  • Counterintuitive Amateur Selection: In vanilla contrastive decoding, researchers typically use a much smaller model as the amateur (e.g., a 1B model vs. a 7B model). CoLD reveals that using the same strong base model as the amateur yields superior results (+33.06% accuracy vs +28.43% with TinyLlama). The base model acts as a highly precise mirror, allowing the system to suppress nuanced mistakes rather than just stark, obvious errors.
  • The Latency Paradox: Contrastive decoding inherently requires more raw floating-point operations (FLOPs) per token. Crucially, however, CoLD actually decreases end-to-end latency. Because the contrastive penalty steers the model away from repetitive, verbose, and rambling failure modes common in greedy decoding, the model generates significantly more concise answers, finishing the overall request much faster.

Key Results

Downstream Task Performance

On the GSM8K arithmetic reasoning benchmark, CoLD significantly outperformed standard LoRA configurations:

Performance comparison on the GSM8K arithmetic dataset

CoLD achieved an accuracy of 33.06%, outperforming the standard LoRA greedy baseline (27.06%) by 5.54% and vanilla contrastive decoding by 4.63%.

Efficiency and Latency Gains

Thanks to the custom NPU kernel, CoLD bypasses the memory bottlenecks that plague naive implementations:

Figure 2: TPOT comparison between Gather-BMM and BGMV on Ascend NPU. Gather-BMM runs out of memory at rank 64 for batch size larger than 16.

While standard batched matrix multiplication (Gather-BMM) triggers Out-Of-Memory (OOM) errors at higher ranks and batch sizes, the custom BGMV kernel scales smoothly with minimal overhead.

Furthermore, when looking at end-to-end performance on Ascend-vLLM, CoLD achieved a 28.6% lower average latency than greedy decoding, while maintaining a competitive generation throughput of 31.20 tokens/second.

Decoding efficiency comparison with Ascend-vLLM

Limitations and Future Work

The authors note that CoLD is not a silver bullet for every LLM task. On highly deterministic tasks like structured data-to-text generation (evaluated on the ViGGO dataset), CoLD provided a negligible improvement of just 0.10% in BLEU score. Because contrastive decoding inherently optimizes for diversity and informativeness, it can occasionally mislead the generation process on tasks that demand strict, literal adherence to input data structures.

As a next step, the authors suggest exploring how adaptive contrastive decoding or search mechanisms could be integrated into the CoLD framework to dynamically tune the contrastive penalty based on the nature of the task.

Summary updated

BibTeX
@inproceedings{heisler2025enhancing,
  author = {Morgan Lindsay Heisler and Linzi Xing and Ge Shi and Hanieh Sadri and Gursimran Singh and Weiwei Zhang and Tao Ye and Ying Xiong and Yong Zhang and Zhenan Fan},
  title = {{Enhancing Learned Knowledge in LoRA Adapters Through Efficient Contrastive Decoding on Ascend NPUs}},
  booktitle = {ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
  year = {2025},
}
Figure