moshi: make bitsandbytes optional (fix #385)#415
Open
Kymi808 wants to merge 1 commit into
Open
Conversation
bitsandbytes is only used in moshi.utils.quantize.QLinear, which is constructed exclusively under explicit quantization paths (replace_linear_with_qlinear in lm.py and transformer.py, gated by a `quantize` flag). Upstream bitsandbytes ships only x86_64-linux and Windows wheels — no aarch64-linux wheels — so keeping it as a hard dependency broke `pip install moshi` on aarch64 platforms (e.g. DGX Spark) for users who weren't using quantization at all. The same issue blocked dockerized installs in kyutai-labs#357, where the maintainer's suggestion was to remove the dependency since "it's only used when fine-tuning a model." Changes ------- - pyproject.toml: move bitsandbytes from `dependencies` to a new `[project.optional-dependencies]` group `quant`. Users who need quantized linear layers can install via `pip install "moshi[quant]"`. - moshi/utils/quantize.py: wrap the lazy bitsandbytes imports in a small `_import_bitsandbytes` helper that surfaces a clear ImportError pointing at the new extras install command, so users who instantiate `QLinear` without the extra installed get an actionable message rather than a bare `ModuleNotFoundError`. Verified locally ---------------- - pyproject.toml parses as valid TOML; bitsandbytes no longer in main dependencies; new `quant` extra exposes the same constraint previously pinned in `dependencies`. - `import moshi.utils.quantize` succeeds with bitsandbytes unavailable. - Instantiating `QLinear(...)` without bitsandbytes installed raises ImportError with the documented install hint. - `flake8` clean on the changed file. (Pyright reports 2 pre-existing `reportPrivateImportUsage` warnings on the `torch.float` references that already existed in the file; not in this PR's scope.) I, Kymi808, confirm that I have read and understood the terms of the CLA of Kyutai-labs, as outlined in the repository's CONTRIBUTING.md, and I agree to be bound by these terms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #385.
Summary
bitsandbytesis only used inmoshi.utils.quantize.QLinear, which is constructed exclusively under explicit quantization paths (replace_linear_with_qlinearinlm.pyandtransformer.py, gated by aquantizeflag). Upstreambitsandbytesships only x86_64-Linux and Windows wheels — no aarch64-Linux wheels — so keeping it as a harddependenciesentry brokepip install moshion aarch64 platforms (e.g. NVIDIA DGX Spark, ARM cloud instances) for users who weren't using quantization at all.The same install problem surfaced in #357, where you wrote:
This PR follows that direction — moving
bitsandbytesto an opt-in extra.Changes
moshi/pyproject.toml— movebitsandbytesfrom maindependenciesto a new[project.optional-dependencies]group calledquant. Users who need quantized linear layers install viapip install "moshi[quant]". The version pin (>= 0.45, < 0.50.0; sys_platform == 'linux') is preserved unchanged.moshi/moshi/utils/quantize.py— wrap the lazybitsandbytesimports in a small_import_bitsandbytes()helper that surfaces a clearImportErrorpointing at the new extras install command, so users who instantiateQLinearwithout the extra get an actionable error rather than a bareModuleNotFoundError.Verified locally
pyproject.tomlparses as valid TOML;bitsandbytesno longer independencies; the newquantextra exposes the same constraint.import moshi.utils.quantizesucceeds withbitsandbytesunavailable.QLinear(...)withoutbitsandbytesinstalled raisesImportErrorwith the documented install hint:flake8is clean on the changed file. (Pyright reports 2 pre-existingreportPrivateImportUsagewarnings on the existingtorch.floatreferences — out of scope for this PR.)Diff is +26 / -3.
CLA
I, Kymi808, confirm that I have read and understood the terms of the CLA of Kyutai-labs, as outlined in the repository's CONTRIBUTING.md, and I agree to be bound by these terms.