Text Generation
Transformers
PyTorch
multilingual
phi3
torchao
phi
phi4
nlp
code
math
chat
conversational
custom_code
text-generation-inference
Instructions to use pytorch/Phi-4-mini-instruct-INT4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pytorch/Phi-4-mini-instruct-INT4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pytorch/Phi-4-mini-instruct-INT4", 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("pytorch/Phi-4-mini-instruct-INT4", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("pytorch/Phi-4-mini-instruct-INT4", 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 pytorch/Phi-4-mini-instruct-INT4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pytorch/Phi-4-mini-instruct-INT4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pytorch/Phi-4-mini-instruct-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/pytorch/Phi-4-mini-instruct-INT4
- SGLang
How to use pytorch/Phi-4-mini-instruct-INT4 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 "pytorch/Phi-4-mini-instruct-INT4" \ --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": "pytorch/Phi-4-mini-instruct-INT4", "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 "pytorch/Phi-4-mini-instruct-INT4" \ --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": "pytorch/Phi-4-mini-instruct-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use pytorch/Phi-4-mini-instruct-INT4 with Docker Model Runner:
docker model run hf.co/pytorch/Phi-4-mini-instruct-INT4
Commit History
-
Update README.md
Verified signaturecbee0d7 -
Update README.md
Verified signatureea29a3b -
Update README.md
Verified signaturee3d011c -
Update README.md
Verified signature1170503 -
Update README.md
Verified signaturea6100fd -
Update README.md
Verified signaturefe70e1e -
Update README.md
Verified signature7ecf1b2 -
Update README.md
Verified signature070762d -
Update README.md
Verified signature04e792e
-
Update README.md
Verified signature9579235 -
Update README.md
Verified signature169e4da -
Update README.md
Verified signature059d669 -
Update README.md
Verified signature2ab02aa -
Update README.md
Verified signature9af0683 -
Update README.md
Verified signatured1aeb1f -
Update README.md
Verified signaturead9e8b6 -
Update README.md
Verified signature3bce6ad -
Update README.md
Verified signature8531f23 -
Update README.md
Verified signature2ecb413 -
Update README.md
Verified signature4e1c7a0 -
Update README.md
Verified signaturea9f7231
-
Update README.md
Verified signature31f1a7e
-
Update README.md
Verified signaturef6dfa8c -
Update README.md
Verified signature2570290
-
Update README.md
Verified signaturee014bbb
-
Update README.md
Verified signature99442e3 -
Update README.md
Verified signatureb9c2cf5
-
Update README.md
Verified signature9e5aae3
-
Update README.md
Verified signature6655f7f -
Update README.md
Verified signature90e6cd4 -
Update README.md
Verified signature3737ba9 -
Update README.md
Verified signature0e7b2e9 -
Update README.md
Verified signature52e01da
-
Update README.md
Verified signature8ecebaf -
Update LICENSE
Verified signature049a24c -
Create LICENSE
Verified signature34e5a12 -
Update README.md
Verified signature0882b28 -
Update README.md
Verified signature4989b4d -
Update README.md
Verified signaturee38437b -
Update README.md
Verified signature8d76f91
-
Upload tokenizer
Verified signature365d46d -
Upload Phi3ForCausalLM
Verified signature19c2556 -
initial commit
Verified signature635c3ac