|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# |
| 4 | +# Copyright (c) 2023 Intel Corporation |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +from .base_model import BaseModel, register_model_adapter |
| 19 | +import logging |
| 20 | +from fastchat.conversation import get_conv_template, Conversation, register_conv_template, SeparatorStyle |
| 21 | + |
| 22 | +logging.basicConfig( |
| 23 | + format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", |
| 24 | + datefmt="%m/%d/%Y %H:%M:%S", |
| 25 | + level=logging.INFO, |
| 26 | +) |
| 27 | +logger = logging.getLogger(__name__) |
| 28 | + |
| 29 | + |
| 30 | +# Solar-10.7B Chat Template |
| 31 | +# Reference: https://huggingface.co/upstage/SOLAR-10.7B-Instruct-v1.0/blob/main/tokenizer_config.json |
| 32 | +register_conv_template( |
| 33 | + Conversation( |
| 34 | + name="solar", |
| 35 | + system_message="", |
| 36 | + roles=("### User", "### Assistant"), |
| 37 | + sep_style=SeparatorStyle.ADD_COLON_SPACE_SINGLE, |
| 38 | + sep="\n\n", |
| 39 | + stop_str="</s>", |
| 40 | + ) |
| 41 | +) |
| 42 | + |
| 43 | +class SolarModel(BaseModel): |
| 44 | + def match(self, model_path: str): |
| 45 | + """ |
| 46 | + Check if the provided model_path matches the current model. |
| 47 | +
|
| 48 | + Args: |
| 49 | + model_path (str): Path to a model. |
| 50 | +
|
| 51 | + Returns: |
| 52 | + bool: True if the model_path matches, False otherwise. |
| 53 | + """ |
| 54 | + return "solar-" in model_path.lower() and "instruct" in model_path.lower() |
| 55 | + |
| 56 | + def get_default_conv_template(self, model_path: str) -> Conversation: |
| 57 | + """ |
| 58 | + Get the default conversation template for the given model path. |
| 59 | +
|
| 60 | + Args: |
| 61 | + model_path (str): Path to the model. |
| 62 | +
|
| 63 | + Returns: |
| 64 | + Conversation: A default conversation template. |
| 65 | + """ |
| 66 | + return get_conv_template("solar") |
| 67 | + |
| 68 | +register_model_adapter(SolarModel) |
| 69 | + |
0 commit comments