|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | + |
| 4 | +# Copyright 2025 The Baidu team. |
| 5 | +# Copyright 2023 The vLLM team. |
| 6 | +# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. |
| 7 | +# |
| 8 | +# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX |
| 9 | +# and OPT implementations in this library. It has been modified from its |
| 10 | +# original forms to accommodate minor architectural differences compared |
| 11 | +# to GPT-NeoX and OPT used by the Meta AI team that trained the model. |
| 12 | +# |
| 13 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | +# you may not use this file except in compliance with the License. |
| 15 | +# You may obtain a copy of the License at |
| 16 | +# |
| 17 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | +# |
| 19 | +# Unless required by applicable law or agreed to in writing, software |
| 20 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | +# See the License for the specific language governing permissions and |
| 23 | +# limitations under the License. |
| 24 | +"""Inference-only Erine model compatible with HuggingFace weights.""" |
| 25 | +from vllm.config import VllmConfig |
| 26 | +from vllm.model_executor.models.llama import LlamaForCausalLM |
| 27 | + |
| 28 | +from .utils import PPMissingLayer |
| 29 | + |
| 30 | + |
| 31 | +class Ernie4_5_ForCausalLM(LlamaForCausalLM): |
| 32 | + |
| 33 | + def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""): |
| 34 | + super().__init__(vllm_config=vllm_config, prefix=prefix) |
| 35 | + # Hack Llama model to fit HF format Ernie4.5 dense implementation |
| 36 | + # Attention difference between Ernie and Llama: |
| 37 | + # 1. rotary_dim and no Neox style. |
| 38 | + # 2. There is no bias for o_proj in attention |
| 39 | + for layer in self.model.layers: |
| 40 | + if not isinstance(layer, PPMissingLayer): |
| 41 | + layer.self_attn.rotary_emb.is_neox_style = False |
| 42 | + layer.self_attn.o_proj.bias = None |
| 43 | + layer.self_attn.o_proj.skip_bias_add = True |
0 commit comments