Hi ptrblck,
Thank you so much for your reply!
position: cuda:0
mask    : cuda:0
input   : cuda:0

(The same pattern reoccur for multiple times before the error occurs).
I print the device as you suggested. To my surprise all are on cuda:0.