Rust in Everything

GLM-4-9B-Chat

LLM 语言模型
提示:左侧拓扑图支持「紧凑总览 / 标准观察 / 全展开+算子」及单个模块独立收起与展开

智谱第四代对话基座(9.4B):采用极致 16:1 GQA (`multi_query_group_num = 2`)、融合单矩阵 `dense_h_to_4h` SwiGLU 与 50% Partial RoPE。

01.极致 16:1 GQA (`32Q : 2KV`):全层仅保留 2 个 KV 头(每 Token 单层仅缓存 512 个标量),KV Cache 开销仅为同级 8KV 模型的 1/4,天生适合超高并发或百万上下文扩展。
02.算子融合单矩阵 FFN (`gate_up_proj` `[4096 → 27392]`):将 Gate 与 Up 两条分支合并为一次大矩阵乘法后再切半执行 SwiGLU,提升 GPU Tensor Core 利用率。
03.ChatGLM 专属字段体系:使用 `padded_vocab_size = 151552`、QKV 偏置 (`add_qkv_bias = true`) 与半维旋转位置编码 (`rotary_percent = 0.5`)。

THUDM/glm-4-9b-chat

GLM Extreme GQAbfloat16
Source: Curated Model Atlas (Official Config)· Class: ChatGLMModel
总参数量 / 单 Token 激活
9.40B (100% Dense)
主干维度 (Layers × Hidden)
40L × 4096d
Vocab: 151552
KV Cache 压缩效率
16.0× vs MHA
512 elems/tok/layer
上下文窗口 & 位置编码
128K ctx
RoPE θ=10K · 50%d
Embedding: 620.8M (6.6%)Attention / SSM: 1.43B (15.2%)Dense FFN: 6.73B (71.6%)Output Head: 620.8M (6.6%)
Macro Forward Pass (点击任意模块钻取细节)
视图粒度:
input_ids : int64 [B, S]
h_0 : [B, S, 4096]
Layers 0–39 (×40) · 当前观测 Layer #0
0/39
xResidual Skip #1
Self-Attention
KV ÷16.0×
GQA (32Q:2KV × 128d)
RoPE θ=10K · 50%d · 35.7M/layer
+h_mid = x + Mixer(Norm(x)) : [B, S, 4096]
hResidual Skip #2
Gated MLP (FFN)
168.3M/layer
Fused GateUp FFN (silu, I=13696)
+h_out = h_mid + FFN(Norm(h_mid)) : [B, S, 4096]
h_final : [B, S, 4096]
▾ Output & Decoding Stage
logits : float [B, S, 151552]
Operator Subgraph · Layer #0
x_norm [B, S, 4096]q_proj (+bias)[4096 → 4096] (32×128)k_proj (+bias)[4096 → 256] (2×128)v_proj (+bias)[4096 → 256] (2×128)Reshape + PosRoPE θ=10K · 50%dReshape + PosQ:KV Group = 16:1★ KV Cache (K & V): 2 × [B, 2, S, 128] (512 elems/tok/layer)Scaled Dot-Product Attention (1/√128 · Causal Mask)Softmax(Q · Kᵀ) · V → Concat [B, S, 4096]o_proj [4096 → 4096] (no bias)Output: [B, S, 4096] → Residual Add (+)
部署量化精度
上下文长度 (Context)
并发序列数 (Batch)
预估推理总显存:19.46 GiB
硬件建议:24 GB 级(1× RTX 3090 / 4090 / L4)
模型权重: 17.51 GiB
KV Cache: 1.25 GiB
激活/工作区: 717.2 MiB
★ 架构收益:在当前 B=1、Ctx=32768 配置下,相比标准多头注意力 (MHA 需 20.00 GiB) 节省了 18.75 GiB 缓存显存!