Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent loss/metrics with jax backend #20388

Closed
dkgaraujo opened this issue Oct 21, 2024 · 9 comments
Closed

Inconsistent loss/metrics with jax backend #20388

dkgaraujo opened this issue Oct 21, 2024 · 9 comments

Comments

@dkgaraujo
Copy link
Contributor

Training an LSTM-based model with mean_squared_error loss, I got the following training results, for which the math doesn't add up: the values of the loss (MSE) and metric (RMSE) are inconsistent.

Would anyone have an insight as to what could be happening here? Thank you in advance.

Screenshot 2024-10-21 at 23 33 39
@dkgaraujo
Copy link
Contributor Author

Apologies, the data is proprietary so I cannot post a reproducible example. However, the network is relatively simple and comprises only off-the-shelf layers.

@dkgaraujo
Copy link
Contributor Author

Update: I noted a similar thing also on tensorflow backend. Shouldn't the metric and the loss be calculated on the same data, the same way?

@dkgaraujo
Copy link
Contributor Author

For context: found this post here suggesting that kernel regularization is also used when calculating the "official" loss metric but not the validation metric. However, I couldn't find a confirmation in the documentation.

The model I am training is indeed using a L2 regularisation.

@mehtamansi29 mehtamansi29 added type:Bug keras-team-review-pending Pending review by a Keras team member. labels Oct 23, 2024
@jeffcarp
Copy link
Member

@dkgaraujo thanks for reporting, can you see what the results are with L2 normalization off?

@jeffcarp
Copy link
Member

One guess: it could be because the metrics are computed at a different frequency than losses.

@fchollet
Copy link
Collaborator

What's your code for RMSE? The most likely explanation is non-commutativity of the sqrt operation.

@sachinprasadhs sachinprasadhs added stat:awaiting response from contributor and removed keras-team-review-pending Pending review by a Keras team member. labels Oct 28, 2024
Copy link

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label Nov 12, 2024
@dkgaraujo
Copy link
Contributor Author

Actually I was able to track the issue. Apparently the loss (MSE) and the metric (RMSE) diverge when there is a regularization penalty added to a layer (https://keras.io/api/layers/regularizers/), because this gets added up to the loss but is not reflected in the metric. So from my perspective as an user, not a bug, but could be better documented perhaps.

@fchollet, I did not use custom RMSE code.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants