Environment
- OS: macOS 14.6 (Apple Silicon, M1 Max)
- Python: 3.11.9
- PyTorch: 2.13.0
- mps-bitsandbytes: 0.7.0 (PyPI; same setup.py as current master)
- Xcode Command Line Tools + Metal Toolchain installed
What happened
pip install mps-bitsandbytes fails to build the native extension, with two compile
errors in mps_bitsandbytes/csrc/mps_bitsandbytes.mm, both originating from
<torch/include/ATen/native/mps/OperationUtils.h>:
error: no template named 'type_identity' in namespace 'std'; did you mean '__type_identity'?
error: no member named 'contains' in 'std::unordered_map<...>'
Root cause
std::type_identity and std::unordered_map::contains() are both C++20 library
features. setup.py hardcodes:
extra_compile_args=["-std=c++17", "-O3", "-DNDEBUG"],
but PyTorch 2.13's MPS backend headers now require C++20. Locally bumping this to
-std=c++20 resolves both errors and lets the extension build successfully.
Also worth noting (smaller, separate issue)
pip install mps-bitsandbytes also fails first with ModuleNotFoundError: No module named 'torch' during the build step, since torch isn't declared as a build-time
requirement -- pip's isolated build env doesn't have it. --no-build-isolation works
around this; might be worth declaring torch under [build-system] requires in
pyproject.toml, or documenting the flag in the README.
Suggested fix
- extra_compile_args=["-std=c++17", "-O3", "-DNDEBUG"],
+ extra_compile_args=["-std=c++20", "-O3", "-DNDEBUG"],
Happy to open a PR with this change (plus the pyproject.toml build-dependency fix)
if useful.
Environment
What happened
pip install mps-bitsandbytesfails to build the native extension, with two compileerrors in
mps_bitsandbytes/csrc/mps_bitsandbytes.mm, both originating from<torch/include/ATen/native/mps/OperationUtils.h>:Root cause
std::type_identityandstd::unordered_map::contains()are both C++20 libraryfeatures.
setup.pyhardcodes:but PyTorch 2.13's MPS backend headers now require C++20. Locally bumping this to
-std=c++20resolves both errors and lets the extension build successfully.Also worth noting (smaller, separate issue)
pip install mps-bitsandbytesalso fails first withModuleNotFoundError: No module named 'torch'during the build step, sincetorchisn't declared as a build-timerequirement -- pip's isolated build env doesn't have it.
--no-build-isolationworksaround this; might be worth declaring
torchunder[build-system] requiresinpyproject.toml, or documenting the flag in the README.Suggested fix
Happy to open a PR with this change (plus the
pyproject.tomlbuild-dependency fix)if useful.