# Backward function takes long and batches

**URL:** <https://discuss.pennylane.ai/t/backward-function-takes-long-and-batches/164>\
**Category:** PennyLane Help\
**Created:** [June 18, 2019, 5:17pm UTC](https://discuss.pennylane.ai/t/backward-function-takes-long-and-batches/164 "2019-06-18T17:17:45Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![erinaldiq](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/erinaldiq/32/1423_2.png) [@erinaldiq](https://discuss.pennylane.ai/u/erinaldiq)\
**Post date:** [January 12, 2023, 6:51am UTC](https://discuss.pennylane.ai/t/backward-function-takes-long-and-batches/164/8 "2023-01-12T06:51:36Z")

</div>

Thanks for the reply @Tom_Bromley

I am using `pennylane-0.28.0` and for a circuit with batched inputs I still get `dev.num_executions==10` if the batch size is 10 when using the `qiskit.ibmq` device. Your example gives `dev.num_executions==1` with the `default.qubit` device, and I can reproduce that.

The transpose in the return of the forward function is rearranging the output and changing the first dimension from being the batch size to being the number of wires. Removing the `.T` seems to be correct but I may be wrong.

I see that the `TorchLayer` forward pass is unstacking the first dimension:

```auto
        if len(inputs.shape) > 1:
            # If the input size is not 1-dimensional, unstack the input along its first dimension,
            # recursively call the forward pass on each of the yielded tensors, and then stack the
            # outputs back into the correct shape
            reconstructor = [self.forward(x) for x in torch.unbind(inputs)]
            return torch.stack(reconstructor)

```

while in your example you call `qlayer.qnode` on the entire batch.  
This seems to do what I expect and a single job is submitted to the IBMQ backend with a number of circuits equal to the batch size.

Can you explain (some of) the reason(s) why this is not the default behavior?

Thank you again for the quick reply!

---

_[View the full topic](https://discuss.pennylane.ai/t/backward-function-takes-long-and-batches/164)._
