Skip to content

Add torch.tensor_split op support for PyTorch frontend#2715

Open
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:feat/tensor-split
Open

Add torch.tensor_split op support for PyTorch frontend#2715
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:feat/tensor-split

Conversation

@eyupcanakman
Copy link
Copy Markdown
Contributor

Summary

Converting a TorchScript model that calls torch.tensor_split fails with PyTorch convert function for op 'tensor_split' not implemented.

Adds a converter that computes the split sizes and lowers to mb.split, for both an integer section count (first dim_size % n pieces get one extra element) and an explicit list of indices. Non-monotonic indices raise NotImplementedError, since they map to overlapping slices mb.split cannot represent.

torch.export already decomposes tensor_split into slice ops, so this only affects the TorchScript frontend.

Test plan

  • pytest test_torch_ops.py::TestTensorSplit covers integer sections, index lists with negative indexing, and the non-monotonic refusal, across all frontend and backend combinations.

Fixes #2226.

tensor_split was not implemented in the TorchScript frontend. Add a converter that lowers to mb.split, for an integer number of sections (first dim_size % n pieces get one extra element) and a list of split indices. Non-monotonic indices raise NotImplementedError since they map to overlapping slices that mb.split cannot represent.

Fixes apple#2226.
@TobyRoseman
Copy link
Copy Markdown
Collaborator

Thanks @eyupcanakman. This change looks good.

CI: https://gitlab.com/coremltools1/coremltools/-/pipelines/2554644433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please add support for torch.tensor_split

2 participants