[MM] Cache common token sequences (#53560)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk> Signed-off-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -91,7 +91,9 @@ class BaseDummyInputsBuilder(ABC, Generic[_I]):
|
||||
# prompt tokens.
|
||||
dummy_prompt = []
|
||||
else:
|
||||
dummy_prompt = tokenizer.encode(dummy_text, truncation=False)
|
||||
from .processor import cached_encode
|
||||
|
||||
dummy_prompt = cached_encode(tokenizer, dummy_text, truncation=False)
|
||||
|
||||
return ProcessorInputs(
|
||||
prompt=dummy_prompt,
|
||||
|
||||
@@ -57,10 +57,15 @@ def cached_encode(
|
||||
tokenizer: TokenizerLike,
|
||||
text: str,
|
||||
*,
|
||||
truncation: bool | None = None,
|
||||
add_special_tokens: bool = True,
|
||||
) -> list[int]:
|
||||
"""Encode text while caching repeated tokenizer calls."""
|
||||
return tokenizer.encode(text, add_special_tokens=add_special_tokens)
|
||||
return tokenizer.encode(
|
||||
text,
|
||||
truncation=truncation,
|
||||
add_special_tokens=add_special_tokens,
|
||||
)
|
||||
|
||||
|
||||
class _GetMatchIndex(Protocol):
|
||||
|
||||
Reference in New Issue
Block a user