Skip to content

Commit 2e1bcff

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 48a63e9 commit 2e1bcff

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
@@ -1458,7 +1458,6 @@ inline static void ggml_vec_scale_f32(const int n, float * y, const float v) {
14581458
inline static void ggml_vec_norm_f32 (const int n, float * s, const float * x) { ggml_vec_dot_f32(n, s, x, x); *s = sqrtf(*s); }
14591459
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]; }
14601460
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]); }
1461-
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]); }
14621461
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]); }
14631462
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]); }
14641463
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); }
@@ -1654,7 +1653,6 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
16541653
"DIV",
16551654
"SQR",
16561655
"SQRT",
1657-
"EXP",
16581656
"LOG",
16591657
"SUM",
16601658
"SUM_ROWS",
@@ -1688,7 +1686,6 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
16881686
"DIAG_MASK_ZERO",
16891687
"SOFT_MAX",
16901688
"SOFT_MAX_BACK",
1691-
"SOFT_PLUS",
16921689
"ROPE",
16931690
"ROPE_BACK",
16941691
"ALIBI",
@@ -1729,7 +1726,7 @@ static const char * GGML_OP_NAME[GGML_OP_COUNT] = {
17291726
"CROSS_ENTROPY_LOSS_BACK",
17301727
};
17311728

1732-
static_assert(GGML_OP_COUNT == 75, "GGML_OP_COUNT != 75");
1729+
static_assert(GGML_OP_COUNT == 73, "GGML_OP_COUNT != 73");
17331730

17341731
static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
17351732
"none",
@@ -1743,7 +1740,6 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
17431740
"x/y",
17441741
"x^2",
17451742
"√x",
1746-
"e^x", // or should this be "exp(x)"?
17471743
"log(x)",
17481744
"Σx",
17491745
"Σx_k",
@@ -1777,7 +1773,6 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
17771773
"diag_mask_zero(x)",
17781774
"soft_max(x)",
17791775
"soft_max_back(x)",
1780-
"soft_plus(x)",
17811776
"rope(x)",
17821777
"rope_back(x)",
17831778
"alibi(x)",
@@ -1818,7 +1813,7 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
18181813
"cross_entropy_loss_back(x,y)",
18191814
};
18201815

1821-
static_assert(GGML_OP_COUNT == 75, "GGML_OP_COUNT != 75");
1816+
static_assert(GGML_OP_COUNT == 73, "GGML_OP_COUNT != 73");
18221817

18231818
static_assert(GGML_OP_POOL_COUNT == 2, "GGML_OP_POOL_COUNT != 2");
18241819

@@ -3630,39 +3625,6 @@ struct ggml_tensor * ggml_sqrt_inplace(
36303625
return ggml_sqrt_impl(ctx, a, true);
36313626
}
36323627

3633-
// ggml_exp
3634-
3635-
static struct ggml_tensor * ggml_exp_impl(
3636-
struct ggml_context * ctx,
3637-
struct ggml_tensor * a,
3638-
bool inplace) {
3639-
bool is_node = false;
3640-
3641-
if (!inplace && (a->grad)) {
3642-
is_node = true;
3643-
}
3644-
3645-
struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
3646-
3647-
result->op = GGML_OP_EXP;
3648-
result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL;
3649-
result->src[0] = a;
3650-
3651-
return result;
3652-
}
3653-
3654-
struct ggml_tensor * ggml_exp(
3655-
struct ggml_context * ctx,
3656-
struct ggml_tensor * a) {
3657-
return ggml_exp_impl(ctx, a, false);
3658-
}
3659-
3660-
struct ggml_tensor * ggml_exp_inplace(
3661-
struct ggml_context * ctx,
3662-
struct ggml_tensor * a) {
3663-
return ggml_exp_impl(ctx, a, true);
3664-
}
3665-
36663628
// ggml_log
36673629

