I was able to use this function for the same task by summing over the “output” tensor and passing it into the function along with the input tensor as-is. The first tensor in the result tuple contains the same number of batches as the input tensor.