ezorita:

Slicing is very inefficient in this case because it reallocs the whole remainder of a, so the overall procedure does not fit in memory.


That shouldn’t be the case, if I understand your use case correctly.
The output tensor will of course allocate new memory, but since the input is just sliced, it should not trigger a copy.
Do you have a code snippet so that we can have a look?