Closed madeleineth closed 5 years ago
Thanks for reporting. This is still a work-in-progress, so @VMatthijs will have to report back on this one. I hadn't even realized he was tackling a neg-binomial GLM.
Thanks for spotting this, @madeleineth ! This is fixed by PR https://github.com/stan-dev/math/pull/687 once that gets merged. Please note that your first suggested way changing the tests does not work. The second suggested way is correct, however.
Closed via #687
Summary:
neg_binomial_2_log_glm_lpmf
has suspicious behavior in its partial derivative with respect toalpha
.Description:
I am seeing inconsistent results in the adjoint of
alpha
when computed withneg_binomial_2_log_lpmf
andneg_binomial_2_log_glm_lpmf
. The adjoint computed withneg_binomial_2_log_lpmf
matches the numeric derivative (computed in unit tests of a different system), so I suspect an issue withneg_binomial_2_log_glm_lpmf
. (I may also just be confused; this is my first time descending into the stan math code.)Reproducible Steps:
I've repeated the
alpha_adj
check on macOS 10.13.4 (Apple LLVM version 9.1.0 (clang-902.0.39.1)
) with the same results.Additional Information:
My guess is that there is a bug in the
neg_binomial_2_log_glm_lpmf
gradient code. Theglm_matches_neg_binomial_2_log_vars
test doesn't find it because it callsrecover_memory
, then referencesalpha
, etc. (which are invalidated byrecover_memory
) afterwards in such a way that the adjoints from theneg_binomial_2_log_glm_lpmf
are getting compared to themselves, so all the tests pass. Indeed, this patch:leads to this output:
Note that
alpha
andalpha2
are completely independent. Stan is using the arena allocator, so ASan wouldn't catch the use-after-free.I haven't looked hard enough at
neg_binomial_2_log_glm_lpmf.hpp
to find the real bug (if any), though.Current Version:
develop
HEAD (cefeb9843181354148ddc74b68c2644533bcfe2e)