Instructions to use allenai/OLMo-7B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use allenai/OLMo-7B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="allenai/OLMo-7B-Instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use allenai/OLMo-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-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-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/allenai/OLMo-7B-Instruct
- SGLang
How to use allenai/OLMo-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-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-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-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-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use allenai/OLMo-7B-Instruct with Docker Model Runner:
docker model run hf.co/allenai/OLMo-7B-Instruct
Update README.md
#4
by shanearora - opened
README.md
CHANGED
|
@@ -24,7 +24,7 @@ We release all code, checkpoints, logs (coming soon), and details involved in tr
|
|
| 24 |
OLMo 7B Instruct and OLMo SFT are two adapted versions of these models trained for better question answering.
|
| 25 |
They show the performance gain that OLMo base models can achieve with existing fine-tuning techniques.
|
| 26 |
|
| 27 |
-
*Note:* This model requires installing `ai2-olmo` with pip and using HuggingFace Transformers<=4.39. New versions of the model will be released soon with compatibility improvements.
|
| 28 |
|
| 29 |
## Model Details
|
| 30 |
|
|
@@ -82,11 +82,9 @@ pip install ai2-olmo
|
|
| 82 |
```
|
| 83 |
Now, proceed as usual with HuggingFace:
|
| 84 |
```python
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
olmo = AutoModelForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct")
|
| 89 |
-
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-7B-Instruct")
|
| 90 |
chat = [
|
| 91 |
{ "role": "user", "content": "What is language modeling?" },
|
| 92 |
]
|
|
@@ -99,17 +97,8 @@ response = olmo.generate(input_ids=inputs.to(olmo.device), max_new_tokens=100, d
|
|
| 99 |
print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])
|
| 100 |
>> '<|user|>\nWhat is language modeling?\n<|assistant|>\nLanguage modeling is a type of natural language processing (NLP) task or machine learning task that...'
|
| 101 |
```
|
| 102 |
-
Alternatively, with the pipeline abstraction:
|
| 103 |
-
```python
|
| 104 |
-
import hf_olmo
|
| 105 |
-
|
| 106 |
-
from transformers import pipeline
|
| 107 |
-
olmo_pipe = pipeline("text-generation", model="allenai/OLMo-7B-Instruct")
|
| 108 |
-
print(olmo_pipe("What is language modeling?"))
|
| 109 |
-
>> '[{'generated_text': 'What is language modeling?\nLanguage modeling is a type of natural language processing (NLP) task...'}]'
|
| 110 |
-
```
|
| 111 |
|
| 112 |
-
|
| 113 |
The quantized model is more sensitive to typing / cuda, so it is recommended to pass the inputs as `inputs.input_ids.to('cuda')` to avoid potential issues.
|
| 114 |
|
| 115 |
Note, you may see the following error if `ai2-olmo` is not installed correctly, which is caused by internal Python check naming. We'll update the code soon to make this error clearer.
|
|
|
|
| 24 |
OLMo 7B Instruct and OLMo SFT are two adapted versions of these models trained for better question answering.
|
| 25 |
They show the performance gain that OLMo base models can achieve with existing fine-tuning techniques.
|
| 26 |
|
| 27 |
+
*Note:* This model requires installing `ai2-olmo` with pip and using `ai2-olmo`>=0.3.0 or HuggingFace Transformers<=4.39. New versions of the model will be released soon with compatibility improvements.
|
| 28 |
|
| 29 |
## Model Details
|
| 30 |
|
|
|
|
| 82 |
```
|
| 83 |
Now, proceed as usual with HuggingFace:
|
| 84 |
```python
|
| 85 |
+
from hf_olmo import OLMoForCausalLM, OLMoTokenizerFast
|
| 86 |
+
olmo = OLMoForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct")
|
| 87 |
+
tokenizer = OLMoTokenizerFast.from_pretrained("allenai/OLMo-7B-Instruct")
|
|
|
|
|
|
|
| 88 |
chat = [
|
| 89 |
{ "role": "user", "content": "What is language modeling?" },
|
| 90 |
]
|
|
|
|
| 97 |
print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])
|
| 98 |
>> '<|user|>\nWhat is language modeling?\n<|assistant|>\nLanguage modeling is a type of natural language processing (NLP) task or machine learning task that...'
|
| 99 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
You can make this slightly faster by quantizing the model, e.g. `OLMoForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct", torch_dtype=torch.float16, load_in_8bit=True)` (requires `bitsandbytes`).
|
| 102 |
The quantized model is more sensitive to typing / cuda, so it is recommended to pass the inputs as `inputs.input_ids.to('cuda')` to avoid potential issues.
|
| 103 |
|
| 104 |
Note, you may see the following error if `ai2-olmo` is not installed correctly, which is caused by internal Python check naming. We'll update the code soon to make this error clearer.
|