-
Notifications
You must be signed in to change notification settings - Fork 353
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
Provide Tensor Padding Helpers #960 #1097
Conversation
Create padding implementation for the last two dimensions of Float and Int Tensors. Create PadMode Enum, allowing Constant padding. Create Padding Struct with Uniform, Asymmetric, height, and width implementations. Create tests for the padding implementation.
remove unneeded import
Use crate Element Swap from old from_data() to new from_data_devauto()
Formatting changes from cargo fmt --all
One more format change that cargo fmt didn't get the first time.
Modify Example to ensure it works.
better names for impl / input variables.
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.
Thanks for the contribution! I primarily reviewed the API, but there are still some fixes to be made regarding remaining prints and comments.
burn-tensor/src/tensor/api/base.rs
Outdated
// Create the padded tensor | ||
let padded_shape = Shape::from(padded_dims); | ||
let padded_data = Data::full(padded_shape, padding_value); | ||
let padded_tensor = Tensor::<B, D, K>::from_data_devauto(padded_data); | ||
|
||
// Assign the original tensor data to the appropriate slice of the padded tensor | ||
padded_tensor.slice_assign(ranges, self) |
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.
Using Data
is not efficient; it's preferable to use Tensor::full(shape, value)
instead of Data::full
.
burn-tensor/src/tensor/api/base.rs
Outdated
pub fn pad( | ||
self, | ||
pad_amount: Padding, | ||
pad_mode: PadMode, |
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 would change a bit the API
Padding
=> PadSize
.
The mode should contains the value:
let tensor = tensor.pad(PadSize::uniform(2), PadMode::Constant(0));
burn-tensor/src/tensor/api/base.rs
Outdated
} | ||
|
||
/// Represents padding quantity for a tensor. | ||
pub struct Padding { |
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.
PadSize
- Change Padding to PadSize. - integrate padding value into PadMode. - update tests and examples.
Improve comments+naming and remove println
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.
Just some minor comments to be updated with the new changes added to the API.
Let us know if you need more assistance with this PR. |
Got bogged down the last couple weeks, should be able to get it fixed this weekend! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1097 +/- ##
==========================================
+ Coverage 86.32% 86.34% +0.02%
==========================================
Files 680 681 +1
Lines 77647 77761 +114
==========================================
+ Hits 67030 67145 +115
+ Misses 10617 10616 -1 ☔ View full report in Codecov by Sentry. |
@nathanielsimard, I have cleaned up this PR and resolved all the issues so we can merge it. The remaining work (bool tensor) is in a separate ticket #1535 (assigned to you) |
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! Apart from the existing review comment I only have one minor comment regarding parameter naming but I'm approving in advance.
Pull Request for Tensor Padding Feature Enhancement
Checklist
run-checks all
script has been executed.Related Issues/PRs
Fixes #960
Changes
This PR addresses the need for padding functionality in tensors of float and integer types. This is an initial implementation covering only constant value padding. The solution implemented involves adding methods for both constant padding mode and handling different padding sizes. The changes enhance the library's functionality by enabling users to easily manipulate tensor dimensions. The functionality is largely based on pytorch listed as an example.
Testing
The testing for these changes involves unit tests added to the tensor API testing module. These tests cover multiple scenarios including padding 2D and 4D tensors with constant values, and applying asymmetric padding. The tests ensure the correct implementation of padding across different tensor types and dimensions. All new tests have been executed successfully with the existing test suite, confirming that the new feature works as expected.
Remaining Work
#1535