Instructions to use mlx-community/Phi-4-mini-instruct-8bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mlx-community/Phi-4-mini-instruct-8bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mlx-community/Phi-4-mini-instruct-8bit", 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("mlx-community/Phi-4-mini-instruct-8bit", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("mlx-community/Phi-4-mini-instruct-8bit", 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]:])) - MLX
How to use mlx-community/Phi-4-mini-instruct-8bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("mlx-community/Phi-4-mini-instruct-8bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
- vLLM
How to use mlx-community/Phi-4-mini-instruct-8bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mlx-community/Phi-4-mini-instruct-8bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/Phi-4-mini-instruct-8bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mlx-community/Phi-4-mini-instruct-8bit
- SGLang
How to use mlx-community/Phi-4-mini-instruct-8bit 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 "mlx-community/Phi-4-mini-instruct-8bit" \ --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": "mlx-community/Phi-4-mini-instruct-8bit", "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 "mlx-community/Phi-4-mini-instruct-8bit" \ --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": "mlx-community/Phi-4-mini-instruct-8bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Pi new
How to use mlx-community/Phi-4-mini-instruct-8bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/Phi-4-mini-instruct-8bit"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mlx-community/Phi-4-mini-instruct-8bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use mlx-community/Phi-4-mini-instruct-8bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/Phi-4-mini-instruct-8bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default mlx-community/Phi-4-mini-instruct-8bit
Run Hermes
hermes
- MLX LM
How to use mlx-community/Phi-4-mini-instruct-8bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "mlx-community/Phi-4-mini-instruct-8bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "mlx-community/Phi-4-mini-instruct-8bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/Phi-4-mini-instruct-8bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Docker Model Runner
How to use mlx-community/Phi-4-mini-instruct-8bit with Docker Model Runner:
docker model run hf.co/mlx-community/Phi-4-mini-instruct-8bit
Unexpected and Incoherent Responses from mlx-community/Phi-4-mini-instruct-8bit
Description:
When using the mlx-community/Phi-4-mini-instruct-8bit model, I encountered issues where it generates unexpected or incoherent responses. The output does not align with the provided prompt, and the model behavior appears inconsistent. Additionally, I observed a possible degradation in generation quality, with unusually low coherence and relevancy.
Steps to reproduce:
- Run the following command:
mlx_lm.generate --model mlx-community/Phi-4-mini-instruct-8bit --prompt "What is your name?" - Observe the generated output.
mlx_lm.generate --model mlx-community/Phi-4-mini-instruct-8bit --prompt "What is your name?"
config.json: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 3.30k/3.30k [00:00<00:00, 26.2MB/s]
sample_finetune.py: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 6.17k/6.17k [00:00<00:00, 17.8MB/s]
model.safetensors.index.json: 100%|βββββββββββββββββββββββββββββββββββββββββββββββ| 32.6k/32.6k [00:00<00:00, 22.1MB/s]
modeling_phi3.py: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 54.3k/54.3k [00:00<00:00, 3.84MB/s]
configuration_phi3.py: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 10.9k/10.9k [00:00<00:00, 8.84MB/s]
added_tokens.json: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 249/249 [00:00<00:00, 450kB/s]
special_tokens_map.json: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 587/587 [00:00<00:00, 1.52MB/s]
tokenizer_config.json: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 2.96k/2.96k [00:00<00:00, 6.78MB/s]
merges.txt: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 2.42M/2.42M [00:00<00:00, 2.48MB/s]
tokenizer.json: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 15.5M/15.5M [00:01<00:00, 12.6MB/s]
vocab.json: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 3.91M/3.91M [00:01<00:00, 2.84MB/s]
model.safetensors: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 4.08G/4.08G [02:35<00:00, 26.1MB/s]
Fetching 12 files: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 12/12 [02:36<00:00, 13.05s/it]
==========tensors: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 4.08G/4.08G [02:35<00:00, 26.3MB/s]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!01<00:00, 2.85MB/s]
==========
Prompt: 8 tokens, 15.097 tokens-per-sec
Generation: 100 tokens, 11.463 tokens-per-sec
Peak memory: 4.116 GB