Right, I was referring to these lines:
log.record(pos=pos, trn_loss=trn_loss, end='\r')
log.record(pos=pos, val_loss=val_loss, end='\r')

and changing them to something like
log.record(pos=pos, trn_loss=trn_loss.detach().clone(), end='\r')
log.record(pos=pos, val_loss=val_loss.detach().clone(), end='\r')