01.模型介绍

7月28日晚,智谱带来新一代旗舰模型——GLM-4.5!GLM-4.5 系列模型是专为智能体设计的基础模型。GLM-4.5拥有 3550 亿总参数量,其中 320 亿活跃参数;GLM-4.5-Air 采用更紧凑的设计,拥有 1060 亿总参数量,其中 120 亿活跃参数。GLM-4.5模型统一了推理、编码和智能体能力,以满足智能体应用的复杂需求。

GLM-4.5 和 GLM-4.5-Air 都是混合推理模型,提供两种模式:用于复杂推理和工具使用的思考模式,以及用于即时响应的非思考模式。

研究团队已开源了 GLM-4.5 和 GLM-4.5-Air 的基础模型、混合推理模型以及混合推理模型的FP8版本。它们采用MIT开源许可证发布,可用于商业用途和二次开发。

在研究团队对12项行业标准基准的全面评估中,GLM-4.5表现卓越,得分 63.2,在所有专有和开源模型中排名第3 。值得注意的是,GLM-4.5-Air在保持优异效率的同时,仍取得了 59.8 的竞争性成绩。

代码:

https://github.com/zai-org/GLM-4.5

体验链接:

https://modelscope.cn/studios/ZhipuAI/GLM-4.5-Demo

02.模型下载

