Norod78/hebrew_lyrics_prompting_finetune
Viewer • Updated • 40.2k • 471
How to use Norod78/hebrew_lyrics-gemma2_2b with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Norod78/hebrew_lyrics-gemma2_2b")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Norod78/hebrew_lyrics-gemma2_2b")
model = AutoModelForCausalLM.from_pretrained("Norod78/hebrew_lyrics-gemma2_2b")
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 Norod78/hebrew_lyrics-gemma2_2b with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Norod78/hebrew_lyrics-gemma2_2b"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Norod78/hebrew_lyrics-gemma2_2b",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/Norod78/hebrew_lyrics-gemma2_2b
How to use Norod78/hebrew_lyrics-gemma2_2b with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Norod78/hebrew_lyrics-gemma2_2b" \
--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": "Norod78/hebrew_lyrics-gemma2_2b",
"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 "Norod78/hebrew_lyrics-gemma2_2b" \
--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": "Norod78/hebrew_lyrics-gemma2_2b",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use Norod78/hebrew_lyrics-gemma2_2b with Docker Model Runner:
docker model run hf.co/Norod78/hebrew_lyrics-gemma2_2b
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import TextStreamer
import torch
model_id = "Norod78/hebrew_lyrics-gemma2_2b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16,
)
print(f"model.device = {model.device}")
input_text = "כתוב לי שיר על תפוח אדמה עם חרדה חברתית"
input_template = tokenizer.apply_chat_template([{"role": "user", "content": input_text}], tokenize=False, add_generation_prompt=True)
input_ids = tokenizer(input_template, return_tensors="pt").to(model.device)
outputs = model.generate(**input_ids, max_new_tokens=256, repetition_penalty=1.05, temperature=0.5, no_repeat_ngram_size = 4, do_sample = True)
decoded_output = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
result = decoded_output.replace("user\n", "משתמש:\n").replace("model\n", "\nמודל:\n")
print("result = ", result)
chat = [
{"role": "user", "content": input_text},
{"role": "asistant"}
]
chat_with_template = tokenizer.apply_chat_template(chat, tokenize=False)
inputs = tokenizer(
[
chat_with_template
], return_tensors = "pt").to(model.device)
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens=256 , repetition_penalty=1.1, temperature=0.6, top_p=0.4, top_k=40, do_sample = True)