nn.DataParallel will create replicas of your model and chunk the input in dim0 into smaller batches for each GPU. If you use to(device) in your forward method, you force this tensor to be on a specific device, which will throw this error.
Usually you would push the input data to the default device in your training loop, not the forward method.
Is there a specific reason, why you would use it in forward?