I also met the same error when evaluating the model
RuntimeError: CUDA error: an illegal memory access was encountered
My code looks like
correct = 0
total = 0
for i, (input, target) in tqdm.tqdm(enumerate(data_loader), total=len(dataset)//batch_size):
    target = target.to(device)
    input = input.to(device)
    output = self.model.forward_t(input)
    c = output.argmax(dim=1)
    total += len(target)
    correct += sum(target.cpu().numpy() == c.cpu().numpy())
    acc = float(correct) / total

It is also strange that, if I do not use .cpu.numpy() to convert the data first, the result will be incorrect.