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/Split Operator #2490

Merged
merged 35 commits into from
Nov 21, 2024
Merged

Feat/Split Operator #2490

merged 35 commits into from
Nov 21, 2024

Conversation

agelas
Copy link
Contributor

@agelas agelas commented Nov 14, 2024

Pull Request Template

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

#2440

Changes

Adds support for the split operation. The ONNX -> Burn conversion will be part of a separate PR.

Testing

Added tests under burn-tensor.

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 66.31356% with 159 lines in your changes missing coverage. Please review.

Project coverage is 82.86%. Comparing base (6d105ea) to head (86f5d31).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/burn-tensor/src/tensor/ops/qtensor.rs 0.00% 30 Missing ⚠️
crates/burn-tensor/src/tensor/api/base.rs 58.82% 28 Missing ⚠️
crates/burn-tch/src/ops/base.rs 0.00% 21 Missing ⚠️
crates/burn-autodiff/src/ops/int_tensor.rs 0.00% 14 Missing ⚠️
crates/burn-autodiff/src/ops/bool_tensor.rs 0.00% 10 Missing ⚠️
crates/burn-tch/src/ops/bool_tensor.rs 0.00% 10 Missing ⚠️
crates/burn-tch/src/ops/int_tensor.rs 0.00% 10 Missing ⚠️
crates/burn-tch/src/ops/tensor.rs 0.00% 10 Missing ⚠️
crates/burn-tensor/src/tensor/ops/bool_tensor.rs 0.00% 10 Missing ⚠️
crates/burn-tensor/src/tensor/ops/int_tensor.rs 0.00% 10 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2490      +/-   ##
==========================================
- Coverage   82.93%   82.86%   -0.08%     
==========================================
  Files         815      817       +2     
  Lines      105344   105853     +509     
==========================================
+ Hits        87371    87714     +343     
- Misses      17973    18139     +166     

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


🚨 Try these New Features:

@agelas agelas marked this pull request as ready for review November 15, 2024 20:40
@@ -4,6 +4,7 @@ mod tests {
use alloc::vec::Vec;
use burn_tensor::{Int, Shape, Tensor, TensorData};

#[test]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was accidentally left out in #998

@@ -107,6 +107,7 @@ macro_rules! testgen_quantization {
burn_tensor::testgen_q_sin!();
burn_tensor::testgen_q_slice!();
burn_tensor::testgen_q_sort_argsort!();
// burn_tensor::testgen_q_split!();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@antimora @louisfd It looks like there's some sort of nuance here that I'm a bit out of the loop on- do I need to do something extra for the quantized set of tests/do I even need quantized tests here?

Copy link
Member

Choose a reason for hiding this comment

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

Adding quantized tests is not well documented at the moment, so you're not expected to do it.
@laggui will work on making it more straightforward and he'll be able to adapt your non-quantized tests.

Comment on lines +25 to +41
pub fn split<B: Backend, K: TensorKind<B> + BasicOps<B>>(
tensor: K::Primitive,
split_size: usize,
dim: usize,
) -> Vec<K::Primitive> {
let size = K::shape(&tensor).dims[dim];
let mut tensors = Vec::new();

let mut start = 0;
while start < size {
let length = usize::min(split_size, size - start);
tensors.push(narrow::<B, K>(tensor.clone(), dim, start, length));
start += length;
}

tensors
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this function will likely by the fastest in most cases, since there is not kernel to execute, only metadata to update.

Copy link
Member

@louisfd louisfd left a comment

Choose a reason for hiding this comment

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

LGTM

///
/// To split a tensor, users should prefer the [Tensor::split](Tensor::split) function,
/// which is more high-level and designed for public use.
fn split(tensor: Self::Primitive, split_size: usize, dim: usize) -> Vec<Self::Primitive>;
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between this version of split and chunk? Is it only that split takes the size of the new chunks while chunk takes the number of chunks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct- and then split_with_sizes goes a step further and lets you specify the size of each chunk.

@@ -107,6 +107,7 @@ macro_rules! testgen_quantization {
burn_tensor::testgen_q_sin!();
burn_tensor::testgen_q_slice!();
burn_tensor::testgen_q_sort_argsort!();
// burn_tensor::testgen_q_split!();
Copy link
Member

Choose a reason for hiding this comment

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

Adding quantized tests is not well documented at the moment, so you're not expected to do it.
@laggui will work on making it more straightforward and he'll be able to adapt your non-quantized tests.

@nathanielsimard nathanielsimard merged commit d1398d6 into tracel-ai:main Nov 21, 2024
9 checks passed
@Luni-4
Copy link
Collaborator

Luni-4 commented Nov 21, 2024

Thanks a lot @agelas for your implementation! And thank you, @louisfd and @nathanielsimard for your reviews!

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.

4 participants