Skip to content

Commit 63c6042

Browse files
committed
Use string_view::find() to search for tokenization to avoid unnecessary looking up beyond the fragment range
1 parent 267c139 commit 63c6042

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/llama-vocab.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,14 +2220,12 @@ void llama_vocab::impl::tokenizer_st_partition(std::forward_list<fragment_buffer
22202220
// find the first occurrence of a given special token in this fragment
22212221
// passing offset argument only limit the "search area" but match coordinates
22222222
// are still relative to the source full raw_text
2223-
auto match = raw_text.find(text, raw_text_base_offset);
2223+
// string_view begins at pos 0 for the same reason
2224+
auto match = std::string_view(raw_text.data(), raw_text_base_offset + raw_text_base_length).find(text, raw_text_base_offset);
22242225

22252226
// no occurrences found, stop processing this fragment for a given special token
22262227
if (match == std::string::npos) break;
22272228

2228-
// check if match is within bounds of offset <-> length
2229-
if (match + text.length() > raw_text_base_offset + raw_text_base_length) break;
2230-
22312229
#ifdef PRETOKENIZERDEBUG
22322230
LLAMA_LOG_WARN("FF: (%ld %ld %ld) '%s'\n", raw_text->length(), raw_text_base_offset, raw_text_base_length, raw_text->substr(raw_text_base_offset, raw_text_base_length).c_str());
22332231
#endif

0 commit comments

Comments
 (0)