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

Optimize rule/marginalrule dispatch #299

Merged
merged 11 commits into from
Mar 24, 2023
Merged

Conversation

bvdmitri
Copy link
Member

@bvdmitri bvdmitri commented Mar 22, 2023

This PR improves upon #290 and addresses #284 even further.

A better version of the #292 without breaking changes. The PR improves execution time and memory allocation profile in 100% test-cases by various degree. Particularly useful for small models and real-time inference at a high rate, but also improves the performance of variational iterations.

Timings
benchmark_ar_22-03-2023-19-14_v1.8.5.txt: Time  (mean ± σ):   116.908 ms ±  11.944 ms  ┊ GC (mean ± σ):  12.96% ±  6.93%
benchmark_ar_22-03-2023-19-19_v1.8.5.txt: Time  (mean ± σ):   154.613 ms ±   9.033 ms  ┊ GC (mean ± σ):  11.50% ±  4.04%
benchmark_cvi_22-03-2023-19-16_v1.8.5.txt: Time  (mean ± σ):   4.135 s ± 4.514 ms  ┊ GC (mean ± σ):  7.59% ± 0.27%
benchmark_cvi_22-03-2023-19-21_v1.8.5.txt: Time  (mean ± σ):   4.396 s ± 10.455 ms  ┊ GC (mean ± σ):  7.13% ± 0.10%
benchmark_gmm_multivariate_22-03-2023-19-14_v1.8.5.txt: Time  (mean ± σ):   190.276 ms ±  13.886 ms  ┊ GC (mean ± σ):  15.70% ±  4.46%
benchmark_gmm_multivariate_22-03-2023-19-19_v1.8.5.txt: Time  (mean ± σ):   186.198 ms ±  13.032 ms  ┊ GC (mean ± σ):  16.57% ±  4.53%
benchmark_gmm_univariate_22-03-2023-19-14_v1.8.5.txt: Time  (mean ± σ):   11.074 ms ±  3.562 ms  ┊ GC (mean ± σ):  10.65% ± 15.79%
benchmark_gmm_univariate_22-03-2023-19-19_v1.8.5.txt: Time  (mean ± σ):   11.120 ms ±  3.382 ms  ┊ GC (mean ± σ):  10.43% ± 15.56%
benchmark_hgf_22-03-2023-19-15_v1.8.5.txt: Time  (mean ± σ):   254.252 ms ±   4.763 ms  ┊ GC (mean ± σ):  7.19% ± 1.54%
benchmark_hgf_22-03-2023-19-20_v1.8.5.txt: Time  (mean ± σ):   316.044 ms ±   5.141 ms  ┊ GC (mean ± σ):  7.57% ± 1.16%
benchmark_iid_mv_covariance_22-03-2023-19-15_v1.8.5.txt: Time  (mean ± σ):   54.497 ms ±  7.338 ms  ┊ GC (mean ± σ):  10.90% ± 10.16%
benchmark_iid_mv_covariance_22-03-2023-19-20_v1.8.5.txt: Time  (mean ± σ):   67.399 ms ±  6.689 ms  ┊ GC (mean ± σ):  10.33% ±  8.46%
benchmark_iid_mv_precision_22-03-2023-19-15_v1.8.5.txt: Time  (mean ± σ):   45.121 ms ±  6.445 ms  ┊ GC (mean ± σ):  11.46% ± 11.09%
benchmark_iid_mv_precision_22-03-2023-19-20_v1.8.5.txt: Time  (mean ± σ):   58.066 ms ±  6.896 ms  ┊ GC (mean ± σ):  11.72% ±  9.91%
benchmark_iid_mv_wishart_known_mean_22-03-2023-19-15_v1.8.5.txt: Time  (mean ± σ):   23.165 ms ±  4.812 ms  ┊ GC (mean ± σ):  11.62% ± 14.38%
benchmark_iid_mv_wishart_known_mean_22-03-2023-19-20_v1.8.5.txt: Time  (mean ± σ):   30.276 ms ±  5.276 ms  ┊ GC (mean ± σ):  10.82% ± 12.71%
benchmark_lar_22-03-2023-19-14_v1.8.5.txt: Time  (mean ± σ):   234.965 ms ±  16.567 ms  ┊ GC (mean ± σ):  15.16% ±  3.30%
benchmark_lar_22-03-2023-19-19_v1.8.5.txt: Time  (mean ± σ):   238.453 ms ±  13.296 ms  ┊ GC (mean ± σ):  14.84% ±  2.98%
benchmark_linreg_22-03-2023-19-16_v1.8.5.txt: Time  (mean ± σ):   13.958 ms ±  3.618 ms  ┊ GC (mean ± σ):  8.58% ± 14.03%
benchmark_linreg_22-03-2023-19-21_v1.8.5.txt: Time  (mean ± σ):   20.549 ms ±  3.664 ms  ┊ GC (mean ± σ):  6.90% ± 11.73%
benchmark_linreg_broadcasted_22-03-2023-19-16_v1.8.5.txt: Time  (mean ± σ):   14.122 ms ±  3.813 ms  ┊ GC (mean ± σ):  8.72% ± 14.17%
benchmark_linreg_broadcasted_22-03-2023-19-21_v1.8.5.txt: Time  (mean ± σ):   20.054 ms ±  3.583 ms  ┊ GC (mean ± σ):  6.99% ± 11.83%
benchmark_mlgssm_22-03-2023-19-15_v1.8.5.txt: Time  (mean ± σ):   19.812 ms ±  4.303 ms  ┊ GC (mean ± σ):  8.82% ± 13.48%
benchmark_mlgssm_22-03-2023-19-20_v1.8.5.txt: Time  (mean ± σ):   20.083 ms ±  4.356 ms  ┊ GC (mean ± σ):  9.25% ± 13.81%
benchmark_probit_22-03-2023-19-15_v1.8.5.txt: Time  (mean ± σ):   9.169 ms ±  2.067 ms  ┊ GC (mean ± σ):  5.79% ± 11.77%
benchmark_probit_22-03-2023-19-20_v1.8.5.txt: Time  (mean ± σ):   9.676 ms ±  2.084 ms  ┊ GC (mean ± σ):  5.71% ± 11.62%
benchmark_ulgssm_22-03-2023-19-14_v1.8.5.txt: Time  (mean ± σ):   9.080 ms ±  3.266 ms  ┊ GC (mean ± σ):  9.75% ± 14.96%
benchmark_ulgssm_22-03-2023-19-19_v1.8.5.txt: Time  (mean ± σ):   9.809 ms ±  2.915 ms  ┊ GC (mean ± σ):  8.74% ± 14.35%
Memory profile
benchmark_ar_22-03-2023-19-14_v1.8.5.txt: Memory estimate: 104.76 MiB, allocs estimate: 1741637.Julia Version 1.8.5
benchmark_ar_22-03-2023-19-19_v1.8.5.txt: Memory estimate: 121.36 MiB, allocs estimate: 2216360.Julia Version 1.8.5
benchmark_cvi_22-03-2023-19-16_v1.8.5.txt: Memory estimate: 4.00 GiB, allocs estimate: 129789350.Julia Version 1.8.5
benchmark_cvi_22-03-2023-19-21_v1.8.5.txt: Memory estimate: 4.01 GiB, allocs estimate: 130044244.Julia Version 1.8.5
benchmark_gmm_multivariate_22-03-2023-19-14_v1.8.5.txt: Memory estimate: 231.92 MiB, allocs estimate: 3273546.Julia Version 1.8.5
benchmark_gmm_multivariate_22-03-2023-19-19_v1.8.5.txt: Memory estimate: 239.39 MiB, allocs estimate: 3403106.Julia Version 1.8.5
benchmark_gmm_univariate_22-03-2023-19-14_v1.8.5.txt: Memory estimate: 13.92 MiB, allocs estimate: 286684.Julia Version 1.8.5
benchmark_gmm_univariate_22-03-2023-19-19_v1.8.5.txt: Memory estimate: 14.65 MiB, allocs estimate: 297058.Julia Version 1.8.5
benchmark_hgf_22-03-2023-19-15_v1.8.5.txt: Memory estimate: 226.40 MiB, allocs estimate: 5484048.Julia Version 1.8.5
benchmark_hgf_22-03-2023-19-20_v1.8.5.txt: Memory estimate: 268.21 MiB, allocs estimate: 6464078.Julia Version 1.8.5
benchmark_iid_mv_covariance_22-03-2023-19-15_v1.8.5.txt: Memory estimate: 64.36 MiB, allocs estimate: 1108077.Julia Version 1.8.5
benchmark_iid_mv_covariance_22-03-2023-19-20_v1.8.5.txt: Memory estimate: 75.98 MiB, allocs estimate: 1432148.Julia Version 1.8.5
benchmark_iid_mv_precision_22-03-2023-19-15_v1.8.5.txt: Memory estimate: 59.14 MiB, allocs estimate: 1033058.Julia Version 1.8.5
benchmark_iid_mv_precision_22-03-2023-19-20_v1.8.5.txt: Memory estimate: 70.99 MiB, allocs estimate: 1357129.Julia Version 1.8.5
benchmark_iid_mv_wishart_known_mean_22-03-2023-19-15_v1.8.5.txt: Memory estimate: 34.89 MiB, allocs estimate: 615055.Julia Version 1.8.5
benchmark_iid_mv_wishart_known_mean_22-03-2023-19-20_v1.8.5.txt: Memory estimate: 41.10 MiB, allocs estimate: 801087.Julia Version 1.8.5
benchmark_lar_22-03-2023-19-14_v1.8.5.txt: Memory estimate: 264.62 MiB, allocs estimate: 2170307.Julia Version 1.8.5
benchmark_lar_22-03-2023-19-19_v1.8.5.txt: Memory estimate: 275.21 MiB, allocs estimate: 2406969.Julia Version 1.8.5
benchmark_linreg_22-03-2023-19-16_v1.8.5.txt: Memory estimate: 14.62 MiB, allocs estimate: 375571.Julia Version 1.8.5
benchmark_linreg_22-03-2023-19-21_v1.8.5.txt: Memory estimate: 19.19 MiB, allocs estimate: 507296.Julia Version 1.8.5
benchmark_linreg_broadcasted_22-03-2023-19-16_v1.8.5.txt: Memory estimate: 14.56 MiB, allocs estimate: 374379.Julia Version 1.8.5
benchmark_linreg_broadcasted_22-03-2023-19-21_v1.8.5.txt: Memory estimate: 19.13 MiB, allocs estimate: 506104.Julia Version 1.8.5
benchmark_mlgssm_22-03-2023-19-15_v1.8.5.txt: Memory estimate: 20.65 MiB, allocs estimate: 378579.Julia Version 1.8.5
benchmark_mlgssm_22-03-2023-19-20_v1.8.5.txt: Memory estimate: 21.58 MiB, allocs estimate: 400093.Julia Version 1.8.5
benchmark_probit_22-03-2023-19-15_v1.8.5.txt: Memory estimate: 8.39 MiB, allocs estimate: 109137.Julia Version 1.8.5
benchmark_probit_22-03-2023-19-20_v1.8.5.txt: Memory estimate: 8.82 MiB, allocs estimate: 119065.Julia Version 1.8.5
benchmark_ulgssm_22-03-2023-19-14_v1.8.5.txt: Memory estimate: 10.20 MiB, allocs estimate: 223408.Julia Version 1.8.5
benchmark_ulgssm_22-03-2023-19-19_v1.8.5.txt: Memory estimate: 11.10 MiB, allocs estimate: 241919.Julia Version 1.8.5

