Views
No views yet
Base Model: Llama-3.2-1B
Parameters: Approximately 1 Billion
Quantization: 4-bit using the bitsandbytes library
Fine-tuning Method: PEFT with LoRAFine-tuning Configuration:
LoRA Rank (r): 8
LoRA Alpha: 16
LoRA Dropout: 0.5
Number of Epochs: 30
Batch Size: 2 (per device)
Learning Rate: 2e-5
Evaluation Strategy: Evaluated at each epoch
Optimizer: AdamW
Mixed Precision: FP16
Hardware Used: Single RTX 4070 8GB
Libraries:
transformers
datasets
peft
bitsandbytes
trl
evaluate1 from transformers import AutoModelForCausalLM, AutoTokenizer
2 from peft import PeftModel, PeftConfig
3
4 peft_model_id = "Chryslerx10/Llama-3.2-1B-finetuned-generalQA-peft-4bit"
5 config = PeftConfig.from_pretrained(peft_model_id, device_map='auto')
6
7 model = AutoModelForCausalLM.from_pretrained(
8 config.base_model_name_or_path,
9 device_map='auto',
10 return_dict=True
11 )
12
13 tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
14 tokenizer.pad_token = tokenizer.eos_token
15
16 peft_loaded_model = PeftModel.from_pretrained(model, peft_model_id, device_map='auto')1 def create_chat_template(question, context):
2 text = f"""
3 [Instruction] You are a question-answering agent which answers the question based on the related reviews.
4 If related reviews are not provided, you can generate the answer based on the question.\n
5 [Question] {question}\n
6 [Related Reviews] {context}\n
7 [Answer]
8 """
9 return text
10
11 def generate_response(question, context):
12 text = create_chat_template(question, context)
13 inputs = tokenizer([text], return_tensors='pt', padding=True, truncation=True).to(device)
14
15 config = GenerationConfig(
16 max_length=256,
17 temperature=0.5,
18 top_k=5,
19 top_p=0.95,
20 repetition_penalty=1.2,
21 do_sample=True,
22 penalty_alpha=0.6
23 )
24
25 response = model.generate(**inputs, generation_config=config)
26 output = tokenizer.decode(response[0], skip_special_tokens=True)
27 return output
28
29 # Example usage
30 question = "Explain the process of photosynthesis."
31 response = generate_response(question)
32 print(response)