Skip to content

Commit

Permalink
sync: update ggml
Browse files Browse the repository at this point in the history
  • Loading branch information
leejet committed Aug 27, 2023
1 parent d765b95 commit c8f85a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ggml
Submodule ggml updated 47 files
+2 −0 .gitignore
+3 −3 README.md
+29 −13 build.zig
+1 −0 examples/CMakeLists.txt
+43 −0 examples/common.cpp
+18 −1 examples/common.h
+7 −7 examples/dolly-v2/main.cpp
+7 −7 examples/gpt-2/main.cpp
+8 −8 examples/gpt-j/main.cpp
+7 −7 examples/gpt-neox/main.cpp
+7 −7 examples/mpt/main.cpp
+115 −0 examples/python/README.md
+14 −0 examples/python/api.h
+25 −0 examples/python/example_add_quant.py
+68 −0 examples/python/example_test_all_quants.py
+58 −0 examples/python/ggml/__init__.py
+2,431 −0 examples/python/ggml/__init__.pyi
+11 −0 examples/python/ggml/cffi.py
+7 −0 examples/python/ggml/ffi/__init__.pyi
+182 −0 examples/python/ggml/utils.py
+42 −0 examples/python/regenerate.py
+128 −0 examples/python/stubs.py
+258 −0 examples/python/test_tensor.py
+7 −7 examples/replit/main.cpp
+13 −0 examples/sam/CMakeLists.txt
+89 −0 examples/sam/README.md
+134 −0 examples/sam/convert-pth-to-ggml.py
+2,158 −0 examples/sam/main.cpp
+3 −1 examples/starcoder/convert-hf-to-ggml.py
+7 −7 examples/starcoder/main.cpp
+7,987 −0 examples/stb_image.h
+1,724 −0 examples/stb_image_write.h
+26 −0 include/ggml/ggml-alloc.h
+237 −37 include/ggml/ggml.h
+2 −0 scripts/sync-llama.sh
+5 −1 src/CMakeLists.txt
+579 −0 src/ggml-alloc.c
+1,019 −392 src/ggml-cuda.cu
+19 −23 src/ggml-cuda.h
+9 −3 src/ggml-metal.h
+88 −128 src/ggml-metal.m
+473 −498 src/ggml-metal.metal
+1,871 −372 src/ggml.c
+25 −0 tests/CMakeLists.txt
+175 −0 tests/test-conv-transpose.c
+84 −0 tests/test-rel-pos.c
+87 −0 tests/test-xpos.c
25 changes: 15 additions & 10 deletions stable-diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ void image_vec_to_ggml(const std::vector<uint8_t>& vec,
}
}

struct ggml_tensor * ggml_group_norm_32(struct ggml_context * ctx,
struct ggml_tensor * a) {
return ggml_group_norm(ctx, a, 32);
}

/*================================================== CLIPTokenizer ===================================================*/

