Views
No views yet
Qwen/Qwen2.5-3B<|im_start|> and <|im_end|>) with role mappings configured to "user" and "assistant".float16 / 32-bit precision to bypass hardware limitations with bfloat16.q_proj, v_proj, k_proj, o_projpeft library.pip install transformers accelerate peft1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5# Configuration
6base_model_id = "Qwen/Qwen2.5-3B"
7adapter_id = "essam04/Qwen2.5-3B-FineTome-LoRA"
8
9# 1. Load the Base Model and Tokenizer
10tokenizer = AutoTokenizer.from_pretrained(base_model_id)
11base_model = AutoModelForCausalLM.from_pretrained(
12 base_model_id,
13 torch_dtype=torch.float16,
14 device_map="auto"
15)
16
17# 2. Load and Merge the LoRA Adapter
18model = PeftModel.from_pretrained(base_model, adapter_id)
19
20# 3. Format the Prompt using ChatML
21messages = [
22 {"role": "system", "content": "You are a highly logical and helpful assistant."},
23 {"role": "user", "content": "Can you explain the benefits of using LoRA for model fine-tuning?"}
24]
25
26text = tokenizer.apply_chat_template(
27 messages,
28 tokenize=False,
29 add_generation_prompt=True
30)
31
32# 4. Generate Response
33inputs = tokenizer([text], return_tensors="pt").to(model.device)
34outputs = model.generate(
35 **inputs,
36 max_new_tokens=512,
37 temperature=0.7,
38 top_p=0.9
39)
40
41print(tokenizer.decode(outputs[0], skip_special_tokens=True))NotImplementedError crashes associated with BFloat16 operations on older architectures.