This PR also removes the @symmetrical macro (was unused really) and removes options from the rule macro (was unused too).

EDIT: This PR also adds documentation/docstrings for the @rule, @call_rule, @marginalrule and @call_marginalrule.

@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2023

Codecov Report

Patch coverage: 37.28% and project coverage change: +1.74 🎉

Comparison is base (5b54ef1) 62.57% compared to head (2146eab) 64.32%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #299      +/-   ##
==========================================
+ Coverage   62.57%   64.32%   +1.74%     
==========================================
  Files         197      197              
  Lines        7394     7363      -31     
==========================================
+ Hits         4627     4736     +109     
+ Misses       2767     2627     -140     
Impacted Files Coverage Δ
src/constraints/form.jl 16.12% <ø> (ø)
src/message.jl 31.52% <0.00%> (+1.08%) ⬆️
src/nodes/delta/layouts/cvi.jl 0.00% <0.00%> (ø)
src/nodes/delta/layouts/default.jl 0.00% <0.00%> (ø)
src/nodes/gamma_mixture.jl 0.00% <0.00%> (ø)
src/nodes/mixture.jl 0.00% <0.00%> (ø)
src/rules/gamma_mixture/switch.jl 0.00% <0.00%> (ø)
src/score/node.jl 0.00% <0.00%> (ø)
src/score/score.jl 61.53% <0.00%> (ø)
src/node.jl 39.62% <25.00%> (+0.14%) ⬆️
... and 5 more

... and 5 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@bvdmitri bvdmitri marked this pull request as ready for review March 23, 2023 10:42
@bvdmitri
Copy link
Member Author

Thanks for fixing the docs @bartvanerp . Are you okay with the remaining changes? Or did you plan to change text in other places?

@bvdmitri bvdmitri merged commit a300917 into master Mar 24, 2023
@bvdmitri bvdmitri deleted the optimized-rule-dispatch branch March 24, 2023 12:07
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.

4 participants