# How to record loss during training with Flux.jl?

**URL:** https://discourse.julialang.org/t/how-to-record-loss-during-training-with-flux-jl/77877
**Category:** Machine Learning
**Tags:** flux
**Created:** [March 14, 2022, 4:26pm UTC](https://discourse.julialang.org/t/how-to-record-loss-during-training-with-flux-jl/77877 "2022-03-14T16:26:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)
#### Post date: [March 14, 2022, 4:26pm UTC](https://discourse.julialang.org/t/how-to-record-loss-during-training-with-flux-jl/77877/1 "2022-03-14T16:26:05Z")

</div>

I want to record the training-loss, along with the test-loss, during a training process. I have to compute the test-loss seperatly from the training process, but I am thinking that I should be able to hook into the training machinery to access and save the train-loss.

But after spending some time with dead-end errors and non-terminating training loops, I need help - how can I record the training loss during training, without re-evaluating it?

---

<div class="post-metadata">

### Author: ![trahflow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trahflow/32/30585_2.png) [@trahflow](https://discourse.julialang.org/u/trahflow)
#### Post date: [March 14, 2022, 4:35pm UTC](https://discourse.julialang.org/t/how-to-record-loss-during-training-with-flux-jl/77877/2 "2022-03-14T16:35:05Z")

</div>

See at the very bottom of the [‘Training Models’ section of Flux’s documentation](https://fluxml.ai/Flux.jl/stable/training/training/)

There it suggests to use `Zygote.pullback()` for that purpose (and gives example code). Make sure though to read the whole section. This currently requires you to use a custom training loop instead of `Flux.train!()`.

Btw, I can recommend [https://github.com/JuliaLogging/TensorBoardLogger.jl](https://github.com/JuliaLogging/TensorBoardLogger.jl) to log this.
