Remove legacy sparse functionality#1881
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
matthewdouglas
left a comment
There was a problem hiding this comment.
PR Review: #1881 — Remove legacy sparse functionality
Removes spmm_coo, spmm_coo_very_sparse, all COO/CSR/CSC sparse tensor types, Cusparse_Context, and the cusparse/hipsparse library dependencies. The PR description's claim that no downstream library uses these functions is verified — grep across Transformers, PEFT, Accelerate, TGI, and vLLM integration points in agents/downstream_integrations.md shows zero references.
No blocking issues.
What was checked:
-
Python caller verification:
grepacross the entire Python tree confirms zero remaining references to all removed symbols (spmm_coo,COOSparseTensor,CSRSparseTensor,CSCSparseTensor,Cusparse_Context,coo_zeros,coo2csr,coo2csc). ✓ -
C/CUDA/HIP sweep:
grepacrosscsrc/andCMakeLists.txtconfirms zero remaining references tocusparse,hipsparse,ContextCusparse,ContextHipsparse,get_cusparse, orcspmm*. ✓ -
CUDA/HIP symmetry: Both backends receive identical removals (kernel, launcher, header, Python interface). ✓
-
Build system:
CUDA::cusparseremoved fromtarget_link_librariesin CUDA path;find_package_and_print_version(hipsparse REQUIRED)androc::hipsparseremoved from HIP path. CMake change is correct and minimal. ✓ -
CI workflow:
cusparseandcusparse_devremoved fromsub-packagesin bothpython-package.ymlandtest-runner.yml. Correct. ✓ -
Test import cleanup: The removed sparse test classes were the only users of
HIP_ENVIRONMENTintest_functional.py. The import was correctly narrowed toROCM_WARP_SIZE_64only. ✓ -
Comment fix in
cuda/ops.py: The stale "COO tensor" comment at bitsandbytes/backends/cuda/ops.py:174 is updated to accurately describe what the function does. Minor but correct. -
Agent docs:
api_surface.md(section 4.9 removed + 4.10–4.13 renumbered,Cusparse_Contextsingleton removed, Tier 4 list updated),architecture_guide.md(dependency table),code_standards.md(singleton list + error-checking macro example), andissue_patterns.md(libcusparse error pattern generalized) are all consistently updated. ✓ -
Downstream impact: The sparse API was not used by any downstream integration (Transformers, PEFT, Accelerate, TGI, vLLM). ✓
-
Security: Clear (internal author, removes a dependency — reduces attack surface)
-
Downstream impact: None (no downstream consumers of sparse API)
-
Tests: Adequate (sparse test classes removed with the code; remaining suite passes)
-
CI: All pass (CUDA, ROCm, CPU, XPU, Windows)
-
Serialization: Not affected
-
torch.compile: Not affected
Summary
Removes the sparse matrix multiplication (
spmm_coo,spmm_coo_very_sparse) feature and all supporting infrastructure. No downstream library (Transformers, PEFT, Accelerate, TGI, vLLM) uses these functions, and GitHub code search finds zero independent callers outside of forks of this repo.Removes the
cusparse(CUDA) andhipsparse(ROCm) library dependencies entirely.What was removed
CUDA/HIP kernels (
csrc/kernels.cu,csrc/kernels.hip):kspmm_coo_very_sparse_naive<T, SPMM_ITEMS, BITS>kernel + 6 explicit template instantiationsDENORM,MAX_SPARSE_COUNT,SMEM_SIZEmacrosKernel headers (
csrc/kernels.cuh,csrc/kernels_hip.cuh):kspmm_coo_very_sparse_naivedeclarationOps-level launchers (
csrc/ops.cu,csrc/ops.hip):spmm_coo()(cusparse/hipsparse SpMM wrapper)spmm_coo_very_sparse_naive<T, BITS>()+ template instantiationsOp headers (
csrc/ops.cuh,csrc/ops_hip.cuh):#include <cusparse.h>/#include <hipsparse/hipsparse.h>CHECK_CUSPARSE/CHECK_HIPSPARSEerror-checking macrosContextCusparse/ContextHipsparsehandle wrapper classesspmm_cooandspmm_coo_very_sparse_naivedeclarationsPython interface (
csrc/pythonInterface.cpp):get_cusparse()factory functioncspmm_coo()cspmm_coo_very_sparse_naive_fp16()/_int8()#defines forContextCusparseandcusparseHandle_tPython API (
bitsandbytes/functional.py):COOSparseTensor,CSRSparseTensor,CSCSparseTensorcoo_zeros(),coo2csr(),coo2csc()spmm_coo(),spmm_coo_very_sparse()Cusparse_ContextsingletonLibrary loader (
bitsandbytes/cextension.py):lib.get_cusparse.restyperegistrationBuild system (
CMakeLists.txt):CUDA::cusparselink targetfind_package(hipsparse REQUIRED)+roc::hipsparselink targetTests (
tests/test_functional.py):TestSpMMFunctionalclass (test_spmm_coo,test_spmm_bench,test_spmm_coo_very_sparse,test_spmm_coo_dequant)TestSparseTensorFunctionalclass (test_coo2csr,test_coo2csc)CI (
.github/workflows/):cusparseandcusparse_devfrom CUDA sub-packages in bothtest-runner.ymlandpython-package.ymlAgent guide updates
agents/api_surface.md: removed section 4.9 (Sparse Operations),Cusparse_Contextsingleton entry, and Tier 4 list entries; renumbered subsequent sectionsagents/architecture_guide.md: removedcusparse/hipsparsefrom build dependency tableagents/code_standards.md: removedCHECK_CUSPARSEfrom error-checking examples andCusparse_Contextfrom singleton listagents/issue_patterns.md: updated "Missing libcusparse" issue pattern to generic shared-library mismatch (bitsandbytes no longer links cusparse)