const std::string UNK_TOKEN = "<|endoftext|>";
Expand Down Expand Up @@ -899,7 +904,7 @@ struct ResBlock {

// in_layers
// group norm 32
auto h = ggml_group_norm(ctx, x);
auto h = ggml_group_norm_32(ctx, x);
h = ggml_add(ctx,
ggml_mul(ctx,
ggml_repeat(ctx,
Expand Down Expand Up @@ -929,7 +934,7 @@ struct ResBlock {
// out_layers
h = ggml_add(ctx, h, emb_out);
// group norm 32
h = ggml_group_norm_inplace(ctx, h);
h = ggml_group_norm_inplace(ctx, h, 32);
h = ggml_add(ctx,
ggml_mul(ctx, ggml_repeat(ctx, ggml_reshape_4d(ctx, out_layer_0_w, 1, 1, out_layer_0_w->ne[0], 1), h), h),
ggml_repeat(ctx, ggml_reshape_4d(ctx, out_layer_0_b, 1, 1, out_layer_0_b->ne[0], 1), h));
Expand Down Expand Up @@ -1122,7 +1127,7 @@ struct SpatialTransformer {

auto x_in = x;
// group norm 32
x = ggml_group_norm(ctx, x);
x = ggml_group_norm_32(ctx, x);
x = ggml_add(ctx,
ggml_mul(ctx, ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_w, 1, 1, norm_w->ne[0], 1), x), x),
ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_b, 1, 1, norm_b->ne[0], 1), x));
Expand Down Expand Up @@ -1424,7 +1429,7 @@ struct UpSample {

struct ggml_tensor* forward(struct ggml_context* ctx, struct ggml_tensor* x) {
// x: [N, channels, h, w]
x = ggml_upscale(ctx, x); // [N, channels, h*2, w*2]
x = ggml_upscale(ctx, x, 2); // [N, channels, h*2, w*2]
x = ggml_conv_2d(ctx, conv_w, x, 1, 1, 1, 1, 1, 1);

x = ggml_add(ctx,
Expand Down Expand Up @@ -1815,7 +1820,7 @@ struct UNetModel {

// out
// group norm 32
h = ggml_group_norm(ctx, h);
h = ggml_group_norm_32(ctx, h);
h = ggml_add(ctx,
ggml_mul(ctx,
ggml_repeat(ctx,
Expand Down Expand Up @@ -1919,7 +1924,7 @@ struct ResnetBlock {
// z: [N, in_channels, h, w]

// group norm 32
auto h = ggml_group_norm(ctx, z);
auto h = ggml_group_norm_32(ctx, z);
h = ggml_mul(ctx,
ggml_repeat(ctx,
ggml_reshape_4d(ctx, norm1_w, 1, 1, norm1_w->ne[0], 1),
Expand All @@ -1941,7 +1946,7 @@ struct ResnetBlock {
h)); // [N, out_channels, h, w]

// group norm 32
h = ggml_group_norm(ctx, h);
h = ggml_group_norm_32(ctx, h);
h = ggml_add(ctx,
ggml_mul(ctx, ggml_repeat(ctx, ggml_reshape_4d(ctx, norm2_w, 1, 1, norm2_w->ne[0], 1), h), h),
ggml_repeat(ctx, ggml_reshape_4d(ctx, norm2_b, 1, 1, norm2_b->ne[0], 1), h));
Expand Down Expand Up @@ -2028,7 +2033,7 @@ struct AttnBlock {
// x: [N, in_channels, h, w]

// group norm 32
auto h_ = ggml_group_norm(ctx, x);
auto h_ = ggml_group_norm_32(ctx, x);
h_ = ggml_add(ctx,
ggml_mul(ctx, ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_w, 1, 1, norm_w->ne[0], 1), h_), h_),
ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_b, 1, 1, norm_b->ne[0], 1), h_));
Expand Down Expand Up @@ -2253,7 +2258,7 @@ struct Encoder {
h = mid.block_2.forward(ctx, h); // [N, block_in, h, w]

// group norm 32
h = ggml_group_norm(ctx, h);
h = ggml_group_norm_32(ctx, h);
h = ggml_add(ctx,
ggml_mul(ctx, ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_out_w, 1, 1, norm_out_w->ne[0], 1), h), h),
ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_out_b, 1, 1, norm_out_b->ne[0], 1), h));
Expand Down Expand Up @@ -2435,7 +2440,7 @@ struct Decoder {
}

// group norm 32
h = ggml_group_norm(ctx, h);
h = ggml_group_norm_32(ctx, h);
h = ggml_add(ctx,
ggml_mul(ctx, ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_out_w, 1, 1, norm_out_w->ne[0], 1), h), h),
ggml_repeat(ctx, ggml_reshape_4d(ctx, norm_out_b, 1, 1, norm_out_b->ne[0], 1), h));
Expand Down

0 comments on commit c8f85a4

Please sign in to comment.