Skip to content

[FIX] llama_chat_format.py: Update llama.llama_model_get_vocab -> lla… #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions llama_cpp/llama_chat_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import numpy as np
import numpy.typing as npt

import llama_cpp.llama_cpp as llama_cpp
import llama_cpp.llama as llama
import llama_cpp.llama_types as llama_types
import llama_cpp.llama_grammar as llama_grammar
Expand Down Expand Up @@ -594,7 +594,7 @@ def chat_completion_handler(
tool_choice=tool_choice,
)
prompt = llama.tokenize(
vocab=llama.llama_model_get_vocab(llama.model),
vocab=llama_cpp.llama_model_get_vocab(llama.model),
text=result.prompt.encode("utf-8"),
add_bos=not result.added_special,
special=True,
Expand Down Expand Up @@ -2813,8 +2813,8 @@ def __call__(
text = template.render(
messages=messages,
add_generation_prompt=True,
eos_token=llama.detokenize(vocab=llama.llama_model_get_vocab(llama.model), tokens=[llama.token_eos()]),
bos_token=llama.detokenize(vocab=llama.llama_model_get_vocab(llama.model), tokens=[llama.token_bos()]),
eos_token=llama.detokenize(vocab=llama_cpp.llama_model_get_vocab(llama.model), tokens=[llama.token_eos()]),
bos_token=llama.detokenize(vocab=llama_cpp.llama_model_get_vocab(llama.model), tokens=[llama.token_bos()]),
)
split_text = self.split_text_on_image_urls(text, image_urls)

Expand All @@ -2828,7 +2828,7 @@ def __call__(
for type_, value in split_text:
if type_ == "text":
tokens = llama.tokenize(
vocab=llama.llama_model_get_vocab(llama.model),
vocab=llama_cpp.llama_model_get_vocab(llama.model),
text=value.encode("utf8"), add_bos=False, special=True
)
if llama.n_tokens + len(tokens) > llama.n_ctx():
Expand Down