# Parallel training of samples in a batch

**URL:** <https://discuss.pennylane.ai/t/parallel-training-of-samples-in-a-batch/791>\
**Category:** PennyLane Help\
**Created:** [January 29, 2021, 3:20pm UTC](https://discuss.pennylane.ai/t/parallel-training-of-samples-in-a-batch/791 "2021-01-29T15:20:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanruiwang](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/hanruiwang/32/431_2.png) [@hanruiwang](https://discuss.pennylane.ai/u/hanruiwang)\
**Post date:** [January 29, 2021, 3:20pm UTC](https://discuss.pennylane.ai/t/parallel-training-of-samples-in-a-batch/791/1 "2021-01-29T15:20:40Z")

</div>

Hi PennyLane Team,

I’m trying to train a hybrid classical-quantum network for MNIST classification using the pennylane and pytorch. I’m wondering if there is a way to parallel process samples in a batch to speedup the processing.

It seems to me that samples in a batch are processed sequentially as in pennylane/qnn/torch.py:302.

```
    def forward(self, inputs): # pylint: disable=arguments-differ
    """Evaluates a forward pass through the QNode based upon input data and the initialized
    weights.

    Args:
        inputs (tensor): data to be processed

    Returns:
        tensor: output data
    """
    if len(inputs.shape) == 1:
        return self._evaluate_qnode(inputs)

    return torch.stack([self._evaluate_qnode(x) for x in inputs])
```

---

<div class="post-metadata">

**Author:** ![antalszava](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/antalszava/32/171_2.png) [@antalszava](https://discuss.pennylane.ai/u/antalszava)\
**Post date:** [January 29, 2021, 8:54pm UTC](https://discuss.pennylane.ai/t/parallel-training-of-samples-in-a-batch/791/2 "2021-01-29T20:54:21Z")

</div>

Hi @hanruiwang,

Welcome to the forum and thank you for your question! 🙂

Indeed, batches of samples are processed sequentially. As you suggest, the ability to do that parallelly would be great to have and we would like to look into adding this in the future.

One thing to note is that some devices allow batched execution when computing gradients (e.g., the [PennyLane-Braket Plugin](https://amazon-braket-pennylane-plugin-python.readthedocs.io/en/latest/)) to execute quantum circuits parallelly.

---

<div class="post-metadata">

**Author:** ![hanruiwang](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/hanruiwang/32/431_2.png) [@hanruiwang](https://discuss.pennylane.ai/u/hanruiwang)\
**Post date:** [February 3, 2021, 9:50pm UTC](https://discuss.pennylane.ai/t/parallel-training-of-samples-in-a-batch/791/3 "2021-02-03T21:50:05Z")

</div>

Hi @antalszava,

Got it. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![glassnotes](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/glassnotes/32/327_2.png) [@glassnotes](https://discuss.pennylane.ai/u/glassnotes)\
**Post date:** [February 5, 2021, 12:52pm UTC](https://discuss.pennylane.ai/t/parallel-training-of-samples-in-a-batch/791/4 "2021-02-05T12:52:21Z")

</div>


