{"record":{"id":"9d93c58827dc7602","repo":"huggingface/transformers","slug":"framework-return-tensors-not-recognized","errorCode":null,"errorMessage":"Framework '{return_tensors}' not recognized!","messagePattern":"Framework '(.+?)' not recognized!","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/data_collator.py","lineNumber":46,"sourceCode":"InputDataClass = Any\n\n\"\"\"\nA DataCollator is a function that takes a list of samples from a Dataset and collate them into a batch, as a dictionary\nof PyTorch tensors or NumPy arrays.\n\"\"\"\nDataCollator = Callable[[list[InputDataClass]], dict[str, Any]]\n\n\nclass DataCollatorMixin:\n    def __call__(self, features, return_tensors: str | None = None):\n        if return_tensors is None:\n            return_tensors = self.return_tensors\n        if return_tensors == \"pt\":\n            return self.torch_call(features)\n        elif return_tensors == \"np\":\n            return self.numpy_call(features)\n        else:\n            raise ValueError(f\"Framework '{return_tensors}' not recognized!\")\n\n\ndef pad_without_fast_tokenizer_warning(tokenizer, *pad_args, **pad_kwargs):\n    \"\"\"\n    Pads without triggering the warning about how using the pad function is sub-optimal when using a fast tokenizer.\n    \"\"\"\n\n    # To avoid errors when using Feature extractors\n    if not hasattr(tokenizer, \"deprecation_warnings\"):\n        return tokenizer.pad(*pad_args, **pad_kwargs)\n\n    # Save the state of the warning, then disable it\n    warning_state = tokenizer.deprecation_warnings.get(\"Asking-to-pad-a-fast-tokenizer\", False)\n    tokenizer.deprecation_warnings[\"Asking-to-pad-a-fast-tokenizer\"] = True\n\n    try:\n        padded = tokenizer.pad(*pad_args, **pad_kwargs)\n    finally:","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/data_collator.py#L28-L64","documentation":"Raised by DataCollatorMixin.__call__ (data_collator.py:46). The collator dispatches on the requested tensor framework: 'pt' routes to torch_call, 'np' routes to numpy_call; anything else (including 'tf', 'jax', or a typo like 'torch'/'numpy') is not recognized and raises. Note this dispatch only supports torch and numpy — the TensorFlow/JAX paths were removed from this code path.","triggerScenarios":"Calling collator(features, return_tensors='tf'), return_tensors='jax', return_tensors='torch' (instead of 'pt'), or constructing a dataclass collator with return_tensors='tf' as a field default; the dispatch in __call__ then hits the else branch.","commonSituations":"Porting old training scripts (written when 'tf' was accepted) to current transformers; passing the string 'torch'/'numpy' because other APIs (e.g. tokenizer __call__/pad use return_tensors='pt'|'np') are remembered differently; stale tutorials.","solutions":["Use 'pt' for PyTorch or 'np' for NumPy.","If you passed 'torch'/'numpy' out of habit, switch to the exact short codes 'pt'/'np'.","If you were relying on 'tf'/'jax' output, produce numpy output ('np') and convert with tf.convert_to_tensor / jnp.array in your training loop."],"exampleFix":"# before\nbatch = collator(features, return_tensors='tf')\n\n# after\nimport numpy as np, tensorflow as tf\nbatch_np = collator(features, return_tensors='np')\nbatch = {k: tf.convert_to_tensor(v) for k, v in batch_np.items()}","handlingStrategy":"validation","validationCode":"ALLOWED = {'pt', 'np'}\nassert return_tensors in ALLOWED, f\"return_tensors must be one of {ALLOWED}, got {return_tensors!r}\"\nbatch = collator(features, return_tensors=return_tensors)","typeGuard":"def is_supported_return_tensors(rt: str | None) -> bool:\n    return rt in ('pt', 'np', None)","tryCatchPattern":null,"preventionTips":["Use only 'pt' or 'np' with collators; convert to tf/jax tensors downstream yourself.","Centralize the return_tensors choice in one config constant so typos surface once.","When porting older scripts, grep for return_tensors='tf'/'jax' — they are no longer accepted here."],"tags":["data-collator","return-tensors","api-misuse","framework"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}