Try changing from:
loss, tr_logits = model(input_ids=ids, attention_mask=mask, labels=targets)

to:
outputs = model(input_ids=ids, attention_mask=mask, labels=targets)
loss = outputs["loss"]
tr_logits = outputs["logits"]