Skip to content

Commit 2700c19

Browse files
committed
ggml : remove ggml_exp and ggml_soft_plus
They did not exist anyway outside of this branch, and since ggml_ssm_scan fused operations together, they are unused. It's always possible to bring them back if needed.
1 parent 3dd654c commit 2700c19

File tree

2 files changed

+2
-208
lines changed

2 files changed

+2
-208
lines changed

ggml.c

Lines changed: 2 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,6 @@ inline static void ggml_vec_scale_f32(const int n, float * y, const float v) {
15001500
inline static void ggml_vec_norm_f32 (const int n, float * s, const float * x) { ggml_vec_dot_f32(n, s, 0, x, 0, x, 0, 1); *s = sqrtf(*s); }
15011501
inline static void ggml_vec_sqr_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = x[i]*x[i]; }
15021502
inline static void ggml_vec_sqrt_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = sqrtf(x[i]); }
1503-
inline static void ggml_vec_exp_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = expf(x[i]); }
15041503
inline static void ggml_vec_log_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = logf(x[i]); }
15051504
inline static void ggml_vec_abs_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = fabsf(x[i]); }
15061505
inline static void ggml_vec_sgn_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = (x[i] > 0.f) ? 1.f : ((x[i] < 0.f) ? -1.f : 0.f); }
@@ -1696,7 +1695,6 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
16961695
"DIV",
16971696
"SQR",
16981697
"SQRT",
1699-
"EXP",
17001698
"LOG",
17011699
"SUM",
17021700
"SUM_ROWS",
@@ -1730,7 +1728,6 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
17301728
"DIAG_MASK_ZERO",
17311729
"SOFT_MAX",
17321730
"SOFT_MAX_BACK",
1733-
"SOFT_PLUS",
17341731
"ROPE",
17351732
"ROPE_BACK",
17361733
"ALIBI",
@@ -1771,7 +1768,7 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
17711768
"CROSS_ENTROPY_LOSS_BACK",
17721769
};
17731770

1774-
static_assert(GGML_OP_COUNT == 75, "GGML_OP_COUNT != 75");
1771+
static_assert(GGML_OP_COUNT == 73, "GGML_OP_COUNT != 73");
17751772

17761773
static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
17771774
"none",
@@ -1785,7 +1782,6 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
17851782
"x/y",
17861783
"x^2",
17871784
"√x",
1788-
"e^x", // or should this be "exp(x)"?
17891785
"log(x)",
17901786
"Σx",
17911787
"Σx_k",
@@ -1819,7 +1815,6 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
18191815
"diag_mask_zero(x)",
18201816
"soft_max(x)",
18211817
"soft_max_back(x)",
1822-
"soft_plus(x)",
18231818
"rope(x)",
18241819
"rope_back(x)",
18251820
"alibi(x)",
@@ -1860,7 +1855,7 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
18601855
"cross_entropy_loss_back(x,y)",
18611856
};
18621857

1863-
static_assert(GGML_OP_COUNT == 75, "GGML_OP_COUNT != 75");
1858+
static_assert(GGML_OP_COUNT == 73, "GGML_OP_COUNT != 73");
18641859

18651860
static_assert(GGML_OP_POOL_COUNT == 2, "GGML_OP_POOL_COUNT != 2");
18661861

@@ -3673,39 +3668,6 @@ struct ggml_tensor * ggml_sqrt_inplace(
36733668
return ggml_sqrt_impl(ctx, a, true);
36743669
}
36753670

