Skip to content
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

Add Split-20 - change uneven split behavior to be more torch-like #5321

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

p-wysocki
Copy link
Contributor

Description

Introduce Split-20, which performs uneven tensor split in torch's manner: instead of reducing only the size of the last dimension of the output, it reduces the last n dimensions' sized by 1 each.

This was done using a mode attribute, which has 2 possible values: torch (default) and legacy. It's up to discussion if it should stay like that or maybe it should be renamed or changed to a boolean.

Motivation and Context

Issue: #4742

TODO

  • Update reference evaluator
  • Confirm the correctness of setting a 0-size dimension in ONNX (test_split_uneven_split_3d_4)
  • Add more test cases and assert backend tests are correct

Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
@p-wysocki p-wysocki requested review from a team as code owners June 15, 2023 15:02
onnx/defs/tensor/defs.cc Outdated Show resolved Hide resolved
"Uneven split mode. "
"Possible values are 'torch' (default) and 'legacy'.",
AttributeProto::STRING,
std::string("torch"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the legacy as default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know torch is the desired one, and I set legacy to be default in version converter when coming from opset 19 to 20. I can change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I think the current choice is ok. Especially if it is only the torch exporter that uses this, and presumably the torch converter needs the new option, not the old one.

Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
@p-wysocki p-wysocki marked this pull request as draft June 15, 2023 15:33
split.push_back(chunk_size);
}
} else {
int chunk_size = (split_dim_value / num_outputs) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this doesn't always work. Eg., if we split 7 values into 5, then this will produce 4, 4, 4, 4, -1 which doesn't make sense. We should do 4, 3, 0, 0, 0, I think. We may need to change the description accordingly. In the other mode, we will do 2, 2, 1, 1, 1.

@gramalingam gramalingam added the operator Issues related to ONNX operators label Jul 5, 2023
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
onnx/defs/tensor/defs.cc Outdated Show resolved Hide resolved
onnx/defs/tensor/defs.cc Outdated Show resolved Hide resolved
"Split",
inputs=["input"],
outputs=["output_1", "output_2", "output_3"],
axis=0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing the axis, it would make sense to change the new attribute introduced minimize_diff or whatever it is called. At least, I am looking for some test-case to show the difference that attribute makes, whether that is this test or some other test.

@gramalingam
Copy link
Contributor

Hi, is this ready for review? Would it be possible to complete this PR for the upcoming release?

@justinchuby
Copy link
Contributor

@p-wysocki

@justinchuby justinchuby added this to the 1.15 milestone Aug 30, 2023
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
@justinchuby justinchuby added the auto update doc Generate md/proto files automatically using the CI pipeline label Sep 22, 2023
p-wysocki and others added 2 commits September 22, 2023 16:44
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
onnx/test/shape_inference_test.py Fixed Show fixed Hide fixed
onnx/test/shape_inference_test.py Fixed Show fixed Hide fixed
onnx/test/shape_inference_test.py Fixed Show fixed Hide fixed
onnx/test/shape_inference_test.py Fixed Show fixed Hide fixed
p-wysocki and others added 3 commits October 5, 2023 15:51
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
Signed-off-by: p-wysocki <przemyslaw.wysocki@intel.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@p-wysocki
Copy link
Contributor Author

Added new tests, generated docs and test files are on the way - I'm currently having some issues with protobuf in my environment, which stops me from generating them.

@gramalingam
Copy link
Contributor

It will also have to be moved to a later opset (21, I guess?)

@zhenhuaw-me
Copy link
Member

Spec like mode:torch requires background of how Torch implements it.

We can make it more specific by:

  1. Keep num_outputs, and change the semantic to match numpy.array_split and torch.tensor_split

If indices_or_sections is an integer n or a zero dimensional long tensor with value n, input is split into n sections along dimension dim. If input is divisible by n along dimension dim, each section will be of equal size, input.size(dim) / n. If input is not divisible by n, the sizes of the first int(input.size(dim) % n) sections will have size int(input.size(dim) / n) + 1, and the rest will have size int(input.size(dim) / n).

  1. Introduce split_size, which is the same as torch.split:

If split_size_or_sections is an integer type, then tensor will be split into equally sized chunks (if possible). Last chunk will be smaller if the tensor size along the given dimension dim is not divisible by split_size.

@justinchuby justinchuby modified the milestones: 1.16, 1.17 Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto update doc Generate md/proto files automatically using the CI pipeline operator Issues related to ONNX operators
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

None yet

5 participants