[ChatStream] lightblue/karasu-7B-chat-plus 用 ChatPrompt

[ChatStream] lightblue/karasu-7B-chat-plus 用 ChatPrompt

こんにちは! (株)Qualiteg プロダクト開発部 です!


本稿では lightblue/karasu-7B-chat-plus 用の ChatPrompt をご紹介します。
旧バージョンの ChatStream をご利用のお客様は本ChatPromptをインポートすることで利用可能となります。(最新の配信バージョンではバンドルされております)

from chatstream import AbstractChatPrompt
from chatstream.chat_prompt.role_type import RoleType

SYSTEM_PROMPT = """\
あなたはAIアシスタントです。\
"""


class ChatPromptLightblueKarasuChatPlus(AbstractChatPrompt):

    def __init__(self):
        super().__init__()  # Call the initialization of the base class
        self.set_system(f"<s>[INST] <<SYS>>\n{SYSTEM_PROMPT}\n<</SYS>>\n\n")
        self.set_requester("")
        self.set_responder("")

    def get_stop_strs(self):
        if not self.chat_mode:
            return None
        return []

    def get_custom_skip_echo_len(self, skip_echo_len):

        num_turn = self.get_turn()
        if num_turn >= 2:
            modified_skip_echo_len = skip_echo_len + 1 * self.get_turn() - 1  
            return modified_skip_echo_len
        return skip_echo_len

    def get_replacement_when_input(self):
        return None

    def get_replacement_when_output(self):  # replace when response_text gotten
        return None

    def create_prompt(self, opts={}):

        ret = self.system

        for chat_content in self.get_contents(opts):

            chat_content_role_type = chat_content.get_role_type()
            chat_content_message = chat_content.get_message()

            if chat_content_message:
                merged_message = ""
                if chat_content_role_type == RoleType.REQUESTER:
                    merged_message = f"{chat_content_message} [/INST] "
                elif chat_content_role_type == RoleType.RESPONDER:
                    merged_message = f"{chat_content_message} </s><s>[INST] "
                ret += merged_message
            else:
                pass

        return ret

    async def build_initial_prompt(self, chat_prompt):
        # 初期プロンプトは実装しない
        pass

勘の良い方はお気づきかもしれませんが本モデルは Llama2 をベースモデルとしているため、 Llama2 対応として以下処理パートが特徴的となっております。

    def get_custom_skip_echo_len(self, skip_echo_len):

        num_turn = self.get_turn()
        if num_turn >= 2:
            modified_skip_echo_len = skip_echo_len + 1 * self.get_turn() - 1  
            return modified_skip_echo_len
        return skip_echo_len

ご参考
https://blog.qualiteg.com/llama2-dui-ying-no-chatpromptshi-zhuang/

Read more

「Blackwell」は 1 つではなかった。NVIDIA の Compute Capability 番号のわかりにくさを整理する

「Blackwell」は 1 つではなかった。NVIDIA の Compute Capability 番号のわかりにくさを整理する

こんにちは! NVIDIA の GPU を扱っていると、sm_120 や sm_100 といった番号を見かけます。Compute Capability と呼ばれる番号です。 この番号、製品の世代名と対応しているように見えて、実はずれています。 きっかけは、2026年9月23日に公開された TensorRT-LLM の v1.3.0rc28 でした。リリースノートに「SM107」という記述があります。次世代の Rubin に対応した、という文脈です。 ここで引っかかります。Blackwell の GeForce は sm_120 です。次の世代の Rubin が、なぜ 107 という小さい番号なのでしょうか。 調べてみると、引っかかりの原因は Rubin ではありませんでした。

By Qualiteg プロダクト開発部