Could you add an assert statement and check, that all tensors in your relation_geo_attention funtion are on the same device?
nn.DataParallel will split the data tensors in dim0 and send each chunk to the corresponding device.
I.e. if the first chunk has a batch_size of 51, all other tensors passed to the forward method will have the same batch size.
Also, make sure to use the forward method, as nn.DataParallel uses this method to split the data.
If you are using a custom function as mode.my_fun(data), you would have to take care of the splitting yourself.