Moving memory expensive losses to different device

Could you post the custom loss function? From what I’ve seen it’s easy to accidentally keep data in memory that should be detached. (see FAQ Memory Topic)