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

Provide Tensor Padding Helpers #960

Closed
dcvz opened this issue Nov 16, 2023 · 1 comment · Fixed by #1097
Closed

Provide Tensor Padding Helpers #960

dcvz opened this issue Nov 16, 2023 · 1 comment · Fixed by #1097
Labels
feature The feature request good first issue Good for newcomers

Comments

@dcvz
Copy link
Contributor

dcvz commented Nov 16, 2023

Feature description

Would be great to have helpers in Tensor for padding. Similar to PyTorch's pad and Candle's pad_with_zeros

Additional Information

Some API like this would likely be good (result of conversation on Discord):

pub fn pad<const D: usize>(self, pad: Padding, pad_mode: PadMode, value: K::Elem) -> Tensor<B, D, K>


// Possible definition of padding
pub struct Padding {
    left: usize,
    right: usize,
    top: usize,
    bottom: usize,
}
impl Padding {
    pub fn uniform(value: usize) -> Self {
        Self {
            left: value,
            right: value,
            top: value,
            bottom: value,
        }
    }
    
    // Additional helpers to create useful padding configs
}
@antimora antimora added feature The feature request good first issue Good for newcomers labels Nov 16, 2023
@jcmullwh
Copy link
Contributor

Hi, I can take a shot at this one!

antimora added a commit that referenced this issue Mar 27, 2024
* Initial padding approach

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.

* Update padding.rs

remove unneeded import

* Update from Merge

Use crate Element

Swap from old from_data() to new from_data_devauto()

* Formatting Changes

Formatting changes from cargo fmt --all

* Additional Format Change

One more format change that cargo fmt didn't get the first time.

* Changes to Example

Modify Example to ensure it works.

* modify naming

better names for impl / input variables.

* Modify API

- Change Padding to PadSize.
- integrate padding value into PadMode.
- update tests and examples.

* Comments and print

Improve comments+naming and remove println

* Pad Fixes

Moved pad to numeric

Simplified PadMode Element

updated tensor creations

fixed doc example

* Fix test location

* Simplified pad API

* Fix for failed unit tests

* Remove bool_full

* Rename `pads` to `padding`

---------

Co-authored-by: Dilshod Tadjibaev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature The feature request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants