tairov / llama2.mojo

Inference Llama 2 in one file of pure 🔥
https://www.modular.com/blog/community-spotlight-how-i-built-llama2-by-aydyn-tairov
MIT License
2.09k stars 139 forks source link

Segmentation fault on M1 Max 32GB #53

Closed shroominic closed 10 months ago

shroominic commented 10 months ago
> MOJO_PYTHON_LIBRARY="/Users/shroominic/dev/miniforge3/lib" mojo llama2.mojo stories110M.bin -i "hello"
num parallel workers: 10  SIMD width: 8

Stack dump:
0.      Program arguments: mojo llama2.mojo stories110M.bin -i hello
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  mojo                     0x0000000100f79990 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  mojo                     0x0000000100f77af0 llvm::sys::RunSignalHandlers() + 112
2  mojo                     0x0000000100f7a02c SignalHandler(int) + 344
3  libsystem_platform.dylib 0x000000018dd06a24 _sigtramp + 56
4  libsystem_platform.dylib 0x0000000280058ac8 _sigtramp + 4063568092
5  libsystem_platform.dylib 0x000000028005807c _sigtramp + 4063565456
6  mojo                     0x00000001012ca24c M::KGEN::ExecutionEngine::runProgram(llvm::StringRef, llvm::StringRef, llvm::function_ref<M::ErrorOrSuccess (void*)>) + 1156
7  mojo                     0x0000000100ed3c64 run(M::State const&) + 3980
8  mojo                     0x0000000100ebcb2c main + 1672
9  dyld                     0x000000018d97ff28 start + 2236
[79626:9834787:20231019,201441.806415:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)

[1]    79624 segmentation fault  MOJO_PYTHON_LIBRARY="/Users/shroominic/dev/miniforge3/lib" mojo llama2.mojo  -i

Not sure what this all means but I am just trying to run this on my MacBook Pro based on the README.md ... I installed mojo and I am able to run basic hello world scripts and I've put the path of my conda base env.

Here another try with LLVM Symbolizer and the smaller model:

Stack dump:
0.      Program arguments: mojo llama2.mojo stories15M.bin -s 42 -m 256 -t 0.5 -i hello -z tokenizer.bin
 #0 0x0000000100729990 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/shroominic/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x1000c5990)
 #1 0x0000000100727af0 llvm::sys::RunSignalHandlers() (/Users/shroominic/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x1000c3af0)
 #2 0x000000010072a02c SignalHandler(int) (/Users/shroominic/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x1000c602c)
 #3 0x000000018dd06a24 (/usr/lib/system/libsystem_platform.dylib+0x18042ea24)
 #4 0x0000000280052c7c 
 #5 0x0000000280051fc4 
 #6 0x0000000100a7a24c M::KGEN::ExecutionEngine::runProgram(llvm::StringRef, llvm::StringRef, llvm::function_ref<M::ErrorOrSuccess (void*)>) (/Users/shroominic/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x10041624c)
 #7 0x0000000100683c64 run(M::State const&) (/Users/shroominic/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x10001fc64)
 #8 0x000000010066cb2c main (/Users/shroominic/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x100008b2c)
 #9 0x000000018d97ff28 
[35841:10187750:20231020,185712.713361:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
[1]    35839 segmentation fault  MOJO_PYTHON_LIBRARY= LLVM_SYMBOLIZER_PATH= mojo llama2.mojo stories15M.bin -s
Joywalker commented 10 months ago

I too have the same system as you and I've managed to run.

Screenshot 2023-10-20 at 20 36 18

Can you check if you have the same versions here:

Screenshot 2023-10-20 at 20 26 41

Here's the llama2.mojo run:

Screenshot 2023-10-20 at 20 26 11

Check if you have added the mojo executable:

 echo 'export MODULAR_HOME="/Users/<your_uname>/.modular"' >> ~/.zshrc\n
 echo 'export PATH="/Users/<your_uname>/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.zshrc\nsource ~/.zshrc\n

In my case I'm using zshrc, if you're using bash just change .zshrc with .bashrc.

And then when you run, simply call mojo llama2.mojo stories15M.bin -s 100 -n 256 -t 0.5 -i "hello" from the root of llama2.mojo repo.

@shroominic Here's the run with compiled version also:

Screenshot 2023-10-20 at 20 48 53
tairov commented 10 months ago

Hi @shroominic , Try to set full path to library file (not to the directory):

On my environment it looks like this :

export MOJO_PYTHON_LIBRARY="/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/Python"

Python is a lib file:

file /opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/Python
/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/Python: Mach-O 64-bit dynamically linked shared library arm64
shroominic commented 10 months ago

Niiiice thanks it works now 🚀