Does lightning.gpu really have acceleration

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?

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 :slight_smile:.

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.

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

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

Let me know if that helps!

ok,thank you , i will have a try.
i am wondering that different diff_method will have different result?

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 :slight_smile:

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

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?

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 on this!

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

Here is my output of qml.about()

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! :smile:

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?