Text Generation
Transformers
Safetensors
English
flex_olmo
Mixture of Experts
olmo
flexolmo
conversational
Instructions to use allenai/Flex-code-2x7B-1T with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use allenai/Flex-code-2x7B-1T with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="allenai/Flex-code-2x7B-1T") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("allenai/Flex-code-2x7B-1T") model = AutoModelForCausalLM.from_pretrained("allenai/Flex-code-2x7B-1T", device_map="auto") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use allenai/Flex-code-2x7B-1T with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "allenai/Flex-code-2x7B-1T" # 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/Flex-code-2x7B-1T", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/allenai/Flex-code-2x7B-1T
- SGLang
How to use allenai/Flex-code-2x7B-1T 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/Flex-code-2x7B-1T" \ --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/Flex-code-2x7B-1T", "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/Flex-code-2x7B-1T" \ --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/Flex-code-2x7B-1T", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use allenai/Flex-code-2x7B-1T with Docker Model Runner:
docker model run hf.co/allenai/Flex-code-2x7B-1T
Update README.md
Browse files
README.md
CHANGED
|
@@ -28,16 +28,17 @@ This information and more can also be found:
|
|
| 28 |
|
| 29 |
# Use
|
| 30 |
|
| 31 |
-
Install `transformers`
|
| 32 |
```python
|
| 33 |
-
from transformers import
|
| 34 |
import torch
|
| 35 |
|
| 36 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 37 |
|
| 38 |
-
MODEL_NAME = "allenai/
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
inputs = tokenizer("Bitcoin is", return_tensors="pt")
|
| 42 |
inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
|
| 43 |
out = model.generate(**inputs, max_length=64)
|
|
|
|
| 28 |
|
| 29 |
# Use
|
| 30 |
|
| 31 |
+
Install `transformers` with version `4.57.0` or newer and run:
|
| 32 |
```python
|
| 33 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 34 |
import torch
|
| 35 |
|
| 36 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 37 |
|
| 38 |
+
MODEL_NAME = "allenai/Flex-code-2x7B-1T"
|
| 39 |
+
TOKENIZER_NAME = "allenai/dolma2-tokenizer"
|
| 40 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to(DEVICE)
|
| 41 |
+
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_NAME)
|
| 42 |
inputs = tokenizer("Bitcoin is", return_tensors="pt")
|
| 43 |
inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
|
| 44 |
out = model.generate(**inputs, max_length=64)
|