Text Generation
Transformers
Safetensors
English
Chinese
glm_moe_dsa
conversational
Eval Results
fp8
Instructions to use zai-org/GLM-5.3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/GLM-5.3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="zai-org/GLM-5.3") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("zai-org/GLM-5.3") model = AutoModelForCausalLM.from_pretrained("zai-org/GLM-5.3", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use zai-org/GLM-5.3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "zai-org/GLM-5.3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/GLM-5.3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/zai-org/GLM-5.3
- SGLang
How to use zai-org/GLM-5.3 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "zai-org/GLM-5.3" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/GLM-5.3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "zai-org/GLM-5.3" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/GLM-5.3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use zai-org/GLM-5.3 with Docker Model Runner:
docker model run hf.co/zai-org/GLM-5.3
Make the chat template work in llama.cpp and add a response template
#34
by Rocketknight1 HF Staff - opened
- chat_template.jinja +16 -6
- tokenizer_config.json +48 -1
chat_template.jinja
CHANGED
|
@@ -72,11 +72,11 @@ For each function call, output the function name and arguments within the follow
|
|
| 72 |
{%- macro render_tool_response(m) -%}
|
| 73 |
{%- if m.content is string -%}
|
| 74 |
{{- tool_response(m.content) -}}
|
| 75 |
-
{%- elif m.content and m.content is not mapping and m.content
|
| 76 |
{{- tool_references_to_response(m.content) -}}
|
| 77 |
{%- elif is_list_of_outputs(m) -%}
|
| 78 |
{%- for tr in m.content -%}
|
| 79 |
-
{%- if tr.output is iterable and tr.output is not string and tr.output is not mapping and tr.output and tr.output
|
| 80 |
{{- tool_references_to_response(tr.output) -}}
|
| 81 |
{%- else -%}
|
| 82 |
{{- tool_response(visible_text(tr.output)) -}}
|
|
@@ -94,7 +94,7 @@ For each function call, output the function name and arguments within the follow
|
|
| 94 |
{%- endif -%}
|
| 95 |
{%- endmacro -%}
|
| 96 |
{%- macro is_list_of_outputs(m) -%}
|
| 97 |
-
{%- if m.content and m.content
|
| 98 |
{%- endmacro -%}
|
| 99 |
{%- macro has_dup_tool_result_id(lo, hi, target) -%}
|
| 100 |
{%- set ns_cnt = namespace(n=0) -%}
|
|
@@ -123,6 +123,16 @@ For each function call, output the function name and arguments within the follow
|
|
| 123 |
{%- endfor -%}
|
| 124 |
{%- if ns_f.found -%}1{%- endif -%}
|
| 125 |
{%- endmacro -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
{%- set ns = namespace(last_user_index=-1) -%}
|
| 127 |
{%- for m in messages %}
|
| 128 |
{%- if m.role == 'user' %}
|
|
@@ -195,9 +205,9 @@ For each function call, output the function name and arguments within the follow
|
|
| 195 |
{%- endfor -%}
|
| 196 |
{%- if '' in ns_chk.res or '' in ns_chk.tcs -%}
|
| 197 |
{%- set ns_chk.can_sort = false -%}
|
| 198 |
-
{%- elif ns_chk.res
|
| 199 |
{%- set ns_chk.can_sort = false -%}
|
| 200 |
-
{%- elif ns_chk.tcs
|
| 201 |
{%- set ns_chk.can_sort = false -%}
|
| 202 |
{%- else -%}
|
| 203 |
{%- for eid in ns_chk.res -%}
|
|
@@ -227,7 +237,7 @@ For each function call, output the function name and arguments within the follow
|
|
| 227 |
{%- set m = messages[ns_chk.mk[pair.p]] -%}
|
| 228 |
{%- if ns_chk.ek[pair.p] >= 0 -%}
|
| 229 |
{%- set entry = m.content[ns_chk.ek[pair.p]] -%}
|
| 230 |
-
{%- if entry.output is iterable and entry.output is not string and entry.output is not mapping and entry.output and entry.output
|
| 231 |
{{- tool_references_to_response(entry.output) -}}
|
| 232 |
{%- else -%}
|
| 233 |
{{- tool_response(visible_text(entry.output)) -}}
|
|
|
|
| 72 |
{%- macro render_tool_response(m) -%}
|
| 73 |
{%- if m.content is string -%}
|
| 74 |
{{- tool_response(m.content) -}}
|
| 75 |
+
{%- elif m.content and m.content is not mapping and m.content[0].type == "tool_reference" -%}
|
| 76 |
{{- tool_references_to_response(m.content) -}}
|
| 77 |
{%- elif is_list_of_outputs(m) -%}
|
| 78 |
{%- for tr in m.content -%}
|
| 79 |
+
{%- if tr.output is iterable and tr.output is not string and tr.output is not mapping and tr.output and tr.output[0].type == "tool_reference" -%}
|
| 80 |
{{- tool_references_to_response(tr.output) -}}
|
| 81 |
{%- else -%}
|
| 82 |
{{- tool_response(visible_text(tr.output)) -}}
|
|
|
|
| 94 |
{%- endif -%}
|
| 95 |
{%- endmacro -%}
|
| 96 |
{%- macro is_list_of_outputs(m) -%}
|
| 97 |
+
{%- if m.content and m.content[0].output is defined -%}1{%- endif -%}
|
| 98 |
{%- endmacro -%}
|
| 99 |
{%- macro has_dup_tool_result_id(lo, hi, target) -%}
|
| 100 |
{%- set ns_cnt = namespace(n=0) -%}
|
|
|
|
| 123 |
{%- endfor -%}
|
| 124 |
{%- if ns_f.found -%}1{%- endif -%}
|
| 125 |
{%- endmacro -%}
|
| 126 |
+
{%- macro has_duplicates(ids) -%}
|
| 127 |
+
{%- set ns_dup = namespace(seen=[], found=false) -%}
|
| 128 |
+
{%- for x in ids -%}
|
| 129 |
+
{%- if x in ns_dup.seen -%}
|
| 130 |
+
{%- set ns_dup.found = true -%}
|
| 131 |
+
{%- endif -%}
|
| 132 |
+
{%- set ns_dup.seen = ns_dup.seen + [x] -%}
|
| 133 |
+
{%- endfor -%}
|
| 134 |
+
{%- if ns_dup.found -%}1{%- endif -%}
|
| 135 |
+
{%- endmacro -%}
|
| 136 |
{%- set ns = namespace(last_user_index=-1) -%}
|
| 137 |
{%- for m in messages %}
|
| 138 |
{%- if m.role == 'user' %}
|
|
|
|
| 205 |
{%- endfor -%}
|
| 206 |
{%- if '' in ns_chk.res or '' in ns_chk.tcs -%}
|
| 207 |
{%- set ns_chk.can_sort = false -%}
|
| 208 |
+
{%- elif has_duplicates(ns_chk.res) -%}
|
| 209 |
{%- set ns_chk.can_sort = false -%}
|
| 210 |
+
{%- elif has_duplicates(ns_chk.tcs) -%}
|
| 211 |
{%- set ns_chk.can_sort = false -%}
|
| 212 |
{%- else -%}
|
| 213 |
{%- for eid in ns_chk.res -%}
|
|
|
|
| 237 |
{%- set m = messages[ns_chk.mk[pair.p]] -%}
|
| 238 |
{%- if ns_chk.ek[pair.p] >= 0 -%}
|
| 239 |
{%- set entry = m.content[ns_chk.ek[pair.p]] -%}
|
| 240 |
+
{%- if entry.output is iterable and entry.output is not string and entry.output is not mapping and entry.output and entry.output[0].type == "tool_reference" -%}
|
| 241 |
{{- tool_references_to_response(entry.output) -}}
|
| 242 |
{%- else -%}
|
| 243 |
{{- tool_response(visible_text(entry.output)) -}}
|
tokenizer_config.json
CHANGED
|
@@ -29,5 +29,52 @@
|
|
| 29 |
"pad_token": "<|endoftext|>",
|
| 30 |
"padding_side": "left",
|
| 31 |
"remove_space": false,
|
| 32 |
-
"tokenizer_class": "TokenizersBackend"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
|
|
|
| 29 |
"pad_token": "<|endoftext|>",
|
| 30 |
"padding_side": "left",
|
| 31 |
"remove_space": false,
|
| 32 |
+
"tokenizer_class": "TokenizersBackend",
|
| 33 |
+
"response_template": {
|
| 34 |
+
"defaults": {
|
| 35 |
+
"role": "assistant"
|
| 36 |
+
},
|
| 37 |
+
"start_anchor": "<|assistant|>",
|
| 38 |
+
"fields": {
|
| 39 |
+
"reasoning_content": {
|
| 40 |
+
"open_pattern": "<think>|(?=</think>)",
|
| 41 |
+
"close_pattern": "</think>|(?=<tool_call>)",
|
| 42 |
+
"content": "text",
|
| 43 |
+
"content_args": {
|
| 44 |
+
"strip": true
|
| 45 |
+
},
|
| 46 |
+
"repeats": true,
|
| 47 |
+
"join": ""
|
| 48 |
+
},
|
| 49 |
+
"tool_calls": {
|
| 50 |
+
"open_pattern": "\\s*<tool_call>\\s*(?P<name>[^<]*?)\\s*(?=<arg_key>|</tool_call>)",
|
| 51 |
+
"close": "</tool_call>",
|
| 52 |
+
"repeats": true,
|
| 53 |
+
"content": "xml-inline",
|
| 54 |
+
"content_args": {
|
| 55 |
+
"tag_pattern": "<arg_key>\\s*(?P<key>.*?)\\s*</arg_key>\\s*<arg_value>(?P<value>.*?)</arg_value>"
|
| 56 |
+
},
|
| 57 |
+
"transform": {
|
| 58 |
+
"type": "function",
|
| 59 |
+
"function": {
|
| 60 |
+
"name": "{name}",
|
| 61 |
+
"arguments": "{content}"
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
},
|
| 65 |
+
"content": {
|
| 66 |
+
"close": [
|
| 67 |
+
"<|user|>",
|
| 68 |
+
"<|observation|>",
|
| 69 |
+
"<|endoftext|>"
|
| 70 |
+
],
|
| 71 |
+
"content": "text",
|
| 72 |
+
"content_args": {
|
| 73 |
+
"strip": false
|
| 74 |
+
},
|
| 75 |
+
"repeats": true,
|
| 76 |
+
"join": ""
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
}
|