Compare commits

...

2 Commits

Author SHA1 Message Date
copybara-service[bot] 8aaeb7c868
Merge c4107cc9e7 into 38f1ea9b80 2024-04-19 11:33:48 +08:00
Paul Chang 38f1ea9b80 Eliminate redundant copies of TokenString()
Move this function outside of HWY_NAMESPACE since it doesn't need to be
optimized for any particular architecture.

PiperOrigin-RevId: 626098641
2024-04-18 11:31:50 -07:00
1 changed files with 7 additions and 7 deletions

View File

@ -550,6 +550,13 @@ struct GemmaImpl : public GemmaInterface {
hwy::AlignedUniquePtr<Activations<Config, 1>> state;
};
template <class TConfig>
std::string TokenString(GemmaImpl<TConfig>& gemma, int token) {
std::string token_str;
gemma.Tokenizer()->Decode({token}, &token_str);
return "'" + std::regex_replace(token_str, std::regex("\n"), "\\n") + "'";
}
} // namespace gcpp
#endif // GEMMA_ONCE
@ -1123,13 +1130,6 @@ void GenerateImpl(GemmaImpl<TConfig>& gemma, size_t max_tokens,
}
}
template <class TConfig>
std::string TokenString(GemmaImpl<TConfig>& gemma, int token) {
std::string token_str;
gemma.Tokenizer()->Decode({token}, &token_str);
return "'" + std::regex_replace(token_str, std::regex("\n"), "\\n") + "'";
}
#define TOKEN(token_id) TokenString(gemma, token_id).c_str()
template <class TConfig>