Instructions to use mlx-community/phi-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/phi-2 with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("mlx-community/phi-2") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use mlx-community/phi-2 with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "mlx-community/phi-2" --prompt "Once upon a time"
Assistance to run phi-2
Hello, I am getting this error when I am trying to run phi-2. Can you help?
Users/thisdev/.env/lib/python3.9/site-packages/urllib3/init.py:34: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
warnings.warn(
Traceback (most recent call last):
File "/Users/thisdev/mlx-examples/llms/phi2/phi2.py", line 198, in
model, tokenizer = load_model(args.model_path)
File "/Users/thisdev/mlx-examples/llms/phi2/phi2.py", line 161, in load_model
weights = mx.load(str(model_path / "weights.npz"))
RuntimeError: [load] Failed to open file weights.npz
Are you sure you downloaded the weights file?
Yes. I can see the 5.56Gb file in the phi2 folder
hi @sasidhar92 ,
can you please make sure you running the command python llms/phi2/phi2.py --prompt "My name is" from /mlx-examples
and your model is located /mlx-examples/phi2 , or you have the option to pass the model path python llms/phi2/phi2.py --prompt "My name is" --model-pat ./mlx-examples/phi2 whenever it is located
Hello! this helped. Than you