-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split-18 performs differently compared to np.array_split, torch.tensor_split for last element in uneven split #4742
Comments
The current implementation follows the specifications. Split a tensor into a list of tensors, along the specified ‘axis’. Either input ‘split’ or the attribute ‘num_outputs’ should be specified, but not both. If the attribute ‘num_outputs’ is specified, then the tensor is split into equal sized parts. If the tensor is not evenly splittable into num_outputs, the last chunk will be smaller. If the input ‘split’ is specified, it indicates the sizes of each output in the split. You suggest adding a new attribute PR #4743 fixes the implementation but do not change the behaviour. |
It is also unclear from specification what should happen in this particular case: split 9 elements into 4 outputs: |
As weird as it seems, that's what the specifications says. |
Agree that it would be useful to add a flag to get the torch behavior. |
What about SplitToSequence and its usage in the Torch exporter? Does it have a similar requirement? @justinchuby ? |
We tested with torch.split and it seems fine. torch.tensor_split seems to behave differently |
The Split-18 spec is broken for some combinations. e.g. split 5 into 4 is impossible as you'd need 2, 1, 1, 1 as 2, 2, 2, 0 has too many elements. |
I think @liqunfu 's proposal in #5766 (comment) makes more sense, as a One step further, we can fix the current attribute
|
Bug Report
Is the issue related to model conversion?
No
Describe the bug
In uneven Split-18, only the last element would be less than others.
Though in np.array_split/torch.tensor_split it would make target axis length of each element at least 1 less.
With this difference, exporting split operation to opset 18 would be a hard job
System information
Reproduction instructions
tensor_split
/array_split
runs like:But Split-18 will split it like:
Also reference implementation should act same:
onnx/onnx/reference/ops/op_split.py
Line 22 in 9125ac3
Expected behavior
There should be a
mode
attributeNotes
The text was updated successfully, but these errors were encountered: