If you want to add a custom callback inside the training loop you can add it in the trainer.py file. For example, if you want to record the losses at line 546, the losses for that iteration are stored in a dictionary losses which can be used to save to file.
# Report losses every 100 iterations in trainer.py
if step % 100 == 0:
for name, loss in losses.items():
print(name, loss)