transformers icon indicating copy to clipboard operation
transformers copied to clipboard

Improve BatchFeature: stack list and nested lists of torch tensors

Open yonigozlan opened this issue 1 month ago • 2 comments

I have been wanting to change that for a while, it shouldn't be a breaking change, but align what we support in BatchFeature between numpy arrays and torch tensors. The issue was that np.array() works on lists of array and even nested list of arrays), but torch.tensor() doesn't, so if we tried to call batch feature, with lists of tensors, we would get an error. I haven't added support for nested lists of tensors as I haven't seen the need anywhere. Also the errors we were getting were very generic, and not very useful, this should help with that.

yonigozlan avatar Dec 09 '25 21:12 yonigozlan

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

[For maintainers] Suggested jobs to run (before merge)

run-slow: beit, bridgetower, cohere2_vision, convnext, deepseek_vl, deepseek_vl_hybrid, depth_pro, dinov3_vit, donut, dpt, efficientloftr, efficientnet, eomt, flava, fuyu, gemma3

github-actions[bot] avatar Dec 09 '25 22:12 github-actions[bot]