Instructions to use zai-org/glm-4-9b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/glm-4-9b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="zai-org/glm-4-9b", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("zai-org/glm-4-9b", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use zai-org/glm-4-9b 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-9b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/glm-4-9b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/zai-org/glm-4-9b
- SGLang
How to use zai-org/glm-4-9b 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-9b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/glm-4-9b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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-9b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/glm-4-9b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use zai-org/glm-4-9b with Docker Model Runner:
docker model run hf.co/zai-org/glm-4-9b
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: unexpected end of data
Traceback (most recent call last):
File "D:\text-generation-webui\modules\text_generation.py", line 405, in generate_reply_HF
new_content = get_reply_from_output_ids(output, state, starting_from=starting_from)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\text-generation-webui\modules\text_generation.py", line 277, in get_reply_from_output_ids
first_token = first_token.decode('utf8')
^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: unexpected end of data
聊几句就出这个
因为输入中文了吧,在命令行输入中文的原因
因为输入中文了吧,在命令行输入中文的原因
难道智谱清言的模型不能输入中文?
我也是这个问题,我用text-generation-webui的transformer加载模型,每次都是输入中文prompt,大部分情况都正常输出,但偶尔会在输出特定中文字符的时候中断输出。一般是输出到一些稍微复杂一点特定汉字或者符号,就会弹出这个错误然后中断输出
这个不是模型的问题,是系统的问题,utf8很有可能是环境中执行报错,你报错的地方应该都在模型运行的外侧,而不是transformer内
这个不是模型的问题,是系统的问题,utf8很有可能是环境中执行报错,你报错的地方应该都在模型运行的外侧,而不是transformer内
但是我只有这个模型有这个问题,其他几个本地模型都没有特定字符偶尔UnicodeDecodeError打断输出的情况。我测试后发现至少“嚎”、“啕”、“讪”、“匕”、“奂”、“嗔”、“蝼”、“缨”’、“猾”、“狰”、“狞”、“囔”、“饴”、“岌”这些字,还有“╒”这种特殊字符是稳定打断输出的,还有很多其他的字。
例如,我在text-generation-webui的defeat选项卡,Prompt选none,在input里直接输入:
请重复一次以下语句:“你好,我是GLM-4-9b。美轮美奂,叹为观止。”
raw格式下得到的output为:
请重复一次以下语句:“你好,我是GLM-4-9b。美轮美奂,叹为观止。”你好,我是GLM-4-9b。美轮美
就会在输出“奂”字之前,显示“UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: unexpected end of data”,并且中断输出。
update:
还有特殊字符💰也会中断输出,但后台显示错位略有区别:“UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-2: unexpected end of data”