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
This commit is contained in:
Paul Chang 2024-04-18 11:31:24 -07:00 committed by Copybara-Service
parent a8ceb75f43
commit 38f1ea9b80
1 changed files with 7 additions and 7 deletions

View File

@ -548,6 +548,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
@ -1121,13 +1128,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>