Views
No views yet
TinyLlama/TinyLlama-1.1B-Chat-v1.0| Model | Accuracy (HellaSwag) |
|---|---|
| Original TinyLlama | 24% |
| WikiLlama (LoRA) | 30% |
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load the model and tokenizer
5model_id = "rudranshjoshi/WikiLlama"
6
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 torch_dtype=torch.float16,
11 device_map="auto"
12)
13
14# Prepare input
15messages = [
16 {"role": "user", "content": "What is the capital of France?"}
17]
18
19# Apply chat template (if available) or format prompt
20prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
21inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
22
23# Generate response
24outputs = model.generate(
25 **inputs,
26 max_new_tokens=256,
27 temperature=0.7,
28 do_sample=True
29)
30
31response = tokenizer.decode(outputs[0], skip_special_tokens=True)
32print(response)
33Note: Fine-tuning on WikiText-103 resulted in a 6% absolute improvement in accuracy on the HellaSwag benchmark compared to the vanilla TinyLlama-1.1B checkpoint.