Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions chatglm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,7 @@ int BaseModelForConditionalGeneration::generate_next_token(const std::vector<int

ggml_build_forward_expand(&ctx_.gf, lm_logits);
#ifdef GGML_USE_METAL
if (input_ids.size() == 1) {
ggml_metal_graph_compute(ctx_.ctx_metal.get(), &ctx_.gf);
} else {
ggml_graph_compute_helper(ctx_.work_buffer, &ctx_.gf, n_threads);
}
ggml_metal_graph_compute(ctx_.ctx_metal.get(), &ctx_.gf);
#else
ggml_graph_compute_helper(ctx_.work_buffer, &ctx_.gf, n_threads);
#endif
Expand Down Expand Up @@ -1190,6 +1186,11 @@ ggml_tensor *GLM2MLP::forward(ModelContext *ctx, ggml_tensor *hidden_states) con
#ifdef GGML_USE_CUBLAS
x0 = ggml_cont(gctx, x0);
tensor_assign_buffers(x0);
#elif defined(GGML_USE_METAL)
if (x0->ne[1] > 1) {
x0 = ggml_cont(gctx, x0);
tensor_assign_buffers(x0);
}
#endif
x0 = ggml_silu_inplace(gctx, x0);
tensor_assign_buffers(x0);
Expand All @@ -1199,6 +1200,11 @@ ggml_tensor *GLM2MLP::forward(ModelContext *ctx, ggml_tensor *hidden_states) con
#ifdef GGML_USE_CUBLAS
x1 = ggml_cont(gctx, x1);
tensor_assign_buffers(x1);
#elif defined(GGML_USE_METAL)
if (x1->ne[1] > 1) {
x1 = ggml_cont(gctx, x1);
tensor_assign_buffers(x1);
}
#endif

output = ggml_mul_inplace(gctx, x0, x1);
Expand Down
4 changes: 2 additions & 2 deletions chatglm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ TEST_F(ChatGLMTest, GLM2Block) {
EXPECT_EQ(out_y1->backend, x1->backend);
out_y1->backend = GGML_BACKEND_CPU;
ggml_build_forward_expand(&ctx.gf, out_y1);
cpu_graph_compute(get_num_threads());
device_graph_compute(get_num_threads());

expect_all_close(ref_y1, out_y1, eps);
}
Expand Down Expand Up @@ -759,7 +759,7 @@ TEST_F(ChatGLMTest, BenchmarkGLM2Block) {
ggml_tensor *self_attn_y = model.forward(&ctx, self_attn_x, 0);
ggml_build_forward_expand(&ctx.gf, self_attn_y);
std::cout << "[Benchmark] GLM2Block " << ggml_type_name(dtype)
<< " self attn time: " << perf_cpu_graph_compute() << " ms\n";
<< " self attn time: " << perf_device_graph_compute() << " ms\n";
}

// cross attention
Expand Down
2 changes: 1 addition & 1 deletion third_party/ggml
Submodule ggml updated from 244776 to 6319ae