-
Notifications
You must be signed in to change notification settings - Fork 645
[Perf] Interpolate optimizations #3077
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3077 +/- ##
==========================================
- Coverage 81.16% 81.15% -0.01%
==========================================
Files 815 816 +1
Lines 117201 117265 +64
==========================================
+ Hits 95121 95163 +42
- Misses 22080 22102 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Tested locally and with the super-resolution model code (ESRGAN) which prompted this PR.
Just a minor comment on the contiguous checks
} else if *stride != 1 { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add more tests (e.g., your tensor of shape [1, 1, 1, 9]
with strides [72, 1, 72, 8]
which prompted this fix). Better illustrates what is expected to be contiguous or not, even in more complex cases.
Also @nathanielsimard I just realized we seem to have another is_contiguous
fn in fusion, but the implementations are slightly diverging with the latest changes
burn/crates/burn-cubecl-fusion/src/base.rs
Lines 141 to 169 in e096b0c
pub(crate) fn is_contiguous(shape: &[usize], strides: &[usize]) -> bool { | |
if shape.is_empty() { | |
return true; | |
} | |
if shape.len() == 1 { | |
return strides[0] == 1; | |
} | |
let mut prev_stride = 1; | |
let mut current_num_elems_shape = 1; | |
for (i, (stride, shape)) in strides.iter().zip(shape).rev().enumerate() { | |
if i > 0 { | |
if current_num_elems_shape != *stride { | |
return false; | |
} | |
if prev_stride >= *stride { | |
return false; | |
} | |
} | |
current_num_elems_shape *= shape; | |
prev_stride = *stride; | |
} | |
true | |
} |
The definition of contiguous should probably match 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test, but leaving this unresolved because of the fusion thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, so I'll merge but will open a small PR to use the same is_contiguous
fn across the crates.
Pull Request Template
Checklist
run-checks all
script has been executed.Related Issues/PRs
Also fixes #3076
Changes
Refactors interpolation to use NHWC layout to allow for potential vectorization when used with NHWC layout tensors (i.e. from convolution), as well as other perf optimizations. Also fixes a bug in
is_contiguous
and a clippy warning for slices.Testing
All tests pass