Repository: ggml-org/llama.cpp
Pull request: reset glmedge chat template

*Make sure to read the [contributing guidelines](https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md) before submitting a PR*


Hi, @ngxson,I’d like to know why the glmedge model needs to be added [gMASK]<sop>. I tried using the code below, and through testing, I found that the edge model does not exist. I think we shouldn’t add it, right? 

````
from transformers import AutoModelForCausalLM, AutoTokenizer

MODEL_PATH = "<path>"

tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto")

message = [{"role": "user", "content": "hello!"}]

inputs = tokenizer.apply_chat_template(
    message,
    return_tensors="pt",
    add_generation_prompt=True,
    return_dict=True,
).to(model.device)
print(tokenizer.decode(inputs["input_ids"][0],skip_special_tokens=False))
````

the output is 
![image](https://github.com/user-attachments/assets/c71300cd-15d3-4e3f-a59e-412a8b405ced)

Also, what are the poor performance issues that arise from this?


Changed files:
filename: src/llama-chat.cpp
patch: @@ -447,7 +447,7 @@ int32_t llm_chat_apply_template(
         if (add_ass) {
             ss << "
";
         }
-    } else if (tmpl == LLM_CHAT_TEMPLATE_CHATGLM_4 || tmpl == LLM_CHAT_TEMPLATE_GLMEDGE) {
+    } else if (tmpl == LLM_CHAT_TEMPLATE_CHATGLM_4) {
         ss << "[gMASK]" << "<sop>";
         for (auto message : chat) {
             std::string role(message->role);
@@ -456,6 +456,14 @@ int32_t llm_chat_apply_template(
         if (add_ass) {
             ss << "
\n";
         }
+    } else if (tmpl == LLM_CHAT_TEMPLATE_GLMEDGE) {
+        for (auto message : chat) {
+            std::string role(message->role);
+            ss << "<|" << role << "|>" << "\n" << message->content;
+        }
+        if (add_ass) {
+            ss << "
";
+        }
     } else if (tmpl == LLM_CHAT_TEMPLATE_MINICPM) {
         // MiniCPM-3B-OpenHermes-2.5-v2-GGUF
         for (auto message : chat) {

filename: tests/test-chat-template.cpp
patch: @@ -187,15 +187,14 @@ int main(void) {
             /* .bos_token= */ "",
             /* .eos_token= */ "",
         },
-        // TODO @ngxson : GLMEdge produces poor result without `[gMASK]<sop>`, so we're temporarily using GLM4 template for it. We should fix this in the future.
-        // {
-        //     /* .name= */ "GLMEdge",
-        //     /* .template_str= */ "{% for item in messages %}{% if item['role'] == 'system' %}
\n{{ item['content'] }}{% elif item['role'] == 'user' %}
\n{{ item['content'] }}{% elif item['role'] == 'assistant' %}
\n{{ item['content'] }}{% endif %}{% endfor %}
",
-        //     /* .expected_output= */ "
\nYou are a helpful assistant
\nHello
\nHi there
\nWho are you
\n   I am an assistant   
\nAnother question
",
-        //     /* .expected_output_jinja= */ "
\nYou are a helpful assistant
\nHello
\nHi there
\nWho are you
\n   I am an assistant   
\nAnother question
",
-        //     /* .bos_token= */ "",
-        //     /* .eos_token= */ "",
-        // },
+        {
+            /* .name= */ "GLMEdge",
+            /* .template_str= */ "{% for item in messages %}{% if item['role'] == 'system' %}
\n{{ item['content'] }}{% elif item['role'] == 'user' %}
\n{{ item['content'] }}{% elif item['role'] == 'assistant' %}
\n{{ item['content'] }}{% endif %}{% endfor %}
",
+            /* .expected_output= */ "
\nYou are a helpful assistant
\nHello
\nHi there
\nWho are you
\n   I am an assistant   
\nAnother question
",
+            /* .expected_output_jinja= */ "
\nYou are a helpful assistant
\nHello
\nHi there
\nWho are you
\n   I am an assistant   
\nAnother question
",
+            /* .bos_token= */ "",
+            /* .eos_token= */ "",
+        },
         {
             /* .name= */ "MiniCPM-3B-OpenHermes-2.5-v2-GGUF",
             /* .template_str= */ U8C("{% for message in messages %}{% if message['role'] == 'user' %}{{'<用户>' + message['content'].strip() + '<AI>'}}{% else %}{{message['content'].strip()}}{% endif %}{% endfor %}"),