Views
No views yet
RedQueenProtocol/llama-3.2-3b-it-sinhala-rq (Meta's Llama-3.2-3B-IT copies into a private repo for ease of use), was fine-tuned on the entirety of the Sinhala Wikipedia to create a foundational model with a comprehensive grasp of the language.RedQueenProtocol/all-articles-from-sinhala-wikipedia-2025-parquet.RedQueenProtocol/sinhala-wiki-2025-LoRA-merged.RedQueenProtocol/sinhala-qna-530-rows).ihalage/sinhala-finetune-qa-eli5 dataset.janani-rane/SiQuAD dataset, formatting the inputs as "Context: ... Question: ... Answer: ...".1
2# For Kaggle:
3#from kaggle_secrets import UserSecretsClient
4#from huggingface_hub import login
5#user_secrets = UserSecretsClient()
6#hf_token = user_secrets.get_secret("HF_TOKEN")
7#login(token=hf_token)
8
9# For Colab:
10#from huggingface_hub import notebook_login
11#notebook_login()
12
13# --- 1. Install Libraries ---
14!pip install -q -U transformers accelerate bitsandbytes peft
15
16# --- 2. Import Libraries ---
17import torch
18from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
19from peft import PeftModel
20import warnings
21
22# --- 3. Configuration ---
23# Now both the base model and adapter are loaded from the iCIIT organization.
24base_model_id = "iCIIT/redqueenprotocol-sin-llama3.2-3B-model"
25adapter_id = "iCIIT/redqueenprotocol-sin-llama3.2-3B-LoRA"
26device = "cuda" if torch.cuda.is_available() else "cpu"
27
28# --- 4. Load Model and Adapter ---
29print(f"Loading base model from: {base_model_id}")
30base_model = AutoModelForCausalLM.from_pretrained(
31 base_model_id,
32 torch_dtype=torch.bfloat16,
33 device_map=device,
34)
35tokenizer = AutoTokenizer.from_pretrained(base_model_id)
36tokenizer.pad_token = tokenizer.eos_token
37
38print(f"Applying LoRA adapter from: {adapter_id}")
39model = PeftModel.from_pretrained(base_model, adapter_id)
40print("\n Model and adapter loaded successfully from the iCIIT repositories.")
41
42# --- 5. Run a Sample Prompt ---
43generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
44question = "ශ්රී ලංකා ජාතික ධජය නිර්මාණය කළේ කවුද?"
45
46prompt = f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\\n\\n{question}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n\\n"
47
48print("\n" + "="*50)
49print(f"USER: {question}")
50print("\nASSISTANT: Generating...")
51
52outputs = generator(
53 prompt,
54 max_new_tokens=256,
55 eos_token_id=tokenizer.eos_token_id,
56 do_sample=True,
57 temperature=0.6,
58 top_p=0.9,
59)
60
61full_response = outputs[0]['generated_text']
62answer = full_response.split("<|start_header_id|>assistant<|end_header_id|>\\n\\n")[1].replace("<|eot_id|>", "")
63
64print(answer.strip())
65print("="*50)