Skip to content

Commit ed37498

Browse files
committed
fix: set eps of ggml_norm(LayerNorm) to 1e-5
1 parent 4c96185 commit ed37498

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

stable-diffusion.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "rng_philox.h"
1919
#include "stable-diffusion.h"
2020

21+
#define EPS 1e-05
22+
2123
static SDLogLevel log_level = SDLogLevel::INFO;
2224

2325
#define __FILENAME__ "stable-diffusion.cpp"
@@ -586,7 +588,7 @@ struct ResidualAttentionBlock {
586588

587589
// layer norm 1
588590
{
589-
x = ggml_norm(ctx, x, 1e-6f);
591+
x = ggml_norm(ctx, x, EPS);
590592
x = ggml_add(ctx,
591593
ggml_mul(ctx, ggml_repeat(ctx, ln1_w, x), x),
592594
ggml_repeat(ctx, ln1_b, x));
@@ -636,7 +638,7 @@ struct ResidualAttentionBlock {
636638

637639
// layer norm 2
638640
{
639-
x = ggml_norm(ctx, x, 1e-6f);
641+
x = ggml_norm(ctx, x, EPS);
640642

641643
x = ggml_add(ctx, ggml_mul(ctx, ggml_repeat(ctx, ln2_w, x), x),
642644
ggml_repeat(ctx, ln2_b, x));
@@ -766,7 +768,7 @@ struct CLIPTextModel {
766768

767769
// final layer norm
768770
{
769-
x = ggml_norm(ctx, x, 1e-6f);
771+
x = ggml_norm(ctx, x, EPS);
770772

771773
x = ggml_add(ctx, ggml_mul(ctx, ggml_repeat(ctx, final_ln_w, x), x),
772774
ggml_repeat(ctx, final_ln_b, x));
@@ -1200,7 +1202,7 @@ struct SpatialTransformer {
12001202
// layer norm 1
12011203
{
12021204
x = ggml_reshape_2d(ctx, x, c, w * h * n);
1203-
x = ggml_norm(ctx, x, 1e-6f);
1205+
x = ggml_norm(ctx, x, EPS);
12041206
x = ggml_add(ctx,
12051207
ggml_mul(ctx,
12061208
ggml_repeat(ctx, transformer.norm1_w, x),
@@ -1248,7 +1250,7 @@ struct SpatialTransformer {
12481250

12491251
// layer norm 2
12501252
{
1251-
x = ggml_norm(ctx, x, 1e-6f);
1253+
x = ggml_norm(ctx, x, EPS);
12521254
x = ggml_add(ctx,
12531255
ggml_mul(ctx,
12541256
ggml_repeat(ctx, transformer.norm2_w, x), x),
@@ -1299,7 +1301,7 @@ struct SpatialTransformer {
12991301
// layer norm 3
13001302
{
13011303
x = ggml_reshape_2d(ctx, x, c, h * w * n); // [N * h * w, in_channels]
1302-
x = ggml_norm(ctx, x, 1e-6f);
1304+
x = ggml_norm(ctx, x, EPS);
13031305
x = ggml_add(ctx,
13041306
ggml_mul(ctx,
13051307
ggml_repeat(ctx, transformer.norm3_w, x), x),

0 commit comments

Comments
 (0)