mirror of
https://github.com/ikawrakow/ik_llama.cpp.git
synced 2026-03-13 15:30:03 +00:00
WIP: add reduce and fake_cpy ops
This commit is contained in:
@@ -689,6 +689,9 @@ extern "C" {
|
||||
|
||||
GGML_OP_GLU,
|
||||
|
||||
GGML_OP_REDUCE,
|
||||
GGML_OP_FAKE_CPY,
|
||||
|
||||
GGML_OP_COUNT,
|
||||
};
|
||||
|
||||
@@ -3034,6 +3037,17 @@ extern "C" {
|
||||
struct ggml_tensor ** splits;
|
||||
} ggml_split_tensor_t;
|
||||
|
||||
GGML_API struct ggml_tensor * ggml_reduce(
|
||||
struct ggml_context * ctx,
|
||||
struct ggml_tensor ** a,
|
||||
int n,
|
||||
enum ggml_op op);
|
||||
|
||||
GGML_API struct ggml_tensor * ggml_fake_cpy(
|
||||
struct ggml_context * ctx,
|
||||
struct ggml_tensor * dst,
|
||||
struct ggml_tensor * src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4290,10 +4290,13 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
|
||||
"CROSS_ENTROPY_LOSS",
|
||||
"CROSS_ENTROPY_LOSS_BACK",
|
||||
|
||||
"REDUCE",
|
||||
"FAKE_CPY",
|
||||
|
||||
"GLU",
|
||||
};
|
||||
|
||||
static_assert(GGML_OP_COUNT == 92, "GGML_OP_COUNT != 92");
|
||||
static_assert(GGML_OP_COUNT == 94, "GGML_OP_COUNT != 94");
|
||||
|
||||
static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
|
||||
"none",
|
||||
@@ -4398,10 +4401,13 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
|
||||
"cross_entropy_loss(x,y)",
|
||||
"cross_entropy_loss_back(x,y)",
|
||||
|
||||
"glu(x),"
|
||||
"glu(x),",
|
||||
|
||||
"reduce(x1,x2,...)",
|
||||
"fake_cpy(x,y)",
|
||||
};
|
||||
|
||||
static_assert(GGML_OP_COUNT == 92, "GGML_OP_COUNT != 92");
|
||||
static_assert(GGML_OP_COUNT == 94, "GGML_OP_COUNT != 94");
|
||||
|
||||
static_assert(GGML_OP_POOL_COUNT == 2, "GGML_OP_POOL_COUNT != 2");
|
||||
|
||||
@@ -6060,6 +6066,38 @@ struct ggml_tensor * ggml_dup_inplace(
|
||||
return ggml_dup_impl(ctx, a, true);
|
||||
}
|
||||
|
||||
struct ggml_tensor * ggml_reduce(
|
||||
struct ggml_context * ctx,
|
||||
struct ggml_tensor ** a,
|
||||
int n,
|
||||
enum ggml_op op) {
|
||||
GGML_ASSERT(n > 1 && n <= GGML_MAX_SRC);
|
||||
GGML_ASSERT(op == GGML_OP_ADD); // currently we only handle reduce_add
|
||||
struct ggml_tensor * result = ggml_view_tensor(ctx, a[n-1]);
|
||||
int nhave = 0;
|
||||
for (int j = 0; j < n; ++j) {
|
||||
result->src[j] = a[j];
|
||||
if (a[j]) ++nhave;
|
||||
}
|
||||
GGML_ASSERT(nhave > 1);
|
||||
result->op_params[0] = (int)op;
|
||||
result->op_params[1] = n;
|
||||
result->op_params[2] = nhave;
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ggml_tensor * ggml_fake_cpy(
|
||||
struct ggml_context * ctx,
|
||||
struct ggml_tensor * dst,
|
||||
struct ggml_tensor * src) {
|
||||
struct ggml_tensor * result = ggml_view_tensor(ctx, dst);
|
||||
result->src[0] = dst;
|
||||
result->src[1] = src;
|
||||
result->op = GGML_OP_FAKE_CPY;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// ggml_add
|
||||
|
||||
static struct ggml_tensor * ggml_add_impl(
|
||||
|
||||
Reference in New Issue
Block a user