Skip to content

Conversation

yebai
Copy link
Member

@yebai yebai commented Mar 5, 2025

No description provided.

Optimize and refactor various functions for better performance and maintainability.

* **bench/benchmarks.jl**
  - Uncomment the AD backends in the `for` loop.
  - Add Mooncake and Enzyme AD backends for testing.

* **bench/normallognormal.jl**
  - Optimize the `LogDensityProblems.logdensity` function by separating the log density calculations for `LogNormal` and `MvNormal`.

* **ext/AdvancedVIBijectorsExt.jl**
  - Refactor the `AdvancedVI.apply` function to remove repetitive code for different types.
  - Introduce `apply_clip_scale` function to handle different distribution types.

* **src/AdvancedVI.jl**
  - Simplify the `optimize` function structure for better readability and maintainability.
  - Add detailed documentation for the `optimize` function.

* **src/families/location_scale.jl**
  - Optimize the `Distributions.logpdf` function by separating the standardization step.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/TuringLang/AdvancedVI.jl?shareId=XXXX-XXXX-XXXX-XXXX).
@yebai yebai marked this pull request as draft March 5, 2025 21:34
@yebai yebai marked this pull request as ready for review March 5, 2025 21:38
@yebai
Copy link
Member Author

yebai commented Mar 5, 2025

I experimented with Co-pilot -- all seem very reasonable suggestions!

@yebai yebai requested a review from Red-Portal March 5, 2025 21:40
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.78%. Comparing base (02da94e) to head (de81456).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #163      +/-   ##
==========================================
+ Coverage   91.76%   91.78%   +0.02%     
==========================================
  Files          13       13              
  Lines         352      353       +1     
==========================================
+ Hits          323      324       +1     
  Misses         29       29              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark Results

Benchmark suite Current: de81456 Previous: c55528e Ratio
normal/RepGradELBO + STL/meanfield/Zygote 15382128189 ns 13802519072 ns 1.11
normal/RepGradELBO + STL/meanfield/ForwardDiff 4537244324.5 ns 3356403413.5 ns 1.35
normal/RepGradELBO + STL/meanfield/ReverseDiff 3471695161 ns 3021926516 ns 1.15
normal/RepGradELBO + STL/meanfield/Mooncake 9336748853 ns
normal/RepGradELBO + STL/fullrank/Zygote 15312445282 ns 13681473373 ns 1.12
normal/RepGradELBO + STL/fullrank/ForwardDiff 4546036635.5 ns 3689636504.5 ns 1.23
normal/RepGradELBO + STL/fullrank/ReverseDiff 6567681491 ns 5663417464 ns 1.16
normal/RepGradELBO + STL/fullrank/Mooncake 9539435397 ns
normal/RepGradELBO/meanfield/Zygote 7035276783 ns 6116693013 ns 1.15
normal/RepGradELBO/meanfield/ForwardDiff 2466526668 ns 2466536350 ns 1.00
normal/RepGradELBO/meanfield/ReverseDiff 1493587239 ns 1321012473 ns 1.13
normal/RepGradELBO/meanfield/Mooncake 7339348743 ns
normal/RepGradELBO/fullrank/Zygote 7075901888 ns 6203991729 ns 1.14
normal/RepGradELBO/fullrank/ForwardDiff 2886252837.5 ns 2629277548 ns 1.10
normal/RepGradELBO/fullrank/ReverseDiff 2900271879 ns 2459356113 ns 1.18
normal/RepGradELBO/fullrank/Mooncake 7598264040 ns
normal + bijector/RepGradELBO + STL/meanfield/Zygote 23715507310 ns 22084065176 ns 1.07
normal + bijector/RepGradELBO + STL/meanfield/ForwardDiff 13497905690 ns 10546466980 ns 1.28
normal + bijector/RepGradELBO + STL/meanfield/ReverseDiff 4670737107.5 ns 4530973116.5 ns 1.03
normal + bijector/RepGradELBO + STL/meanfield/Mooncake 25964400761 ns
normal + bijector/RepGradELBO + STL/fullrank/Zygote 23566405974 ns 22345253347 ns 1.05
normal + bijector/RepGradELBO + STL/fullrank/ForwardDiff 13685992287 ns 10945544739 ns 1.25
normal + bijector/RepGradELBO + STL/fullrank/ReverseDiff 8462077032 ns 7859941162 ns 1.08
normal + bijector/RepGradELBO + STL/fullrank/Mooncake 26526217091 ns
normal + bijector/RepGradELBO/meanfield/Zygote 14611902776 ns 13813477870 ns 1.06
normal + bijector/RepGradELBO/meanfield/ForwardDiff 11096163496 ns 9270416271 ns 1.20
normal + bijector/RepGradELBO/meanfield/ReverseDiff 2563882411 ns 2587262809 ns 0.99
normal + bijector/RepGradELBO/meanfield/Mooncake 23737562263 ns
normal + bijector/RepGradELBO/fullrank/Zygote 14787023027 ns 14000051621 ns 1.06
normal + bijector/RepGradELBO/fullrank/ForwardDiff 10888674674 ns 9875600981 ns 1.10
normal + bijector/RepGradELBO/fullrank/ReverseDiff 4294694220 ns 4083240829 ns 1.05
normal + bijector/RepGradELBO/fullrank/Mooncake 24388566270 ns

This comment was automatically generated by workflow using github-action-benchmark.

@yebai yebai merged commit f257bce into main Mar 7, 2025
15 of 18 checks passed
@yebai yebai deleted the yebai/optimize-code branch March 7, 2025 20:29
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.

1 participant