TripleBits
Collection
Submission of team TripleBits • 3 items • Updated • 1
How to use iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b")
model = PeftModel.from_pretrained(base_model, "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP")How to use iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP", dtype="auto")How to use iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP
How to use iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP with Docker Model Runner:
docker model run hf.co/iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP
TripleBits-Sinhala-Gemma-2-2b is a Gemma-2-2B-based model that has undergone continual pretraining (CPT) on a diverse Sinhala corpus.
Use the code below to get started with the model.
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
from huggingface_hub import login
login(token="your_hf_token")
# Load base model
base_model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
# Load fine-tuned LoRA adapter
model = PeftModel.from_pretrained(base_model, "iCIIT/TripleBits-Sinhala-Gemma-2-2b-CP")
question = "ශ්රී ලංකාවේ අගනුවර කුමක්ද?"
instruction = f"""පහත සදහන් ප්රශ්නයට නිවැරදි පිළිතුරක් ලබා දෙන්න. පිළිතුරු ලබා දීමේදී ප්රශ්නයේ ස්වභාවය අනුව - සරල ප්රශ්න සඳහා කෙටි පිළිතුරු ද, සංකීර්ණ ප්රශ්න සඳහා විස්තරාත්මක පැහැදිලි කිරීම් ද ලබා දෙන්න.
### ප්රශ්නය: {question}
### පිළිතුර:"""
inputs = tokenizer(instruction, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=100,
num_beams=10,
repetition_penalty=1.2,
no_repeat_ngram_size=3,
do_sample=False,
early_stopping=True,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id
)
generated_answer_tokens = outputs[0][inputs.input_ids.shape[1]:]
generated_answer = tokenizer.decode(generated_answer_tokens, skip_special_tokens=True).strip()
print(generated_answer)
Base model
google/gemma-2-2b