mlx icon indicating copy to clipboard operation
mlx copied to clipboard

Symbol not found: _cblas_sgemm$NEWLAPACK while running mlx mistral example

Open dineshdharme opened this issue 2 years ago • 12 comments

System details :

Sonoma 14.2.1 xcode-select version 2405

I am trying to run the default example provided by mlx-examples directory.

python mistral.py --model_path Mistral-7B-Instruct-v0.2/ --prompt "My name is"

I am getting the following error :

ImportError: dlopen(/opt/homebrew/anaconda3/envs/language_models_env/lib/python3.10/site-packages/mlx/core.cpython-310-darwin.so, 0x0002): Symbol not found: _cblas_sgemm$NEWLAPACK
  Referenced from: <F6C66D71-1323-3E71-9C97-70DC2D75278D> /opt/homebrew/anaconda3/envs/language_models_env/lib/python3.10/site-packages/mlx/lib/libmlx.dylib
  Expected in:     <70C4EEC6-ACCF-3E75-804C-659DD8DA930F> /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate

It is looking for Accelerate library at a wrong location.

Output of the command :

ls -al /System/Library/Frameworks/Accelerate.framework/Versions/A/

is below

total 0
drwxr-xr-x  5 root  wheel  160 Dec 15 20:13 ./
drwxr-xr-x  4 root  wheel  128 Dec 15 20:13 ../
drwxr-xr-x  4 root  wheel  128 Dec 15 20:13 Frameworks/
drwxr-xr-x  7 root  wheel  224 Dec 15 20:13 Resources/
drwxr-xr-x  3 root  wheel   96 Dec 15 20:13 _CodeSignature/

While output of command :

ls -al /System/Library/Frameworks/Accelerate.framework/

is as below :

total 0
drwxr-xr-x    6 root  wheel   192 Dec 15 20:13 ./
drwxr-xr-x  255 root  wheel  8160 Dec 15 20:13 ../
lrwxr-xr-x    1 root  wheel    27 Dec 15 20:13 Accelerate@ -> Versions/Current/Accelerate
lrwxr-xr-x    1 root  wheel    27 Dec 15 20:13 Frameworks@ -> Versions/Current/Frameworks
lrwxr-xr-x    1 root  wheel    26 Dec 15 20:13 Resources@ -> Versions/Current/Resources
drwxr-xr-x    4 root  wheel   128 Dec 15 20:13 Versions/

I found something relevant :

https://stackoverflow.com/a/70550565/3238085

The reason is explained here: https://developer.apple.com/forums/thread/655588 Since Big Sur, it somehow all became virtual. I still don't understand how it works though, but it works...

That release note says: As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache

I don't care how Apple internally handles these things. But as it stands currently it is not working for me. Any debugging steps that will help resolve this for me are welcome.

dineshdharme avatar Dec 23 '23 10:12 dineshdharme

Did you install with pip?

awni avatar Dec 23 '23 15:12 awni

@awni : Yes with pip.

dineshdharme avatar Dec 23 '23 15:12 dineshdharme

I will try installing on 14.2.1 to see if I can reproduce this..

awni avatar Dec 23 '23 15:12 awni

I am on M3 Max if it is of any help. I submitted the same issue here. https://github.com/ggerganov/llama.cpp/issues/4440 I updated to 14.2.1 this morning hoping it would resolve the issue linked here.

dineshdharme avatar Dec 23 '23 16:12 dineshdharme

What's the output of:

xcrun -sdk macosx --show-sdk-version

awni avatar Dec 23 '23 16:12 awni

PS I'm looking at this issue which seems related: https://github.com/numpy/numpy/issues/25026

awni avatar Dec 23 '23 16:12 awni

command : xcrun -sdk macosx --show-sdk-version
output : 14.2

Edit : more info

command : sw_vers -productVersion output : 14.2.1

dineshdharme avatar Dec 23 '23 16:12 dineshdharme

A bit of a shot in the dark:

  1. Maybe try reinstalling mlx: pip install --U mlx
  2. Try this: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

If neither of those helps we'll need to investigate further...

awni avatar Dec 23 '23 19:12 awni

Tried both of these steps. Still getting the same error.

dineshdharme avatar Dec 24 '23 08:12 dineshdharme

I encountered a similar problem. My Apple system version is 13.3 and the chip is M1 max.

kkxwz avatar Jan 12 '24 03:01 kkxwz

@kkxwz try upgrading your OS (MLX support >=13.5 )

awni avatar Jan 12 '24 04:01 awni

I had a similar issue, after uninstalling mlx and updating to the latest version (0.3) it was fixed.

alew3 avatar Feb 22 '24 10:02 alew3