mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-19 01:04:55 +02:00
qwen4exp: add hc ops (#28901)
This commit is contained in:
+30
-11
@@ -4157,6 +4157,9 @@ struct test_dsv4_hc : public test_case {
|
||||
if (name == "post") {
|
||||
lo = 0.0f; hi = 2.0f; return true;
|
||||
}
|
||||
if (name == "gate") {
|
||||
lo = -4.0f; hi = 4.0f; return true;
|
||||
}
|
||||
if (name == "x" || name == "residual") {
|
||||
lo = -1.0f; hi = 1.0f; return true;
|
||||
}
|
||||
@@ -4221,6 +4224,7 @@ struct test_dsv4_hc_comb : public test_dsv4_hc {
|
||||
struct test_dsv4_hc_pre : public test_dsv4_hc {
|
||||
const int64_t n_embd;
|
||||
const int64_t n_tokens;
|
||||
const bool gated;
|
||||
|
||||
std::string op_desc(ggml_tensor * t) override {
|
||||
GGML_UNUSED(t);
|
||||
@@ -4228,20 +4232,27 @@ struct test_dsv4_hc_pre : public test_dsv4_hc {
|
||||
}
|
||||
|
||||
std::string vars() override {
|
||||
return VARS_TO_STR2(n_embd, n_tokens);
|
||||
return VARS_TO_STR3(n_embd, n_tokens, gated);
|
||||
}
|
||||
|
||||
test_dsv4_hc_pre(int64_t n_embd = 31, int64_t n_tokens = 17)
|
||||
: n_embd(n_embd), n_tokens(n_tokens) {}
|
||||
test_dsv4_hc_pre(int64_t n_embd = 31, int64_t n_tokens = 17, bool gated = false)
|
||||
: n_embd(n_embd), n_tokens(n_tokens), gated(gated) {}
|
||||
|
||||
ggml_tensor * build_graph(ggml_context * ctx) override {
|
||||
ggml_tensor * x = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, n_embd, hc, n_tokens);
|
||||
ggml_set_name(x, "x");
|
||||
|
||||
ggml_tensor * weights = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, hc, n_tokens);
|
||||
ggml_set_name(weights, "weights");
|
||||
if (gated) {
|
||||
ggml_tensor * gate = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, n_embd, hc, n_tokens);
|
||||
ggml_set_name(gate, "gate");
|
||||
|
||||
out = ggml_dsv4_hc_pre(ctx, x, weights);
|
||||
out = ggml_dsv4_hc_pre_gated(ctx, x, gate, 1.0f/hc);
|
||||
} else {
|
||||
ggml_tensor * weights = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, hc, n_tokens);
|
||||
ggml_set_name(weights, "weights");
|
||||
|
||||
out = ggml_dsv4_hc_pre(ctx, x, weights);
|
||||
}
|
||||
ggml_set_name(out, "out");
|
||||
return out;
|
||||
}
|
||||
@@ -4250,6 +4261,7 @@ struct test_dsv4_hc_pre : public test_dsv4_hc {
|
||||
struct test_dsv4_hc_post : public test_dsv4_hc {
|
||||
const int64_t n_embd;
|
||||
const int64_t n_tokens;
|
||||
const bool identity;
|
||||
|
||||
std::string op_desc(ggml_tensor * t) override {
|
||||
GGML_UNUSED(t);
|
||||
@@ -4257,11 +4269,11 @@ struct test_dsv4_hc_post : public test_dsv4_hc {
|
||||
}
|
||||
|
||||
std::string vars() override {
|
||||
return VARS_TO_STR2(n_embd, n_tokens);
|
||||
return VARS_TO_STR3(n_embd, n_tokens, identity);
|
||||
}
|
||||
|
||||
test_dsv4_hc_post(int64_t n_embd = 31, int64_t n_tokens = 17)
|
||||
: n_embd(n_embd), n_tokens(n_tokens) {}
|
||||
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) {}
|
||||
|
||||
ggml_tensor * build_graph(ggml_context * ctx) override {
|
||||
ggml_tensor * x = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n_embd, n_tokens);
|
||||
@@ -4273,8 +4285,11 @@ 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");
|
||||
|
||||
ggml_tensor * comb = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, hc, hc, n_tokens);
|
||||
ggml_set_name(comb, "comb");
|
||||
ggml_tensor * comb = nullptr;
|
||||
if (!identity) {
|
||||
comb = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, hc, hc, n_tokens);
|
||||
ggml_set_name(comb, "comb");
|
||||
}
|
||||
|
||||
out = ggml_dsv4_hc_post(ctx, x, residual, post, comb);
|
||||
ggml_set_name(out, "out");
|
||||
@@ -8960,11 +8975,15 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
|
||||
test_cases.emplace_back(new test_dsv4_hc_pre(31, 17));
|
||||
test_cases.emplace_back(new test_dsv4_hc_pre(128, 257));
|
||||
test_cases.emplace_back(new test_dsv4_hc_pre(4096, 21));
|
||||
test_cases.emplace_back(new test_dsv4_hc_pre(31, 17, true));
|
||||
test_cases.emplace_back(new test_dsv4_hc_pre(4096, 21, true));
|
||||
|
||||
test_cases.emplace_back(new test_dsv4_hc_post(1, 1));
|
||||
test_cases.emplace_back(new test_dsv4_hc_post(31, 17));
|
||||
test_cases.emplace_back(new test_dsv4_hc_post(128, 257));
|
||||
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));
|
||||
|
||||
// glu ops
|
||||
for (ggml_type type : {GGML_TYPE_F16, GGML_TYPE_F32}) {
|
||||
|
||||
Reference in New Issue
Block a user