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

PHPz
发布: 2024-02-09 15:54:04
转载
869 人浏览过

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

问题内容

我正在运行 python 3.11 和最新版本的 llama-cpp-python 以及 一个 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])
登录后复制


正确答案


typeerror: llama_tokenize() missing 2 required positional arguments: 'add_bos' and 'special'
登录后复制

要解决该错误,您需要将参数 add_bosspecial 包含到 llama_tokenize() 函数中。

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])
登录后复制

来自 llama_cpp.py (github),从 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
登录后复制

以上是类型错误:llama_tokenize() 缺少 2 个必需的位置参数:'add_bos”和'special”的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:stackoverflow.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!