3676-
// ggml_exp
3677-
3678-
static struct ggml_tensor * ggml_exp_impl(
3679-
struct ggml_context * ctx,
3680-
struct ggml_tensor * a,
3681-
bool inplace) {
3682-
bool is_node = false;
3683-
3684-
if (!inplace && (a->grad)) {
3685-
is_node = true;
3686-
}
3687-
3688-
struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
3689-
3690-
result->op = GGML_OP_EXP;
3691-
result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL;
3692-
result->src[0] = a;
3693-
3694-
return result;
3695-
}
3696-
3697-
struct ggml_tensor * ggml_exp(
3698-
struct ggml_context * ctx,
3699-
struct ggml_tensor * a) {
3700-
return ggml_exp_impl(ctx, a, false);
3701-
}
3702-
3703-
struct ggml_tensor * ggml_exp_inplace(
3704-
struct ggml_context * ctx,
3705-
struct ggml_tensor * a) {
3706-
return ggml_exp_impl(ctx, a, true);
3707-
}
3708-
37093671
// ggml_log
37103672

37113673
static struct ggml_tensor * ggml_log_impl(
@@ -5186,40 +5148,6 @@ struct ggml_tensor * ggml_soft_max_back_inplace(
51865148
return ggml_soft_max_back_impl(ctx, a, b, true);
51875149
}
51885150

5189-
// ggml_soft_plus
5190-
5191-
static struct ggml_tensor * ggml_soft_plus_impl(
5192-
struct ggml_context * ctx,
5193-
struct ggml_tensor * a,
5194-
bool inplace) {
5195-
5196-
bool is_node = false;
5197-
5198-
if (a->grad) {
5199-
is_node = true; // TODO : implement backward pass
5200-
}
5201-
5202-
struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
5203-
5204-
result->op = GGML_OP_SOFT_PLUS;
5205-
result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL;
5206-
result->src[0] = a;
5207-
5208-
return result;
5209-
}
5210-
5211-
struct ggml_tensor * ggml_soft_plus(
5212-
struct ggml_context * ctx,
5213-
struct ggml_tensor * a) {
5214-
return ggml_soft_plus_impl(ctx, a, false);
5215-
}
5216-
5217-
struct ggml_tensor * ggml_soft_plus_inplace(
5218-
struct ggml_context * ctx,
5219-
struct ggml_tensor * a) {
5220-
return ggml_soft_plus_impl(ctx, a, true);
5221-
}
5222-
52235151
// ggml_rope
52245152

52255153
static struct ggml_tensor * ggml_rope_impl(
@@ -8501,57 +8429,6 @@ static void ggml_compute_forward_sqrt(
85018429
}
85028430
}
85038431

8504-
// ggml_compute_forward_exp
8505-
8506-
static void ggml_compute_forward_exp_f32(
8507-
const struct ggml_compute_params * params,
8508-
const struct ggml_tensor * src0,
8509-
struct ggml_tensor * dst) {
8510-
GGML_ASSERT(ggml_is_contiguous_except_dim_1(src0));
8511-
GGML_ASSERT(ggml_is_contiguous_except_dim_1(dst));
8512-
GGML_ASSERT(ggml_are_same_shape(src0, dst));
8513-
8514-
if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
8515-
return;
8516-
}
8517-
8518-
const int ith = params->ith;
8519-
const int nth = params->nth;
8520-
8521-
const int nc = src0->ne[0];
8522-
const int nr = ggml_nrows(src0);
8523-
8524-
// rows per thread
8525-
const int dr = (nr + nth - 1)/nth;
8526-
8527-
// row range for this thread
8528-
const int ir0 = dr*ith;
8529-
const int ir1 = MIN(ir0 + dr, nr);
8530-
8531-
for (int i1 = ir0; i1 < ir1; i1++) {
8532-
ggml_vec_exp_f32(nc,
8533-
(float *) ((char *) dst->data + i1*( dst->nb[1])),
8534-
(float *) ((char *) src0->data + i1*(src0->nb[1])));
8535-
};
8536-
}
8537-
8538-
static void ggml_compute_forward_exp(
8539-
const struct ggml_compute_params * params,
8540-
const struct ggml_tensor * src0,
8541-
struct ggml_tensor * dst) {
8542-
switch (src0->type) {
8543-
case GGML_TYPE_F32:
8544-
{
8545-
ggml_compute_forward_exp_f32(params, src0, dst);
8546-
} break;
8547-
case GGML_TYPE_F16: // TODO: use ggml_table_exp_f16
8548-
default:
8549-
{
8550-
GGML_ASSERT(false);
8551-
} break;
8552-
}
8553-
}
8554-
85558432
// ggml_compute_forward_log
85568433

