{"record":{"id":"c35fc9cb199568bf","repo":"huggingface/transformers","slug":"unable-to-convert-output-key-type-type-valu","errorCode":null,"errorMessage":"Unable to convert output '{key}' (type: {type(value).__name__}) to tensor: {str(e)}\nYou can try:\n  1. Use padding=True to ensure all outputs have the same shape\n  2. Set return_tensors=None to return Python objects instead of tensors","messagePattern":"Unable to convert output '(.+?)' \\(type: (.+?)\\) to tensor: (.+?)\nYou can try:\n  1\\. Use padding=True to ensure all outputs have the same shape\n  2\\. Set return_tensors=None to return Python objects instead of tensors","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/feature_extraction_utils.py","lineNumber":206,"sourceCode":"            # Skip keys explicitly marked for no conversion\n            if skip_tensor_conversion and key in skip_tensor_conversion:\n                continue\n\n            # Skip values that are not array-like\n            if not _is_tensor_or_array_like(value):\n                continue\n\n            try:\n                if not is_tensor(value):\n                    tensor = as_tensor(value)\n                    self[key] = tensor\n            except Exception as e:\n                if key == \"overflowing_values\":\n                    raise ValueError(\n                        f\"Unable to create tensor for '{key}' with overflowing values of different lengths. \"\n                        f\"Original error: {str(e)}\"\n                    ) from e\n                raise ValueError(\n                    f\"Unable to convert output '{key}' (type: {type(value).__name__}) to tensor: {str(e)}\\n\"\n                    f\"You can try:\\n\"\n                    f\"  1. Use padding=True to ensure all outputs have the same shape\\n\"\n                    f\"  2. Set return_tensors=None to return Python objects instead of tensors\"\n                ) from e\n\n        return self\n\n    def to(self, *args, **kwargs) -> \"BatchFeature\":\n        \"\"\"\n        Send all values to device by calling `v.to(*args, **kwargs)` (PyTorch only). This should support casting in\n        different `dtypes` and sending the `BatchFeature` to a different `device`.\n\n        Args:\n            args (`Tuple`):\n                Will be passed to the `to(...)` function of the tensors.\n            kwargs (`Dict`, *optional*):\n                Will be passed to the `to(...)` function of the tensors.","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/feature_extraction_utils.py#L188-L224","documentation":"The generic tensor-conversion failure in BatchFeature.convert_to_tensors: as_tensor(value) raised for a non-overflow key (ragged nested lists, mismatched lengths across the batch, unsupported element types). The error names the key, its python type, and the underlying message, and suggests padding or returning python objects.","triggerScenarios":"Calling a feature extractor with return_tensors='pt'/'np' on an unpadded ragged batch (sequences of different lengths), or a value that is a nested list of inconsistent shapes for a key other than overflowing_values.","commonSituations":"Batching variable-length audio without padding=True; mixing single example and batched arrays; passing strings or object arrays as feature values.","solutions":["Add padding=True (plus max_length if a fixed size is needed) so all sequences align","Use return_tensors=None when you need to keep ragged python/numpy structures","Verify each key in the batch has a consistent shape before conversion"],"exampleFix":"# before\nfe(list_of_variable_length_audio, return_tensors=\"pt\")\n\n# after\nfe(list_of_variable_length_audio, return_tensors=\"pt\", padding=True)","handlingStrategy":"fallback","validationCode":"def lengths_uniform(values) -> bool:\n    import numpy as np\n    if isinstance(values, (list, tuple)) and values and isinstance(values[0], (list, tuple, np.ndarray)):\n        return len({len(v) for v in values}) == 1\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    out = fe(batch, return_tensors=\"pt\")\nexcept ValueError as e:\n    if \"to tensor\" in str(e):\n        out = fe(batch, return_tensors=\"pt\", padding=True)\n    else:\n        raise","preventionTips":["Always pad variable-length batches before tensor conversion","Fall back to return_tensors=None for ragged data","Shape-check each key before requesting tensors"],"tags":["feature-extractor","batchfeature","tensor-conversion","transformers"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}