Views
No views yet
meta-llama/Llama-3.2-1B-Instruct model.meta-llama/Llama-3.2-1B-Instruct. It was trained using DPO on a preference dataset that the base model generated itself. An LLM Judge, powered by GPT-3.5-Turbo, evaluated pairs of model-generated responses to create the chosen/rejected pairs for training.meta-llama/Llama-3.2-1B-Instructmeta-llama/Llama-3.2-1B-Instruct) and then apply the adapters from this repository.1import torch
2from peft import PeftModel
3from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
4
5# Set base model ID and adapter path
6base_model_id = "meta-llama/Llama-3.2-1B-Instruct"
7adapter_id = "NilayR/llama32-iterative-dpo-iter1"
8
9# Configure BitsAndBytes for 4-bit quantization
10bnb_config = BitsAndBytesConfig(
11 load_in_4bit=True,
12 bnb_4bit_quant_type="nf4",
13 bnb_4bit_compute_dtype=torch.bfloat16
14)
15
16# Load the base model with quantization
17base_model = AutoModelForCausalLM.from_pretrained(
18 base_model_id,
19 quantization_config=bnb_config,
20 device_map="auto",
21 trust_remote_code=True,
22)
23
24# Load the tokenizer
25tokenizer = AutoTokenizer.from_pretrained(base_model_id)
26tokenizer.pad_token = tokenizer.eos_token
27
28# Load and apply the PEFT adapters
29model = PeftModel.from_pretrained(base_model, adapter_id)
30
31# --- Generate a response ---
32prompt = "What are the key benefits of meditation?"
33messages = [
34 {"role": "system", "content": "You are a helpful assistant."},
35 {"role": "user", "content": prompt}
36]
37
38input_ids = tokenizer.apply_chat_template(
39 messages,
40 add_generation_prompt=True,
41 return_tensors="pt"
42).to(model.device)
43
44outputs = model.generate(
45 input_ids,
46 max_new_tokens=200,
47 do_sample=True,
48 temperature=0.7,
49 top_p=0.95
50)
51
52response = tokenizer.decode(outputs[0], skip_special_tokens=True)
53print(response.split("assistant")[-1].strip())meta-llama/Llama-3.2-1B-Instruct model itself.GPT-3.5-Turbo was used to compare pairs of the generated responses, creating a dataset of 56 chosen/rejected pairs.DPOTrainer.trl.DPOTrainerpaged_adamw_8bit0.6405r): 16lora_alpha): 32q_proj, k_proj, v_proj, o_projtransformers, peft, trl, bitsandbytes