dleemiller / WordLlama

Things you can do with the token embeddings of an LLM
MIT License
1.31k stars 42 forks source link

Fedora Linux: Illegal instruction (core dumped) #10

Closed russellballestrini closed 1 week ago

russellballestrini commented 1 month ago

word.py

from wordllama import WordLlama

# Load pre-trained embeddings
# truncate dimension to 64
wl = WordLlama.load(trunc_dim=64)

# Embed text
embeddings = wl.embed(["the quick brown fox jumps over the lazy dog", "and all that jazz"])
print(embeddings.shape)  # (2, 64)
python word.py 
Illegal instruction (core dumped)

I'm not sure if this will automatically fetch the model or if I'm doing something wrong but I don't get any errors besides the core dump.

(env) (base) [fox@blanka battleship-solvers]$ cat dump.log 
           PID: 338903 (python)
           UID: 1000 (fox)
           GID: 1000 (fox)
        Signal: 4 (ILL)
     Timestamp: Sun 2024-09-15 10:32:44 EDT (49s ago)
  Command Line: python word.py
    Executable: /usr/bin/python3.11
 Control Group: /user.slice/user-1000.slice/user@1000.service/app.slice/app-org.gnome.Terminal.slice/vte-spawn-1a8d40ce-bf1d-4df3-897e-479c1e3fb9d6.scope
          Unit: user@1000.service
     User Unit: vte-spawn-1a8d40ce-bf1d-4df3-897e-479c1e3fb9d6.scope
         Slice: user-1000.slice
     Owner UID: 1000 (fox)
       Boot ID: 044f88c6180945228cfc40b041aa72aa
    Machine ID: b0fc5b93e5f141e6960c05cedd8d0958
      Hostname: blanka.foxhop.net
       Storage: /var/lib/systemd/coredump/core.python.1000.044f88c6180945228cfc40b041aa72aa.338903.1726410764000000.zst (present)
  Size on Disk: 5.2M
       Package: python3.11/3.11.9-2.fc38
      build-id: 133ef71ede9cfc667089e58eec6086f88cb01dbc
       Message: Process 338903 (python) of user 1000 dumped core.

                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy.libs/libquadmath-96973f99-934c22de.so.0.0.0 without build-id.
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy.libs/libquadmath-96973f99-934c22de.so.0.0.0
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy.libs/libgfortran-040039e1-0352e75f.so.5.0.0 without build-id.
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy.libs/libgfortran-040039e1-0352e75f.so.5.0.0
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-ff651d7f.so without build-id.
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-ff651d7f.so
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so without build-id.
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy/linalg/_umath_linalg.cpython-311-x86_64-linux-gnu.so without build-id.
                Module /home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/numpy/linalg/_umath_linalg.cpython-311-x86_64-linux-gnu.so
                Module libffi.so.8 from rpm libffi-3.4.4-2.fc38.x86_64
                Module _ctypes.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _pickle.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _contextvars.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _opcode.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _multibytecodec.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module unicodedata.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module liblzma.so.5 from rpm xz-5.4.1-1.fc38.x86_64
                Module _lzma.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module libbz2.so.1 from rpm bzip2-1.0.8-13.fc38.x86_64
                Module _bz2.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _csv.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module zlib.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _json.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _queue.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _heapq.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module libb2.so.1 from rpm libb2-0.98.1-8.fc38.x86_64
                Module _blake2.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _hashlib.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module libcrypto.so.3 from rpm openssl-3.0.9-2.fc38.x86_64
                Module libssl.so.3 from rpm openssl-3.0.9-2.fc38.x86_64
                Module _ssl.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _sha512.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _random.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _bisect.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _struct.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module libz.so.1 from rpm zlib-1.2.13-3.fc38.x86_64
                Module binascii.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module array.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module select.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _socket.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _typing.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module libmpdec.so.3 from rpm mpdecimal-2.5.1-6.fc38.x86_64
                Module _decimal.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module _datetime.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module math.cpython-311-x86_64-linux-gnu.so from rpm python3.11-3.11.9-2.fc38.x86_64
                Module libpython3.11.so.1.0 from rpm python3.11-3.11.9-2.fc38.x86_64
                Module python3.11 from rpm python3.11-3.11.9-2.fc38.x86_64
                Stack trace of thread 338903:
                #0  0x00007fee030d2b85 n/a (/home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/env/lib/python3.11/site-packages/wordllama/algorithms/kmeans_helpers.cpython-311-x86_64-linux-gnu.so + 0x9b85)
                #1  0x00007fee12642093 PyModule_ExecDef (libpython3.11.so.1.0 + 0x242093)
                #2  0x00007fee120ce890 n/a (n/a + 0x0)
                ELF object binary architecture: AMD x86-64

When I compile myself instead of using pypi it works.

(base) [fox@blanka battleship-solvers]$ python3 -m venv env
(base) [fox@blanka battleship-solvers]$ . env/bin/activate
(env) (base) [fox@blanka battleship-solvers]$ cd WordLlama/
(env) (base) [fox@blanka WordLlama]$ pip install .
(env) (base) [fox@blanka battleship-solvers]$ cd ..
(env) (base) [fox@blanka battleship-solvers]$ python word.py 
(2, 64)
dleemiller commented 1 month ago

Thanks for testing local compilation. My first instinct is that this has to do with numpy version compatibility. Can you let me know what library version you're using and I'll see if I can reproduce it?