你可以在 ModelScope(https://modelscope.cn/studios/ZhipuAI/GLM-4.5-Demo) 上直接体验模型,也可以按照下面的链接下载模型。

模型

下载链接

模型大小

精度

GLM-4.5

🤖 ModelScope:https://modelscope.cn/models/ZhipuAI/GLM-4.5

355B-A32B

BF16

GLM-4.5-Air

🤖 ModelScope:

https://modelscope.cn/models/ZhipuAI/GLM-4.5-Air

106B-A12B

BF16

GLM-4.5-FP8

🤖 ModelScope:

https://modelscope.cn/models/ZhipuAI/GLM-4.5-FP8

355B-A32B

FP8

GLM-4.5-Air-FP8

🤖 ModelScope:

https://modelscope.cn/models/ZhipuAI/GLM-4.5-Air-FP8

106B-A12B

FP8

GLM-4.5-Base

🤖 ModelScope:

https://modelscope.cn/models/ZhipuAI/GLM-4.5-Base

355B-A32B

BF16

GL

M-4.5-Air-Base

🤖 ModelScope:

https://modelscope.cn/models/ZhipuAI/GLM-4.5-Air-Base

106B-A12B

BF16

03.模型推理

推理推荐配置

研究团队提供了"全功能"模型推理的最低和推荐配置。下表中的数据基于以下条件:

  1. 所有模型都使用MTP层,并指定--speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4 以确保具有竞争力的推理速度。

  2. 不使用 cpu-offload 参数。

  3. 推理批处理大小不超过 8

  4. 所有操作都在原生支持FP8推理的设备上执行,确保权重和缓存都采用FP8格式。

  5. 服务器内存必须超过 1T 以确保正常的模型加载和运行。

模型可在下表配置下运行:

模型

精度

GPU类型和数量

测试框架

GLM-4.5

BF16

H100 x 16 / H200 x 8

sglang

GLM-4.5

FP8

H100 x 8 / H200 x 4

sglang

GLM-4.5-Air

BF16

H100 x 4 / H200 x 2

sglang

GLM-4.5-Air

FP8

H100 x 2 / H200 x 1

sglang

 

在下表配置下,模型可以充分利用其128K上下文长度:

模型

精度

GPU类型和数量

测试框架

GLM-4.5

BF16

H100 x 32 / H200 x 16

sglang

GLM-4.5

FP8

H100 x 16 / H200 x 8

sglang

GLM-4.5-Air

BF16

H100 x 8 / H200 x 4

sglang

GLM-4.5-Air

FP8

H100 x 4 / H200 x 2

sglang

 

vLLM

  • BF16和FP8都可以用以下代码启动(使用main分支):

vllm serve zai-org/GLM-4.5-Air \
    --tensor-parallel-size 8 \
    --tool-call-parser glm45 \
    --reasoning-parser glm45 \
    --enable-auto-tool-choice \
    --served-model-name glm-4.5-air

如果您使用8x H100 GPU并且在运行GLM-4.5模型时遇到内存不足的问题,您需要使用--cpu-offload-gb 16(仅适用于vLLM)。

如果遇到flash infer问题,请使用VLLM_ATTENTION_BACKEND=XFORMERS作为临时替代方案。您也可以指定 TORCH_CUDA_ARCH_LIST='9.0+PTX'来使用flash infer(不同GPU有不同的TORCH_CUDA_ARCH_LIST值,请相应检查)。

 

SGLang

  • BF16

python3 -m sglang.launch_server \
  --model-path zai-org/GLM-4.5-Air \
  --tp-size 8 \
  --tool-call-parser glm45  \
  --reasoning-parser glm45 \
  --speculative-algorithm EAGLE \
  --speculative-num-steps 3 \
  --speculative-eagle-topk 1 \
  --speculative-num-draft-tokens 4 \
  --mem-fraction-static 0.7 \
  --served-model-name glm-4.5-air \
  --host 0.0.0.0 \
  --port 8000
  • FP8

python3 -m sglang.launch_server \
  --model-path zai-org/GLM-4.5-Air-FP8 \
  --tp-size 4 \
  --tool-call-parser glm45  \
  --reasoning-parser glm45  \
  --speculative-algorithm EAGLE \
  --speculative-num-steps 3  \
  --speculative-eagle-topk 1  \
  --speculative-num-draft-tokens 4 \
  --mem-fraction-static 0.7 \
  --disable-shared-experts-fusion \
  --served-model-name glm-4.5-air-fp8 \
  --host 0.0.0.0 \
  --port 8000

请求参数说明

  • 使用vLLMSGLang时,发送请求时默认启用思考模式。如果要禁用思考开关,需要添加 extra_body={"chat_template_kwargs": {"enable_thinking": False}}参数。

  • 两者都支持工具调用。请使用OpenAI风格的工具描述格式进行调用。

  • 具体代码请参考inference文件夹中的api_request.py

04.模型微调

我们介绍使用ms-swift集成的megatron & LoRA对GLM-4.5-Air进行思考到非思考的微调。你需要准备4卡96GiB或8卡80GiB的显卡资源。ms-swift是魔搭社区官方提供的大模型与多模态大模型训练部署框架。

 

下表为我们推荐的微调配置:

模型

GPU类型和数量

策略

批处理大小(每GPU)

GLM-4.5

H20 (96GiB) x 16

Lora

1

GLM-4.5-Air

H20 (96GiB) x 4

Lora

1

GLM-4.5

H20 (96GiB) x 128

SFT

1

GLM-4.5-Air

H20 (96GiB) x 32

SFT

1

GLM-4.5

H20 (96GiB) x 128

RL

1

GLM-4.5-Air

H20 (96GiB) x 32

RL

1

 

ms-swift开源地址:

https://github.com/modelscope/ms-swift

在开始微调之前,请确保您的环境已准备妥当。

 

对megatron相关依赖的安装可以查看megatron-swift训练文档(可直接使用镜像):https://swift.readthedocs.io/zh-cn/latest/Instruction/Megatron-SWIFT%E8%AE%AD%E7%BB%83.html

git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
pip install -e .

微调数据集准备格式如下(system字段可选),在训练脚本中指定`--dataset <dataset_path>`即可。

{"messages": [{"role": "user", "content": "浙江的省会在哪?"}, {"role": "assistant", "content": "浙江的省会在杭州。"}]}

1、HF格式的权重转为Megatron格式,并测试转换精度:

# 4 * 80GiB
# 若要测试转换精度,请设置`--test_convert_precision true`
CUDA_VISIBLE_DEVICES=0,1,2,3 \
swift export \
    --model ZhipuAI/GLM-4.5-Air \
    --to_mcore true \
    --torch_dtype bfloat16 \
    --output_dir GLM-4.5-Air-mcore

2、对GLM-4.5-Air-mcore进行LoRA微调。在8卡H20上所需显存资源为:4 * 95GiB。

# thinking -> non-thinking
# 4 * 95GiB
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
NPROC_PER_NODE=4 \
CUDA_VISIBLE_DEVICES=0,1,2,3 \
megatron sft \
    --load GLM-4.5-Air-mcore \
    --dataset 'swift/Chinese-Qwen3-235B-2507-Distill-data-110k-SFT' \
    --train_type lora \
    --lora_rank 32 \
    --lora_alpha 64 \
    --target_modules linear_qkv linear_proj \
    --split_dataset_ratio 0.01 \
    --moe_permute_fusion true \
    --expert_model_parallel_size 4 \
    --moe_grouped_gemm true \
    --moe_shared_expert_overlap true \
    --moe_aux_loss_coeff 1e-3 \
    --micro_batch_size 1 \
    --global_batch_size 16 \
    --recompute_granularity full \
    --recompute_method uniform \
    --recompute_num_layers 1 \
    --max_epochs 2 \
    --finetune true \
    --cross_entropy_loss_fusion true \
    --lr 1e-4 \
    --lr_warmup_fraction 0.05 \
    --min_lr 1e-5 \
    --save megatron_output/GLM-4.5-Air \
    --eval_interval 200 \
    --save_interval 200 \
    --packing true \
    --max_length 8192 \
    --num_workers 8 \
    --dataset_num_proc 8 \
    --no_save_optim true \
    --no_save_rng true \
    --sequence_parallel true \
    --attention_backend flash

 

训练显存占用:

 

损失曲线:(总训练耗时:16小时)

 

3、将Megatron格式权重转为HF格式,并测试转换精度:

# 4 * 80GiB
CUDA_VISIBLE_DEVICES=0,1,2,3 \
swift export \
    --mcore_adapters megatron_output/GLM-4.5-Air/vx-xxx \
    --to_hf true \
    --torch_dtype bfloat16 \
    --output_dir megatron_output/GLM-4.5-Air/vx-xxx-hf

4、训练完成后,使用以下命令进行推理:

# 4 * 80GiB
# 或者使用main分支vllm进行推理加速
CUDA_VISIBLE_DEVICES=0,1,2,3 \
swift infer \
    --model megatron_output/GLM-4.5-Air/vx-xxx-hf \
    --stream true \
    --max_new_tokens 2048

 

5、推送模型到ModelScope:

swift export \
    --model output/vx-xxx/checkpoint-xxx \
    --push_to_hub true \
    --hub_model_id '<your-model-id>' \
    --hub_token '<your-sdk-token>'

点击链接,即可跳转模型链接~

https://modelscope.cn/models/ZhipuAI/GLM-4.5-Base

Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