{"record":{"id":"f08f8b1347fbf998","repo":"huggingface/transformers","slug":"you-should-supply-an-instance-of-transformers-bat","errorCode":null,"errorMessage":"You should supply an instance of `transformers.BatchFeature` or list of `transformers.BatchFeature` to this method that includes {self.model_input_names[0]}, but you provided {list(processed_features.keys())}","messagePattern":"You should supply an instance of `transformers\\.BatchFeature` or list of `transformers\\.BatchFeature` to this method that includes (.+?), but you provided (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/feature_extraction_sequence_utils.py","lineNumber":129,"sourceCode":"\n                [What are attention masks?](../glossary#attention-mask)\n            return_tensors (`str` or [`~utils.TensorType`], *optional*):\n                If set, will return tensors instead of list of python integers. Acceptable values are:\n\n                - `'pt'`: Return PyTorch `torch.Tensor` objects.\n                - `'np'`: Return Numpy `np.ndarray` objects.\n        \"\"\"\n        # If we have a list of dicts, let's convert it in a dict of lists\n        # We do this to allow using this method as a collate_fn function in PyTorch Dataloader\n        if isinstance(processed_features, (list, tuple)) and isinstance(processed_features[0], (dict, BatchFeature)):\n            # Call .keys() explicitly for compatibility with TensorDict and other Mapping subclasses\n            processed_features = {\n                key: [example[key] for example in processed_features] for key in processed_features[0].keys()\n            }\n\n        # The model's main input name, usually `input_values`, has be passed for padding\n        if self.model_input_names[0] not in processed_features:\n            raise ValueError(\n                \"You should supply an instance of `transformers.BatchFeature` or list of `transformers.BatchFeature`\"\n                f\" to this method that includes {self.model_input_names[0]}, but you provided\"\n                f\" {list(processed_features.keys())}\"\n            )\n\n        required_input = processed_features[self.model_input_names[0]]\n        return_attention_mask = (\n            return_attention_mask if return_attention_mask is not None else self.return_attention_mask\n        )\n\n        if len(required_input) == 0:\n            if return_attention_mask:\n                processed_features[\"attention_mask\"] = []\n            return processed_features\n\n        # If we have PyTorch tensors or lists as inputs, we cast them as Numpy arrays\n        # and rebuild them afterwards if no return_tensors is specified\n        # Note that we lose the specific device the tensor may be on for PyTorch","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/feature_extraction_sequence_utils.py#L111-L147","documentation":"Sequence feature extractors (Wav2Vec2, Whisper feature branch, etc.) pad a batch by reading their primary model input name (usually 'input_values' or 'input_features'). If that key is missing from the processed features, padding cannot proceed and this ValueError is raised, listing the keys actually provided.","triggerScenarios":"Calling feature_extractor(..., padding=True/padding='longest') on a dict/BatchFeature that lacks the main input key — e.g. passing only 'attention_mask', or a truncated/renamed batch dict.","commonSituations":"Rebuilding feature dicts manually and dropping the main key; collating partial batches in a DataLoader; passing text-tokenizer-style dicts to an audio feature extractor.","solutions":["Pass the output of feature_extractor(...) itself (which always contains the main input) instead of a hand-built dict","Check the error message: it names the required key and what you actually provided — add the missing key","Inspect feature_extractor.model_input_names[0] to see the exact expected key"],"exampleFix":"# before\nfe.pad({\"attention_mask\": mask}, padding=True)\n\n# after\nfe.pad({\"input_values\": raw_audio, \"attention_mask\": mask}, padding=True)","handlingStrategy":"validation","validationCode":"def validate_for_padding(fe, batch):\n    main = fe.model_input_names[0]\n    if main not in batch:\n        raise KeyError(f\"missing {main}; has {list(batch.keys())}\")\n    return batch","typeGuard":"def has_main_input(fe, batch: dict) -> bool:\n    return fe.model_input_names[0] in batch","tryCatchPattern":"try:\n    fe.pad(batch, padding=True)\nexcept ValueError as e:\n    if \"You should supply\" in str(e):\n        raise ValueError(\"rebuild batch via the feature extractor before padding\") from e\n    raise","preventionTips":["Read fe.model_input_names once and assert the key exists before padding","Never hand-prune feature dicts","Prefer calling __call__ on raw audio instead of re-padding custom dicts"],"tags":["feature-extractor","padding","audio","transformers"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}