nvidia/OpenMathInstruct-2
Viewer โข Updated โข 22M โข 34k โข 243
How to use benjamin/Gemma2-2B-Distilled-Math with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="benjamin/Gemma2-2B-Distilled-Math") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("benjamin/Gemma2-2B-Distilled-Math")
model = AutoModelForCausalLM.from_pretrained("benjamin/Gemma2-2B-Distilled-Math")How to use benjamin/Gemma2-2B-Distilled-Math with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "benjamin/Gemma2-2B-Distilled-Math"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "benjamin/Gemma2-2B-Distilled-Math",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/benjamin/Gemma2-2B-Distilled-Math
How to use benjamin/Gemma2-2B-Distilled-Math with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "benjamin/Gemma2-2B-Distilled-Math" \
--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": "benjamin/Gemma2-2B-Distilled-Math",
"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 "benjamin/Gemma2-2B-Distilled-Math" \
--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": "benjamin/Gemma2-2B-Distilled-Math",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use benjamin/Gemma2-2B-Distilled-Math with Docker Model Runner:
docker model run hf.co/benjamin/Gemma2-2B-Distilled-Math
Gemma2-2B distilled from OpenMath2-Llama3.1-8B for math tasks.
This model greatly outperforms the general-purpose Gemma2 instruction-tuning finetune on math tasks.
| Benchmark | Gemma2-2B-Distilled-Math | Original Gemma2-2B-IT |
|---|---|---|
| GSM8K (zero-shot) | 65.1 | 6.1 |
| MATH (zero-shot) | 52.1 | 9.9 |
Details on the training methodology are forthcoming.
import torch
from transformers import pipeline
template = "<|start_header_id|>user<|end_header_id|>\n\nSolve the following math problem. Make sure to put the answer (and only answer) inside \boxed{}.\n\n{{problem}}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
problem = "What is the minimum value of $a^2+6a-7$?"
pipe = pipeline(
"text-generation",
model="benjamin/Gemma2-2B-Distilled-Math",
model_kwargs={"torch_dtype": torch.bfloat16},
eos_token_id=107,
device_map="auto",
)
outputs = pipe(template.format(problem), max_new_tokens=256)
assistant_response = outputs[0]["generated_text"].strip()
print(assistant_response)