Problem solved.
I made a very stupid mistake.
There is a line in the head which is
os.environ["CUDA_VISIBLE_DEVICES"] = '3'.
I did not notice it first time I ran the program and got another error. I revised it to os.environ["CUDA_VISIBLE_DEVICES"] = '0' without restarting the kernel. Then l got this error.
Restart the program with os.environ["CUDA_VISIBLE_DEVICES"] = '0'can solve the problem.