{"record":{"id":"b8d33b60cae14f7c","repo":"huggingface/transformers","slug":"return-tensors-must-be-one-of-pt-np-retur","errorCode":null,"errorMessage":"return_tensors must be one of (\"pt\", \"np\"), {return_tensors=} not supported","messagePattern":"return_tensors must be one of \\(\"pt\", \"np\"\\), (.+?) not supported","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/data_collator.py","lineNumber":1477,"sourceCode":"                max_length = max(max_length, len(input_ids))\n\n        if self.return_flash_attn_kwargs:\n            batch[\"cu_seq_lens_q\"] = batch[\"cu_seq_lens_k\"] = cu_seq_lens\n            batch[\"max_length_q\"] = batch[\"max_length_k\"] = max_length\n\n        # FlashAttentionKwargs and seq_idx are expected to be int32s.\n        if return_tensors == \"pt\":\n            import torch\n\n            data_cls = torch.tensor\n            dtype_64 = torch.int64\n            dtype_32 = torch.int32\n        elif return_tensors == \"np\":\n            data_cls = np.array\n            dtype_64 = np.int64\n            dtype_32 = np.int32\n        else:\n            raise ValueError(f'return_tensors must be one of (\"pt\", \"np\"), {return_tensors=} not supported')\n\n        for k, v in batch.items():\n            if k in self._batch_dim_keys:\n                v = [v]\n            # Flash attention max_len_{q,k} are python ints\n            if k not in self._py_int_keys:\n                batch[k] = data_cls(v, dtype=dtype_64 if k in self._int_64_keys else dtype_32)\n\n        return batch\n","sourceCodeStart":1459,"sourceCodeEnd":1487,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/data_collator.py#L1459-L1487","documentation":"Raised by DataCollatorWithFlattening.__call__ when return_tensors is neither 'pt' nor 'np'. This collator concatenates samples into one packed sequence and must materialize them as PyTorch tensors or NumPy arrays (with int64/int32 dtypes for the flash-attention keys); other frameworks' tensor types are not supported, and unlike other collators there is no 'tf' or 'jax' branch.","triggerScenarios":"Calling DataCollatorWithFlattening(...)(features, return_tensors='tf') or 'jax', or constructing it with return_tensors='tf' (that default flows into __call__).","commonSituations":"Copying a TensorFlow/JAX collator setup from another pipeline into the packing collator; a Trainer configured for TF attempting to use sequence packing.","solutions":["Use return_tensors='pt' (PyTorch) or 'np' (NumPy) with this collator.","For JAX/TF training, take the NumPy output (return_tensors='np') and convert with jnp.asarray / tf.convert_to_tensor downstream.","If you need native TF collation, use DataCollatorWithPadding or DefaultDataCollator instead of the flattening collator."],"exampleFix":"# before\ncollator = DataCollatorWithFlattening(return_tensors='tf')\n\n# after\ncollator = DataCollatorWithFlattening(return_tensors='np')\nbatch = {k: jnp.asarray(v) for k, v in collator(features).items()}  # JAX example","handlingStrategy":"validation","validationCode":"rt = cfg.get('return_tensors', 'pt')\nif rt not in ('pt', 'np'):\n    raise ValueError(f'DataCollatorWithFlattening supports only pt/np, got {rt}')\ncollator = DataCollatorWithFlattening(return_tensors=rt)","typeGuard":"def is_supported_tensors(value: str) -> bool:\n    return value in ('pt', 'np')","tryCatchPattern":null,"preventionTips":["Restrict your config schema for packing collators to return_tensors in {'pt','np'}.","Convert to jnp/tf tensors downstream of the collator rather than asking it for framework-native output."],"tags":["data-collator","sequence-packing","return-tensors","configuration"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}