NVIDIA / modulus-sym

Framework providing pythonic APIs, algorithms and utilities to be used with Modulus core to physics inform model training as well as higher level abstraction for domain experts
https://developer.nvidia.com/modulus
Apache License 2.0
165 stars 68 forks source link

:bug: [BUG]: Incorrect get_num_losses return value when using custom loss function #24

Open zinccat opened 1 year ago

zinccat commented 1 year ago

The implementation of get_num_losses in domain.py is summing up the number of output names in constraints. Yet this is not the case when using custom loss function, e.g. when using variational constraint like the case in https://docs.nvidia.com/deeplearning/modulus/modulus-sym/user_guide/intermediate/variational_example.html

NickGeneva commented 1 year ago

Thanks for the report, I agree this is a bug. The get_num_losses in domain uses the output names of each constraint to get a total number of losses.

The custom loss, particularly in the variational constraint does not give its output variables ahead of time and the variational constraint constructor will have 0 output keys (and thus say it has zero losses) since there are no output keys of a variational data set.

Unsure about a clean fix, without requiring additional user information its not possible presently to tell that a custom loss exists in this constraint without a forward pass. Example impacted.