36683630
static struct ggml_tensor * ggml_log_impl(
@@ -5143,40 +5105,6 @@ struct ggml_tensor * ggml_soft_max_back_inplace(
51435105
return ggml_soft_max_back_impl(ctx, a, b, true);
51445106
}
51455107

5146-
// ggml_soft_plus
5147-
5148-
static struct ggml_tensor * ggml_soft_plus_impl(
5149-
struct ggml_context * ctx,
5150-
struct ggml_tensor * a,
5151-
bool inplace) {
5152-
5153-
bool is_node = false;
5154-
5155-
if (a->grad) {
5156-
is_node = true; // TODO : implement backward pass
5157-
}
5158-
5159-
struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
5160-
5161-
result->op = GGML_OP_SOFT_PLUS;
5162-
result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL;
5163-
result->src[0] = a;
5164-
5165-
return result;
5166-
}
5167-
5168-
struct ggml_tensor * ggml_soft_plus(
5169-
struct ggml_context * ctx,
5170-
struct ggml_tensor * a) {
5171-
return ggml_soft_plus_impl(ctx, a, false);
5172-
}
5173-
5174-
struct ggml_tensor * ggml_soft_plus_inplace(
5175-
struct ggml_context * ctx,
5176-
struct ggml_tensor * a) {
5177-
return ggml_soft_plus_impl(ctx, a, true);
5178-
}
5179-
51805108
// ggml_rope
51815109

51825110
static struct ggml_tensor * ggml_rope_impl(
@@ -8458,57 +8386,6 @@ static void ggml_compute_forward_sqrt(
84588386
}
84598387
}
84608388

8461-
// ggml_compute_forward_exp
8462-
8463-
static void ggml_compute_forward_exp_f32(
8464-
const struct ggml_compute_params * params,
8465-
const struct ggml_tensor * src0,
8466-
struct ggml_tensor * dst) {
8467-
GGML_ASSERT(ggml_is_contiguous_except_dim_1(src0));
8468-
GGML_ASSERT(ggml_is_contiguous_except_dim_1(dst));
8469-
GGML_ASSERT(ggml_are_same_shape(src0, dst));
8470-
8471-
if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
8472-
return;
8473-
}
8474-
8475-
const int ith = params->ith;
8476-
const int nth = params->nth;
8477-
8478-
const int nc = src0->ne[0];
8479-
const int nr = ggml_nrows(src0);
8480-
8481-
// rows per thread
8482-
const int dr = (nr + nth - 1)/nth;
8483-
8484-
// row range for this thread
8485-
const int ir0 = dr*ith;
8486-
const int ir1 = MIN(ir0 + dr, nr);
8487-
8488-
for (int i1 = ir0; i1 < ir1; i1++) {
8489-
ggml_vec_exp_f32(nc,
8490-
(float *) ((char *) dst->data + i1*( dst->nb[1])),
8491-
(float *) ((char *) src0->data + i1*(src0->nb[1])));
8492-
};
8493-
}
8494-
8495-
static void ggml_compute_forward_exp(
8496-
const struct ggml_compute_params * params,
8497-
const struct ggml_tensor * src0,
8498-
struct ggml_tensor * dst) {
8499-
switch (src0->type) {
8500-
case GGML_TYPE_F32:
8501-
{
8502-
ggml_compute_forward_exp_f32(params, src0, dst);
8503-
} break;
8504-
case GGML_TYPE_F16: // TODO: use ggml_table_exp_f16
8505-
default:
8506-
{
8507-
GGML_ASSERT(false);
8508-
} break;
8509-
}
8510-
}
8511-
85128389
// ggml_compute_forward_log
85138390

85148391
static void ggml_compute_forward_log_f32(
@@ -11771,48 +11648,6 @@ static void ggml_compute_forward_soft_max_back(
1177111648
}
1177211649
}
1177311650

11774-
static void ggml_compute_forward_soft_plus_f32(
11775-
const struct ggml_compute_params * params,
11776-
const struct ggml_tensor * src0,
11777-
struct ggml_tensor * dst) {
11778-
GGML_ASSERT(params->ith == 0);
11779-
GGML_ASSERT(ggml_are_same_shape(src0, dst));
11780-
11781-
if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
11782-
return;
11783-
}
11784-
11785-
const int nc = src0->ne[0];
11786-
const int nr = ggml_nrows(src0);
11787-
11788-
GGML_ASSERT( dst->nb[0] == sizeof(float));
11789-
GGML_ASSERT(src0->nb[0] == sizeof(float));
11790-
11791-
for (int i = 0; i < nr; ++i) {
11792-
float * x = (float *) ((char *) dst->data + i*( dst->nb[1]));
11793-
float * y = (float *) ((char *) src0->data + i*(src0->nb[1]));
11794-
for (int j = 0; j < nc; ++j) {
11795-
x[j] = logf(1.0f + expf(y[j]));
11796-
}
11797-
}
11798-
}
11799-
11800-
static void ggml_compute_forward_soft_plus(
11801-
const struct ggml_compute_params * params,
11802-
const struct ggml_tensor * src0,
11803-
struct ggml_tensor * dst) {
11804-
switch (src0->type) {
11805-
case GGML_TYPE_F32:
11806-
{
11807-
ggml_compute_forward_soft_plus_f32(params, src0, dst);
11808-
} break;
11809-
default:
11810-
{
11811-
GGML_ASSERT(false);
11812-
} break;
11813-
}
11814-
}
11815-
1181611651
// ggml_compute_forward_alibi
1181711652

