ALM Transfers
Collection
4 items โข Updated โข 1
How to use benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer")
model = AutoModelForCausalLM.from_pretrained("benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer")
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 benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer
How to use benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer" \
--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": "benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer",
"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 "benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer" \
--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": "benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer with Docker Model Runner:
docker model run hf.co/benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer
Gemma2-2B-IT transferred to the Qwen2 Tokenizer. The model approximately preserves performance of the original on most benchmarks, except for some slight degradations.
| Benchmark | Gemma2-2B w/ Qwen Tokenizer | Original Gemma2-2B-IT |
|---|---|---|
| PiQA | 76.9 | 79.6 |
| HS | 70.7 | 72.5 |
| ARC-C | 46.8 | 50.4 |
| BoolQ | 82.8 | 83.8 |
| MMLU | 53.8 | 56.9 |
| Arith. | 83.9 | 84.8 |
| IFEval | 62.5 | 62.5 |
Details on the training methodology are forthcoming.
import torch
from transformers import pipeline
pipe = pipeline(
"text-generation",
model="benjamin/Gemma2-2B-IT-with-Qwen2-Tokenizer",
model_kwargs={"torch_dtype": torch.bfloat16},
device="cuda", # replace with "mps" to run on a Mac device
)
messages = [
{"role": "user", "content": "Who are you? Please, answer in pirate-speak."},
]
outputs = pipe(messages, max_new_tokens=256)
assistant_response = outputs[0]["generated_text"][-1]["content"].strip()
print(assistant_response)