It looks like you’re running all your code on cuda but you don’t do any synchronization when timing.
The cuda api is asynchronous, so you need to manually add torch.cuda.synchronize() before calling time.time() if you want to measure the actual runtime.