I guess your first code snippet is missing the with torch.no_grad() guard or with torch.inference_mode()? If so, then yes you wouldn’t need to detach() the tensors as no computation graph would be created. However, it would also be a no-op so you could also leave it if you are already using it.