Views
No views yet
This repository contains LoRA adapter weights only. Base model required:Qwen/Qwen2.5-7B
1max_new_tokens=60
2do_sample=False
3repetition_penalty=1.11import torch
2
3from transformers import (
4 AutoModelForCausalLM,
5 AutoTokenizer,
6 BitsAndBytesConfig,
7)
8
9from peft import PeftModel
10
11base_model = "Qwen/Qwen2.5-7B"
12adapter = "K-saif/apj-kalam-instruct"
13
14quant_config = BitsAndBytesConfig(
15 load_in_4bit=True,
16 bnb_4bit_quant_type="nf4",
17 bnb_4bit_compute_dtype=torch.bfloat16,
18 bnb_4bit_use_double_quant=True,
19)
20
21tokenizer = AutoTokenizer.from_pretrained(adapter)
22
23model = AutoModelForCausalLM.from_pretrained(
24 base_model,
25 quantization_config=quant_config,
26 device_map="auto",
27)
28
29model = PeftModel.from_pretrained(model, adapter)
30
31model.eval()
32
33messages = [
34 {
35 "role": "system",
36 "content": (
37 "You are APJ Abdul Kalam, former President of India, "
38 "known as the Missile Man. Speak with humility, wisdom, "
39 "inspiration, and deep love for science, education, and "
40 "the youth of India. Use simple, heartfelt, and profound "
41 "language. Always answer in first person as if you are "
42 "Kalam himself."
43 )
44 },
45 {
46 "role": "user",
47 "content": "What is the purpose of life?"
48 }
49]
50
51text = tokenizer.apply_chat_template(
52 messages,
53 tokenize=False,
54 add_generation_prompt=True
55)
56
57inputs = tokenizer(
58 text,
59 return_tensors="pt"
60).to(model.device)
61
62with torch.no_grad():
63
64 outputs = model.generate(
65 **inputs,
66 max_new_tokens=60,
67 do_sample=False,
68 repetition_penalty=1.1,
69 )
70
71response = tokenizer.decode(
72 outputs[0][inputs["input_ids"].shape[1]:],
73 skip_special_tokens=True
74)
75
76print(response)