Daporte commited on
Commit
5ab9498
·
1 Parent(s): 6ed6eb1

Filter the max_length warning by message, since unsetting it does not work

Browse files

generation_config.max_length is already None after load -- checked at
runtime -- so the previous commit's assignment changed nothing. Whisper's
generate() reconstructs max_length from config.max_target_positions (448)
internally, which is why the warned value is exactly 448 and why nothing on
this side can unset it. max_new_tokens takes precedence either way.

So filter that one message on the transformers logger instead of implying
the cause was fixed.

Files changed (1) hide show
  1. whisper_decoder.py +22 -8
whisper_decoder.py CHANGED
@@ -164,14 +164,28 @@ class Whisper:
164
  self.model.eval().to(self.device)
165
  self.mel_bins: int = self.model.config.num_mel_bins
166
 
167
- # The checkpoint's generation_config carries max_length=448, and
168
- # every call here passes max_new_tokens, which transformers warns
169
- # about once per generate(). Over a few thousand utterances that is a
170
- # few thousand lines burying the running WER. max_new_tokens wins
171
- # either way -- the warning says so -- so drop the field that is
172
- # being overridden rather than silence the warning and keep the
173
- # ambiguity.
174
- self.model.generation_config.max_length = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
  # The checkpoint carries no tokenizer of its own; it is the stock
177
  # whisper-medium one. Loading it from a local directory keeps first
 
164
  self.model.eval().to(self.device)
165
  self.mel_bins: int = self.model.config.num_mel_bins
166
 
167
+ # Silence one warning, per process, by message.
168
+ #
169
+ # Every call here passes max_new_tokens, and Whisper's generate()
170
+ # fills max_length in from config.max_target_positions (448) on its
171
+ # way through, so transformers reports them both set -- once per
172
+ # utterance, which over a few thousand buries the running WER.
173
+ #
174
+ # Clearing generation_config.max_length does not stop it: it is
175
+ # already None after load (checked), because the value is
176
+ # reconstructed inside generate() rather than read from the
177
+ # checkpoint. Nothing on this side can unset it, and max_new_tokens
178
+ # takes precedence regardless -- the warning says so itself. So drop
179
+ # the record rather than pretend to fix the cause.
180
+ import logging
181
+
182
+ class _NoMaxLengthClash(logging.Filter):
183
+ def filter(self, record: logging.LogRecord) -> bool:
184
+ return "seem to have been set" not in record.getMessage()
185
+
186
+ logging.getLogger("transformers.generation.utils").addFilter(
187
+ _NoMaxLengthClash()
188
+ )
189
 
190
  # The checkpoint carries no tokenizer of its own; it is the stock
191
  # whisper-medium one. Loading it from a local directory keeps first