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

feat: resize onnx import #1863

Merged
merged 7 commits into from
Jun 11, 2024
Merged

Conversation

mosure
Copy link
Contributor

@mosure mosure commented Jun 7, 2024

checklist

  • confirmed that run-checks all script has been executed.
  • made sure the book is up to date with changes in this PR.

related issues/PRs

changes

support Resize onnx import

testing

cargo test -p burn-import --color=always -- --color=always
cargo test -p onnx-tests --color=always

@mosure
Copy link
Contributor Author

mosure commented Jun 7, 2024

I'm looking for feedback to solve:

onnx resize sizes tensor -> burn interpolate size constant

image

when parsing the resize node, sizes input is a tensor, however, I have not found a method to do constant folding over the sizes input tensor, burn interpolate requires size constants:

pub fn interpolate<R: JitRuntime, E: JitElement + Element>(
    input: JitTensor<R, E, 4>,
    output_size: [usize; 2],
    options: InterpolateOptions,
) -> JitTensor<R, E, 4> {
...

@laggui
Copy link
Member

laggui commented Jun 7, 2024

In the codegen for the node you could get the values in the size tensor. Something like

#size.to_data().value

/edit: shoot I didn't realize the output_size is a fixed size array, that won't work.

@mosure
Copy link
Contributor Author

mosure commented Jun 7, 2024

In the codegen for the node you could get the values in the size tensor. Something like

#size.to_data().value

/edit: shoot I didn't realize the output_size is a fixed size array, that won't work.

it is a good idea, something like:

let output_size: [usize; 2] = #output_size.to_data()
    .value
    .iter()
    .map(|x| x.elem::<i64>() as usize)
    .collect::<Vec<usize>>()
    .try_into()
    .unwrap();

@laggui
Copy link
Member

laggui commented Jun 7, 2024

Yeah something like that could work to preserve the flexibility.

I think in most cases the sizes could be constant so we might be able to get the values directly when parsing the graph, but not entirely sure.

I see in the spec that ONNX also supports providing a scales instead, but let's limit the scope of this PR. We can just parse the other unsupported fields/inputs and throw an error message for the cases we don't support.

@mosure mosure marked this pull request as ready for review June 7, 2024 23:00
Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 95.55556% with 10 lines in your changes missing coverage. Please review.

Project coverage is 86.14%. Comparing base (671ec8c) to head (6e00ba9).

Files Patch % Lines
crates/burn-import/src/onnx/dim_inference.rs 80.95% 4 Missing ⚠️
crates/burn-import/src/onnx/op_configuration.rs 75.00% 4 Missing ⚠️
crates/burn-import/src/burn/node/resize.rs 98.67% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1863      +/-   ##
==========================================
+ Coverage   86.11%   86.14%   +0.03%     
==========================================
  Files         777      778       +1     
  Lines       90555    90780     +225     
==========================================
+ Hits        77979    78202     +223     
- Misses      12576    12578       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@Luni-4 Luni-4 left a comment

Choose a reason for hiding this comment

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

Thanks a lot @mosure! It's fine for me!

I'm going to wait for a final review by @laggui though, just to be sure I haven't forgotten something

Copy link
Member

@laggui laggui left a comment

Choose a reason for hiding this comment

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

LGTM! Just a minor request to remove the commented dead code

I think this is probably the operator with the most attributes and optional inputs I've seen thus far 😅

Glad you didn't try to cover every use case because we can't support them anyway hahah

/edit: oh and we need to fix the merge conflicts

crates/burn-import/src/onnx/dim_inference.rs Outdated Show resolved Hide resolved
@laggui laggui merged commit 71bd5ef into tracel-ai:main Jun 11, 2024
14 checks passed
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.

3 participants