Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Yu, Zhentao <[email protected]>
  • Loading branch information
zhentaoyu committed Mar 25, 2024
1 parent 2bcb437 commit 03d2f6c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions neural_speed/models/model_utils/model_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,12 @@ struct beam_hypotheses {

int len() { return beams.size(); }

void add(beam b, const uint32_t& n_prompt_tokens, const bool penalize_prompt=false) {
void add(beam b, const uint32_t& n_prompt_tokens, const bool penalize_prompt = false) {
auto comp = [](const beam& a, const beam& b) { return a.score > b.score; };
uint32_t cur_len = b.eos() ? b.token_ids.size() - 1 : b.token_ids.size();
float score;
// reference: https://github.com/huggingface/transformers/blob/v4.38.2/src/transformers/generation/beam_search.py#L954-L960
// reference:
// https://github.com/huggingface/transformers/blob/v4.38.2/src/transformers/generation/beam_search.py#L954-L960
if (penalize_prompt) {
score = b.score / std::pow(cur_len + n_prompt_tokens, length_penalty);
} else {
Expand All @@ -354,8 +355,8 @@ struct beam_hypotheses {
#ifdef NS_BEAM_SEARCH_VERBOSE_ON
printf("add beam hypos: \n");
b.print();
printf("origin_score: %12.6f, new_score: %12.6f, generated_len: %d, sentence_len: %d \n", b.score, score,
cur_len, cur_len + n_prompt_tokens);
printf("origin_score: %12.6f, new_score: %12.6f, generated_len: %d, sentence_len: %d \n", b.score, score, cur_len,
cur_len + n_prompt_tokens);
printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
#endif
b.score = score;
Expand Down

0 comments on commit 03d2f6c

Please sign in to comment.