NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

LoRACode: LoRA Adapters for Code Embeddings

Saumya Chaturvedi, Aman Chadha, Laurent Bindschaedler

TL;DR

LoRACode applies Low-Rank Adaptation (LoRA) to code embedding models (such as UniXcoder and CodeBERT), updating under 2% of total parameters while drastically reducing training costs (fine-tuning 2 million samples in just 25 minutes on two H100 GPUs). Crucially, the authors discover that deploying dedicated, language-specific adapters for Text-to-Code search dramatically outperforms generalized multilingual adapters—yielding up to an 86.69% relative improvement in Mean Reciprocal Rank (MRR).

What Problem Does This Paper Address?

Semantic code search—finding relevant code snippets using natural language descriptions (Text2Code) or other code snippets (Code2Code)—demands a precise grasp of syntax, control flow, and programming semantics.

Existing solutions face a difficult trade-off:

  • Smaller, open-source models like CodeBERT and UniXcoder are computationally tractable but struggle with complex retrieval accuracy.
  • Massive proprietary models (e.g., Voyage-Code-2, OpenAI Embeddings) offer strong retrieval but incur high computational and financial costs, cannot be easily customized on-premise, and are often generative LLMs rather than dedicated embedding models.
  • Full fine-tuning on multilingual code corpora is resource-intensive and often forces models to blur the distinct syntactic quirks of individual programming languages.

Methods

LoRACode adopts Parameter-Efficient Fine-Tuning (PEFT) via LoRA, freezing base models and inserting low-rank decomposition matrices into the attention projection layers (specifically Query and Value modules).

Key technical components include:

  • Parameter Efficiency: Trains only 1.83%–1.85% of the base model parameters, testing ranks $r \in \{16, 32, 64\}$ with $\alpha = 2r$.
  • Contrastive Learning: Employs a custom ContrastiveTrainer using cosine similarity loss to pull query and positive code representations together while repelling negatives.
  • Masked Token Pooling: Averages token representations across sequence lengths while modifying attention masks to explicitly discard padding tokens, preserving contextual fidelity.
  • Adapter Modularization:
  • Task-specific adapters trained across combined multilingual datasets for Code2Code and Text2Code tasks.
  • Language-specific adapters where separate LoRA matrices are trained on individual languages for Text2Code retrieval.
  • Base Models Explored: Evaluated on CodeBERT, GraphCodeBERT, StarCoder (targeting middle-layer attention projections), and UniXcoder (which served as the primary evaluation backbone).

Datasets

The authors utilized three standard, open benchmarks:

  1. CodeSearchNet (CSN): Over 2 million method–docstring pairs across six languages (Go, Java, JavaScript, PHP, Python, Ruby) used for Text2Code fine-tuning and evaluation.
  2. CosQA: A human-annotated Python question-answering dataset (~20,000 query-code pairs) used for high-precision Text2Code experiments.
  3. XLCost: A parallel code intelligence benchmark across seven languages (C++, Java, Python, C#, JavaScript, PHP, C) containing aligned code snippets and full programs, used for Code2Code retrieval.

No new datasets were introduced.

Key Insights and Ideas

  • Multilingual vs. Monolingual Capacity Dilemma: In Text2Code retrieval, training a single adapter over a mixture of languages yielded almost no gain over the base UniXcoder model. Because LoRA adapters modify under 2% of weights, force-feeding them multiple distinct syntaxes (e.g., Python's indentation vs. Java's braces) dilutes adapter capacity.
  • The "Aha!" of Language-Specific Adapters: Giving each programming language its own dedicated adapter unlocked massive performance boosts. Specializing the adapter allows it to dedicate its limited rank entirely to language-specific syntax and semantic constructs.
  • Code2Code Behaves Differently: In contrast to Text2Code, Code2Code search benefited cleanly from a unified multilingual adapter (improving MRR across all seven evaluated languages). The shared structural and algorithmic logic across programming languages makes code-to-code alignment easier to learn jointly than natural-language-to-code mappings.
  • Dataset Scale Drives Specialization: The largest language subsets in CodeSearchNet saw the most dramatic adapter gains, demonstrating that LoRA adapters still require sufficient sample volume (~10k–15k pairs) to learn robust syntactic nuances.

Key Results

  • Efficiency: Training on 2 million code samples required only 25 minutes on 2× H100 GPUs. Inference latency remained negligible compared to unadapted base models (e.g., generating Python embeddings took 9:17 MM:SS vs. 8:24 for the base model).
  • Text2Code Search (Language-Specific Adapters on CSN):
  • Python: MRR rose from 29.76 to 55.56 (+86.69%); NDCG@10 jumped from 32.83 to 59.49.
  • Go: MRR increased from 49.59 to 82.88 (+67.13%).
  • PHP: MRR increased from 35.22 to 52.46 (+48.94%).
  • Java: MRR increased from 34.47 to 53.47 (+31.91%).
  • JavaScript & Ruby: Saw smaller, dataset-size-constrained gains of +20.9% and +3.9% in MRR, respectively.
  • Text2Code Search (CosQA): A rank-64 combined adapter boosted MRR from 31.36 to 36.02 (+14.8%) and NDCG@10 from 35.64 to 40.44 (+13.5%).
  • Code2Code Search (XLCost): A rank-64 combined adapter improved MRR over UniXcoder across every tested language: C (+9.10%), C++ (+7.47%), Java (+6.54%), C# (+5.82%), JavaScript (+4.43%), PHP (+3.80%), and Python (+3.40%).

Limitations and Future Work

  • Domain Diversity: Datasets like CodeSearchNet reflect GitHub open-source repositories, which may bias models toward specific repository conventions and coding styles.
  • Unevaluated Language Isolation in Code2Code: The authors only evaluated combined adapters for Code2Code search; language-specific adapter dynamics for Code2Code remain unexplored.
  • StarCoder Retrieval Weakness: StarCoder showed subpar retrieval results, illustrating that generic generative code LLMs struggle to maintain dense retrieval contexts without substantial re-architecting.
  • Future Directions: Investigating language-specific adapters for Code2Code search and exploring cross-language transfer mechanisms between related programming languages.

Summary updated

BibTeX
@inproceedings{chaturvedi2025loracode,
  author = {Saumya Chaturvedi and Aman Chadha and Laurent Bindschaedler},
  title = {{LoRACode: LoRA Adapters for Code Embeddings}},
  booktitle = {DL4C @ ICLR},
  year = {2025},
  url = {https://openreview.net/forum?id=b0foNPsPaH},
}
Figure