[ROCm] Try multiple hipBLASLt heuristic algos and fall back to fp32 for unsupported int8 shapes#1934
Open
Abdennacer-Badaoui wants to merge 1 commit intobitsandbytes-foundation:mainfrom
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. |
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.
Description
On AMD MI300X (
gfx942),igemmlt's HIP path was crashing for certain small-batch int8 GEMM shapes (e.g.m=2048, n=4, k=6144from BLOOM's QKV projection).Root cause: With
max_workspace_size = 0, hipBLASLt's heuristic returns very few candidate algorithms (3 in our case), and on MI300X all of them fail athipblasLtMatmultime withHIPBLAS_STATUS_INVALID_VALUE. The code requested onlyrequest_solutions = 1and used the first algo unconditionally, so the failure was unrecoverable.This PR makes the HIP path resilient:
1. Try multiple algos
Bump
request_solutionsfrom1to8and loop through the heuristic results, accepting the first one that actually runs (bnb_blasLtMatmulreturnsBNB_BLAS_STATUS_SUCCESS). Most shapes succeed on algo 0, the loop only kicks in for pathological cases.2. Drain the HIP error flag
Call
hipGetLastError()after a fully-failed loop, so the next unrelated HIP call doesn't inherit a stale invalid device ordinal error.3. Signal Python to fall back to fp32
Return
ERR_NOT_IMPLEMENTED(100) when no algo works. The Python wrapper inbitsandbytes/backends/cuda/ops.pypreviously raisedNotImplementedErroron code100; this PR replaces that with the samefp32torch.matmulfallback already used forlda % 4 != 0, plus a one-timeRuntimeWarning. This implements the existing TODO in the file: "Warn and implement a fallback to fp32 compute?"Context
Found while validating
accelerateend-to-end on 8× MI300X (ROCm 7.1, PyTorch 2.8.0+rocm7.1.0), specifically:tests/test_quantization.py::MixedInt8EmptyModelTest::test_cpu_gpu_disk_loading_custom_device_map_kwargsThis test exercises bnb 8-bit inference on BLOOM. Without this fix, the int8 path is unusable for any model whose QKV projection produces this shape on MI300X. With it, the test passes — small-n cases silently degrade to fp32 (slower but correct) instead of crashing.