Repository navigation
cuda: fix the q8_0 and iq4_nl dequantization kernels - #29292
yeahdongcn wants to merge 2 commits into
Conversation
dequantize_block_q8_0_f16() was guarded by "#if __CUDA_ARCH__ >= GGML_CUDA_CC_PASCAL". mcc never defines __CUDA_ARCH__, so the guard was false on MUSA and the kernel body was dropped entirely - NO_DEVICE_CODE expands to nothing when __CUDA_ARCH__ is undefined, so the launch succeeded and y was left untouched. Every q8_0 -> f16 dequantization used an uninitialized buffer: the quantized matmul fallback, MUL_MAT_ID, and quantized KV cache for flash attention. On an MTT S5000 this is 19 MUL_MAT, 31 MUL_MAT_ID and the q8_0 FLASH_ATTN_EXT test cases; all of them pass after the fix.
dequantize_block_iq4_nl writes QK_K values per block, but a row can be shorter than that (an IQ4_NL row is only guaranteed to be a multiple of QK4_NL). Threads whose 32-value sub-block starts at or past k currently read and write past the end of the row. Skip those sub-blocks; for rows that are a multiple of QK_K the check never fires.
This comment was marked as resolved.
This comment was marked as resolved.
|
|
I see that Just wanted to clarify whether you'd like us to follow the HIP approach and disable features based on |
|
Or we just define |
Traditionally you would then check
I'm not familiar with MUSA, but whichever would be the safe value I guess, as with HIP. |
|
To follow // common.cuh:283-302
#if !defined(GGML_USE_HIP) && __CUDA_ARCH__ == GGML_CUDA_CC_VOLTA → #define VOLTA_MMA_AVAILABLE
#if !defined(GGML_USE_HIP) && __CUDA_ARCH__ >= GGML_CUDA_CC_TURING → #define TURING_MMA_AVAILABLE
#if !defined(GGML_USE_HIP) && __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE → #define AMPERE_MMA_AVAILABLE
#if !defined(GGML_USE_HIP) && __CUDA_ARCH__ >= GGML_CUDA_CC_BLACKWELL && < RUBIN → #define BLACKWELL_MMA_AVAILABLE
#if !defined(GGML_USE_HIP) && __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE → #define CP_ASYNC_AVAILABLE |
As is done right above: llama.cpp/ggml/src/ggml-cuda/common.cuh Lines 267 to 269 in 1484399 |
Can I open a new PR to align this with the HIP approach? |
Up to @ggml-org/ggml-cuda, I'll stop butting in now. :) |
|
Replaced with #29508 |
Overview
Two fixes to the
ggml-cudadequantization kernels:dequantize_block_q8_0_f16is guarded by__CUDA_ARCH__ >= GGML_CUDA_CC_PASCAL. MUSA'smccdefines__MUSA_ARCH__in the device pass and not__CUDA_ARCH__, so the condition is false, the body is dropped and the kernel is launched empty — everyq8_0dequantization produces garbage. Also guard on__MUSA_ARCH__; NVIDIA builds are unaffected becausedefined(__MUSA_ARCH__)is false there.dequantize_block_iq4_nlwritesQK_Kvalues per block, but anIQ4_NLrow is only guaranteed to be a multiple ofQK4_NL, and ops such asMUL_MATdo use shorter rows. Threads whose 32-value sub-block starts at or past the end of the row were reading and writing past the end of the output. Skip those sub-blocks. For rows that are a multiple ofQK_Kthe check never fires.Both were found with
test-backend-opson an MTT S5000 (MUSA architecture31); theq8_0case is MUSA specific, theiq4_nlcase is backend independent.Additional information
Requirements