{"record":{"id":"8cbb73ad3cae7ca7","repo":"oobabooga/textgen","slug":"penalty-has-to-be-strictly-positive-but-is-pen","errorCode":null,"errorMessage":"`penalty` has to be strictly positive, but is {penalty}","messagePattern":"`penalty` has to be strictly positive, but is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/sampler_hijack.py","lineNumber":486,"sourceCode":"        indices_to_remove = sorted_indices_to_remove.unsqueeze(0).scatter(1, sorted_indices.unsqueeze(0), sorted_indices_to_remove.unsqueeze(0))\n        scores = scores.masked_fill(indices_to_remove, self.filter_value)\n        return scores\n\n\nclass SpyLogitsWarper(LogitsProcessor):\n    def __init__(self):\n        pass\n\n    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:\n        global global_scores\n        global_scores = scores\n        return scores\n\n\nclass RepetitionPenaltyLogitsProcessorWithRange(LogitsProcessor):\n    def __init__(self, penalty: float, _range: int):\n        if not (penalty > 0):\n            raise ValueError(f\"`penalty` has to be strictly positive, but is {penalty}\")\n        self.penalty = penalty\n        self._range = _range\n\n    def apply_repetition_penalty(self, input_ids_row, scores_row):\n        unique_ids = torch.unique(input_ids_row)\n        score = torch.gather(scores_row, 0, unique_ids)\n\n        # Apply multiplicative repetition penalty\n        score = torch.where(score < 0, score * self.penalty, score / self.penalty)\n        scores_row.scatter_(0, unique_ids, score)\n        return scores_row\n\n    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:\n        input_ids = input_ids[:, -self._range:]\n        for input_ids_row, scores_row in zip(input_ids, scores):\n            scores_row = self.apply_repetition_penalty(input_ids_row, scores_row)\n\n        return scores","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/sampler_hijack.py#L468-L504","documentation":"Error \"`penalty` has to be strictly positive, but is {penalty}\" thrown in oobabooga/textgen.","triggerScenarios":"Raised during sampler validation when a repetition/frequency `penalty` value is not strictly positive (<= 0). Triggers when penalty parameters are set to 0 or negative in generation settings.","commonSituations":"See trigger scenarios.","solutions":["Set the penalty to a value strictly greater than 0; typical values are around 1.0-1.2."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}