@@ -21,14 +21,14 @@ __global__ void gated_delta_net_cuda(const float * q,
2121 int64_t sb1,
2222 int64_t sb2,
2323 int64_t sb3,
24- int64_t rq1 ,
24+ int64_t neqk1 ,
2525 int64_t rq3,
2626 float scale) {
2727 const int64_t h_idx = blockIdx .x ;
2828 const int64_t sequence = blockIdx .y ;
2929 const int col = threadIdx .x ; // each thread owns one column
3030
31- const int64_t iq1 = h_idx / rq1 ;
31+ const int64_t iq1 = h_idx % neqk1 ;
3232 const int64_t iq3 = sequence / rq3;
3333
3434 const int64_t attn_score_elems = S_v * H * n_tokens * n_seqs;
@@ -119,11 +119,11 @@ static void launch_gated_delta_net(
119119 const float * q_d, const float * k_d, const float * v_d,
120120 const float * g_d, const float * b_d, const float * s_d,
121121 float * dst_d,
122- int64_t S_v, int64_t H, int64_t n_tokens, int64_t n_seqs,
123- int64_t sq1, int64_t sq2, int64_t sq3,
124- int64_t sv1, int64_t sv2, int64_t sv3,
125- int64_t sb1, int64_t sb2, int64_t sb3,
126- int64_t rq1 , int64_t rq3,
122+ int64_t S_v, int64_t H, int64_t n_tokens, int64_t n_seqs,
123+ int64_t sq1, int64_t sq2, int64_t sq3,
124+ int64_t sv1, int64_t sv2, int64_t sv3,
125+ int64_t sb1, int64_t sb2, int64_t sb3,
126+ int64_t neqk1 , int64_t rq3,
127127 float scale, cudaStream_t stream) {
128128
129129 dim3 grid_dims (H, n_seqs, 1 );
@@ -134,19 +134,19 @@ static void launch_gated_delta_net(
134134 gated_delta_net_cuda<32 , KDA ><<<grid_dims, block_dims, 0 , stream>>> (
135135 q_d, k_d, v_d, g_d, b_d, s_d, dst_d, H,
136136 n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
137- sb1, sb2, sb3, rq1 , rq3, scale);
137+ sb1, sb2, sb3, neqk1 , rq3, scale);
138138 break ;
139139 case 64 :
140140 gated_delta_net_cuda<64 , KDA ><<<grid_dims, block_dims, 0 , stream>>> (
141141 q_d, k_d, v_d, g_d, b_d, s_d, dst_d, H,
142142 n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
143- sb1, sb2, sb3, rq1 , rq3, scale);
143+ sb1, sb2, sb3, neqk1 , rq3, scale);
144144 break ;
145145 case 128 :
146146 gated_delta_net_cuda<128 , KDA ><<<grid_dims, block_dims, 0 , stream>>> (
147147 q_d, k_d, v_d, g_d, b_d, s_d, dst_d, H,
148148 n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
149- sb1, sb2, sb3, rq1 , rq3, scale);
149+ sb1, sb2, sb3, neqk1 , rq3, scale);
150150 break ;
151151 default :
152152 GGML_ABORT (" fatal error" );
@@ -163,10 +163,12 @@ void ggml_cuda_op_gated_delta_net(ggml_backend_cuda_context & ctx, ggml_tensor *
163163 ggml_tensor * src_state = dst->src [5 ];
164164
165165 GGML_TENSOR_LOCALS (int64_t , neq, src_q, ne);
166- GGML_TENSOR_LOCALS (size_t , nbq, src_q, nb);
166+ GGML_TENSOR_LOCALS (size_t , nbq, src_q, nb);
167+ GGML_TENSOR_LOCALS (int64_t , nek, src_k, ne);
168+ GGML_TENSOR_LOCALS (size_t , nbk, src_k, nb);
167169 GGML_TENSOR_LOCALS (int64_t , nev, src_v, ne);
168- GGML_TENSOR_LOCALS (size_t , nbv, src_v, nb);
169- GGML_TENSOR_LOCALS (size_t , nbb, src_beta, nb);
170+ GGML_TENSOR_LOCALS (size_t , nbv, src_v, nb);
171+ GGML_TENSOR_LOCALS (size_t , nbb, src_beta, nb);
170172
171173 const int64_t S_v = nev0;
172174 const int64_t H = nev1;
@@ -175,7 +177,9 @@ void ggml_cuda_op_gated_delta_net(ggml_backend_cuda_context & ctx, ggml_tensor *
175177
176178 const bool kda = (src_g->ne [0 ] == S_v);
177179
178- const int64_t rq1 = nev1 / neq1;
180+ GGML_ASSERT (neq1 == nek1);
181+ const int64_t neqk1 = neq1;
182+
179183 const int64_t rq3 = nev3 / neq3;
180184
181185 const float * q_d = (const float *) src_q->data ;
@@ -214,10 +218,10 @@ void ggml_cuda_op_gated_delta_net(ggml_backend_cuda_context & ctx, ggml_tensor *
214218 if (kda) {
215219 launch_gated_delta_net<true >(q_d, k_d, v_d, g_d, b_d, s_d, dst_d,
216220 S_v, H, n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
217- sb1, sb2, sb3, rq1 , rq3, scale, stream);
221+ sb1, sb2, sb3, neqk1 , rq3, scale, stream);
218222 } else {
219223 launch_gated_delta_net<false >(q_d, k_d, v_d, g_d, b_d, s_d, dst_d,
220224 S_v, H, n_tokens, n_seqs, sq1, sq2, sq3, sv1, sv2, sv3,
221- sb1, sb2, sb3, rq1 , rq3, scale, stream);
225+ sb1, sb2, sb3, neqk1 , rq3, scale, stream);
222226 }
223227}
0 commit comments