If the issue is only occurring when you truncate the dimension, (for now) you can also download the native 64-dim model like this:

wl = WordLlama.load(dim=64)

I'd still like to get to the bottom of the issue though.

chapmanjacobd commented 1 month ago

@russellballestrini try the latest release!

I'm on Fedora 40 with python3.12 and wordllama-0.2.6.post2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl with numpy 2.1.1 works fine for me. Fedora 38 is a tiny bit older but I would be surprised if it didn't work for you as well

russellballestrini commented 1 month ago
(env) (base) [fox@blanka battleship-solvers]$ python3 -m venv env2

(env) (base) [fox@blanka battleship-solvers]$ . env2/bin/activate

(env2) (base) [fox@blanka battleship-solvers]$ python word.py 

Traceback (most recent call last):
  File "/home/fox/git/russell.ballestrini.net/content/uploads/2024/battleship-solvers/word.py", line 1, in <module>
    from wordllama import WordLlama
ModuleNotFoundError: No module named 'wordllama'

(env2) (base) [fox@blanka battleship-solvers]$ pip install wordllama
Collecting wordllama
  Downloading wordllama-0.2.6.post2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.7/17.7 MB 21.5 MB/s eta 0:00:00
Collecting numpy
  Using cached numpy-2.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.3 MB)
Collecting safetensors
  Using cached safetensors-0.4.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (435 kB)
Collecting tokenizers
  Using cached tokenizers-0.20.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB)
Collecting toml
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting pydantic>=2
  Using cached pydantic-2.9.1-py3-none-any.whl (434 kB)
Collecting requests
  Using cached requests-2.32.3-py3-none-any.whl (64 kB)
Collecting annotated-types>=0.6.0
  Using cached annotated_types-0.7.0-py3-none-any.whl (13 kB)
Collecting pydantic-core==2.23.3
  Using cached pydantic_core-2.23.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
Collecting typing-extensions>=4.6.1
  Using cached typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140 kB)
Collecting idna<4,>=2.5
  Downloading idna-3.10-py3-none-any.whl (70 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 70.4/70.4 kB 9.0 MB/s eta 0:00:00
Collecting urllib3<3,>=1.21.1
  Using cached urllib3-2.2.3-py3-none-any.whl (126 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2024.8.30-py3-none-any.whl (167 kB)
Collecting huggingface-hub<1.0,>=0.16.4
  Using cached huggingface_hub-0.24.7-py3-none-any.whl (417 kB)
Collecting filelock
  Using cached filelock-3.16.0-py3-none-any.whl (16 kB)
Collecting fsspec>=2023.5.0
  Using cached fsspec-2024.9.0-py3-none-any.whl (179 kB)
Collecting packaging>=20.9
  Using cached packaging-24.1-py3-none-any.whl (53 kB)
Collecting pyyaml>=5.1
  Using cached PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (762 kB)
Collecting tqdm>=4.42.1
  Using cached tqdm-4.66.5-py3-none-any.whl (78 kB)
Installing collected packages: urllib3, typing-extensions, tqdm, toml, safetensors, pyyaml, packaging, numpy, idna, fsspec, filelock, charset-normalizer, certifi, annotated-types, requests, pydantic-core, pydantic, huggingface-hub, tokenizers, wordllama
Successfully installed annotated-types-0.7.0 certifi-2024.8.30 charset-normalizer-3.3.2 filelock-3.16.0 fsspec-2024.9.0 huggingface-hub-0.24.7 idna-3.10 numpy-2.1.1 packaging-24.1 pydantic-2.9.1 pydantic-core-2.23.3 pyyaml-6.0.2 requests-2.32.3 safetensors-0.4.5 tokenizers-0.20.0 toml-0.10.2 tqdm-4.66.5 typing-extensions-4.12.2 urllib3-2.2.3 wordllama-0.2.6.post2

[notice] A new release of pip available: 22.3.1 -> 24.2
[notice] To update, run: pip install --upgrade pip

(env2) (base) [fox@blanka battleship-solvers]$ python word.py 
Illegal instruction (core dumped)
dleemiller commented 1 month ago

If I have time, I'll setup an environment and try to reproduce it tonight.

Looks like there are some similar issues previously reported for numpy: https://github.com/numpy/numpy/issues/18131 https://github.com/numpy/numpy/issues/24028

Are you using ARM platform by chance?

russellballestrini commented 1 month ago

Thinkpad T430s (intel i5 dual core, 4 hyperthreads)

dleemiller commented 1 week ago

I think I've got this sorted out in the newest version.

I added a numpy>=2 requirement so that I could change the backend for hamming distance to use this newer bitwise operation in numpy: https://numpy.org/devdocs/reference/generated/numpy.bitwise_count.html

It seems there are some CPUs that don't support popcount instructions. It is simpler to determine at compile time if the hardware is supporting it, that's why it worked when you built it locally. But since we're already using numpy, it makes the most sense to leverage their implementation which is fast and handles all of that complexity already.

Let me know if it doesn't work and I'll think about it some more. I don't think I have anything to test it on, but I'm reasonably certain this is the issue.

russellballestrini commented 1 week ago

@dleemiller thank man for following up. I actually upgraded to fedora 40 from 38 -> 39. I bet the numpy implementation is solid and I will test again when I grok cool ways to implement WordLlama, thanks again for the work.