Views
No views yet
TinyLlama/TinyLlama-1.1B-Chat-v1.0 on the Alpaca instruction-following dataset.peft + bitsandbytes with the following configuration:| Hyperparameter | Value |
|---|---|
| LoRA rank (r) | 16 |
| LoRA alpha | 32 |
| LoRA dropout | 0.1 |
| Target modules | q_proj, v_proj, k_proj, o_proj |
| Quantization | 4-bit NF4, double quant |
| Batch size | 2 (effective 16 with grad accum) |
| Learning rate | 1e-4 |
| Epochs | 2 |
| Max sequence length | 512 |
| Warmup steps | 50 |
| Optimizer | AdamW (paged) |
| Metric | Value |
|---|---|
| Final loss | 1.22 |
| Train samples/sec | 6.96 |
| Train steps/sec | 0.43 |
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5# Base model
6base_model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
7adapter_name = "zaid646/tinyllama-1.1b-alpaca-qlora"
8
9# Load tokenizer
10tokenizer = AutoTokenizer.from_pretrained(base_model_name)
11tokenizer.pad_token = tokenizer.eos_token
12
13# Load model with 4-bit quantization
14quant_config = BitsAndBytesConfig(
15 load_in_4bit=True,
16 bnb_4bit_compute_dtype=torch.bfloat16,
17 bnb_4bit_use_double_quant=True,
18 bnb_4bit_quant_type="nf4",
19)
20
21model = AutoModelForCausalLM.from_pretrained(
22 base_model_name,
23 quantization_config=quant_config,
24 device_map="auto",
25 torch_dtype=torch.bfloat16,
26)
27
28# Load adapter
29model = PeftModel.from_pretrained(model, adapter_name)
30
31# Inference
32prompt = "### Instruction:\nExplain what machine learning is.\n### Response:\n"
33inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
34outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.7)
35print(tokenizer.decode(outputs[0], skip_special_tokens=True))1git clone https://github.com/ZAID646/fine-tuning-recipes.git
2cd fine-tuning-recipes
3pip install -e .
4python -m src.cli train --config recipes/qlora.yaml### Instruction:\n...\n### Response:\n)