mirror of
https://github.com/ikawrakow/ik_llama.cpp.git
synced 2026-07-21 02:05:35 +00:00
Various
This commit is contained in:
@@ -4970,6 +4970,7 @@ GGML_CALL static bool ggml_backend_cuda_supports_op(ggml_backend_t backend, cons
|
||||
//case GGML_OP_ROPE:
|
||||
// return ggml_is_contiguous(op->src[0]);
|
||||
case GGML_OP_ARGSORT:
|
||||
return true;
|
||||
case GGML_OP_ARGSORT_THRESH:
|
||||
// The CUDA bitonic argsort launches one thread per (padded) column, so the
|
||||
// row width rounded up to a power of 2 must fit in a single CUDA block (<=1024
|
||||
|
||||
+35
-12
@@ -14998,8 +14998,6 @@ static void ggml_compute_forward_concat_any(
|
||||
GGML_ASSERT(src0->type == src1->type && src0->type == dst->type);
|
||||
|
||||
const int32_t dim = ggml_get_op_params_i32(dst, 0);
|
||||
// Let's do it for dim = 0 only for now
|
||||
GGML_ASSERT(dim == 0);
|
||||
|
||||
int ith = params->ith;
|
||||
int nth = params->nth;
|
||||
@@ -15007,21 +15005,46 @@ static void ggml_compute_forward_concat_any(
|
||||
int64_t nrows = ggml_nrows(dst);
|
||||
int64_t nrows_per_thread = (nrows + nth - 1)/nth;
|
||||
int64_t first_row = ith*nrows_per_thread;
|
||||
if (first_row >= nrows) return;
|
||||
int64_t last_row = MIN(first_row + nrows_per_thread, nrows);
|
||||
if (first_row >= last_row) return;
|
||||
|
||||
int64_t src0_row_size = ggml_row_size(src0->type, src0->ne[0]);
|
||||
int64_t src1_row_size = ggml_row_size(src1->type, src1->ne[0]);
|
||||
|
||||
for (int64_t row = first_row; row < last_row; ++row) {
|
||||
int64_t i3 = row/(dst->ne[1]*dst->ne[2]);
|
||||
int64_t i2 = (row - i3*dst->ne[1]*dst->ne[2])/dst->ne[1];
|
||||
int64_t i1 = row - i3*dst->ne[1]*dst->ne[2] - i2*dst->ne[1];
|
||||
char * y = (char *)dst->data + i1*dst->nb[1] + i2*dst->nb[2] + i3*dst->nb[3];
|
||||
const char * x0 = (const char *)src0->data + i1*src0->nb[1] + i2*src0->nb[2] + i3*src0->nb[3];
|
||||
const char * x1 = (const char *)src1->data + i1*src1->nb[1] + i2*src1->nb[2] + i3*src1->nb[3];
|
||||
memcpy(y, x0, src0_row_size);
|
||||
memcpy(y + src0_row_size, x1, src1_row_size);
|
||||
if (dim == 0) {
|
||||
for (int64_t row = first_row; row < last_row; ++row) {
|
||||
int64_t i3 = row/(dst->ne[1]*dst->ne[2]);
|
||||
int64_t i2 = (row - i3*dst->ne[1]*dst->ne[2])/dst->ne[1];
|
||||
int64_t i1 = row - i3*dst->ne[1]*dst->ne[2] - i2*dst->ne[1];
|
||||
char * y = (char *)dst->data + i1*dst->nb[1] + i2*dst->nb[2] + i3*dst->nb[3];
|
||||
const char * x0 = (const char *)src0->data + i1*src0->nb[1] + i2*src0->nb[2] + i3*src0->nb[3];
|
||||
const char * x1 = (const char *)src1->data + i1*src1->nb[1] + i2*src1->nb[2] + i3*src1->nb[3];
|
||||
memcpy(y, x0, src0_row_size);
|
||||
memcpy(y + src0_row_size, x1, src1_row_size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
GGML_ASSERT(src0_row_size == src1_row_size);
|
||||
for (int64_t row = first_row; row < last_row; ++row) {
|
||||
int64_t i3 = row/(dst->ne[1]*dst->ne[2]);
|
||||
int64_t i2 = (row - i3*dst->ne[1]*dst->ne[2])/dst->ne[1];
|
||||
int64_t i1 = row - i3*dst->ne[1]*dst->ne[2] - i2*dst->ne[1];
|
||||
char * y = (char *)dst->data + i1*dst->nb[1] + i2*dst->nb[2] + i3*dst->nb[3];
|
||||
const char * x;
|
||||
if (dim == 1) {
|
||||
x = i1 < src0->ne[1] ? (const char *)src0->data + i1*src0->nb[1] + i2*src0->nb[2] + i3*src0->nb[3]
|
||||
: (const char *)src1->data + (i1 - src0->ne[1])*src1->nb[1] + i2*src1->nb[2] + i3*src1->nb[3];
|
||||
}
|
||||
else if (dim == 2) {
|
||||
x = i2 < src0->ne[2] ? (const char *)src0->data + i1*src0->nb[1] + i2*src0->nb[2] + i3*src0->nb[3]
|
||||
: (const char *)src1->data + i1*src1->nb[1] + (i2 - src0->ne[2])*src1->nb[2] + i3*src1->nb[3];
|
||||
}
|
||||
else {
|
||||
x = i3 < src0->ne[3] ? (const char *)src0->data + i1*src0->nb[1] + i2*src0->nb[2] + i3*src0->nb[3]
|
||||
: (const char *)src1->data + i1*src1->nb[1] + i2*src1->nb[2] + (i3 - src0->ne[3])*src1->nb[3];
|
||||
}
|
||||
memcpy(y, x, src0_row_size);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -635,14 +635,15 @@ static ggml_tensor * build_deepseek2_dsa_fa_mask(const llama_context & lctx, ggm
|
||||
return KQ_mask;
|
||||
}
|
||||
|
||||
GGML_ASSERT(sorted->ne[1] == lctx.inp_mask_inf->ne[1]);
|
||||
auto top_k = ggml_view_2d(ctx0, sorted, n_top_k, sorted->ne[1], sorted->nb[1], 0);
|
||||
auto mask32 = ggml_blend(ctx0, lctx.inp_mask_inf, top_k, 0.0f);
|
||||
if (KQ_mask->ne[1] == sorted->ne[1]) {
|
||||
if (KQ_mask->ne[1] == mask32->ne[1]) {
|
||||
auto mask16 = ggml_add(ctx0, KQ_mask, mask32);
|
||||
return mask16;
|
||||
}
|
||||
auto kq1 = ggml_view_2d(ctx0, KQ_mask, KQ_mask->ne[0], sorted->ne[1], KQ_mask->nb[1], 0);
|
||||
auto kq2 = ggml_view_2d(ctx0, KQ_mask, KQ_mask->ne[0], KQ_mask->ne[1] - sorted->ne[1], KQ_mask->nb[1], sorted->ne[1]*KQ_mask->nb[1]);
|
||||
auto kq1 = ggml_view_2d(ctx0, KQ_mask, KQ_mask->ne[0], mask32->ne[1], KQ_mask->nb[1], 0);
|
||||
auto kq2 = ggml_view_2d(ctx0, KQ_mask, KQ_mask->ne[0], KQ_mask->ne[1] - mask32->ne[1], KQ_mask->nb[1], mask32->ne[1]*KQ_mask->nb[1]);
|
||||
kq1 = ggml_add(ctx0, kq1, mask32);
|
||||
auto mask16 = ggml_concat(ctx0, kq1, kq2, 1);
|
||||
return mask16;
|
||||
@@ -1196,7 +1197,7 @@ ggml_cgraph * llm_build_context::build_deepseek2() {
|
||||
cb(lctx.inp_dsa_sink, "dsa_sink", -1);
|
||||
ggml_set_input(lctx.inp_dsa_sink);
|
||||
}
|
||||
auto minus_inf = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, KQ_mask->ne[0], KQ_mask->ne[1]);
|
||||
auto minus_inf = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, KQ_mask->ne[0], n_tokens);
|
||||
minus_inf = ggml_fill_inplace(ctx0, minus_inf, -INFINITY);
|
||||
ggml_build_forward_expand(gf, minus_inf);
|
||||
lctx.inp_mask_inf = minus_inf;
|
||||
|
||||
Reference in New Issue
Block a user