merve/turkish_instructions
Viewer • Updated • 51.6k • 490 • 62
How to use ardaorcun/finetuned_cosmos2603 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="ardaorcun/finetuned_cosmos2603") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("ardaorcun/finetuned_cosmos2603")
model = AutoModelForCausalLM.from_pretrained("ardaorcun/finetuned_cosmos2603")How to use ardaorcun/finetuned_cosmos2603 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "ardaorcun/finetuned_cosmos2603"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ardaorcun/finetuned_cosmos2603",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/ardaorcun/finetuned_cosmos2603
How to use ardaorcun/finetuned_cosmos2603 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "ardaorcun/finetuned_cosmos2603" \
--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": "ardaorcun/finetuned_cosmos2603",
"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 "ardaorcun/finetuned_cosmos2603" \
--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": "ardaorcun/finetuned_cosmos2603",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use ardaorcun/finetuned_cosmos2603 with Docker Model Runner:
docker model run hf.co/ardaorcun/finetuned_cosmos2603
This model is a fine-tuned version of YTU's Cosmos GPT2 Language Model. You can check the code from here:Fine Tuning Cosmos by LoRA and QLoRA
The model was fine-tuned using LoRA and QLoRA techniques. Training parameters are defined below.
For training, I used Merve's Turkish Instructions Dataset, which you can check here: Merve's Turkish Instructions Dataset
def format_instruction(sample):
return f"""Sen cevap vermeyi seven yardımcı bir dil modelisin.
### Input:
{sample["talimat"]}
### Context:
{sample[" giriş"]}
### Response:
{sample[" çıktı"]}
"""
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_id = "ardaorcun/finetuned_cosmos2603"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id,
device_map='auto',
load_in_8bit=True)
sampling_params = dict(do_sample=True, temperature=0.3, top_k=50, top_p=0.9)
pipe = pipeline("text-generation",
model=model,
tokenizer=tokenizer,
device_map="auto",
max_new_tokens=512,
return_full_text=True,
repetition_penalty=1.1
)
DEFAULT_SYSTEM_PROMPT = "Sen cevap vermeyi seven yardımcı bir dil modelisin.\n"
def format_instruction(sample):
return f"""{DEFAULT_SYSTEM_PROMPT}
### Input:
{sample["talimat"]}
### Context:
{sample["giriş"]}
### Response:
{sample["çıktı"]}"""
prompt = "your_prompt"
girdi = "your_entry"
instruction = f"""Sen cevap vermeyi seven yardımcı bir dil modelisin.\n### Input:\n{prompt}\n\n### Context:\n{girdi}\n\n### Response:"""
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_length = 2048)
result = pipe(instruction)
print(result[0]['generated_text'][len(instruction):])