-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from tpapp/tp/benchmarktools-requires
Load BenchmarkTools conditionally, fix deps versions.
- Loading branch information
Showing
7 changed files
with
60 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using .BenchmarkTools: @belapsed | ||
using .ForwardDiff | ||
|
||
""" | ||
$(SIGNATURES) | ||
Default chunk sizes to try for benchmarking. Fewer than `M`, always contains `1` and `N`. | ||
""" | ||
function heuristic_chunks(N, M = 20) | ||
step = max(N ÷ M, 1) | ||
Ns = 1:step:N | ||
if N ∉ Ns | ||
Ns = vcat(Ns, N) | ||
end | ||
Ns | ||
end | ||
|
||
""" | ||
$(SIGNATURES) | ||
Benchmark a log density problem with various chunk sizes using ForwardDiff. | ||
`chunks`, which defaults to all possible chunk sizes, determines the chunks that are tried. | ||
The function returns `chunk => time` pairs, where `time` is the benchmarked runtime in | ||
seconds, as determined by `BenchmarkTools.@belapsed`. The gradient is evaluated at `x` | ||
(defaults to zeros). | ||
*Runtime may be long* because of tuned benchmarks, so when `markprogress == true` (the | ||
default), dots are printed to mark progress. | ||
This function is not exported, but part of the API. | ||
*It is loaded conditionally when both `ForwardDiff` and `BenchmarkTools` are loaded.* | ||
""" | ||
function benchmark_ForwardDiff_chunks(ℓ; | ||
chunks = heuristic_chunks(dimension(ℓ), 20), | ||
markprogress = true, | ||
x = zeros(dimension(ℓ))) | ||
map(chunks) do chunk | ||
∇ℓ = ADgradient(Val(:ForwardDiff), ℓ; chunk = ForwardDiff.Chunk(chunk)) | ||
markprogress && print(".") | ||
chunk => @belapsed logdensity_and_gradient($(∇ℓ), $(x)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
507d358
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
507d358
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/41389
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: