Skip to content

Commit

Permalink
mention how to use metrics in the docs. (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfalbel authored May 14, 2023
1 parent ecb9b1c commit 65448bb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vignettes/custom-loop.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ net <- nn_module(
ctx$loss <- list()
for (opt_name in names(ctx$optimizers)) {
pred <- ctx$model(ctx$input)
ctx$pred <- ctx$model(ctx$input)
opt <- ctx$optimizers[[opt_name]]
loss <- nnf_cross_entropy(pred, target)
Expand Down Expand Up @@ -187,6 +187,9 @@ The important things to notice here are:

- Callbacks that would be called inside the default `step()` method like `on_train_batch_after_pred`, `on_train_batch_after_loss`, etc, won't be automatically called. You can still cal them manually by adding `ctx$call_callbacks("<callback name>")` inside your training step. See the code for `fit_one_batch()` and `valid_one_batch` to find all the callbacks that won't be called.

- If you want luz metrics to work with your custom `step()` method, you must assign `ctx$pred` with the model predictions
as metrics will always be called with `metric$update(ctx$pred, ctx$target)`.

## Next steps

In this article you learned how to customize the `step()` of your training loop using luz layered functionality.
Expand Down

0 comments on commit 65448bb

Please sign in to comment.