Views
No views yet
transformers, trl, peft, bitsandbytes| Setting | Value |
|---|---|
| Learning rate | 2e-4 |
| Batch size | 2 |
| Epochs | 2 |
1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5BASE = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
6ADAPTER = "leesusan/tinyllama-dpo-lora"
7
8bnb_cfg = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_compute_dtype=torch.float16,
11 bnb_4bit_use_double_quant=True,
12 bnb_4bit_quant_type="nf4",
13)
14
15tok = AutoTokenizer.from_pretrained(BASE)
16model = AutoModelForCausalLM.from_pretrained(BASE, quantization_config=bnb_cfg, device_map="auto")
17model = PeftModel.from_pretrained(model, ADAPTER)
18
19prompt = "Why do people experience jealousy in workplaces?"
20inputs = tok(prompt, return_tensors="pt").to(model.device)
21
22with torch.inference_mode():
23 out = model.generate(**inputs, max_new_tokens=150, temperature=0.7, top_p=0.9)
24
25print(tok.decode(out[0], skip_special_tokens=True))
26
27
28
29- **Repository:** [More Information Needed]
30- **Paper [optional]:** [More Information Needed]
31- **Demo [optional]:** [More Information Needed]
32