TypeError: llama_tokenize() に 2 つの必須の位置引数がありません: 'add_bos' と 'special'

PHPz
リリース: 2024-02-09 15:54:04
転載
868 人が閲覧しました

类型错误:llama_tokenize() 缺少 2 个必需的位置参数:“add_bos”和“special”

質問の内容

Python 3.11 と最新バージョンの llama-cpp-python および a を実行しています。 gguf モデル

コードをチャットボットのように正常に実行したいのですが、次のエラーが発生します:

リーリー

これは私のトークン化コードです:

traceback (most recent call last):
  file "d:\ai custom\ai arush\server.py", line 223, in <module>
    init()
  file "d:\ai custom\ai arush\server.py", line 57, in init
    m_eval(model, m_tokenize(model, prompt_init, true), false, "starting up...")
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  file "d:\ai custom\ai arush\server.py", line 182, in m_tokenize
    n_tokens = llama_cpp.llama_tokenize(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
typeerror: llama_tokenize() missing 2 required positional arguments: 'add_bos' and 'special'
ログイン後にコピー


正解


def m_tokenize(model: llama_cpp.Llama, text: bytes, add_bos=False, special=False):
    assert model.ctx is not None
    n_ctx = llama_cpp.llama_n_ctx(model.ctx)
    tokens = (llama_cpp.llama_token * int(n_ctx))()
    n_tokens = llama_cpp.llama_tokenize(
        model.ctx,
        text,
        tokens,
        n_ctx,
        llama_cpp.c_bool(add_bos),
    )
    if int(n_tokens) < 0:
        raise RuntimeError(f'Failed to tokenize: text="{text}" n_tokens={n_tokens}')
    return list(tokens[:n_tokens])
ログイン後にコピー

このエラーを解決するには、パラメータ add_bosspecialllama_tokenize() 関数に含める必要があります。

リーリー

llama_cpp.py (github) a> より、1817 から始まる行

リーリー

以上がTypeError: llama_tokenize() に 2 つの必須の位置引数がありません: 'add_bos' と 'special'の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:stackoverflow.com
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!