Views
No views yet
Qwen/Qwen2.5-Coder-0.5B-Instruct model, fine-tuned for the task of Code Search as part of the research mentioned above.| Attribute | Details |
|---|---|
| Base Model | Qwen/Qwen2.5-Coder-0.5B-Instruct |
| Fine-tuning Method | Supervised Contrastive Learning via llm2vec |
| Evaluation Script | CSN_Test_Finetuning_Decoder_Model.py, CoSQA_Plus_Test_Finetuning_Decoder_Model.py |
| Prerequisite Model | This model must be loaded on top of an MNTP pre-trained model. |
llm2vec)llm2vec wrapper to load and use this model.pip install llm2vec transformers torch peft accelerateImportant: Thellm2vecsupervised contrastive (SupCon) models are fine-tuned on top of MNTP (Masked Next Token Prediction) models. Therefore, loading requires first merging the MNTP weights before loading the SupCon adapter.
1import torch
2from transformers import AutoTokenizer, AutoModel, AutoConfig
3from peft import PeftModel
4from llm2vec import LLM2Vec
5
6# --- 1. Define Model IDs ---
7base_model_id = "Qwen/Qwen2.5-Coder-0.5B-Instruct"
8mntp_model_id = "SYSUSELab/DCS-Qwen2.5-Coder-0.5B-It-MNTP"
9supcon_model_id = "SYSUSELab/DCS-Qwen2.5-Coder-0.5B-It-SupCon-CSN"
10
11# --- 2. Load Base Model and MNTP Adapter ---
12tokenizer = AutoTokenizer.from_pretrained(base_model_id)
13config = AutoConfig.from_pretrained(base_model_id, trust_remote_code=True)
14model = AutoModel.from_pretrained(
15 base_model_id,
16 trust_remote_code=True,
17 config=config,
18 torch_dtype=torch.bfloat16,
19 device_map="cuda" if torch.cuda.is_available() else "cpu",
20)
21model = PeftModel.from_pretrained(model, mntp_model_id)
22model = model.merge_and_unload()
23
24# --- 3. Load the Supervised (this model) Adapter on top of the MNTP-merged model ---
25model = PeftModel.from_pretrained(model, supcon_model_id)
26
27# --- 4. Use the LLM2Vec Wrapper for Encoding ---
28l2v = LLM2Vec(model, tokenizer, pooling_mode="mean", max_length=512)
29
30queries = ["how to read a file in Python?"]
31code_snippets = ["with open('file.txt', 'r') as f:\n content = f.read()"]
32query_embeddings = l2v.encode(queries)
33code_embeddings = l2v.encode(code_snippets)
34
35print("Query Embedding Shape:", query_embeddings.shape)
36# This usage example is adapted from the official llm2vec repository. Credits to the original authors.llm2vec, please also cite their foundational work.1@article{chen2024decoder,
2 title={Are Decoder-Only Large Language Models the Silver Bullet for Code Search?},
3 author={Chen, Yuxuan and Liu, Mingwei and Ou, Guangsheng and Li, Anji and Dai, Dekun and Wang, Yanlin and Zheng, Zibin},
4 journal={arXiv preprint arXiv:2410.22240},
5 year={2024}
6}1@article{vaishaal2024llm2vec,
2 title={LLM2Vec: Large Language Models Are Good Contextual Text Encoders},
3 author={Vaishaal, Shankar and Bansal, Mohit and Arora, Simran},
4 journal={arXiv preprint arXiv:2404.05961},
5 year={2024}
6}