85578434
static void ggml_compute_forward_log_f32(
@@ -11828,48 +11705,6 @@ static void ggml_compute_forward_soft_max_back(
1182811705
}
1182911706
}
1183011707

11831-
static void ggml_compute_forward_soft_plus_f32(
11832-
const struct ggml_compute_params * params,
11833-
const struct ggml_tensor * src0,
11834-
struct ggml_tensor * dst) {
11835-
GGML_ASSERT(params->ith == 0);
11836-
GGML_ASSERT(ggml_are_same_shape(src0, dst));
11837-
11838-
if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
11839-
return;
11840-
}
11841-
11842-
const int nc = src0->ne[0];
11843-
const int nr = ggml_nrows(src0);
11844-
11845-
GGML_ASSERT( dst->nb[0] == sizeof(float));
11846-
GGML_ASSERT(src0->nb[0] == sizeof(float));
11847-
11848-
for (int i = 0; i < nr; ++i) {
11849-
float * x = (float *) ((char *) dst->data + i*( dst->nb[1]));
11850-
float * y = (float *) ((char *) src0->data + i*(src0->nb[1]));
11851-
for (int j = 0; j < nc; ++j) {
11852-
x[j] = logf(1.0f + expf(y[j]));
11853-
}
11854-
}
11855-
}
11856-
11857-
static void ggml_compute_forward_soft_plus(
11858-
const struct ggml_compute_params * params,
11859-
const struct ggml_tensor * src0,
11860-
struct ggml_tensor * dst) {
11861-
switch (src0->type) {
11862-
case GGML_TYPE_F32:
11863-
{
11864-
ggml_compute_forward_soft_plus_f32(params, src0, dst);
11865-
} break;
11866-
default:
11867-
{
11868-
GGML_ASSERT(false);
11869-
} break;
11870-
}
11871-
}
11872-
1187311708
// ggml_compute_forward_alibi
1187411709

