Heim  >  Artikel  >  Backend-Entwicklung  >  TypeError: llama_tokenize() fehlen zwei erforderliche Positionsparameter: „add_bos“ und „special“

TypeError: llama_tokenize() fehlen zwei erforderliche Positionsparameter: „add_bos“ und „special“

PHPz
PHPznach vorne
2024-02-09 15:54:04871Durchsuche

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

Frageninhalt

Ich verwende Python 3.11 und die neueste Version des llama-cpp-python 以及 一个 gguf-Modells

Ich möchte, dass der Code normal wie ein Chatbot läuft, aber ich erhalte diese Fehlermeldung:

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'

Das ist mein Tokenisierungscode:

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])

Richtige Antwort


typeerror: llama_tokenize() missing 2 required positional arguments: 'add_bos' and 'special'

Um diesen Fehler zu beheben, müssen Sie den Parameter add_bosspecial 包含到 llama_tokenize() an die Funktion übergeben.

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))()
    
    # include the missing arguments in the function call
    n_tokens = llama_cpp.llama_tokenize(
        model.ctx,
        text,
        tokens,
        n_ctx,
        # you should check if llama_cpp.c_bool(add_bos) is returning a c_boo value also you have the arguments add_bos=false and special=false in this function 
        # if i am right all you need is:
        add_bos
        # not
        # llama_cpp.c_bool(add_bos),
        # you should check if llama_cpp.c_bool(special) is returning a c_boo value
        # if i am right all you need is:
        special  # include the special argument
        # not 
        # llama_cpp.c_bool(special) 
    )
    
    if int(n_tokens) < 0:
        raise runtimeerror(f'failed to tokenize: text="{text}" n_tokens={n_tokens}')
    
    return list(tokens[:n_tokens])

Von llama_cpp.py (github) a>, Zeilen beginnen bei 1817

def llama_tokenize(
    model: llama_model_p,
    text: bytes,
    text_len: Union[c_int, int],
    tokens,  # type: Array[llama_token]
    n_max_tokens: Union[c_int, int],
    add_bos: Union[c_bool, bool],
    special: Union[c_bool, bool],
) -> int:
    """Convert the provided text into tokens."""
    return _lib.llama_tokenize(
        model, text, text_len, tokens, n_max_tokens, add_bos, special
    )


_lib.llama_tokenize.argtypes = [
    llama_model_p,
    c_char_p,
    c_int32,
    llama_token_p,
    c_int32,
    c_bool,
    c_bool,
]
_lib.llama_tokenize.restype = c_int32

Das obige ist der detaillierte Inhalt vonTypeError: llama_tokenize() fehlen zwei erforderliche Positionsparameter: „add_bos“ und „special“. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:stackoverflow.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen