Thank you for your answer! It’s much clearer now.
After I captured the “ghost time” by using torch.cuda.synchronize() namely the code I showed above, I just change torch.max(torch.max(inputs.view(b, -1), dim=1)[0]) into torch.max(inputs) and the “ghost” time just vanished from my whole project after a long time of debugging and putting that off to next stage. However I don’t understand the reason behind it. Maybe it’s due to the computation graph or something else to which I didn’t pay much attention. Because when I do these two separately outside my project in a new file, I got the same result as you produced.
Anyway, the problem has gone even though I haven’t figured out why it is that way.