Instructions to use allenai/Olmo-3-7B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use allenai/Olmo-3-7B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="allenai/Olmo-3-7B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("allenai/Olmo-3-7B-Instruct") model = AutoModelForCausalLM.from_pretrained("allenai/Olmo-3-7B-Instruct") 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]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use allenai/Olmo-3-7B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "allenai/Olmo-3-7B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "allenai/Olmo-3-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/allenai/Olmo-3-7B-Instruct
- SGLang
How to use allenai/Olmo-3-7B-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "allenai/Olmo-3-7B-Instruct" \ --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": "allenai/Olmo-3-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
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 "allenai/Olmo-3-7B-Instruct" \ --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": "allenai/Olmo-3-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use allenai/Olmo-3-7B-Instruct with Docker Model Runner:
docker model run hf.co/allenai/Olmo-3-7B-Instruct
Update inference examples to use the correct chat template
#7
by mario-sanz - opened
README.md
CHANGED
|
@@ -45,13 +45,13 @@ You can use OLMo with the standard HuggingFace transformers library:
|
|
| 45 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 46 |
olmo = AutoModelForCausalLM.from_pretrained("allenai/Olmo-3-7B-Instruct")
|
| 47 |
tokenizer = AutoTokenizer.from_pretrained("allenai/Olmo-3-7B-Instruct")
|
| 48 |
-
message = ["Who would win in a fight - a dinosaur or a cow named Moo Moo?"]
|
| 49 |
-
inputs = tokenizer(message, return_tensors='pt',
|
| 50 |
# optional verifying cuda
|
| 51 |
# inputs = {k: v.to('cuda') for k,v in inputs.items()}
|
| 52 |
# olmo = olmo.to('cuda')
|
| 53 |
response = olmo.generate(**inputs, max_new_tokens=100, do_sample=True, top_k=50, top_p=0.95)
|
| 54 |
-
print(tokenizer.
|
| 55 |
>> 'This is a fun and imaginative question! Let’s break it down...'
|
| 56 |
```
|
| 57 |
|
|
@@ -184,8 +184,8 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 184 |
device_map="auto",
|
| 185 |
)
|
| 186 |
|
| 187 |
-
|
| 188 |
-
inputs = tokenizer(
|
| 189 |
|
| 190 |
outputs = model.generate(
|
| 191 |
**inputs,
|
|
@@ -194,7 +194,7 @@ outputs = model.generate(
|
|
| 194 |
max_new_tokens=32768,
|
| 195 |
)
|
| 196 |
|
| 197 |
-
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 198 |
```
|
| 199 |
|
| 200 |
### vllm Example
|
|
@@ -210,8 +210,8 @@ sampling_params = SamplingParams(
|
|
| 210 |
max_tokens=32768,
|
| 211 |
)
|
| 212 |
|
| 213 |
-
|
| 214 |
-
outputs = llm.
|
| 215 |
print(outputs[0].outputs[0].text)
|
| 216 |
```
|
| 217 |
|
|
|
|
| 45 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 46 |
olmo = AutoModelForCausalLM.from_pretrained("allenai/Olmo-3-7B-Instruct")
|
| 47 |
tokenizer = AutoTokenizer.from_pretrained("allenai/Olmo-3-7B-Instruct")
|
| 48 |
+
message = [{"role": "user", "content": "Who would win in a fight - a dinosaur or a cow named Moo Moo?"}]
|
| 49 |
+
inputs = tokenizer.apply_chat_template(message, add_generation_prompt=True, return_tensors='pt', return_dict=True)
|
| 50 |
# optional verifying cuda
|
| 51 |
# inputs = {k: v.to('cuda') for k,v in inputs.items()}
|
| 52 |
# olmo = olmo.to('cuda')
|
| 53 |
response = olmo.generate(**inputs, max_new_tokens=100, do_sample=True, top_k=50, top_p=0.95)
|
| 54 |
+
print(tokenizer.decode(response[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 55 |
>> 'This is a fun and imaginative question! Let’s break it down...'
|
| 56 |
```
|
| 57 |
|
|
|
|
| 184 |
device_map="auto",
|
| 185 |
)
|
| 186 |
|
| 187 |
+
message = [{"role": "user", "content": "Who would win in a fight - a dinosaur or a cow named Moo Moo?"}]
|
| 188 |
+
inputs = tokenizer.apply_chat_template(message, add_generation_prompt=True, return_tensors='pt', return_dict=True).to(model.device)
|
| 189 |
|
| 190 |
outputs = model.generate(
|
| 191 |
**inputs,
|
|
|
|
| 194 |
max_new_tokens=32768,
|
| 195 |
)
|
| 196 |
|
| 197 |
+
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 198 |
```
|
| 199 |
|
| 200 |
### vllm Example
|
|
|
|
| 210 |
max_tokens=32768,
|
| 211 |
)
|
| 212 |
|
| 213 |
+
message = [{"role": "user", "content": "Who would win in a fight - a dinosaur or a cow named Moo Moo?"}]
|
| 214 |
+
outputs = llm.chat(message, sampling_params)
|
| 215 |
print(outputs[0].outputs[0].text)
|
| 216 |
```
|
| 217 |
|