| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | # Adapted from |
| 5 | # https://github.com/huggingface/transformers/blob/v4.28.0/src/transformers/models/llama/modeling_llama.py |
| 6 | # Copyright 2023 The vLLM team. |
| 7 | # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. |
| 8 | # |
| 9 | # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX |
| 10 | # and OPT implementations in this library. It has been modified from its |
| 11 | # original forms to accommodate minor architectural differences compared |
| 12 | # to GPT-NeoX and OPT used by the Meta AI team that trained the model. |
| 13 | # |
| 14 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 15 | # you may not use this file except in compliance with the License. |
| 16 | # You may obtain a copy of the License at |
| 17 | # |
| 18 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | # |
| 20 | # Unless required by applicable law or agreed to in writing, software |
| 21 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 22 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | # See the License for the specific language governing permissions and |
| 24 | # limitations under the License. |
| 25 | |
| 26 | |
| 27 | from vllm.config import VllmConfig |
| 28 | from vllm.model_executor.layers.logits_processor import LogitsProcessor |
| 29 | from vllm.model_executor.models.llama import ( |
| 30 | LlamaForCausalLM, |
| 31 | ) |
| 32 | |
| 33 | |
| 34 | class TeleFLMForCausalLM(LlamaForCausalLM): |
| 35 | def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""): |
| 36 | super().__init__(vllm_config=vllm_config, prefix=prefix) |
| 37 | # mup |
| 38 | self.use_mup = self.config.use_mup |
| 39 | if self.use_mup: |
| 40 | self.mup_scale_factor = self.config.mup_scale_factor |
| 41 | self.output_mult = self.config.output_mult / self.mup_scale_factor |
| 42 | logit_scale = self.output_mult |
| 43 | self.logits_processor = LogitsProcessor( |
| 44 | self.config.vocab_size, scale=logit_scale |
| 45 | ) |