Instructions to use zai-org/GLM-4.7-Flash with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/GLM-4.7-Flash with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="zai-org/GLM-4.7-Flash") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("zai-org/GLM-4.7-Flash") model = AutoModelForCausalLM.from_pretrained("zai-org/GLM-4.7-Flash") 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-4.7-Flash with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "zai-org/GLM-4.7-Flash" # 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-4.7-Flash", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/zai-org/GLM-4.7-Flash
- SGLang
How to use zai-org/GLM-4.7-Flash 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-4.7-Flash" \ --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-4.7-Flash", "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-4.7-Flash" \ --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-4.7-Flash", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use zai-org/GLM-4.7-Flash with Docker Model Runner:
docker model run hf.co/zai-org/GLM-4.7-Flash
DeepseekV3ForCausalLM
The diff reflects that most differences between modeling_glm4_moe_lite.py and modeling_deepseek_v3.py are just naming changes.
Even TODO is copied: https://github.com/huggingface/transformers/blob/main/src/transformers/models/glm4_moe_lite/modeling_glm4_moe_lite.py#L187-L188
Question: can we simply use DeepseekV3ForCausalLM here?
Right, for transformers, I just tried it too, and using DeepseekV3ForCausalLM for simple conversation works, but for sglang and vLLM, they use different hooks, which could cause errors (especially sglang, kernel is different and now still in progress)
As for why even the Todos are the same, it's because the Attention implement in transformers is indeed completely identical to DeepseekV3Attention, and using modular will copy all tools from DeepseekV3.
What if we simply inherit from the DeepseekV3 modular/modeling module rather than duplicating the code?
The Qwen model appears to follow this approach by extending parts of code from its previous version without duplication: https://github.com/huggingface/transformers/blob/9ed801f3ef0029e3733bbd2c9f9f9866912412a2/src/transformers/models/qwen2_5_omni/modular_qwen2_5_omni.py#L2064
I remain skeptical that duplicating the code achieves any meaningful benefit; it strikes me as poor practice to omit acknowledgment for the original author's work.
Additionally, you mentioned this was intended to prevent issues with sglang and vLLM, yet:
- A user has indicated it's incompatible with vLLM: https://huggingface.co/zai-org/GLM-4.7-Flash/discussions/22
- The KV cache consumes excess memory (https://huggingface.co/zai-org/GLM-4.7-Flash/discussions/21) due to the absence of a configuration that recognizes the model as deepseek: https://github.com/vllm-project/vllm/pull/32614
- Support for sglang is still WIP, whereas deepseekv3 runs without any problems
Sorry for the oversight earlier - the modular file does inherit the DSv3 module: https://github.com/huggingface/transformers/blob/main/src/transformers/models/glm4_moe_lite/modular_glm4_moe_lite.py
And it looks like the only thing added on top of DSv3 is to ignore the MTP layer.