# Does lightning.gpu really have acceleration

**URL:** <https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705>\
**Category:** PennyLane Help\
**Created:** [November 20, 2023, 9:11am UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705 "2023-11-20T09:11:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![HotFrog](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@HotFrog](https://discuss.pennylane.ai/u/HotFrog)\
**Post date:** [November 20, 2023, 9:11am UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/1 "2023-11-20T09:11:50Z")

</div>

I am using lightning.gpu and torchlayer for image classification tasks, but using lightning.gpu seems to have no acceleration effect, and may not even be as good as default.qubit. Why is this?

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [November 20, 2023, 2:05pm UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/2 "2023-11-20T14:05:38Z")

</div>

Hey @HotFrog!

It depends on how big your circuit is. Lightning GPU doesn’t offer much of a speedup when you have a small number of qubits because of computational overheads. When you start going to upwards of 20 qubits, you’ll notice a speedup 🙂.

---

<div class="post-metadata">

**Author:** ![HotFrog](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@HotFrog](https://discuss.pennylane.ai/u/HotFrog)\
**Post date:** [November 21, 2023, 1:15am UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/4 "2023-11-21T01:15:33Z")

</div>

when i am using lightning.gpu and pytorch run resnet152 , it is really slow.  
when i use default.qubit and cpu (not cuda) ,it is much more faster than lightning.gpu with cuda.  
if i just use classic method to train resnet152, it takes me 5 mins on cuda, 1.8 hours on cpu. but with quantum , it takes 16 hours on cuda , 2. 2hours on cpu.  
This makes me doubt whether the mixture of quantum and classical networks cannot fully utilize the GPU.

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [November 21, 2023, 2:32pm UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/5 "2023-11-21T14:32:55Z")

</div>

Hey @HotFrog, you might want to try using adjoint differentiation instead:

```auto
@qml.qnode(dev, diff_method="adjoint")
def circuit(params):
    ...

```

Let me know if that helps!

---

<div class="post-metadata">

**Author:** ![HotFrog](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@HotFrog](https://discuss.pennylane.ai/u/HotFrog)\
**Post date:** [November 22, 2023, 2:35am UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/6 "2023-11-22T02:35:29Z")

</div>

ok，thank you , i will have a try.  
i am wondering that different diff\_method will have different result?

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [November 22, 2023, 10:12pm UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/7 "2023-11-22T22:12:36Z")

</div>

Great question! All differentiation methods should be very very close to each other in that the results should be nearly identical! The performance, however, will vary 🙂

---

<div class="post-metadata">

**Author:** ![kevinkawchak](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/kevinkawchak/32/1801_2.png) [@kevinkawchak](https://discuss.pennylane.ai/u/kevinkawchak)\
**Post date:** [November 24, 2023, 8:24am UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/8 "2023-11-24T08:24:52Z")

</div>

Hello @HotFrog, some benchmarking studies, compatibility depends on the model:

> <https://github.com/kevinkawchak/Medical-Quantum-Machine-Learning/tree/main/Code/PennyLane/Benchmarking%20Devices>
>
> //github.com/kevinkawchak/Medical-Quantum-Machine-Learning/tree/main/Code/PennyLane/Benchmarking%20Devices

> <https://github.com/kevinkawchak/Medical-Quantum-Machine-Learning/tree/main/Code/All%20Qiskit%2C%20PennyLane%20QML%20Nov%2023>
>
> //github.com/kevinkawchak/Medical-Quantum-Machine-Learning/tree/main/Code/All%20Qiskit%2C%20PennyLane%20QML%20Nov%2023

---

<div class="post-metadata">

**Author:** ![vishwa](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/vishwa/32/2132_2.png) [@vishwa](https://discuss.pennylane.ai/u/vishwa)\
**Post date:** [November 26, 2023, 6:12pm UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/9 "2023-11-26T18:12:58Z")

</div>

Hi @isaacdevlugt,  
In my case, I noticed that `diff_method="adjoint"` took twice as long to run as compared to the default `diff_method`. Also, the performance seemed to be off by 5-10%.

So it seems to me that `diff_method="adjoint"` doesn’t always improve performance for `lightning.gpu`. Can you help me understand in what situations would it prove beneficial?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [November 27, 2023, 7:09pm UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/10 "2023-11-27T19:09:59Z")

</div>

Hi @vishwa, welcome to the Forum!

Could you please share your code and the output of `qml.about()`?

Also, to be sure I understand your problem, are you doing the comparison between not specifying any `diff_method` and using `diff_method="adjoint"`? Or are you doing a different comparison?

`diff_method="adjoint"` is generally the best method when you’re simulating circuits. If you want to learn how adjoint differentiation works you can take a look at our [demo](https://pennylane.ai/qml/demos/tutorial_adjoint_diff/) on this!

---

<div class="post-metadata">

**Author:** ![vishwa](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/vishwa/32/2132_2.png) [@vishwa](https://discuss.pennylane.ai/u/vishwa)\
**Post date:** [November 27, 2023, 9:32pm UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/11 "2023-11-27T21:32:22Z")

</div>

Yes, I was comparing performance when not specifying any `diff_method` versus specifying `diff_method="adjoint"`

Here is my output of `qml.about()`

```auto
Name: PennyLane
Version: 0.33.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /home/QC/.venv/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning, PennyLane-Lightning-GPU

Platform info: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 1.26.1
Scipy version: 1.11.3
Installed devices:
- lightning.gpu (PennyLane-Lightning-GPU-0.33.1)
- default.gaussian (PennyLane-0.33.1)
- default.mixed (PennyLane-0.33.1)
- default.qubit (PennyLane-0.33.1)
- default.qubit.autograd (PennyLane-0.33.1)
- default.qubit.jax (PennyLane-0.33.1)
- default.qubit.legacy (PennyLane-0.33.1)
- default.qubit.tf (PennyLane-0.33.1)
- default.qubit.torch (PennyLane-0.33.1)
- default.qutrit (PennyLane-0.33.1)
- null.qubit (PennyLane-0.33.1)
- lightning.qubit (PennyLane-Lightning-0.33.1)

```

Thanks for sharing the demo! 😄

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [November 29, 2023, 3:32am UTC](https://discuss.pennylane.ai/t/does-lightning-gpu-really-have-acceleration/3705/12 "2023-11-29T03:32:25Z")

</div>

Thanks for sharing this information @vishwa !

Could you please also share the code that you’re using which exhibits the performance difference that you mentioned before?
