Instructions to use hf-internal-testing/tiny-random-Olmo2ForCausalLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hf-internal-testing/tiny-random-Olmo2ForCausalLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="hf-internal-testing/tiny-random-Olmo2ForCausalLM") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-Olmo2ForCausalLM") model = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-Olmo2ForCausalLM") 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]:])) - Transformers.js
How to use hf-internal-testing/tiny-random-Olmo2ForCausalLM with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-generation', 'hf-internal-testing/tiny-random-Olmo2ForCausalLM'); - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use hf-internal-testing/tiny-random-Olmo2ForCausalLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hf-internal-testing/tiny-random-Olmo2ForCausalLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hf-internal-testing/tiny-random-Olmo2ForCausalLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/hf-internal-testing/tiny-random-Olmo2ForCausalLM
- SGLang
How to use hf-internal-testing/tiny-random-Olmo2ForCausalLM 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 "hf-internal-testing/tiny-random-Olmo2ForCausalLM" \ --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": "hf-internal-testing/tiny-random-Olmo2ForCausalLM", "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 "hf-internal-testing/tiny-random-Olmo2ForCausalLM" \ --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": "hf-internal-testing/tiny-random-Olmo2ForCausalLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use hf-internal-testing/tiny-random-Olmo2ForCausalLM with Docker Model Runner:
docker model run hf.co/hf-internal-testing/tiny-random-Olmo2ForCausalLM
Update README.md
Browse files
README.md
CHANGED
|
@@ -7,7 +7,31 @@ tags: []
|
|
| 7 |
|
| 8 |
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
|
|
|
| 7 |
|
| 8 |
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
|
| 10 |
+
## Code to create the model
|
| 11 |
+
```python
|
| 12 |
+
import torch
|
| 13 |
+
from transformers import Olmo2Config, Olmo2ForCausalLM, AutoTokenizer
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
model_id = 'allenai/OLMo-2-1124-13B-Instruct'
|
| 17 |
+
config = Olmo2Config.from_pretrained(
|
| 18 |
+
model_id,
|
| 19 |
+
hidden_size=32,
|
| 20 |
+
intermediate_size=64,
|
| 21 |
+
num_attention_heads=4,
|
| 22 |
+
num_hidden_layers=2,
|
| 23 |
+
num_key_value_heads=4,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Create model and randomize all weights
|
| 27 |
+
model = Olmo2ForCausalLM(config)
|
| 28 |
+
|
| 29 |
+
torch.manual_seed(0) # Set for reproducibility
|
| 30 |
+
for name, param in model.named_parameters():
|
| 31 |
+
param.data = torch.randn_like(param)
|
| 32 |
+
|
| 33 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 34 |
+
```
|
| 35 |
|
| 36 |
## Model Details
|
| 37 |
|