Text Generation
Transformers
Safetensors
multilingual
phi3
phi
phi4
unsloth
nlp
code
microsoft
math
chat
conversational
custom_code
text-generation-inference
Instructions to use unsloth/Phi-4-mini-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/Phi-4-mini-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/Phi-4-mini-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("unsloth/Phi-4-mini-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("unsloth/Phi-4-mini-instruct", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/Phi-4-mini-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/Phi-4-mini-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": "unsloth/Phi-4-mini-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/Phi-4-mini-instruct
- SGLang
How to use unsloth/Phi-4-mini-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 "unsloth/Phi-4-mini-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": "unsloth/Phi-4-mini-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 "unsloth/Phi-4-mini-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": "unsloth/Phi-4-mini-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use unsloth/Phi-4-mini-instruct with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Phi-4-mini-instruct to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Phi-4-mini-instruct to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/Phi-4-mini-instruct to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/Phi-4-mini-instruct", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/Phi-4-mini-instruct with Docker Model Runner:
docker model run hf.co/unsloth/Phi-4-mini-instruct
Add files using upload-large-folder tool
Browse files- config.json +1 -1
- generation_config.json +1 -4
- special_tokens_map.json +1 -7
- tokenizer_config.json +1 -1
config.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
| 12 |
},
|
| 13 |
"bos_token_id": 199999,
|
| 14 |
"embd_pdrop": 0.0,
|
| 15 |
-
"eos_token_id":
|
| 16 |
"full_attn_mod": 1,
|
| 17 |
"hidden_act": "silu",
|
| 18 |
"hidden_size": 3072,
|
|
|
|
| 12 |
},
|
| 13 |
"bos_token_id": 199999,
|
| 14 |
"embd_pdrop": 0.0,
|
| 15 |
+
"eos_token_id": 200020,
|
| 16 |
"full_attn_mod": 1,
|
| 17 |
"hidden_act": "silu",
|
| 18 |
"hidden_size": 3072,
|
generation_config.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"_from_model_config": true,
|
| 3 |
"bos_token_id": 199999,
|
| 4 |
-
"eos_token_id":
|
| 5 |
-
200020,
|
| 6 |
-
199999
|
| 7 |
-
],
|
| 8 |
"max_length": 131072,
|
| 9 |
"pad_token_id": 200029,
|
| 10 |
"transformers_version": "4.49.0"
|
|
|
|
| 1 |
{
|
| 2 |
"_from_model_config": true,
|
| 3 |
"bos_token_id": 199999,
|
| 4 |
+
"eos_token_id": 200020,
|
|
|
|
|
|
|
|
|
|
| 5 |
"max_length": 131072,
|
| 6 |
"pad_token_id": 200029,
|
| 7 |
"transformers_version": "4.49.0"
|
special_tokens_map.json
CHANGED
|
@@ -6,13 +6,7 @@
|
|
| 6 |
"rstrip": false,
|
| 7 |
"single_word": false
|
| 8 |
},
|
| 9 |
-
"eos_token":
|
| 10 |
-
"content": "<|endoftext|>",
|
| 11 |
-
"lstrip": false,
|
| 12 |
-
"normalized": false,
|
| 13 |
-
"rstrip": false,
|
| 14 |
-
"single_word": false
|
| 15 |
-
},
|
| 16 |
"pad_token": "<|PAD▁TOKEN|>",
|
| 17 |
"unk_token": "�"
|
| 18 |
}
|
|
|
|
| 6 |
"rstrip": false,
|
| 7 |
"single_word": false
|
| 8 |
},
|
| 9 |
+
"eos_token": "<|end|>",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"pad_token": "<|PAD▁TOKEN|>",
|
| 11 |
"unk_token": "�"
|
| 12 |
}
|
tokenizer_config.json
CHANGED
|
@@ -119,7 +119,7 @@
|
|
| 119 |
"bos_token": "<|endoftext|>",
|
| 120 |
"chat_template": "{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% endif %}",
|
| 121 |
"clean_up_tokenization_spaces": false,
|
| 122 |
-
"eos_token": "<|
|
| 123 |
"extra_special_tokens": {},
|
| 124 |
"model_max_length": 131072,
|
| 125 |
"pad_token": "<|PAD▁TOKEN|>",
|
|
|
|
| 119 |
"bos_token": "<|endoftext|>",
|
| 120 |
"chat_template": "{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% endif %}",
|
| 121 |
"clean_up_tokenization_spaces": false,
|
| 122 |
+
"eos_token": "<|end|>",
|
| 123 |
"extra_special_tokens": {},
|
| 124 |
"model_max_length": 131072,
|
| 125 |
"pad_token": "<|PAD▁TOKEN|>",
|