selimc/orpo-dpo-mix-TR-20k
Viewer • Updated • 19.9k • 71 • 7
How to use selimc/OrpoGemma-2-9B-TR with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="selimc/OrpoGemma-2-9B-TR")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("selimc/OrpoGemma-2-9B-TR")
model = AutoModelForCausalLM.from_pretrained("selimc/OrpoGemma-2-9B-TR")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use selimc/OrpoGemma-2-9B-TR with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "selimc/OrpoGemma-2-9B-TR"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "selimc/OrpoGemma-2-9B-TR",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/selimc/OrpoGemma-2-9B-TR
How to use selimc/OrpoGemma-2-9B-TR with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "selimc/OrpoGemma-2-9B-TR" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "selimc/OrpoGemma-2-9B-TR",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "selimc/OrpoGemma-2-9B-TR" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "selimc/OrpoGemma-2-9B-TR",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use selimc/OrpoGemma-2-9B-TR with Docker Model Runner:
docker model run hf.co/selimc/OrpoGemma-2-9B-TR
OrpoGemma-2-9B-TR is a Turkish fine-tuned version of google/gemma-2-9b-it. It is trained using the ORPO Trainer on a subset of 1500 rows from the dataset selimc/orpo-dpo-mix-TR-20k.
Base Model: google/gemma-2-9b-it
Fine-Tuning Technique: ORPO
Training Data: 1500 rows from selimc/orpo-dpo-mix-TR-20k
Training Time: 2.5 hours on NVIDIA H100
lora_r: 16lora_alpha: 32lora_dropout: 0.05lr: 2e-6epochs: 3per_device_train_batch_size: 8gradient_accumulation_steps: 4| Dataset | Score |
|---|---|
| MMLU_TR_V0.2 | 53.0% |
| Truthful_QA_TR_V0.2 | 54.3% |
| ARC_TR_V0.2 | 52.4% |
| HellaSwag_TR_V0.2 | 52.0% |
| GSM8K_TR_V0.2 | 64.8% |
| Winogrande_TR_V0.2 | 58.9% |
| Average | 55.9% |
Thanks to the WiroAI team for evaluating my model. Evaluations were done without any inference engine.
from transformers import pipeline, BitsAndBytesConfig, AutoTokenizer
import torch
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
model_id = "selimc/OrpoGemma-2-9B-TR"
tokenizer = AutoTokenizer.from_pretrained(model_id)
pipe = pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16 ,'quantization_config': bnb_config},
tokenizer=tokenizer,
device_map="auto"
)
messages = [
{"role": "user", "content": "Gökyüzü neden mavi?"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipe(
prompt,
max_new_tokens=512,
do_sample=True,
eos_token_id=[pipe.tokenizer.convert_tokens_to_ids("<end_of_turn>"), pipe.tokenizer.eos_token_id],
temperature=0.67,
)
generated_text = outputs[0]['generated_text']
response = generated_text[len(prompt):]
print(response)
messages = [
{"role": "user", "content": """Bir web sayfasından tüm URL’leri çeken bir Python fonksiyonu yazın ve nasıl çalıştığını açıklayın."""},
]
Bir web sayfasından tüm URL’leri çeken bir Python fonksiyonu yazalım ve nasıl çalıştığını açıklayalım.
```python
import requests
def get_urls_from_page(url):
"""
Bir web sayfasından tüm URL'leri çeker.
Args:
url (str): Web sayfasının URL'i.
Returns:
list: Web sayfasındaki tüm URL'ler.
"""
response = requests.get(url)
response.raise_for_status()
urls = []
for link in response.html.find_all('a', href=True):
urls.append(link['href'])
return urls
# Örnek kullanım
web_page_url = 'https://www.example.com/'
all_urls = get_urls_from_page(web_page_url)
print(f"Bu web sayfasındaki {len(all_urls)} URL bulunmaktadır:\n{all_urls}")
```
**Fonksiyonun nasıl çalıştığı:**
1. **`requests` kütüphanesini içer:** Bu kütüphane web sayfalarına erişmek için kullanılır.
2. **`get_urls_from_page` fonksiyonunu tanımla:**
* Bu fonksiyon, bir web sayfasının URL'ini alır.
* `requests.get()` kullanarak web sayfasına erişir ve `response.raise_for_status()` kullanarak HTTP durum kodunun 200-399 aralığında olup olmadığını kontrol eder.
* `response.html` içine bir HTML belgesini saklar.
* `response.html.find_all('a', href=True)` kullanarak, `href` atributuna sahip tüm `<a>` etiketlerini bulur.
* `urls` listesine URL'leri ekler.
* `urls` listesini döndürür.
3. **Örnek kullanım:**
* `web_page_url` değişkenine bir web sayfasının URL'ini atar.
* `get_urls_from_page` fonksiyonunu kullanarak web sayfasından tüm URL'leri çeker.
* `all_urls` listesini `print()` fonksiyonu kullanarak ekrana yazdır
messages = [
{
"role": "system",
"content":
"""
Sen bir türkçe bilmece ustasısın. Görevin:
- Sorulan bilmecelere mantıklı ve doğru cevaplar vermek
- Bilmecenin çözümünü adım adım açıklamak
"""
},
{
"role": "user",
"content":
"""
Kanadı var, kuş değil.
Suda yüzer, gemi değil.
Kuyruğu var, kedi değil.
Bil bakalım, bu nedir?
"""
},
]
Kanadı var, kuş değil, suda yüzer, gemi değil, kuyruğu var, kedi değil... Bu bir **balık**! 🐟
@misc{orpogemma2-9b-tr,
author = {Selim Çavaş},
title = {OrpoGemma-2-9B-TR: Turkish Fine-tuned Gemma Model},
year = {2024},
url = {https://huggingface.co/selimc/OrpoGemma-2-9B-TR}
}