huggingface/transformers · error · ValueError
Asking to pad but the feature_extractor does not have a padd
Error message
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`.
What it means
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.
Source
Thrown at src/transformers/feature_extraction_sequence_utils.py:364
if padding is True:
padding_strategy = PaddingStrategy.LONGEST # Default to pad to the longest sequence in the batch
elif not isinstance(padding, PaddingStrategy):
padding_strategy = PaddingStrategy(padding)
elif isinstance(padding, PaddingStrategy):
padding_strategy = padding
else:
padding_strategy = PaddingStrategy.DO_NOT_PAD
# Set max length if needed
if max_length is None:
if padding_strategy == PaddingStrategy.MAX_LENGTH:
raise ValueError(
f"When setting ``padding={PaddingStrategy.MAX_LENGTH}``, make sure that max_length is defined"
)
# Test if we have a padding value
if padding_strategy != PaddingStrategy.DO_NOT_PAD and (self.padding_value is None):
raise ValueError(
"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`."
)
return padding_strategy
def fetch_audio(self, audio_url_or_urls: str | list[str] | list[list[str]], sampling_rate: int | None = None):
"""
Convert a single or a list of urls into the corresponding `np.ndarray` objects.
If a single url is passed, the return value will be a single object. If a list is passed a list of objects is
returned.
"""
# Accepted input types for `raw_audio`: "np.ndarray | list[float] | list[np.ndarray] | list[list[float]]"
sampling_rate = sampling_rate if sampling_rate else self.sampling_rate
if isinstance(audio_url_or_urls, list) and not isinstance(audio_url_or_urls[0], float):
return [self.fetch_audio(x, sampling_rate=sampling_rate) for x in audio_url_or_urls]
elif isinstance(audio_url_or_urls, str):View on GitHub (pinned to a597f97485)
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
Example fix
# before fe = MyFeatureExtractor() fe(audio, padding=True) # padding_value is None # after fe.padding_value = 0.0 fe(audio, padding=True)
Defensive patterns
Strategy: validation
Validate before calling
if fe.padding_value is None:
fe.padding_value = 0.0 Type guard
def is_paddable(fe) -> bool:
return fe.padding_value is not None Try / catch
try:
fe.pad(batch, padding=True)
except ValueError as e:
if "padding value" in str(e):
fe.padding_value = 0.0
fe.pad(batch, padding=True)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid padding strategy:{padding_side}
- You should supply an instance of `transformers.BatchFeature`
- Some items in the output dictionary have a different batch s
- When setting ``padding={PaddingStrategy.MAX_LENGTH}``, make
- Found 'model.config.return_loss=True'. Loss computation is n
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/e704c024c8b72d6b.
Report an issue: GitHub.