Skip to content

Commit

Permalink
add BenchmarkCI
Browse files Browse the repository at this point in the history
  • Loading branch information
prbzrg committed Aug 16, 2023
1 parent 01f16ad commit 119741b
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 52 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/Benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run benchmarks
on: pull_request

jobs:
Benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: '1'
arch: x64
show-versioninfo: true
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- name: Install dependencies
run: julia --color=yes -e 'using Pkg; Pkg.add(["PkgBenchmark", "BenchmarkCI"])'
- name: Run benchmarks
run: julia --color=yes -e 'using BenchmarkCI; BenchmarkCI.judge()'
- name: Print judgement
run: julia --color=yes -e 'using BenchmarkCI; BenchmarkCI.displayjudgement()'
- name: Post results
run: julia --color=yes -e 'using BenchmarkCI; BenchmarkCI.postjudge()'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
- RNODE
- FFJORD
- Planar
- Benchmark
- Quality
- Instability
version:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ Manifest.toml
LocalPreferences.toml

.vscode

.benchmarkci
benchmark/*.json
3 changes: 3 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
37 changes: 37 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ContinuousNormalizingFlows, BenchmarkTools, PkgBenchmark

SUITE = BenchmarkGroup()

SUITE["main"] = BenchmarkGroup(["package", "simple"])
SUITE["main"]["0-order"] = BenchmarkGroup(["direct"])
SUITE["main"]["1-order"] = BenchmarkGroup(["gradient"])

BenchmarkTools.DEFAULT_PARAMETERS.samples = 2^13
BenchmarkTools.DEFAULT_PARAMETERS.seconds = convert(Float64, 2 * 60)
BenchmarkTools.DEFAULT_PARAMETERS.evals = 1
BenchmarkTools.DEFAULT_PARAMETERS.overhead = 0.0
BenchmarkTools.DEFAULT_PARAMETERS.gctrial = true
BenchmarkTools.DEFAULT_PARAMETERS.gcsample = false
BenchmarkTools.DEFAULT_PARAMETERS.time_tolerance = convert(Float64, eps(Float16))
BenchmarkTools.DEFAULT_PARAMETERS.memory_tolerance = convert(Float64, eps(Float16))

nvars = 8
n = 128
rng = Random.default_rng()
r = rand(Float32, nvars, n)

nn = FluxCompatLayer(Flux.f32(Flux.Dense(nvars => nvars, tanh)))
icnf = construct(RNODE, nn, nvars; compute_mode = ZygoteMatrixMode)

ps, st = Lux.setup(rng, icnf)
diff_loss_train(x) = loss(icnf, TrainMode(), r, x, st)
diff_loss_test(x) = loss(icnf, TestMode(), r, x, st)
grad_diff_loss_train() = Zygote.gradient(diff_loss_train, ps)
grad_diff_loss_test() = Zygote.gradient(diff_loss_test, ps)
t_loss_train() = loss(icnf, TrainMode(), r, ps, st)
t_loss_test() = loss(icnf, TestMode(), r, ps, st)

SUITE["main"]["0-order"]["train"] = @benchmarkable $t_loss_train()
SUITE["main"]["0-order"]["test"] = @benchmarkable $t_loss_test()
SUITE["main"]["1-order"]["train"] = @benchmarkable $grad_diff_loss_train()
SUITE["main"]["1-order"]["test"] = @benchmarkable $grad_diff_loss_test()
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
AbstractDifferentiation = "c29ec348-61ec-40c8-8164-b8c60e9d9f3d"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
ComputationalResources = "ed09eef8-17a6-5b46-8889-db040fac31e3"
Expand Down
45 changes: 0 additions & 45 deletions test/benchmark_tests.jl

This file was deleted.

5 changes: 0 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ using Test
using AbstractDifferentiation: AbstractDifferentiation
using ADTypes: ADTypes
using Aqua: Aqua
using BenchmarkTools: BenchmarkTools
using ComponentArrays: ComponentArrays
using ComputationalResources: ComputationalResources
using CUDA: CUDA
Expand Down Expand Up @@ -42,10 +41,6 @@ USE_GPU = get(ENV, "USE_GPU", "Yes") == "Yes"
end
end

if GROUP == "All" || GROUP == "Benchmark"
include("benchmark_tests.jl")
end

if GROUP == "All" || GROUP == "Quality"
include("quality_tests.jl")
end
Expand Down

0 comments on commit 119741b

Please sign in to comment.