If you want to do it on the cpu, you might want to look into torch.multiprocessing, but I’m not sure there is a better way using only tensor operations. A naive approach padding each subtensor with 0s so that they have the same size would possibly be slower.