Skip to content

Commit e610947

Browse files
authored
update encoder latency
Differential Revision: D60867022 Pull Request resolved: #4584
1 parent 8c813f9 commit e610947

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

extension/llm/tokenizer/tiktoken.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,14 @@ Error Tiktoken::load(const std::string& path) {
359359
_special_token_decoder = _build_decoder(_special_token_encoder);
360360

361361
_regex = _create_regex(_pattern);
362+
// Warmup re2 as it is slow on the first run, void the return value as it's
363+
// not needed Refer to
364+
// https://github.com/google/re2/blob/6dcd83d60f7944926bfd308cc13979fc53dd69ca/re2/fuzzing/re2_fuzzer.cc#L136-L141
365+
(void)_regex->ReverseProgramSize();
362366

363367
_special_token_regex = _build_special_token_regex(_special_token_encoder);
368+
// Same as above, warm up re2
369+
(void)_special_token_regex->ReverseProgramSize();
364370

365371
// initialize vocab_size, bos_tok, eos_tok
366372
vocab_size_ = _encoder.size() + _special_token_encoder.size();

0 commit comments

Comments
 (0)