-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Loss functions applied in alphabetical order instead of by dictionary keys in Keras 3.5.0 #20596
Comments
A quick update:
I believe a reliable workaround is to use an ordered tuple instead. For example, this works for me:
|
Hi @malcolmlett, Thanks for reporting this issue. I tried to reproduce this issue but the output seems to be correct for both order in the latest version of keras(3.7.0) and tensorflow(2.18.0). |
I expect this will depend on what the Google Colab contributers have to say, but Google Colab's currently defaulting to keras 3.5.0, which has the bug. So I'd be wondering if there's any chance of a backport / fix in keras 3.5.0.....but I leave that up to those who know better. |
Hi, this was a bug with tree that was fixed in the recent versions. Back-fixing would be a bit tough and we aren't sure when Colab will update their image. But, if you use some "Colab magic" you can force the update on your instance:
|
Environment info
Problem description
There seems to be a change in Keras 3.5.0 that has introduced a bug for models with multiple outputs.
The problem is not present in Keras 3.4.1.
Passing a dictionary as
loss
to model.compile() should result in those loss functions being applied to the respective outputs based on output name. But instead they now appear to be applied in alphabetical order of dictionary keys, leading to the wrong loss functions being applied against the model outputs.For example, in the following snippet, "loss_small" gets applied against "output_big" when it should be applied against "output_small". It appears that the loss dictionary gets 1) re-ordered by alphabetical order of key, and then 2) the dictionary values are read off in the resultant order and applied as an ordered list against the model outputs.
This conclusion is the result of flipping the orders of these components and comparing the results. Which is what the following code does...
Code to reproduce
Code outputs on various environments
Current Google Colab env - fails on second ordering:
Downgraded TF version, no change:
Downgraded Keras, and now get correct output for both orderings
Final remarks
This seems related to tensorflow/tensorflow#37887, but looks like someone has since tried to fix that bug and introduced another perhaps?
The text was updated successfully, but these errors were encountered: