bitsandbytes icon indicating copy to clipboard operation
bitsandbytes copied to clipboard

[Bug]Low GLIBC limits bitsandbytes to 0.42.0 (causing Triton issues), while source-compiled newer bitsandbytes lacks __version__ attribute

Open notlu opened this issue 1 year ago • 7 comments

System Info

Problem Description:

Due to an older GLIBC version on my system, the latest pre-built bitsandbytes wheel I can install via pip is 0.42.0. Newer pre-built wheels (e.g., those requiring manylinux_2_28 which implies GLIBC >= 2.28) are not supported on my platform.

When using bitsandbytes==0.42.0, I encounter issues with Triton. Specifically, when trying to use it with what I believe is Triton 3.2.0 (please clarify if this version refers to the triton PyPI package), I get the following error:

ModuleNotFoundError: No module named 'triton.ops' This suggests an incompatibility or an issue with the Triton installation/availability when using bitsandbytes==0.42.0.

And if I want to use 4bit model, I have to install bitsandbytes >= 0.43.2. ValueError: Calling to() is not supported for 4-bit quantized models with the installed version of bitsandbytes. The current device is cuda:0. If you intended to move the model, please install bitsandbytes >= 0.43.2.

To overcome the GLIBC limitation for pre-built wheels and potentially resolve the Triton compatibility issue, I attempted to compile a newer version of bitsandbytes (e.g., a dev version like 0.46.0.dev0) from source.

However, when using this source-compiled version of bitsandbytes, a consuming library (which performs a check like the one below, found in Unsloth) fails with an AttributeError:

HAS_CUDA_STREAM = Version(bnb.version) > Version("0.43.3") This results in the error:

AttributeError: module 'bitsandbytes' has no attribute 'version'

Even though pip show bitsandbytes correctly reports the version (e.g., 0.46.0.dev0) for the source-compiled, editable installation, the version attribute is not available directly on the imported bnb module.

Dilemma:

Using the older, GLIBC-compatible pre-built bitsandbytes==0.42.0 leads to issues with Triton (No module named 'triton.ops'). Using a newer, source-compiled bitsandbytes (which should numerically satisfy version checks like >0.43.3) fails because the version attribute is not exposed in a way that consuming libraries expect, leading to an AttributeError. Could you please provide guidance on how to navigate this situation?

Reproduction

https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Orpheus_(3B)-TTS.ipynb use this code in a linux environment

Expected behavior

run smoothly

notlu avatar May 11 '25 07:05 notlu

Hi, newer versions still have the __version__ attribute set in the __init__.py file, so your last issue seems quite strange. Are you sure you are importing the correct installed module? Running something like the following should first print out the file path to the __init__.py file in the directory you used to build and install from source in editable mode.

import bitsandbytes as bnb
print("loaded from:", bnb.__file__)
print("version:", bnb.__version__)

FrederickVu avatar May 11 '25 10:05 FrederickVu

Hi, newer versions still have the __version__ attribute set in the __init__.py file, so your last issue seems quite strange. Are you sure you are importing the correct installed module? Running something like the following should first print out the file path to the __init__.py file in the directory you used to build and install from source in editable mode.

import bitsandbytes as bnb print("loaded from:", bnb.file) print("version:", bnb.version)

yeah, I tested this: print("version:", bnb.version) ^^^^^^^^^^^^^^^ AttributeError: module 'bitsandbytes' has no attribute 'version'

pip show bitsandbytes Name: bitsandbytes Version: 0.45.2 Summary: k-bit optimizers and matrix multiplication routines. Home-page: https://github.com/bitsandbytes-foundation/bitsandbytes Author: Author-email: Tim Dettmers [email protected] License: MIT License

Copyright (c) Facebook, Inc. and its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Location: /miniconda3/envs/myunsloth/lib/python3.11/site-packages Editable project location: /bitsandbytes Requires: numpy, torch Required-by: unsloth

notlu avatar May 11 '25 15:05 notlu

Okay, I suspect the issue is due to module name shadowing. This can happen if the cloned repository directory /bitsandbytes is at the same level as your project’s scripts or notebooks.

What happens when running import bitsandbytes in your code is that the Python interpreter searches through paths in the list sys.path of paths for the first occurrence of a directory by the name of bitsandbytes. Typically, the script’s directory is searched before the site-packages of your environment (which happens when the empty path occurs before your site-packages’ path in sys.path), so if the repo root directory has the same name as the module you’re trying to import and it’s placed at the same level as your script, the import system won’t reach the __init__.py contained in the true package directory, which in this case is /bitsandbytes/bitsandbytes. In this case, if you were to run print(bnb.__file__), you would get None instead of the path to the __init__.py file.

If this describes your workflow, then one fix is to uninstall bitsandbytes, rename the repo root to something else, and then re-install in editable mode. You can also opt to clone the repo outside of your project directory. Alternatively, if you don't actually plan on editing the package's source code, you can build the wheel, install via the wheel, and delete the cloned repo (or just make sure it's not in your project directory).

PS, you can use backticks to format inline code properly: ` __version__ ` = __version__ while __version__ = version.

FrederickVu avatar May 11 '25 18:05 FrederickVu

I found that using version 0.45.1 leads to error message "Could not load bitsandbytes native library: /usr/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /path/to/conda_env/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda126.so)" (I have GLIBC version 2.31 on Ubuntu system).

On the other hand, using version 0.45.0 leads to the "No module named 'triton.ops'" issue.

bitEEdh avatar May 21 '25 14:05 bitEEdh

Hi @bitEEdh Please see here for your issue with glibc compatibility: https://github.com/bitsandbytes-foundation/bitsandbytes/issues/1610#issuecomment-2836806763

This will be fixed in our next release. Until then, a workaround of using BNB_CUDA_VERSION=125 or less should work for your platform. Alternatively you could downgrade PyTorch to 2.4-2.7 and use a CUDA 12.4 build.

matthewdouglas avatar May 21 '25 15:05 matthewdouglas

The same issue, I am unable to use the unsloth library due to this error. Have you resolved it?

vllbc avatar May 28 '25 12:05 vllbc

Please try the new 0.46.0 release to resolve the issue with glibc compatibility. It is compatible with glibc >= 2.24. For older distributions like CentOS 7 (e.g. glibc 2.17) we cannot provide further support.

If there's a separate issue, please open a new issue.

matthewdouglas avatar May 28 '25 14:05 matthewdouglas