Skip to content

Repeat operation #2090

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

Merged
merged 17 commits into from
Aug 3, 2024
Merged

Repeat operation #2090

merged 17 commits into from
Aug 3, 2024

Conversation

mepatrick73
Copy link
Contributor

@mepatrick73 mepatrick73 commented Aug 1, 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

Closes #1715

Changes

Implementing multi-dimensional repeat operation for burn tensor. Renamed repeat to repeat_dim to better illustrate that repeat_dim only works on a single dimension.

Testing

Added unit tests to verify the correctness of the operation

@mepatrick73 mepatrick73 requested a review from antimora August 1, 2024 20:04
@mepatrick73 mepatrick73 self-assigned this Aug 1, 2024
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 98.21883% with 7 lines in your changes missing coverage. Please review.

Project coverage is 86.23%. Comparing base (62a30e9) to head (cef1084).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/burn-autodiff/src/ops/tensor.rs 40.00% 3 Missing ⚠️
crates/burn-autodiff/src/ops/bool_tensor.rs 0.00% 2 Missing ⚠️
crates/burn-autodiff/src/ops/int_tensor.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2090      +/-   ##
==========================================
+ Coverage   86.18%   86.23%   +0.04%     
==========================================
  Files         687      688       +1     
  Lines       88187    88465     +278     
==========================================
+ Hits        76008    76285     +277     
- Misses      12179    12180       +1     

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

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.

Looks good but I have a few requests:

  1. The book doc needs to be updated.
  2. The doc strings should be updated with what arguments are passed.
  3. Double check if your unit tests do not produce false positives. I linked a bug. So if you data type or shape do not match in addition to values, you'll have wrong assertion.

Self::new(K::repeat_dim(self.primitive, dim, times))
}

/// Repeat the tensor along the given dimensions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to describe arguments in the string docs.

let output = tensor.repeat_dim(0, 4);
let expected = TensorData::from([[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]);

output.into_data().assert_eq(&expected, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beware of the false positives bug: #1982

[[13.0, 14.0, 13.0, 14.0], [15.0, 16.0, 15.0, 16.0]],
]);

output.into_data().assert_eq(&expected, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beware of the false positives bug: #1982

[[13, 14, 13, 14, 13, 14], [15, 16, 15, 16, 15, 16]],
]);

output.into_data().assert_eq(&expected, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beware of the false positives bug: #1982

@mepatrick73 mepatrick73 requested a review from antimora August 2, 2024 19:00
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.

LGTM but there is one small change requested. See inlined. I am approving in advance.

Comment on lines 158 to 159
| `tensor.repeat_dim(2, 4)` | `tensor.repeat([1, 1, 4])` |
| `tensor.repeat(&[(0,2),(2,4)])` | `tensor.repeat([2, 1, 4])` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be consistent we should describe params being passed just like other examples in this doc. Also the pytorch equivalent examples should match. For example, tensor.repeat(&[(0,2),(2,4)]) is not same as tensor.repeat([2, 1, 4])

Comment on lines +56 to +59
[[1.0f32, 2.0f32], [3.0f32, 4.0f32]],
[[5.0f32, 6.0f32], [7.0f32, 8.0f32]],
[[9.0f32, 10.0f32], [11.0f32, 12.0f32]],
[[13.0f32, 14.0f32], [15.0f32, 16.0f32]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to change this but it's sufficient to specify type once (at the beginning) and rust can infer the types.

@mepatrick73 mepatrick73 merged commit f7639bd into main Aug 3, 2024
15 checks passed
@mepatrick73 mepatrick73 deleted the repeat-operation branch August 3, 2024 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Implement multi-dimensional repeat operation and rename existing repeat method
2 participants