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

Fix indices dim check in gather_update_outputs #2149

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions crates/onnx-ir/src/dim_inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,19 +810,20 @@ fn gather_update_outputs(node: &mut Node) {
panic!("Gather requires two inputs: data and indices");
}

let indices_tensor = match &node.inputs[1].ty {
ArgType::Tensor(tensor) => tensor,
_ => panic!("Only tensor indices is valid"),
let indices_dim = match &node.inputs[1].ty {
ArgType::Tensor(tensor) => tensor.dim,
ArgType::Scalar(_) => 0,
_ => panic!("Only tensor indices is valid, got {:?}", node.inputs[1].ty),
};

if indices_tensor.dim > 1 {
if indices_dim > 1 {
panic!("Gather: indices tensor rank above 1 not supported")
}

match &node.inputs[0].ty {
ArgType::Tensor(input_tensor) => {
// Output of rank q+(r-1), where q is rank of indices tensor and r is rank of input
let output_rank = indices_tensor.dim + input_tensor.dim - 1;
let output_rank = indices_dim + input_tensor.dim - 1;

node.outputs[0].ty = ArgType::Tensor(TensorType {
elem_type: input_tensor.elem_type.clone(),
Expand All @@ -833,7 +834,7 @@ fn gather_update_outputs(node: &mut Node) {
ArgType::Shape(_dim) => {
let shape_dim = 1;
// Output of rank q+(r-1), where q is rank of indices tensor and r is rank of input
let output_rank = indices_tensor.dim + shape_dim - 1;
let output_rank = indices_dim + shape_dim - 1;

node.outputs[0].ty = ArgType::Tensor(TensorType {
elem_type: ElementType::Int64,
Expand Down
Loading