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

Reverse mode autodiff for diag_post_multiply #2453

Merged
merged 13 commits into from
Apr 2, 2021

Conversation

gregorp90
Copy link
Contributor

@gregorp90 gregorp90 commented Mar 31, 2021

Summary

Implemented custom reverse mode AD for diag_post_multiply() function. The implementation is based on the reverse mode implementation of diag_pre_multiply().

Tests

Added a test for prim where the arguments are of length zero.

Removed manual ad_tolerances from the mix test, similar to diag_pre_multiply(). Also added 4 mix tests, where the matrix is non-square.

Side Effects

None.

Release notes

Added custom reverse mode for diag_post_multiply() function.

Checklist

@rok-cesnovar
Copy link
Member

@gregorp90 I pushed a fix for an OpenCL test issue that surfaced here.

@t4c1 @bbbales2 can I interest any one of you for a review?

@gregorp90
Copy link
Contributor Author

@gregorp90 I pushed a fix for an OpenCL test issue that surfaced here.

@rok-cesnovar Thank you!

Copy link
Contributor

@t4c1 t4c1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one question.

template <typename T1, typename T2, require_eigen_t<T1>* = nullptr,
require_eigen_vector_t<T2>* = nullptr>
template <typename T1, typename T2,
require_eigen_matrix_dynamic_t<T1>* = nullptr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to this require to not allow vectors?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see this is what required the change to OpenCL tests (although new test is fine as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so this should be require_eigen_t instead of require_eigen_matrix_dynamic_t?

I based this implementation on the implementation of diag_pre_multiply. In that implementation, Ben made this change, as you can see here. Maybe @bbbales2 can provide some more details on this change?

Also, if we are already on this subject. Why does the prim test with 1x1 matrix not fail, if we have require_eigen_matrix_dynamic_t?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah require_eigen_t or require_eigen_matrix_t is fine.

Also, if we are already on this subject. Why does the prim test with 1x1 matrix not fail, if we have require_eigen_matrix_dynamic_t?

It is not the shape of the input that is the issue, but type. We have general matrix type (that can also contain a vector) and special types for row or column vector. The new require does not accept the specialized vector types, while the test probably uses general matrix type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should I revert back to require_eigen_t or leave the implementation as it is?

Thanks for the answer, makes things more clear now!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.
Should I make the same changes for diag_pre_multiply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t4c1 I made the changes to both, diag_pre_multiply and diag_post_multiply.

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.45 3.4 1.01 1.46% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 1.04 4.07% faster
eight_schools/eight_schools.stan 0.11 0.11 1.01 1.0% faster
gp_regr/gp_regr.stan 0.16 0.16 0.98 -1.86% slower
irt_2pl/irt_2pl.stan 5.38 5.37 1.0 0.19% faster
performance.compilation 91.5 89.4 1.02 2.29% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.68 8.72 1.0 -0.45% slower
pkpd/one_comp_mm_elim_abs.stan 30.46 31.1 0.98 -2.09% slower
sir/sir.stan 126.08 120.07 1.05 4.77% faster
gp_regr/gen_gp_data.stan 0.04 0.04 1.0 -0.29% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.02 3.05 0.99 -0.77% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.39 0.39 1.01 0.84% faster
arK/arK.stan 1.85 1.89 0.98 -1.98% slower
arma/arma.stan 0.79 0.77 1.03 2.62% faster
garch/garch.stan 0.64 0.64 1.01 0.67% faster
Mean result: 1.00744965818

Jenkins Console Log
Blue Ocean
Commit hash: d7be4a8


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@bbbales2 bbbales2 merged commit ddde6b2 into stan-dev:develop Apr 2, 2021
@gregorp90 gregorp90 deleted the diag-post-multiply-rev branch April 12, 2021 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants