>  기사  >  백엔드 개발  >  TypeError: llama_tokenize()에 필수 위치 매개변수 2개가 누락되었습니다: 'add_bos' 및 'special'

TypeError: llama_tokenize()에 필수 위치 매개변수 2개가 누락되었습니다: 'add_bos' 및 'special'

PHPz
PHPz앞으로
2024-02-09 15:54:04871검색

类型错误: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])

이 오류를 해결하려면 매개변수 add_bosspecial 包含到 llama_tokenize()를 함수에 전달해야 합니다.

으아악

llama_cpp.py(github) a>에서 1817부터 시작하는 줄

으아악

위 내용은 TypeError: llama_tokenize()에 필수 위치 매개변수 2개가 누락되었습니다: 'add_bos' 및 'special'의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 stackoverflow.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제