1187511710
static void ggml_compute_forward_alibi_f32(
@@ -15279,10 +15114,6 @@ static void ggml_compute_forward(struct ggml_compute_params * params, struct ggm
1527915114
{
1528015115
ggml_compute_forward_sqrt(params, tensor->src[0], tensor);
1528115116
} break;
15282-
case GGML_OP_EXP:
15283-
{
15284-
ggml_compute_forward_exp(params, tensor->src[0], tensor);
15285-
} break;
1528615117
case GGML_OP_LOG:
1528715118
{
1528815119
ggml_compute_forward_log(params, tensor->src[0], tensor);
@@ -15407,10 +15238,6 @@ static void ggml_compute_forward(struct ggml_compute_params * params, struct ggm
1540715238
{
1540815239
ggml_compute_forward_soft_max_back(params, tensor->src[0], tensor->src[1], tensor);
1540915240
} break;
15410-
case GGML_OP_SOFT_PLUS:
15411-
{
15412-
ggml_compute_forward_soft_plus(params, tensor->src[0], tensor);
15413-
} break;
1541415241
case GGML_OP_ROPE:
1541515242
{
1541615243
ggml_compute_forward_rope(params, tensor->src[0], tensor->src[1], tensor);
@@ -15967,10 +15794,6 @@ static void ggml_compute_backward(struct ggml_context * ctx, struct ggml_tensor
1596715794
zero_table);
1596815795
}
1596915796
} break;
15970-
case GGML_OP_EXP:
15971-
{
15972-
GGML_ASSERT(false); // TODO: implement
15973-
} break;
1597415797
case GGML_OP_LOG:
1597515798
{
1597615799
if (src0->grad) {
@@ -16349,10 +16172,6 @@ static void ggml_compute_backward(struct ggml_context * ctx, struct ggml_tensor
1634916172
{
1635016173
GGML_ASSERT(false); // TODO: not implemented
1635116174
} break;
16352-
case GGML_OP_SOFT_PLUS:
16353-
{
16354-
GGML_ASSERT(false); // TODO: not implemented
16355-
} break;
1635616175
case GGML_OP_ROPE:
1635716176
{
1635816177
// necessary for llama
@@ -17074,7 +16893,6 @@ static int ggml_get_n_tasks(struct ggml_tensor * node, int n_threads) {
1707416893
case GGML_OP_ADD:
1707516894
case GGML_OP_ADD1:
1707616895
case GGML_OP_ACC:
17077-
case GGML_OP_EXP:
1707816896
{
1707916897
n_tasks = n_threads;
1708016898
} break;
@@ -17181,10 +16999,6 @@ static int ggml_get_n_tasks(struct ggml_tensor * node, int n_threads) {
1718116999
{
1718217000
n_tasks = MIN(n_threads, ggml_nrows(node->src[0]));
1718317001
} break;
17184-
case GGML_OP_SOFT_PLUS:
17185-
{
17186-
n_tasks = 1; //TODO
17187-
} break;
1718817002
case GGML_OP_CONV_TRANSPOSE_1D:
1718917003
{
1719017004
n_tasks = n_threads;
@@ -17558,7 +17372,6 @@ struct ggml_cplan ggml_graph_plan(const struct ggml_cgraph * cgraph, int n_threa
1755817372
}
1755917373
} break;
1756017374
case GGML_OP_SOFT_MAX:
17561-
case GGML_OP_SOFT_PLUS:
1756217375
case GGML_OP_ROPE:
1756317376
{
1756417377
cur = ggml_type_size(GGML_TYPE_F32) * node->ne[0] * n_tasks;

ggml.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ extern "C" {
406406
GGML_OP_DIV,
407407
GGML_OP_SQR,
408408
GGML_OP_SQRT,
409-
GGML_OP_EXP,
410409
GGML_OP_LOG,
411410
GGML_OP_SUM,
412411
GGML_OP_SUM_ROWS,
@@ -440,7 +439,6 @@ extern "C" {
440439
GGML_OP_DIAG_MASK_ZERO,
441440
GGML_OP_SOFT_MAX,
442441
GGML_OP_SOFT_MAX_BACK,
443-
GGML_OP_SOFT_PLUS,
444442
GGML_OP_ROPE,
445443
GGML_OP_ROPE_BACK,
446444
GGML_OP_ALIBI,
@@ -911,14 +909,6 @@ extern "C" {
911909
struct ggml_context * ctx,
912910
struct ggml_tensor * a);
913911

914-
GGML_API struct ggml_tensor * ggml_exp(
915-
struct ggml_context * ctx,
916-
struct ggml_tensor * a);
917-
918-
GGML_API struct ggml_tensor * ggml_exp_inplace(
919-
struct ggml_context * ctx,
920-
struct ggml_tensor * a);
921-
922912
GGML_API struct ggml_tensor * ggml_log(
923913
struct ggml_context * ctx,
924914
struct ggml_tensor * a);
@@ -1403,15 +1393,6 @@ extern "C" {
14031393
struct ggml_tensor * a,
14041394
struct ggml_tensor * b);
14051395

1406-
GGML_API struct ggml_tensor * ggml_soft_plus(
1407-
struct ggml_context * ctx,
1408-
struct ggml_tensor * a);
1409-
1410-
// in-place, returns view(a)
1411-
GGML_API struct ggml_tensor * ggml_soft_plus_inplace(
1412-
struct ggml_context * ctx,
1413-
struct ggml_tensor * a);
1414-
14151396
// rotary position embedding
14161397
// if mode & 1 == 1, skip n_past elements (DEPRECATED)
14171398
// if mode & 2 == 1, GPT-NeoX style

0 commit comments

Comments
 (0)