1181811653
static void ggml_compute_forward_alibi_f32(
@@ -15220,10 +15055,6 @@ static void ggml_compute_forward(struct ggml_compute_params * params, struct ggm
1522015055
{
1522115056
ggml_compute_forward_sqrt(params, tensor->src[0], tensor);
1522215057
} break;
15223-
case GGML_OP_EXP:
15224-
{
15225-
ggml_compute_forward_exp(params, tensor->src[0], tensor);
15226-
} break;
1522715058
case GGML_OP_LOG:
1522815059
{
1522915060
ggml_compute_forward_log(params, tensor->src[0], tensor);
@@ -15348,10 +15179,6 @@ static void ggml_compute_forward(struct ggml_compute_params * params, struct ggm
1534815179
{
1534915180
ggml_compute_forward_soft_max_back(params, tensor->src[0], tensor->src[1], tensor);
1535015181
} break;
15351-
case GGML_OP_SOFT_PLUS:
15352-
{
15353-
ggml_compute_forward_soft_plus(params, tensor->src[0], tensor);
15354-
} break;
1535515182
case GGML_OP_ROPE:
1535615183
{
1535715184
ggml_compute_forward_rope(params, tensor->src[0], tensor->src[1], tensor);
@@ -15908,10 +15735,6 @@ static void ggml_compute_backward(struct ggml_context * ctx, struct ggml_tensor
1590815735
zero_table);
1590915736
}
1591015737
} break;
15911-
case GGML_OP_EXP:
15912-
{
15913-
GGML_ASSERT(false); // TODO: implement
15914-
} break;
1591515738
case GGML_OP_LOG:
1591615739
{
1591715740
if (src0->grad) {
@@ -16290,10 +16113,6 @@ static void ggml_compute_backward(struct ggml_context * ctx, struct ggml_tensor
1629016113
{
1629116114
GGML_ASSERT(false); // TODO: not implemented
1629216115
} break;
16293-
case GGML_OP_SOFT_PLUS:
16294-
{
16295-
GGML_ASSERT(false); // TODO: not implemented
16296-
} break;
1629716116
case GGML_OP_ROPE:
1629816117
{
1629916118
// necessary for llama
@@ -17015,7 +16834,6 @@ static int ggml_get_n_tasks(struct ggml_tensor * node, int n_threads) {
1701516834
case GGML_OP_ADD:
1701616835
case GGML_OP_ADD1:
1701716836
case GGML_OP_ACC:
17018-
case GGML_OP_EXP:
1701916837
{
1702016838
n_tasks = n_threads;
1702116839
} break;
@@ -17122,10 +16940,6 @@ static int ggml_get_n_tasks(struct ggml_tensor * node, int n_threads) {
1712216940
{
1712316941
n_tasks = MIN(n_threads, ggml_nrows(node->src[0]));
1712416942
} break;
17125-
case GGML_OP_SOFT_PLUS:
17126-
{
17127-
n_tasks = 1; //TODO
17128-
} break;
1712916943
case GGML_OP_CONV_TRANSPOSE_1D:
1713016944
{
1713116945
n_tasks = n_threads;
@@ -17499,7 +17313,6 @@ struct ggml_cplan ggml_graph_plan(const struct ggml_cgraph * cgraph, int n_threa
1749917313
}
1750017314
} break;
1750117315
case GGML_OP_SOFT_MAX:
17502-
case GGML_OP_SOFT_PLUS:
1750317316
case GGML_OP_ROPE:
1750417317
{
1750517318
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,
@@ -900,14 +898,6 @@ extern "C" {
900898
struct ggml_context * ctx,
901899
struct ggml_tensor * a);
902900

903-
GGML_API struct ggml_tensor * ggml_exp(
904-
struct ggml_context * ctx,
905-
struct ggml_tensor * a);
906-
907-
GGML_API struct ggml_tensor * ggml_exp_inplace(
908-
struct ggml_context * ctx,
909-
struct ggml_tensor * a);
910-
911901
GGML_API struct ggml_tensor * ggml_log(
912902
struct ggml_context * ctx,
913903
struct ggml_tensor * a);
@@ -1392,15 +1382,6 @@ extern "C" {
13921382
struct ggml_tensor * a,
13931383
struct ggml_tensor * b);
13941384

1395-
GGML_API struct ggml_tensor * ggml_soft_plus(
1396-
struct ggml_context * ctx,
1397-
struct ggml_tensor * a);
1398-
1399-
// in-place, returns view(a)
1400-
GGML_API struct ggml_tensor * ggml_soft_plus_inplace(
1401-
struct ggml_context * ctx,
1402-
struct ggml_tensor * a);
1403-
14041385
// rotary position embedding
14051386
// if mode & 1 == 1, skip n_past elements (DEPRECATED)
14061387
// if mode & 2 == 1, GPT-NeoX style

0 commit comments

Comments
 (0)