# Trainer log my custom metrics at training step

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-log-my-custom-metrics-at-training-step%2F55204%3E%5C
**Category:** Beginners\
**Created:** [September 16, 2023, 4:41am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-log-my-custom-metrics-at-training-step%2F55204 "2023-09-16T04:41:38Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ch272h](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ch272h/32/29655_2.png) [@ch272h](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fch272h)%5C
**Post date:** [January 24, 2024, 9:14pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-log-my-custom-metrics-at-training-step%2F55204%2F3 "2024-01-24T21:14:20Z")

</div>

If you don’t use gradient accumulation, then I usually just hack by overwriting `Trainer.compute_loss` and tucking in one line of `self.log(compute_my_metric(output)`

If you use gradient accumulation, one alternative is to trigger a CustomCallback per [Metrics for Training Set in Trainer - #7 by Kaveri](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fmetrics-for-training-set-in-trainer%2F2461%2F7). For example, you can do one forward pass on the entire train set on\_epoch\_end or on\_evaluate. It will be repeated work, slow and coarse.

And let me know if you figured out an easy way to log custom loss!

---

_[View the full topic](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-log-my-custom-metrics-at-training-step%2F55204)._
