From 09d5c1b56f94c9df216ef7de020b920fc52a0c14 Mon Sep 17 00:00:00 2001 From: petermcaughan Date: Thu, 1 Feb 2024 23:53:32 -0800 Subject: [PATCH] Fix DEBUG_GENERATION build (#19383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description Currently, ORT will fail a build when the flag DEBUG_GENERATION is set to 1 (used to debug BeamSearch and GreedySearch) in [console_dumper.h](https://github.com/microsoft/onnxruntime/blob/3b63d85c253c50099c70ba0db6c141b842bc7cda/onnxruntime/contrib_ops/cpu/utils/console_dumper.h#L12) with the following error: `onnxruntime/onnxruntime/contrib_ops/cpu/transformers/logits_processor.h:270:15: error: ‘DumpScores’ was not declared in this scope` This is because it is defined in `logits_processor.cc`, and a debugging artifact was passed in an earlier PR where this function is called from `logits_processor.h` before it is defined [[link](https://github.com/microsoft/onnxruntime/blob/3a2ab1963a195fe8df59e6220d3f191e5dfe80ee/onnxruntime/contrib_ops/cpu/transformers/logits_processor.h#L270)]. Builds with the flag have been broken since that PR was merged. This PR moves DumpScores() definition from `logits_processor.cc` to `logits_processor.h` so that all debug statements can be used correctly in `logits_processor.cc` and `logits_processor.h` and build succeeds with this debug flag. --------- Co-authored-by: Peter McAughan --- .../cpu/transformers/logits_processor.cc | 36 ------------------- .../cpu/transformers/logits_processor.h | 4 --- 2 files changed, 40 deletions(-) diff --git a/onnxruntime/contrib_ops/cpu/transformers/logits_processor.cc b/onnxruntime/contrib_ops/cpu/transformers/logits_processor.cc index f39f090c78..c74e9160cc 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/logits_processor.cc +++ b/onnxruntime/contrib_ops/cpu/transformers/logits_processor.cc @@ -17,14 +17,6 @@ namespace onnxruntime { namespace contrib { namespace transformers { -#ifdef DEBUG_GENERATION -template -void DumpScores(const char* name, const NextTokenScores& next_token_scores) { - std::cout << name << std::endl; - ORT_UNUSED_PARAMETER(next_token_scores); -} -#endif - // Interface for all scorers for beam search or beam sample. template MinLengthLogitsProcessor::MinLengthLogitsProcessor(int min_length, int eos_token_id) @@ -36,10 +28,6 @@ void MinLengthLogitsProcessor::Process(const ISequences* sequences, if (sequences->GetSequenceLength() < min_length_) { next_token_scores.SetScore(eos_token_id_, std::numeric_limits::lowest()); } - -#ifdef DEBUG_GENERATION - DumpScores("MinLengthLogitsProcessor", next_token_scores); -#endif } template @@ -68,10 +56,6 @@ void RepetitionPenaltyLogitsProcessor::Process(const ISequences* sequences, beam_token_scores[word_id] = (score < 0 ? score * penalty_ : score / penalty_); } } - -#ifdef DEBUG_GENERATION - DumpScores("RepetitionPenaltyLogitsProcessor", next_token_scores); -#endif } template @@ -109,10 +93,6 @@ void NoRepeatNGramLogitsProcessor::Process(const ISequences* sequences, beam_token_scores[word_id] = std::numeric_limits::lowest(); } } - -#ifdef DEBUG_GENERATION - DumpScores("NoRepeatNGramLogitsProcessor", next_token_scores); -#endif } template @@ -136,10 +116,6 @@ void VocabMaskLogitsProcessor::Process(const ISequences* /*sequences*/, } } } - -#ifdef DEBUG_GENERATION - DumpScores("VocabMaskLogitsProcessor", next_token_scores); -#endif } template @@ -171,10 +147,6 @@ void PrefixVocabMaskLogitsProcessor::Process(const ISequences* /*sequences*/, } } } - -#ifdef DEBUG_GENERATION - DumpScores("PrefixVocabMaskLogitsProcessor", next_token_scores); -#endif } template @@ -193,10 +165,6 @@ void TemperatureLogitsProcessor::Process(const ISequences* /*sequences*/, *p /= temperature_; ++p; } - -#ifdef DEBUG_GENERATION - DumpScores("TemperatureLogitsProcessor", next_token_scores); -#endif } template @@ -218,10 +186,6 @@ void PresencePenaltyLogitsProcessor::Process(const ISequences*, for (size_t i = 0; i < next_token_scores.scores.size(); i++) { *p -= presence_mask_[i] * presence_penalty_; } - -#ifdef DEBUG_GENERATION - DumpScores("PresencePenaltyLogitsProcessor", next_token_scores); -#endif } void LogitsProcessorList::Init(const BeamSearchParameters& parameters) { diff --git a/onnxruntime/contrib_ops/cpu/transformers/logits_processor.h b/onnxruntime/contrib_ops/cpu/transformers/logits_processor.h index 4688ff272c..03d4e89ac2 100644 --- a/onnxruntime/contrib_ops/cpu/transformers/logits_processor.h +++ b/onnxruntime/contrib_ops/cpu/transformers/logits_processor.h @@ -265,10 +265,6 @@ class TimestampLogitsProcessor : public ILogitsProcessor { } } } - -#ifdef DEBUG_GENERATION - DumpScores("TimestampLogitsProcessor", next_token_scores); -#endif } private: