Instructions to use TheBloke/phi-2-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TheBloke/phi-2-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TheBloke/phi-2-GGUF")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("TheBloke/phi-2-GGUF", dtype="auto") - llama-cpp-python
How to use TheBloke/phi-2-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="TheBloke/phi-2-GGUF", filename="phi-2.Q2_K.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use TheBloke/phi-2-GGUF with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf TheBloke/phi-2-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf TheBloke/phi-2-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf TheBloke/phi-2-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf TheBloke/phi-2-GGUF:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf TheBloke/phi-2-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf TheBloke/phi-2-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf TheBloke/phi-2-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf TheBloke/phi-2-GGUF:Q4_K_M
Use Docker
docker model run hf.co/TheBloke/phi-2-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use TheBloke/phi-2-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TheBloke/phi-2-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TheBloke/phi-2-GGUF", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/TheBloke/phi-2-GGUF:Q4_K_M
- SGLang
How to use TheBloke/phi-2-GGUF 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 "TheBloke/phi-2-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TheBloke/phi-2-GGUF", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "TheBloke/phi-2-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TheBloke/phi-2-GGUF", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Ollama
How to use TheBloke/phi-2-GGUF with Ollama:
ollama run hf.co/TheBloke/phi-2-GGUF:Q4_K_M
- Unsloth Studio new
How to use TheBloke/phi-2-GGUF 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 TheBloke/phi-2-GGUF 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 TheBloke/phi-2-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for TheBloke/phi-2-GGUF to start chatting
- Docker Model Runner
How to use TheBloke/phi-2-GGUF with Docker Model Runner:
docker model run hf.co/TheBloke/phi-2-GGUF:Q4_K_M
- Lemonade
How to use TheBloke/phi-2-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull TheBloke/phi-2-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.phi-2-GGUF-Q4_K_M
List all available models
lemonade list
today's version of llama.cpp results in an error
error loading model: unknown model architecture: 'phi2'
llama_load_model_from_file: failed to load model
AVX = 1 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 |
2023-12-18 16:57:06 ERROR:Failed to load the model.
Traceback (most recent call last):
File "/data/text-generation-webui/modules/ui_model_menu.py", line 209, in load_model_wrapper
shared.model, shared.tokenizer = load_model(selected_model, loader)
File "/data/text-generation-webui/modules/models.py", line 89, in load_model
output = load_func_maploader
File "/data/text-generation-webui/modules/models.py", line 259, in llamacpp_loader
model, tokenizer = LlamaCppModel.from_pretrained(model_file)
File "/data/text-generation-webui/modules/llamacpp_model.py", line 91, in from_pretrained
result.model = Llama(**params)
File "/data/llama-cpp-python/llama_cpp/llama.py", line 963, in init
self._n_vocab = self.n_vocab()
File "/data/llama-cpp-python/llama_cpp/llama.py", line 2270, in n_vocab
return self._model.n_vocab()
File "/data/llama-cpp-python/llama_cpp/llama.py", line 252, in n_vocab
assert self.model is not None
AssertionError
I had the same issue using LM studio 0.29
{
"cause": {
"cause": "unknown model architecture: 'phi2'",
"title": "Failed to load model",
"errorData": {
"n_ctx": 2048,
"n_batch": 512,
"n_gpu_layers": 1
}
},
Downloaded and installed the Beta V8 version (https://lmstudio.ai/beta-releases.html) and the problem was solved.
I knew there would be a problem. Just had to :D Every time there is a good model it either doesnt work properly or just doesnt work. At least we got the quantized ver so in the future the llm model apps will fix it.
I think the newest version of llama-cpp works for phi-2 now. The community was hard at work with making adjustments for it's slight differences during the month. (https://github.com/ggerganov/llama.cpp/issues/4437) Just likely need to pip update or remake your build for the latest.
Can't speak for LM studio. I'm not a user of it. Sorry. Though it's good to see that something can load phi-2 gguf quants such as LM Studio.
Can confirm that it worked with upgrading on MAC: CMAKE_ARGS="-DLLAMA_METAL=on" pip install -U llama-cpp-python
@mox Same with my side. I've successfully used phi with the llama-cpp family shorty after my 1st reply 12 days ago. As well as several times since. Feels like a old hat now. Been pretty happy with it.
@LaferriereJC I've not checked, but has LM Studio got it working yet for phi? Likely has. It not, that's a bummer. And really sorry. The wait can be painful sometimes.
Has anyone made it work with CTransformers as i am getting a error for model_type = 'phi-msft'
@NikeshK ctransformers is pretty outdated now. Use something like llama cpp python which is maintained if you want to use llama cpp with python
Has anyone made it work with CTransformers as i am getting a error for model_type = 'phi-msft'
ollama is a good alternative as well. Especially if you wanted to keep api use simple like ctransformers was trying to do. ollama has llama.cpp as the core. And it works on all common consumer os's (linux, mac and windows). As well as common consumer computing acceleration hardware (nvidia, amd, apple MPS, ect.).
Here is the links:
