Instructions to use unsloth/GLM-5.3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/GLM-5.3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/GLM-5.3") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("unsloth/GLM-5.3") model = AutoModelForCausalLM.from_pretrained("unsloth/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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/GLM-5.3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/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": "unsloth/GLM-5.3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/GLM-5.3
- SGLang
How to use unsloth/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 "unsloth/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": "unsloth/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 "unsloth/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": "unsloth/GLM-5.3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use unsloth/GLM-5.3 with Docker Model Runner:
docker model run hf.co/unsloth/GLM-5.3
chat_template: fix tool-call parsing under llama.cpp jinja
Browse files- a.0.b -> a[0].b (4 places): llama.cpp jinja rejects numeric member access with "Static member property must be an identifier"
- guard tc.arguments.items() with "is mapping": llama.cpp probes this branch with arguments as a JSON string, .items() threw, parser generation aborted and it fell back to a content-only grammar, so tool calls were emitted as raw XML in the content field
Rendered prompts are unchanged: 135/135 differential renders byte-identical.
- chat_template.jinja +5 -5
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) -%}
|
|
@@ -154,7 +154,7 @@ For each function call, output the function name and arguments within the follow
|
|
| 154 |
{%- set tc = tc.function %}
|
| 155 |
{%- endif %}
|
| 156 |
{{- '<tool_call>' + tc.name -}}
|
| 157 |
-
{% set _args = tc.arguments %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}</tool_call>{% endfor %}
|
| 158 |
{% endif %}
|
| 159 |
{%- elif m.role == 'tool' -%}
|
| 160 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
|
@@ -221,7 +221,7 @@ For each function call, output the function name and arguments within the follow
|
|
| 221 |
{%- for entry in m.content -%}
|
| 222 |
{%- set eid = id_of(entry) -%}
|
| 223 |
{%- if eid == tc_id -%}
|
| 224 |
-
{%- if entry.output is iterable and entry.output is not string and entry.output is not mapping and entry.output and entry.output
|
| 225 |
{{- tool_references_to_response(entry.output) -}}
|
| 226 |
{%- else -%}
|
| 227 |
{{- 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) -%}
|
|
|
|
| 154 |
{%- set tc = tc.function %}
|
| 155 |
{%- endif %}
|
| 156 |
{{- '<tool_call>' + tc.name -}}
|
| 157 |
+
{% set _args = tc.arguments %}{% if _args is mapping %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}{% endif %}</tool_call>{% endfor %}
|
| 158 |
{% endif %}
|
| 159 |
{%- elif m.role == 'tool' -%}
|
| 160 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
|
|
|
| 221 |
{%- for entry in m.content -%}
|
| 222 |
{%- set eid = id_of(entry) -%}
|
| 223 |
{%- if eid == tc_id -%}
|
| 224 |
+
{%- 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" -%}
|
| 225 |
{{- tool_references_to_response(entry.output) -}}
|
| 226 |
{%- else -%}
|
| 227 |
{{- tool_response(visible_text(entry.output)) -}}
|