Skip to content

Commit 4c66d87

Browse files
authored
GC between benchmarks (#511)
* GC between benchmarks * Always GC immediately before running AD * Only GC when comparing between backends
1 parent 3b068d1 commit 4c66d87

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

bench/run_benchmarks.jl

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ function benchmark_rules!!(test_case_data, default_ratios, include_other_framewo
184184
# Benchmark primal.
185185
@info "Primal"
186186
primals = map(x -> x isa CoDual ? primal(x) : x, args)
187+
include_other_frameworks && GC.gc(true)
187188
suite["primal"] = Chairmarks.benchmark(
188189
() -> primals,
189190
primals -> (primals[1], _deepcopy(primals[2:end])),
@@ -197,6 +198,7 @@ function benchmark_rules!!(test_case_data, default_ratios, include_other_framewo
197198
rule = Mooncake.build_rrule(args...)
198199
coduals = map(x -> x isa CoDual ? x : zero_codual(x), args)
199200
to_benchmark(rule, coduals...)
201+
include_other_frameworks && GC.gc(true)
200202
suite["mooncake"] = Chairmarks.benchmark(
201203
() -> (rule, coduals),
202204
identity,
@@ -208,6 +210,7 @@ function benchmark_rules!!(test_case_data, default_ratios, include_other_framewo
208210
if include_other_frameworks
209211
if should_run_benchmark(Val(:zygote), args...)
210212
@info "Zygote"
213+
GC.gc(true)
211214
suite["zygote"] = @be(
212215
_,
213216
_,
@@ -222,6 +225,7 @@ function benchmark_rules!!(test_case_data, default_ratios, include_other_framewo
222225
tape = ReverseDiff.GradientTape(primals[1], primals[2:end])
223226
compiled_tape = ReverseDiff.compile(tape)
224227
result = map(x -> randn(size(x)), primals[2:end])
228+
GC.gc(true)
225229
suite["rd"] = @be(
226230
_,
227231
_,
@@ -235,6 +239,7 @@ function benchmark_rules!!(test_case_data, default_ratios, include_other_framewo
235239
@info "Enzyme"
236240
_rand_similiar(x) = x isa Real ? randn() : randn(size(x))
237241
dup_args = map(x -> Duplicated(x, _rand_similiar(x)), primals[2:end])
242+
GC.gc(true)
238243
suite["enzyme"] = @be(
239244
_,
240245
_,

0 commit comments

Comments
 (0)