Unfold and Conv1d

Hello everyone!

I need assistance with the effective calculation of conv1d over unfolded tensor.

So I have a tensor of size [b, 2, L_1] - batch size, channels, sequence length. Then I unfold it to have [b, 2, n_frames, L_2] - n_frames is the resulting number of frames after unfolding with kernel size L_2 and some stride. After that, I want to apply Conv1d to this tensor, and here is the problem.

  1. I can reshape it to [b * n_frames, 2, L_2] but this results in copying of the tensor data and a GPU’s memory overflow. DOES NOT WORK
  2. I can iterate in a loop over b (samples of my batch) and treat n_frames is a new batch dimension, feeding tensors of [n_frames, 2, L_2] into my model and that stacking the result after the loop. WORKS BUT SLOW

All that is to be done because of L_2 < L_1, i.e. my inner model takes inputs of length L_2 but an outer one works with sequences of length L_1, so I cut my longer input with overlaps and feed into the inner model.

Thank you!