Instructions to use zai-org/GLM-5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/GLM-5 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="zai-org/GLM-5") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("zai-org/GLM-5") model = AutoModelForCausalLM.from_pretrained("zai-org/GLM-5") 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]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use zai-org/GLM-5 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" # 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", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/zai-org/GLM-5
- SGLang
How to use zai-org/GLM-5 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" \ --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", "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" \ --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", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use zai-org/GLM-5 with Docker Model Runner:
docker model run hf.co/zai-org/GLM-5
"Hierarchical Context Management" Reproducibility?
Hi Z.AI Team, thank you so much for open-sourcing such impressive models and sharing your research!
I have 2 clarifying questions about the context management strategies described in Section 4.2.4 of the tech report, in order to help ensure community reproducibility of the BrowseComp/HLE results.
Question 1) What exactly is discarded in Discard-all?
In Section 4.2.4, you state:
“we discard the entire tool-call history and restart with a fresh context”
Could you clarify precisely what is removed when Discard-all is triggered?
Given a trajectory (as described in the paper):
(q, r_1, a_1, o_1, r_2, a_2, o_2, ..., r_n, a_n, o_n)
Where:
q= questionr_i= reasoning at round ia_i= actiono_i= observation
Does Discard-all reset the context to one of the following?
Scenario A — Keep only system prompt + initial question
(system_prompt, q)
Meaning everything else is discarded:r_i, a_i, o_i for all i.
Scenario B — Remove only observations
(system_prompt, q, r_1, a_1, r_2, a_2, ..., r_n, a_n)
Meaning:o_i discarded for all i.
Scenario C — Remove all tool-related content (actions + observations)
(system_prompt, q, r_1, r_2, ..., r_n)
Meaning:a_i and o_i discarded for all i.
Or is there another variant intended?
Question 2) Interaction between Discard-all and keep-recent-k in HCM
In Section 4.2.4, "Hierarchical Context Management" is described as:
“During inference with keep-recent, if the total context length exceeds a threshold T, we discard the entire tool-call history and restart with a fresh context, while continuing to apply the keep-recent strategy.”
Would you be able to provide clarification on the control flow logic? I see 3 plausible interpretations:
Interpretation 1 — Discard-all triggered once, keep-recent always active
- keep-recent-k is active from the start.
- If
len(context) > T:- Trigger Discard-all once.
- After restart:
- keep-recent-k continues to apply.
- Discard-all is never triggered again.
Pseudocode:
discarded_once = False
while not done:
if len(context) > T and not discarded_once:
context = discard_all(context)
discarded_once = True
context = apply_keep_recent_k(context, k)
Interpretation 2 — Discard-all triggered every time T is exceeded
- keep-recent-k always active.
- Whenever
len(context) > T:- Trigger Discard-all.
- This can happen multiple times during inference.
Pseudocode:
while not done:
if len(context) > T:
context = discard_all(context)
context = apply_keep_recent_k(context, k)
Interpretation 3 — keep-recent-k activated only after first Discard-all
- Initially, no keep-recent-k.
- If
len(context) > T:- Trigger Discard-all.
- Activate keep-recent-k.
- After that:
- keep-recent-k remains active.
- Discard-all is never triggered again.
Pseudocode:
keep_recent_active = False
discarded_once = False
while not done:
if len(context) > T and not discarded_once:
context = discard_all(context)
discarded_once = True
keep_recent_active = True
if keep_recent_active:
context = apply_keep_recent_k(context, k)
Or is there another interpretation intended?
Thanks again for any clarifications you are able to provide, and for your amazing work! 🙏