Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5# Load base + adapter
6bnb_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16)
7base = AutoModelForCausalLM.from_pretrained("google/gemma-2-9b", quantization_config=bnb_config, device_map="auto")
8tokenizer = AutoTokenizer.from_pretrained("mueggi/ka-ai-tokenizer")
9base.resize_token_embeddings(len(tokenizer), mean_resizing=False)
10model = PeftModel.from_pretrained(base, "mueggi/ka-ai-instruct")
11
12# Chat
13messages = [{"role": "user", "content": "რა არის საქართველოს დედაქალაქი?"}]
14template = "{% for message in messages %}<|im_start|>{{ message.role }}\n{{ message.content }}<|im_end|>\n{% endfor %}<|im_start|>assistant\n"
15tokenizer.chat_template = template
16text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
17inputs = tokenizer(text, return_tensors="pt").to(model.device)
18out = model.generate(**inputs, max_new_tokens=256, do_sample=True, temperature=0.7,
19 stop_strings=["<|im_end|>"], tokenizer=tokenizer)
20print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))| Task | Quality |
|---|---|
| Georgian QA | ⭐⭐⭐⭐ |
| Georgian fluency | ⭐⭐⭐⭐ |
| KA→EN translation | ⭐⭐⭐⭐ |
| EN→KA translation | ⭐⭐ |
| Creative writing | ⭐⭐⭐⭐ |
<|im_end|>) requires stop_strings parameter in generation