{"record":{"id":"43538142af210157","repo":"openai/whisper","slug":"best-of-with-greedy-sampling-t-0-is-not-compatib","errorCode":null,"errorMessage":"best_of with greedy sampling (T=0) is not compatible","messagePattern":"best_of with greedy sampling \\(T=0\\) is not compatible","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"whisper/decoding.py","lineNumber":577,"sourceCode":"        if not options.without_timestamps:\n            precision = CHUNK_LENGTH / model.dims.n_audio_ctx  # usually 0.02 seconds\n            max_initial_timestamp_index = None\n            if options.max_initial_timestamp:\n                max_initial_timestamp_index = round(\n                    self.options.max_initial_timestamp / precision\n                )\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            )","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/openai/whisper/blob/5f86d1d86363843179951550570367b37c5d6f78/whisper/decoding.py#L559-L595","documentation":"In _verify_options(): best_of means sampling N candidate sequences and picking the best by average log-probability, which requires stochastic sampling. With temperature=0 the sampler is greedy and deterministic, so drawing N candidates is meaningless and the combination is rejected.","triggerScenarios":"DecodingOptions(temperature=0, best_of=5) with beam_size=None; temperature defaults to 0 when constructing DecodingOptions, so merely setting best_of without touching temperature triggers it.","commonSituations":"Users assuming best_of works like 'top-N greedy'; default temperature sneaking in as 0; porting settings where temperature was previously non-zero.","solutions":["Set a non-zero temperature when using best_of: DecodingOptions(temperature=0.5, best_of=5)","If you want deterministic top-N, use beam search instead: beam_size=5, best_of=None","Remove best_of entirely for plain greedy decoding"],"exampleFix":"# before\noptions = whisper.DecodingOptions(best_of=5)  # temperature defaults to 0 -> ValueError\n\n# after\noptions = whisper.DecodingOptions(temperature=0.7, best_of=5)\n# or deterministic alternative:\n# options = whisper.DecodingOptions(beam_size=5)","handlingStrategy":"validation","validationCode":"def best_of_ok(options) -> bool:\n    return options.best_of is None or (options.temperature or 0) > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember DecodingOptions defaults temperature to 0 — always set temperature when using best_of","Prefer beam_size when determinism is required; it replaces best_of semantics"],"tags":["decoding","options-validation","sampling","temperature"],"backgroundTag":null,"analyzedSha":"5f86d1d86363843179951550570367b37c5d6f78","analyzedAt":"2026-08-14T18:53:59.547Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}