stablelm.py 1.73 KB
Newer Older
Hyunsung Lee's avatar
Hyunsung Lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# coding=utf-8
# Copyright 2023 Stability AI, EleutherAI, and The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This code is based off the following work:
# https://huggingface.co/stabilityai/stablelm-3b-4e1t/blob/main/modeling_stablelm_epoch.py
# https://huggingface.co/stabilityai/stablelm-3b-4e1t/blob/main/config.json
"""Inference-only StabeLM (https://github.com/Stability-AI/StableLM) model compatible with HuggingFace weights."""
Roy's avatar
Roy committed
20
from typing import Optional
Hyunsung Lee's avatar
Hyunsung Lee committed
21
22
23

from transformers import PretrainedConfig

Roy's avatar
Roy committed
24
25
26
27
from vllm.model_executor.layers.linear import LinearMethodBase
from vllm.model_executor.layers.layernorm import LayerNorm
from vllm.model_executor.models.llama import LlamaForCausalLM
from vllm.config import LoRAConfig
Hyunsung Lee's avatar
Hyunsung Lee committed
28
29


Roy's avatar
Roy committed
30
class StablelmForCausalLM(LlamaForCausalLM):
Hyunsung Lee's avatar
Hyunsung Lee committed
31
32
33

    def __init__(
        self,
Roy's avatar
Roy committed
34
        config: Optional[PretrainedConfig] = None,
Hyunsung Lee's avatar
Hyunsung Lee committed
35
        linear_method: Optional[LinearMethodBase] = None,
Roy's avatar
Roy committed
36
        lora_config: Optional[LoRAConfig] = None,
Hyunsung Lee's avatar
Hyunsung Lee committed
37
    ) -> None:
Roy's avatar
Roy committed
38
39
40
41
42
        norm = LayerNorm(config.hidden_size, config.norm_eps)
        super().__init__(config=config,
                         linear_method=linear_method,
                         norm=norm,
                         lora_config=lora_config)