{"record":{"id":"794ed8a0a2329b5d","repo":"openai/whisper","slug":"length-penalty-alpha-should-be-a-value-between-0","errorCode":null,"errorMessage":"length_penalty (alpha) should be a value between 0 and 1","messagePattern":"length_penalty \\(alpha\\) should be a value between 0 and 1","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"whisper/decoding.py","lineNumber":583,"sourceCode":"                )\n            self.logit_filters.append(\n                ApplyTimestampRules(\n                    tokenizer, self.sample_begin, max_initial_timestamp_index\n                )\n            )\n\n    def _verify_options(self, options: DecodingOptions) -> DecodingOptions:\n        if options.beam_size is not None and options.best_of is not None:\n            raise ValueError(\"beam_size and best_of can't be given together\")\n        if options.temperature == 0:\n            if options.best_of is not None:\n                raise ValueError(\"best_of with greedy sampling (T=0) is not compatible\")\n        if options.patience is not None and options.beam_size is None:\n            raise ValueError(\"patience requires beam_size to be given\")\n        if options.length_penalty is not None and not (\n            0 <= options.length_penalty <= 1\n        ):\n            raise ValueError(\"length_penalty (alpha) should be a value between 0 and 1\")\n\n        return options\n\n    def _get_initial_tokens(self) -> Tuple[int]:\n        tokens = list(self.sot_sequence)\n\n        if prefix := self.options.prefix:\n            prefix_tokens = (\n                self.tokenizer.encode(\" \" + prefix.strip())\n                if isinstance(prefix, str)\n                else prefix\n            )\n            if self.sample_len is not None:\n                max_prefix_len = self.n_ctx // 2 - self.sample_len\n                prefix_tokens = prefix_tokens[-max_prefix_len:]\n            tokens = tokens + prefix_tokens\n\n        if prompt := self.options.prompt:","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/openai/whisper/blob/5f86d1d86363843179951550570367b37c5d6f78/whisper/decoding.py#L565-L601","documentation":"_verify_options() constrains length_penalty (the alpha exponent applied to beam sequence length, per the original Whisper paper: ((5+len)/6)^alpha) to the inclusive range [0, 1]. Values outside that range distort the log-probability normalization in ways the implementation does not support, so they are rejected up front.","triggerScenarios":"DecodingOptions(length_penalty=-0.1) or length_penalty=1.2 with beam_size set; floats arriving from CLI/config parsing where 0 and 1 boundaries were misread as exclusive.","commonSituations":"Tuning scripts sweeping penalties beyond the valid range; porting alpha from another seq2seq toolkit where values >1 are legal; YAML configs parsed as strings then float()ed into wrong magnitudes.","solutions":["Clamp the value into [0, 1] (note the check is inclusive, so 0 and 1 are valid)","Leave length_penalty=None to use the default behavior","Fix the config source that produced the out-of-range number"],"exampleFix":"# before\noptions = whisper.DecodingOptions(beam_size=5, length_penalty=1.3)  # ValueError\n\n# after\noptions = whisper.DecodingOptions(beam_size=5, length_penalty=1.0)  # or omit / clamp: max(0.0, min(1.0, lp))","handlingStrategy":"validation","validationCode":"def length_penalty_ok(options) -> bool:\n    lp = options.length_penalty\n    return lp is None or 0 <= lp <= 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp external config values: lp = max(0.0, min(1.0, float(lp))) before building DecodingOptions","Document to ops/tuners that Whisper's alpha range is [0,1], unlike other seq2seq stacks"],"tags":["decoding","options-validation","beam-search","range-check"],"backgroundTag":null,"analyzedSha":"5f86d1d86363843179951550570367b37c5d6f78","analyzedAt":"2026-08-14T18:53:59.547Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}