Skip to content

Commit 4815f37

Browse files
author
Gitty Burstein
committed
Fix: move SparseK op_params indices to 3..6 to avoid array overflow warnings
Co-authored-by: Yael Shuker <[email protected]> Co-authored-by: Gitty Burstein <[email protected]>
1 parent 2ba1921 commit 4815f37

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

ggml/src/ggml-cpu/ops.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5108,10 +5108,10 @@ static void ggml_compute_forward_soft_max_f32(
51085108
const float m1 = powf(2.0f, -(max_bias / 2.0f) / n_head_log2);
51095109

51105110
// SparseK parameters (from op_params)
5111-
const bool use_sparsek = ggml_get_op_params_i32(dst, 30) != 0;
5112-
const int32_t k_top = ggml_get_op_params_i32(dst, 31);
5113-
const int32_t win_local = ggml_get_op_params_i32(dst, 32);
5114-
const int32_t stride_glb = ggml_get_op_params_i32(dst, 33);
5111+
const bool use_sparsek = ggml_get_op_params_i32(dst, 3) != 0;
5112+
const int32_t k_top = ggml_get_op_params_i32(dst, 4);
5113+
const int32_t win_local = ggml_get_op_params_i32(dst, 5);
5114+
const int32_t stride_glb = ggml_get_op_params_i32(dst, 6);
51155115
(void)use_sparsek; (void)k_top; (void)win_local; (void)stride_glb;
51165116

51175117

@@ -5131,8 +5131,9 @@ static void ggml_compute_forward_soft_max_f32(
51315131

51325132
// ALiBi
51335133
const uint32_t h = i02; // head
5134-
const float slope = (max_bias > 0.0f) ? h < n_head_log2 ? powf(m0, h + 1) : powf(m1, 2*(h - n_head_log2) + 1) : 1.0f;
5135-
5134+
const float slope = (max_bias > 0.0f)
5135+
? (h < n_head_log2 ? powf(m0, h + 1) : powf(m1, 2*(h - n_head_log2) + 1))
5136+
: 1.0f;
51365137
float * sp = (float *)((char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03);
51375138
float * dp = (float *)((char *) dst->data + i01*nb1 + i02*nb2 + i03*nb3);
51385139

@@ -8002,11 +8003,11 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
80028003
const float m0 = powf(2.0f, -(max_bias ) / n_head_log2);
80038004
const float m1 = powf(2.0f, -(max_bias / 2.0f) / n_head_log2);
80048005

8005-
// -------- SparseK op_params (לא משנה שום דבר חוץ מקריאת הפרמטרים) --------
8006-
const bool use_sparsek = ggml_get_op_params_i32(dst, 28) != 0;
8007-
const int32_t k_top = ggml_get_op_params_i32(dst, 29);
8008-
const int32_t win_local = ggml_get_op_params_i32(dst, 30);
8009-
const int32_t stride_glb = ggml_get_op_params_i32(dst, 31);
8006+
// -------- SparseK op_params --------
8007+
const bool use_sparsek = ggml_get_op_params_i32(dst, 3) != 0;
8008+
const int32_t k_top = ggml_get_op_params_i32(dst, 4);
8009+
const int32_t win_local = ggml_get_op_params_i32(dst, 5);
8010+
const int32_t stride_glb = ggml_get_op_params_i32(dst, 6);
80108011
// ----------------------------------------------------------------------------
80118012

80128013
ggml_type const k_vec_dot_type = ggml_get_type_traits_cpu(k->type)->vec_dot_type;

ggml/src/ggml.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,10 +5214,10 @@ struct ggml_tensor * ggml_flash_attn_back(
52145214
return result;
52155215
}
52165216

5217-
#define GGML_FA_EXT_PARAM_SPARSEK_FLAG 28
5218-
#define GGML_FA_EXT_PARAM_SPARSEK_KTOP 29
5219-
#define GGML_FA_EXT_PARAM_SPARSEK_WIN 30
5220-
#define GGML_FA_EXT_PARAM_SPARSEK_STRIDE 31
5217+
#define GGML_FA_EXT_PARAM_SPARSEK_FLAG 3
5218+
#define GGML_FA_EXT_PARAM_SPARSEK_KTOP 4
5219+
#define GGML_FA_EXT_PARAM_SPARSEK_WIN 5
5220+
#define GGML_FA_EXT_PARAM_SPARSEK_STRIDE 6
52215221

52225222
void ggml_flash_attn_ext_set_sparsek(struct ggml_tensor * a,
52235223
bool use_sparsek,

tests/test-backend-ops.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7319,6 +7319,7 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
73197319
}
73207320
}
73217321
// ---- SPARSEK_ATTN --------------------------------------------------
7322+
#ifdef GGML_EXPERIMENTAL_SPARSEK_TESTS
73227323
for (int64_t d_qk : {64, 128}) {
73237324
for (int64_t d_v : {64, 128}) {
73247325
for (int64_t n_head : {4, 8}) {
@@ -7335,7 +7336,8 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
73357336
}
73367337
}
73377338
}
7338-
7339+
#endif
7340+
73397341
test_cases.emplace_back(new test_cross_entropy_loss (GGML_TYPE_F32, { 10, 5, 4, 3}));
73407342
test_cases.emplace_back(new test_cross_entropy_loss (GGML_TYPE_F32, {30000, 1, 1, 1}));
73417343
test_cases.emplace_back(new test_cross_entropy_loss_back(GGML_TYPE_F32, { 10, 5, 4, 3}));

0 commit comments

Comments
 (0)