Instructions to use microsoft/Phi-tiny-MoE-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Phi-tiny-MoE-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/Phi-tiny-MoE-instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-tiny-MoE-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-tiny-MoE-instruct", trust_remote_code=True) 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
- vLLM
How to use microsoft/Phi-tiny-MoE-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Phi-tiny-MoE-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": "microsoft/Phi-tiny-MoE-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/Phi-tiny-MoE-instruct
- SGLang
How to use microsoft/Phi-tiny-MoE-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 "microsoft/Phi-tiny-MoE-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": "microsoft/Phi-tiny-MoE-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 "microsoft/Phi-tiny-MoE-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": "microsoft/Phi-tiny-MoE-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/Phi-tiny-MoE-instruct with Docker Model Runner:
docker model run hf.co/microsoft/Phi-tiny-MoE-instruct
Commit ·
3a421cd
1
Parent(s): 274f8d5
Update working
Browse files- configuration_slimmoe.py +1 -1
- modeling_slimmoe.py +9 -1
configuration_slimmoe.py
CHANGED
|
@@ -111,7 +111,7 @@ class PhiMoEConfig(PretrainedConfig):
|
|
| 111 |
>>> configuration = model.config
|
| 112 |
```"""
|
| 113 |
|
| 114 |
-
model_type = "phimoe"
|
| 115 |
keys_to_ignore_at_inference = ["past_key_values"]
|
| 116 |
|
| 117 |
def __init__(
|
|
|
|
| 111 |
>>> configuration = model.config
|
| 112 |
```"""
|
| 113 |
|
| 114 |
+
model_type = "phimoe_slim" # renamed from "phimoe" to bypass transformers >=4.46 conversion_mapping
|
| 115 |
keys_to_ignore_at_inference = ["past_key_values"]
|
| 116 |
|
| 117 |
def __init__(
|
modeling_slimmoe.py
CHANGED
|
@@ -330,9 +330,17 @@ class PhiMoEAttention(nn.Module):
|
|
| 330 |
base=self.rope_theta,
|
| 331 |
)
|
| 332 |
else:
|
| 333 |
-
|
|
|
|
| 334 |
if scaling_type == "longrope":
|
| 335 |
self.rotary_emb = Phi3LongRoPEScaledRotaryEmbedding(self.head_dim, self.config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
else:
|
| 337 |
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
| 338 |
|
|
|
|
| 330 |
base=self.rope_theta,
|
| 331 |
)
|
| 332 |
else:
|
| 333 |
+
# "type" key was renamed to "rope_type" in transformers >=4.46; handle both
|
| 334 |
+
scaling_type = self.config.rope_scaling.get("type") or self.config.rope_scaling.get("rope_type", "")
|
| 335 |
if scaling_type == "longrope":
|
| 336 |
self.rotary_emb = Phi3LongRoPEScaledRotaryEmbedding(self.head_dim, self.config)
|
| 337 |
+
elif not scaling_type or scaling_type == "default":
|
| 338 |
+
# newer transformers injects {"rope_type": "default"} when rope_scaling is absent
|
| 339 |
+
self.rotary_emb = PhiMoERotaryEmbedding(
|
| 340 |
+
self.head_dim,
|
| 341 |
+
max_position_embeddings=self.max_position_embeddings,
|
| 342 |
+
base=self.rope_theta,
|
| 343 |
+
)
|
| 344 |
else:
|
| 345 |
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
| 346 |
|