burn icon indicating copy to clipboard operation
burn copied to clipboard

Add `chunk` Tensor Method

Open dcvz opened this issue 2 years ago • 8 comments

Feature description

Add a chunk method on tensor to faciliate splitting a tensor into a given number of chunks

Feature motivation

Its a fairly common operation supported by other ML frameworks.

Actions

  • [x] Default method implementation (@dcvz)
  • [ ] Backend implementation (@Kelvinyu1117)

dcvz avatar Nov 19 '23 22:11 dcvz

I would like to work on this issue, can you assign it to me?

Kelvinyu1117 avatar Nov 20 '23 14:11 Kelvinyu1117

I would like to work on this issue, can you assign it to me?

Nice! Let me know if you need any guidance. You can also find me in the Discord as @dcvz.

dcvz avatar Nov 20 '23 14:11 dcvz

I would like to work on this issue, can you assign it to me?

Done

antimora avatar Nov 20 '23 15:11 antimora

I just had a brief look at the source code, the file I should modify is src/tensor/api/base.rs right? And the interface is as follows:

pub fn chunk<const D2: usize>(
    Tensor<B, D2, K>& tensor, 
    chunks: usize, 
    dim: usize = 0) -> Vec<Tensor<B, D2, K>>
{
}

Kelvinyu1117 avatar Nov 21 '23 13:11 Kelvinyu1117

I just had a brief look at the source code, the file I should modify is src/tensor/api/base.rs right? And the interface is as follows:

Correct! I think interface can likely be the following, if you do the chunking in base space:

pub fn chunk(self, chunks: usize, dim: usize) -> Vec<Self>

Although given that some of the backends already have their own implementations, it might be better to do this backend specific instead of general (depends on what optimizations they have). What do you say @nathanielsimard ?

dcvz avatar Nov 21 '23 14:11 dcvz

I think leveraging the implementation of the backend is a good idea!

Kelvinyu1117 avatar Nov 22 '23 05:11 Kelvinyu1117

@dcvz can this issue be closed as the main PR is merged?

antimora avatar Nov 29 '23 22:11 antimora

I'm working on the backend implementation, we can use this issue or open another issue as a tracker.

Kelvinyu1117 avatar Nov 30 '23 02:11 Kelvinyu1117