Skip to content

Commit 78af3e9

Browse files
committed
ggml : fix compiler warnings + cosmetic changes
1 parent 0d72207 commit 78af3e9

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

examples/baby-llama/baby-llama.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ int main(int argc, char ** argv) {
12801280
}
12811281

12821282
{
1283-
int n_gen = 1200000000;
1283+
int n_gen = 128;
12841284
int sample_ctx = n_tokens-n_tokens/8;
12851285

12861286
printf("Generating %d tokens.\n", n_gen);

ggml.c

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,7 @@ inline static void ggml_vec_scale_f32(const int n, float * y, const float v) {
39363936
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); }
39373937
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]; }
39383938
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]); }
3939-
inline static void ggml_vec_log_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = log(x[i]); }
3939+
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]); }
39403940
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]); }
39413941
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); }
39423942
inline static void ggml_vec_step_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = (x[i] > 0.f) ? 1.f : 0.f; }
@@ -4009,7 +4009,6 @@ inline static float ggml_silu_backward_f32(float x, float dy) {
40094009

40104010
#ifdef GGML_SILU_FP16
40114011
inline static void ggml_vec_silu_backward_f32(const int n, float * dx, const float * x, const float * dy) {
4012-
uint16_t t;
40134012
for (int i = 0; i < n; ++i) {
40144013
// we did not use x[i] to compute forward silu but its f16 equivalent
40154014
// take derivative at f16 of x[i]:
@@ -6841,7 +6840,7 @@ struct ggml_tensor * ggml_rope(
68416840
int n_dims,
68426841
int mode) {
68436842
return ggml_rope_impl(ctx, a, n_past, n_dims, mode, false);
6844-
};
6843+
}
68456844

68466845
struct ggml_tensor * ggml_rope_inplace(
68476846
struct ggml_context * ctx,
@@ -6850,7 +6849,7 @@ struct ggml_tensor * ggml_rope_inplace(
68506849
int n_dims,
68516850
int mode) {
68526851
return ggml_rope_impl(ctx, a, n_past, n_dims, mode, true);
6853-
};
6852+
}
68546853

68556854
// ggml_rope_back
68566855

@@ -8003,7 +8002,7 @@ static void ggml_compute_forward_add_q_f32(
80038002
const int64_t ne00 = src0->ne[0];
80048003
const int64_t ne01 = src0->ne[1];
80058004
const int64_t ne02 = src0->ne[2];
8006-
const int64_t ne03 = src0->ne[3];
8005+
//const int64_t ne03 = src0->ne[3];
80078006

80088007
const size_t nb00 = src0->nb[0];
80098008
const size_t nb01 = src0->nb[1];
@@ -8028,7 +8027,7 @@ static void ggml_compute_forward_add_q_f32(
80288027
quantize_row_q_t const quantize_row_q = quantize_fns[type].quantize_row_q;
80298028

80308029
// we don't support permuted src0 or src1
8031-
GGML_ASSERT(nb00 == (int) GGML_TYPE_SIZE[type]);
8030+
GGML_ASSERT(nb00 == GGML_TYPE_SIZE[type]);
80328031
GGML_ASSERT(nb10 == sizeof(float));
80338032

80348033
// dst cannot be transposed or permuted
@@ -8131,9 +8130,6 @@ static void ggml_compute_forward_add1_f32(
81318130
return;
81328131
}
81338132

8134-
// scalar to add
8135-
const float v = *(float *) src1->data;
8136-
81378133
const int ith = params->ith;
81388134
const int nth = params->nth;
81398135

@@ -8147,11 +8143,6 @@ static void ggml_compute_forward_add1_f32(
81478143
const size_t nb02 = src0->nb[2];
81488144
const size_t nb03 = src0->nb[3];
81498145

8150-
const size_t nb10 = src1->nb[0];
8151-
const size_t nb11 = src1->nb[1];
8152-
const size_t nb12 = src1->nb[2];
8153-
const size_t nb13 = src1->nb[3];
8154-
81558146
const size_t nb0 = dst->nb[0];
81568147
const size_t nb1 = dst->nb[1];
81578148
const size_t nb2 = dst->nb[2];
@@ -8177,13 +8168,13 @@ static void ggml_compute_forward_add1_f32(
81778168
vDSP_vadd(
81788169
(float *) ((char *) src0->data + i3*nb03 + i2*nb02 + i1*nb01), 1,
81798170
(float *) ((char *) src1->data), 0,
8180-
(float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 ), 1,
8171+
(float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 ), 1,
81818172
ne0);
81828173
#else
81838174
ggml_vec_add1_f32(ne0,
81848175
(float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 ),
81858176
(float *) ((char *) src0->data + i3*nb03 + i2*nb02 + i1*nb01),
8186-
v);
8177+
*(float *) src1->data);
81878178
#endif
81888179
}
81898180
}
@@ -8348,7 +8339,7 @@ static void ggml_compute_forward_add1_q_f32(
83488339
quantize_row_q_t const quantize_row_q = quantize_fns[type].quantize_row_q;
83498340

83508341
// we don't support permuted src0
8351-
GGML_ASSERT(nb00 == (int) GGML_TYPE_SIZE[type]);
8342+
GGML_ASSERT(nb00 == GGML_TYPE_SIZE[type]);
83528343

83538344
// dst cannot be transposed or permuted
83548345
GGML_ASSERT(nb0 <= nb1);
@@ -8510,7 +8501,7 @@ static void ggml_compute_forward_acc_f32(
85108501
vDSP_vadd(
85118502
(float *) ((char *) src0->data + i3*nb03 + i2*nb02 + i1*nb01 + offset), 1,
85128503
(float *) ((char *) src1->data + i3*nb13 + i2*nb12 + i1*nb11), 1,
8513-
(float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 + offset), 1, nc);
8504+
(float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 + offset), 1, nc);
85148505
#else
85158506
ggml_vec_add_f32(nc,
85168507
(float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 + offset),
@@ -9825,28 +9816,30 @@ static void ggml_compute_forward_rms_norm_back_f32(
98259816
for (int64_t i02 = 0; i02 < ne02; i02++) {
98269817
for (int64_t i01 = ith; i01 < ne01; i01 += nth) {
98279818
// src1 is same shape as src0 => same indices
9828-
const auto i11 = i01;
9829-
const auto i12 = i02;
9830-
const auto i13 = i03;
9819+
const int64_t i11 = i01;
9820+
const int64_t i12 = i02;
9821+
const int64_t i13 = i03;
9822+
98319823
const float * x = (float *) ((char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03);
98329824
const float * dz = (float *) ((char *) src1->data + i11*nb11 + i12*nb12 + i13*nb13);
98339825

9834-
ggml_float sum_xx = 0.0;
9826+
ggml_float sum_xx = 0.0;
98359827
ggml_float sum_xdz = 0.0;
9828+
98369829
for (int64_t i00 = 0; i00 < ne00; i00++) {
9837-
sum_xx += (ggml_float)(x[i00] * x[i00]);
9830+
sum_xx += (ggml_float)(x[i00] * x[i00]);
98389831
sum_xdz += (ggml_float)(x[i00] * dz[i00]);
98399832
}
98409833

9841-
const float mean = sum_xx/ne00;
9834+
const float mean = sum_xx/ne00;
98429835
const float mean_eps = sum_xx/ne00 + eps;
9843-
const float sum_eps = sum_xx + eps*ne00;
9836+
const float sum_eps = sum_xx + eps*ne00;
98449837
const float mean_xdz = sum_xdz/ne00;
98459838
// we could cache rms from forward pass to improve performance.
98469839
// to do this implement ggml_rms and compose ggml_rms_norm using ggml_rms.
9847-
const float rms = sqrtf(mean_eps);
9848-
const float rrms = 1.0f / sqrtf(mean_eps);
9849-
const float scale = -rrms/(ne00 * mean_eps); // -1/(n*rms**3)
9840+
const float rms = sqrtf(mean_eps);
9841+
const float rrms = 1.0f / sqrtf(mean_eps);
9842+
const float scale = -rrms/(ne00 * mean_eps); // -1/(n*rms**3)
98509843

98519844
{
98529845
// z = rms_norm(x)
@@ -10760,11 +10753,6 @@ static void ggml_compute_forward_set_f32(
1076010753
// src0 and dst as viewed during set
1076110754
const size_t nb0 = ggml_element_size(src0);
1076210755

10763-
const size_t nb00 = nb0;
10764-
const size_t nb01 = nb1;
10765-
const size_t nb02 = nb2;
10766-
const size_t nb03 = nb3;
10767-
1076810756
const int im0 = (ne10 == 0 ? 0 : ne10-1);
1076910757
const int im1 = (ne11 == 0 ? 0 : ne11-1);
1077010758
const int im2 = (ne12 == 0 ? 0 : ne12-1);
@@ -11154,7 +11142,7 @@ static void ggml_compute_forward_diag_f32(
1115411142
GGML_ASSERT(ne03 == ne3);
1115511143

1115611144
const int nb00 = src0->nb[0];
11157-
const int nb01 = src0->nb[1];
11145+
//const int nb01 = src0->nb[1];
1115811146
const int nb02 = src0->nb[2];
1115911147
const int nb03 = src0->nb[3];
1116011148
const int nb0 = dst->nb[0];

0 commit comments

Comments
 (0)