Same problem. When I try to forward a large image in CNN, same error occurs. I guess it’s because that a single variable takes too large GPU memory. Referring to https://discuss.pytorch.org/t/weird-cuda-illegal-memory-access-error/8848/2?u=liang,  its solution might help.