Closed bwohlberg closed 10 months ago
The bug turns out to be due to a combination of this
https://github.com/lanl/scico/blob/5ffd1f9046fa8e7e2e2f7d37846993a3ab2221dd/scico/functional/_functional.py#L35-L36
and this
https://github.com/lanl/scico/blob/5ffd1f9046fa8e7e2e2f7d37846993a3ab2221dd/scico/loss.py#L126-L129
The copy
call does not result in an __init__
call, so the new Loss
object ends up with _grad
set to the function that was originally constructed when __init__
was called for the "original", unscaled Loss
object.
PR #470 has a simple fix, but this issue raises a few broader design questions:
_grad
attribute of Functional
objects rather than simply defining their grad
method as directly computing the gradient from __call__
?Loss
implementation not be at least slightly simpler if it were derived from ScaledFunctional
rather than Functional
?
There is a bug in
Loss.grad
handling of thescale
attribute, but only when it's set via scalar multiplication:The same bug is not present in
Functional.grad
: