"vscode:/vscode.git/clone" did not exist on "ba0d8920742597269745f3551eb97b1b19f5e582"
glm.py 990 Bytes
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
3
4
5
6
7
8
"""Inference-only HF format GLM-4 model compatible with THUDM weights."""
from vllm.config import VllmConfig
from vllm.model_executor.models.llama import LlamaForCausalLM

from .utils import PPMissingLayer


9
class GlmForCausalLM(LlamaForCausalLM):
10
11

    def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
12
        vllm_config.model_config.hf_config.partial_rotary_factor = 0.5
13
14
15
16
17
18
19
20
21
22
        super().__init__(vllm_config=vllm_config, prefix=prefix)
        # Hack Llama model to fit HF format GLM implementation
        # Attention difference between GLM and Llama:
        # 1. Half partial rotary_dim and no Neox style.
        # 2. There is no bias for o_proj in attention
        for layer in self.model.layers:
            if not isinstance(layer, PPMissingLayer):
                layer.self_attn.rotary_emb.is_neox_style = False
                layer.self_attn.o_proj.bias = None
                layer.self_attn.o_proj.skip_bias_add = True