{"record":{"id":"cd0a30ca9d5872df","repo":"huggingface/transformers","slug":"self-class-is-an-abstract-class-only-classe","errorCode":null,"errorMessage":"{self.__class__} is an abstract class. Only classes inheriting this class can be called.","messagePattern":"(.+?) is an abstract class\\. Only classes inheriting this class can be called\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/logits_process.py","lineNumber":58,"sourceCode":"            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam\n            search or log softmax for each vocabulary token when using beam search\n\n    Return:\n        `torch.FloatTensor` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.\n\n\"\"\"\n\n\nclass LogitsProcessor:\n    \"\"\"Abstract base class for all logit processors that can be applied during generation.\"\"\"\n\n    # Whether the logit processor is supported by continuous batching.\n    # True if it is, False if it is not, None if it is not yet known.\n    supports_continuous_batching: bool | None = None\n\n    @add_start_docstrings(LOGITS_PROCESSOR_INPUTS_DOCSTRING)\n    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:\n        raise NotImplementedError(\n            f\"{self.__class__} is an abstract class. Only classes inheriting this class can be called.\"\n        )\n\n\nclass LogitsProcessorList(list):\n    \"\"\"\n    This class can be used to create a list of [`LogitsProcessor`] to subsequently process a `scores` input tensor.\n    This class inherits from list and adds a specific *__call__* method to apply each [`LogitsProcessor`] to the\n    inputs.\n    \"\"\"\n\n    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> torch.FloatTensor:\n        r\"\"\"\n        Args:\n            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):\n                Indices of input sequence tokens in the vocabulary. [What are input IDs?](../glossary#input-ids)\n            scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):\n                Prediction scores of a language modeling head. These can be logits for each vocabulary when not using","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/logits_process.py#L40-L76","documentation":"LogitsProcessor is an abstract base class; calling its __call__ directly raises NotImplementedError. Every concrete processor overrides __call__; instantiating the base class (or a subclass that forgot to override) and invoking it is a programming error.","triggerScenarios":"lp = LogitsProcessor(); lp(input_ids, scores). Also a custom subclass that defines process() instead of __call__, or one whose __call__ is shadowed/renamed during refactoring.","commonSituations":"Placeholder processors added to a LogitsProcessorList in scaffolding code; copy-paste of a processor skeleton without implementing __call__; metaprogramming that instantiates the base class dynamically.","solutions":["Instantiate a concrete processor (e.g. TemperatureLogitsProcessor) instead of the base class","In custom subclasses, implement __call__(self, input_ids, scores) with the exact signature","For pass-through behavior, implement __call__ returning scores unchanged"],"exampleFix":"# before\nprocessors = LogitsProcessorList([LogitsProcessor()])\n\n# after\nclass NoopProcessor(LogitsProcessor):\n    def __call__(self, input_ids, scores):\n        return scores\nprocessors = LogitsProcessorList([NoopProcessor()])","handlingStrategy":"type-guard","validationCode":"from transformers.generation.logits_process import LogitsProcessor\nfor p in my_processors:\n    assert type(p) is not LogitsProcessor, 'base class instantiated'\n    assert p.__call__ is not LogitsProcessor.__call__, f'{type(p).__name__} does not override __call__'","typeGuard":"def is_concrete_processor(p) -> bool:\n    return isinstance(p, LogitsProcessor) and LogitsProcessor.__call__ is not type(p).__call__","tryCatchPattern":null,"preventionTips":["Never add the base class to a LogitsProcessorList","Implement __call__(self, input_ids, scores) in subclasses","Unit-test custom processors by calling them directly"],"tags":["abstract-class","logits-processor","api-misuse"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}