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 shape ONNX op support #1639

Merged
merged 7 commits into from
Apr 16, 2024
Merged

Add shape ONNX op support #1639

merged 7 commits into from
Apr 16, 2024

Conversation

laggui
Copy link
Member

@laggui laggui commented Apr 15, 2024

Related Issues/PRs

Progress towards #1544

Changes

Added shape ONNX op import support

Testing

Added unit tests for codegen and expected outputs

@laggui laggui requested a review from antimora April 15, 2024 16:01
@laggui laggui marked this pull request as draft April 15, 2024 16:43
@laggui
Copy link
Member Author

laggui commented Apr 15, 2024

Didn't realize torch always exports the shape op with a cast.. that's causing the CI to fail.

image

PR #1634 will fix that, but will fix the included graph for this PR.

Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 88.54167% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 86.34%. Comparing base (6d96e8d) to head (3df2b78).

❗ Current head 3df2b78 differs from pull request most recent head 6a8ed3e. Consider uploading reports for the commit 6a8ed3e to get more accurate results

Files Patch % Lines
crates/burn-import/src/onnx/op_configuration.rs 56.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1639      +/-   ##
==========================================
+ Coverage   86.30%   86.34%   +0.04%     
==========================================
  Files         692      691       -1     
  Lines       79998    79523     -475     
==========================================
- Hits        69040    68666     -374     
+ Misses      10958    10857     -101     

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

@laggui laggui marked this pull request as ready for review April 15, 2024 18:14
Copy link
Collaborator

@antimora antimora left a comment

Choose a reason for hiding this comment

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

One left over comment change. Approving ahead.

We might have to revisit the output type. I know in the standard arrays are treated as 1d tensors but it would worth if we use shape output type because when we will have to feed into a reshape operation, it would be convenient to receive in rust array type.

For now, if your solution works for your use case, we should use it till we encounter other use cases, such as reshape. With ONNX, I am taking a conservative approach because ONNX spec is too complex to implement at once.

pub fn shape_config(curr: &Node) -> (usize, usize) {
if curr.inputs.len() != 1 {
panic!(
"Flatten: multiple inputs are not supported (got {:?})",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Flatten => Shape

@laggui
Copy link
Member Author

laggui commented Apr 16, 2024

We might have to revisit the output type. I know in the standard arrays are treated as 1d tensors but it would worth if we use shape output type because when we will have to feed into a reshape operation, it would be convenient to receive in rust array type.

For now, if your solution works for your use case, we should use it till we encounter other use cases, such as reshape. With ONNX, I am taking a conservative approach because ONNX spec is too complex to implement at once.

I initially thought about returning a shape array but then when I started testing I noticed that most of the time in an ONNX model the shape for a dimension is retrieved with gather to use the resulting scalar on other operations. So by returning a 1d tensor as specified in the standard our gather import should work for this sequence too.

But I agree, importing ONNX is not straightforward.

@laggui laggui merged commit 35b36bb into main Apr 16, 2024
13 checks passed
@laggui laggui deleted the feat/onnx/shape branch April 16, 2024 13:28
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.

2 participants