Instructions to use arcee-ai/Trinity-Mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use arcee-ai/Trinity-Mini with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="arcee-ai/Trinity-Mini", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("arcee-ai/Trinity-Mini", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("arcee-ai/Trinity-Mini", trust_remote_code=True, 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use arcee-ai/Trinity-Mini with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "arcee-ai/Trinity-Mini" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "arcee-ai/Trinity-Mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/arcee-ai/Trinity-Mini
- SGLang
How to use arcee-ai/Trinity-Mini 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 "arcee-ai/Trinity-Mini" \ --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": "arcee-ai/Trinity-Mini", "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 "arcee-ai/Trinity-Mini" \ --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": "arcee-ai/Trinity-Mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use arcee-ai/Trinity-Mini with Docker Model Runner:
docker model run hf.co/arcee-ai/Trinity-Mini
Document inference precision and preserve FP32 expert biases
Browse files- README.md +7 -22
- modeling_afmoe.py +1 -0
README.md
CHANGED
|
@@ -82,17 +82,14 @@ Try it out now at [chat.arcee.ai](http://chat.arcee.ai/)
|
|
| 82 |
|
| 83 |
## Transformers
|
| 84 |
|
| 85 |
-
|
| 86 |
|
| 87 |
-
``
|
| 88 |
-
git clone https://github.com/huggingface/transformers.git
|
| 89 |
-
cd transformers
|
| 90 |
|
| 91 |
-
|
| 92 |
-
pip install '.[torch]'
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
```
|
| 97 |
|
| 98 |
```python
|
|
@@ -104,7 +101,8 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
| 104 |
model = AutoModelForCausalLM.from_pretrained(
|
| 105 |
model_id,
|
| 106 |
torch_dtype=torch.bfloat16,
|
| 107 |
-
device_map="auto"
|
|
|
|
| 108 |
)
|
| 109 |
|
| 110 |
messages = [
|
|
@@ -130,19 +128,6 @@ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
| 130 |
print(response)
|
| 131 |
```
|
| 132 |
|
| 133 |
-
If using a released transformers, simply pass "trust_remote_code=True":
|
| 134 |
-
|
| 135 |
-
```python
|
| 136 |
-
model_id = "arcee-ai/Trinity-Mini"
|
| 137 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 138 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 139 |
-
model_id,
|
| 140 |
-
torch_dtype=torch.bfloat16,
|
| 141 |
-
device_map="auto",
|
| 142 |
-
trust_remote_code=True
|
| 143 |
-
)
|
| 144 |
-
```
|
| 145 |
-
|
| 146 |
## VLLM
|
| 147 |
|
| 148 |
Supported in VLLM release 0.11.1
|
|
|
|
| 82 |
|
| 83 |
## Transformers
|
| 84 |
|
| 85 |
+
**Inference precision:** For unquantized BF16 inference, the intended parameter dtypes are BF16 for normalization and router weights, and FP32 for expert correction biases (`expert_bias`). Preserve FP32 checkpoint bias values during loading.
|
| 86 |
|
| 87 |
+
This checkpoint stores `expert_bias` in BF16; upcast these values to FP32 for inference.
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
Use the bundled model implementation with `transformers==4.57.1` and `trust_remote_code=True`.
|
|
|
|
| 90 |
|
| 91 |
+
```bash
|
| 92 |
+
pip install "transformers==4.57.1" "accelerate==1.11.0"
|
| 93 |
```
|
| 94 |
|
| 95 |
```python
|
|
|
|
| 101 |
model = AutoModelForCausalLM.from_pretrained(
|
| 102 |
model_id,
|
| 103 |
torch_dtype=torch.bfloat16,
|
| 104 |
+
device_map="auto",
|
| 105 |
+
trust_remote_code=True
|
| 106 |
)
|
| 107 |
|
| 108 |
messages = [
|
|
|
|
| 128 |
print(response)
|
| 129 |
```
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
## VLLM
|
| 132 |
|
| 133 |
Supported in VLLM release 0.11.1
|
modeling_afmoe.py
CHANGED
|
@@ -469,6 +469,7 @@ class AfmoeDecoderLayer(GradientCheckpointingLayer):
|
|
| 469 |
|
| 470 |
|
| 471 |
class AfmoePreTrainedModel(PreTrainedModel):
|
|
|
|
| 472 |
config_class = AfmoeConfig
|
| 473 |
base_model_prefix = "model"
|
| 474 |
_no_split_modules = ["AfmoeDecoderLayer"]
|
|
|
|
| 469 |
|
| 470 |
|
| 471 |
class AfmoePreTrainedModel(PreTrainedModel):
|
| 472 |
+
_keep_in_fp32_modules_strict = ["expert_bias"]
|
| 473 |
config_class = AfmoeConfig
|
| 474 |
base_model_prefix = "model"
|
| 475 |
_no_split_modules = ["AfmoeDecoderLayer"]
|