prefill: dense MMQ is HIP only; no q6_k instance or untested code in CUDA builds (#820)
Gemm::native_mmq, its call, the f16_to_f32/set_bounds kernels and the Q6_K case are under __HIPCC__; the CUDA type list loses q6_k. The K % 256 != 0 out-of-bounds read is already refused in native_mmq (kept). Still opt-in: STRATA_DENSE_MMQ=1 on a STRATA_MMQ_KQUANTS=ON HIP build.
This commit is contained in:
1 parent
43881f14a3
commit
ce37456ccd
3 files changed
+18
-8
No files matched your search
+3
-3
@@ -1097,11 +1097,11 @@ if(STRATA_NATIVE_EXPERTS)
|
||||
add_library(strata_mmq STATIC src/prefill/moe_mmq.cu src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu
|
||||
src/prefill/ggml_cuda_host.cu ${_strata_mmq}/quantize.cu)
|
||||
# q8_0: the drafter's matrices (E-9); STRATA_ORCA_Q4KS_MMQ adds q5_0 (#296, in _strata_mmq_types), and
|
||||
# STRATA_MMQ_KQUANTS q4_k q5_k q5_1 q6_k: the experts of Unsloth's UD-Q4_K_XL (docs/UNSLOTH_Q4.md; the dispatch
|
||||
# follows eddoursul/Strata 7706c1b), q6_k also the usual attention weight of the plain i-quant GGUFs
|
||||
# STRATA_MMQ_KQUANTS q4_k q5_k q5_1, the experts of Unsloth's UD-Q4_K_XL (docs/UNSLOTH_Q4.md; the dispatch
|
||||
# follows eddoursul/Strata 7706c1b); q6_k is HIP only
|
||||
set(_strata_mmq_cuda_types ${_strata_mmq_types})
|
||||
if(STRATA_MMQ_KQUANTS)
|
||||
list(APPEND _strata_mmq_cuda_types q4_k q5_k q5_1 q6_k)
|
||||
list(APPEND _strata_mmq_cuda_types q4_k q5_k q5_1)
|
||||
endif()
|
||||
foreach(_t IN LISTS _strata_mmq_cuda_types)
|
||||
target_sources(strata_mmq PRIVATE ${_strata_mmq}/template-instances/mmq-instance-${_t}.cu)
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
// src/prefill/gemm.cu - see include/strata/prefill/gemm.hpp.
|
||||
#include "strata/prefill/gemm.hpp"
|
||||
#include "strata/kernels/dequant_bf16.hpp"
|
||||
#ifdef STRATA_PREFILL_MMQ
|
||||
#if defined(STRATA_PREFILL_MMQ) && defined(__HIPCC__)
|
||||
#include "strata/prefill/moe_mmq.hpp"
|
||||
#endif
|
||||
|
||||
@@ -316,7 +316,7 @@ bool try_hipblaslt(void* opaque_state, strata::prefill::hipblaslt::InputType typ
|
||||
} // namespace
|
||||
|
||||
Gemm::~Gemm() {
|
||||
#ifdef STRATA_PREFILL_MMQ
|
||||
#if defined(STRATA_PREFILL_MMQ) && defined(__HIPCC__)
|
||||
delete static_cast<strata::prefill::mmq::Context*>(mmq_ctx_);
|
||||
if (mmq_buf_) cudaFree(mmq_buf_);
|
||||
#endif
|
||||
@@ -605,7 +605,7 @@ void Gemm::f16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64_
|
||||
STRATA_ABSORB_HIPBLAS_STICKY("cublasGemmEx f16");
|
||||
}
|
||||
|
||||
#ifdef STRATA_PREFILL_MMQ
|
||||
#if defined(STRATA_PREFILL_MMQ) && defined(__HIPCC__)
|
||||
bool Gemm::native_mmq(const uint16_t* X, int type, const void* W, float* Y, int64_t T, int64_t N, int64_t K,
|
||||
int64_t ldy) {
|
||||
namespace mmq = strata::prefill::mmq;
|
||||
@@ -707,7 +707,7 @@ void Gemm::native(const uint16_t* X, int ggml_type, const void* W_blocks, float*
|
||||
(long long) ldx, (long long) K);
|
||||
std::exit(1);
|
||||
}
|
||||
#ifdef STRATA_PREFILL_MMQ
|
||||
#if defined(STRATA_PREFILL_MMQ) && defined(__HIPCC__)
|
||||
if (beta == 0.0f && (ldx == 0 || ldx == K) && native_mmq(X, ggml_type, W_blocks, Y, T, N, K, ldy)) return;
|
||||
#endif
|
||||
if (N * K > scratch_elems_) {
|
||||
|
||||
+11
-1
@@ -99,6 +99,7 @@ __global__ void iota_kernel(int32_t* dst, int64_t n) {
|
||||
if (i < n) dst[i] = (int32_t) i;
|
||||
}
|
||||
|
||||
#if defined(__HIPCC__) // #820: only the HIP dense-MMQ path (Gemm::native_mmq) uses these two
|
||||
__global__ void f16_to_f32_kernel(const uint16_t* __restrict__ x, float* __restrict__ y, int64_t n) {
|
||||
const int64_t i = (int64_t) blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (i < n) y[i] = __half2float(__ushort_as_half(x[i]));
|
||||
@@ -109,6 +110,8 @@ __global__ void set_bounds_kernel(int32_t* d, int32_t rows) {
|
||||
d[1] = rows;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
unsigned blocks(int64_t n) { return (unsigned) ((n + 255) / 256); }
|
||||
|
||||
} // namespace
|
||||
@@ -125,7 +128,10 @@ bool supported(int t) {
|
||||
case GGML_TYPE_IQ3_XXS: case GGML_TYPE_IQ3_S: case GGML_TYPE_IQ4_NL: case GGML_TYPE_IQ4_XS:
|
||||
case GGML_TYPE_Q8_0: // the draft layer's dense matrices (E-9)
|
||||
#ifdef STRATA_MMQ_KQUANTS
|
||||
case GGML_TYPE_Q4_K: case GGML_TYPE_Q5_K: case GGML_TYPE_Q6_K: case GGML_TYPE_Q5_1: // the K-quants: Unsloth's UD-Q4_K_XL experts (CUDA), the dense GGUF projections (STRATA_DENSE_MMQ)
|
||||
case GGML_TYPE_Q4_K: case GGML_TYPE_Q5_K: case GGML_TYPE_Q5_1: // Unsloth's UD-Q4_K_XL experts (CUDA)
|
||||
#if defined(__HIPCC__)
|
||||
case GGML_TYPE_Q6_K: // HIP only: the dense GGUF projections (STRATA_DENSE_MMQ); no CUDA instance is built
|
||||
#endif
|
||||
#endif
|
||||
return true;
|
||||
default:
|
||||
@@ -210,7 +216,9 @@ void Context::run(const Product& p, void* stream) {
|
||||
#ifdef STRATA_MMQ_KQUANTS
|
||||
case GGML_TYPE_Q4_K: mul_mat_q_case<GGML_TYPE_Q4_K>(ctx, a, s); break;
|
||||
case GGML_TYPE_Q5_K: mul_mat_q_case<GGML_TYPE_Q5_K>(ctx, a, s); break;
|
||||
#if defined(__HIPCC__)
|
||||
case GGML_TYPE_Q6_K: mul_mat_q_case<GGML_TYPE_Q6_K>(ctx, a, s); break;
|
||||
#endif
|
||||
case GGML_TYPE_Q5_1: mul_mat_q_case<GGML_TYPE_Q5_1>(ctx, a, s); break;
|
||||
#endif
|
||||
default:
|
||||
@@ -274,6 +282,7 @@ void iota(int32_t* dst, int64_t n, void* stream) {
|
||||
ck(cudaGetLastError(), "iota");
|
||||
}
|
||||
|
||||
#if defined(__HIPCC__)
|
||||
void f16_to_f32(const uint16_t* x, float* y, int64_t n, void* stream) {
|
||||
if (n <= 0) return;
|
||||
f16_to_f32_kernel<<<blocks(n), 256, 0, (cudaStream_t) stream>>>(x, y, n);
|
||||
@@ -284,5 +293,6 @@ void set_bounds(int32_t* dst, int32_t rows, void* stream) {
|
||||
set_bounds_kernel<<<1, 1, 0, (cudaStream_t) stream>>>(dst, rows);
|
||||
ck(cudaGetLastError(), "set_bounds");
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace strata::prefill::mmq
|
||||
Reference in new issue
Block a user