{"record":{"id":"e704c024c8b72d6b","repo":"huggingface/transformers","slug":"asking-to-pad-but-the-feature-extractor-does-not-h","errorCode":null,"errorMessage":"Asking to pad but the feature_extractor does not have a padding value. Please select a value to use as `padding_value`. For example: `feature_extractor.padding_value = 0.0`.","messagePattern":"Asking to pad but the feature_extractor does not have a padding value\\. Please select a value to use as `padding_value`\\. For example: `feature_extractor\\.padding_value = 0\\.0`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/feature_extraction_sequence_utils.py","lineNumber":364,"sourceCode":"            if padding is True:\n                padding_strategy = PaddingStrategy.LONGEST  # Default to pad to the longest sequence in the batch\n            elif not isinstance(padding, PaddingStrategy):\n                padding_strategy = PaddingStrategy(padding)\n            elif isinstance(padding, PaddingStrategy):\n                padding_strategy = padding\n        else:\n            padding_strategy = PaddingStrategy.DO_NOT_PAD\n\n        # Set max length if needed\n        if max_length is None:\n            if padding_strategy == PaddingStrategy.MAX_LENGTH:\n                raise ValueError(\n                    f\"When setting ``padding={PaddingStrategy.MAX_LENGTH}``, make sure that max_length is defined\"\n                )\n\n        # Test if we have a padding value\n        if padding_strategy != PaddingStrategy.DO_NOT_PAD and (self.padding_value is None):\n            raise ValueError(\n                \"Asking to pad but the feature_extractor does not have a padding value. Please select a value to use\"\n                \" as `padding_value`. For example: `feature_extractor.padding_value = 0.0`.\"\n            )\n\n        return padding_strategy\n\n    def fetch_audio(self, audio_url_or_urls: str | list[str] | list[list[str]], sampling_rate: int | None = None):\n        \"\"\"\n        Convert a single or a list of urls into the corresponding `np.ndarray` objects.\n\n        If a single url is passed, the return value will be a single object. If a list is passed a list of objects is\n        returned.\n        \"\"\"\n        # Accepted input types for `raw_audio`: \"np.ndarray | list[float] | list[np.ndarray] | list[list[float]]\"\n        sampling_rate = sampling_rate if sampling_rate else self.sampling_rate\n        if isinstance(audio_url_or_urls, list) and not isinstance(audio_url_or_urls[0], float):\n            return [self.fetch_audio(x, sampling_rate=sampling_rate) for x in audio_url_or_urls]\n        elif isinstance(audio_url_or_urls, str):","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/feature_extraction_sequence_utils.py#L346-L382","documentation":"Padding writes self.padding_value into the padded region. If the extractor's padding_value is None (unset on the instance or subclass), numpy's np.pad would fail ambiguously, so the code raises a clear ValueError up front and suggests a value such as 0.0.","triggerScenarios":"Calling any padding path on a feature extractor whose padding_value attribute is None — typically a custom subclass that did not set it, or an instance where it was explicitly cleared.","commonSituations":"Writing a custom sequence feature extractor and forgetting padding_value; loading a config where padding_value is null; models whose correct pad value is nonzero (e.g. attention-style masks) and was never configured.","solutions":["Set feature_extractor.padding_value = 0.0 (or the correct pad value for your modality) before padding","In a subclass, set self.padding_value in __init__","Persist the value by saving the updated preprocessor config"],"exampleFix":"# before\nfe = MyFeatureExtractor()\nfe(audio, padding=True)  # padding_value is None\n\n# after\nfe.padding_value = 0.0\nfe(audio, padding=True)","handlingStrategy":"validation","validationCode":"if fe.padding_value is None:\n    fe.padding_value = 0.0","typeGuard":"def is_paddable(fe) -> bool:\n    return fe.padding_value is not None","tryCatchPattern":"try:\n    fe.pad(batch, padding=True)\nexcept ValueError as e:\n    if \"padding value\" in str(e):\n        fe.padding_value = 0.0\n        fe.pad(batch, padding=True)\n    else:\n        raise","preventionTips":["Set padding_value in every custom extractor subclass","Assert padding_value is not None before batch jobs","Save the corrected config so the fix persists"],"tags":["feature-extractor","padding","config","transformers"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}