vulkan: fuse qwen4exp's SCALE -> SIGMOID -> SCALE -> hc_post chain (#29520)

This commit is contained in:
François-Xavier Gsell authored and GitHub committed 2026-09-28 14:20:14 +02:00
1 parent c2a9e16068
commit 03a667aa30
6 files changed
+79 -11

No files matched your search

+14 -3
View File
@@ -4342,6 +4342,7 @@ struct test_dsv4_hc_post : public test_dsv4_hc {
const int64_t n_embd;
const int64_t n_tokens;
const bool identity;
const bool gated;
std::string op_desc(ggml_tensor * t) override {
GGML_UNUSED(t);
@@ -4349,11 +4350,14 @@ struct test_dsv4_hc_post : public test_dsv4_hc {
}
std::string vars() override {
return VARS_TO_STR3(n_embd, n_tokens, identity);
return VARS_TO_STR4(n_embd, n_tokens, identity, gated);
}
test_dsv4_hc_post(int64_t n_embd = 31, int64_t n_tokens = 17, bool identity = false)
: n_embd(n_embd), n_tokens(n_tokens), identity(identity) {}
// gated: post = 2*sigmoid(post/hc), as qwen4exp builds it, so backends can fuse the chain
bool run_whole_graph() override { return gated; }
test_dsv4_hc_post(int64_t n_embd = 31, int64_t n_tokens = 17, bool identity = false, bool gated = false)
: n_embd(n_embd), n_tokens(n_tokens), identity(identity), gated(gated) {}
ggml_tensor * build_graph(ggml_context * ctx) override {
ggml_tensor * x = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n_embd, n_tokens);
@@ -4365,6 +4369,10 @@ struct test_dsv4_hc_post : public test_dsv4_hc {
ggml_tensor * post = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, hc, n_tokens);
ggml_set_name(post, "post");
if (gated) {
post = ggml_scale(ctx, ggml_sigmoid(ctx, ggml_scale(ctx, post, 1.0f / (float) hc)), 2.0f);
}
ggml_tensor * comb = nullptr;
if (!identity) {
comb = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, hc, hc, n_tokens);
@@ -9198,6 +9206,9 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
test_cases.emplace_back(new test_dsv4_hc_post(4096, 21));
test_cases.emplace_back(new test_dsv4_hc_post(31, 17, true));
test_cases.emplace_back(new test_dsv4_hc_post(4096, 21, true));
test_cases.emplace_back(new test_dsv4_hc_post(31, 17, true, true));
test_cases.emplace_back(new test_dsv4_hc_post(2560, 21, true, true));
test_cases.emplace_back(new test_dsv4_hc_post(31, 17, false, true));
// glu ops
for (ggml_type type : {GGML_TYPE_F16, GGML_TYPE_F32}) {