diff --git a/DifferentiationInterfaceTest/dev/.documenter-siteinfo.json b/DifferentiationInterfaceTest/dev/.documenter-siteinfo.json index e8c041bd0..0465f8bac 100644 --- a/DifferentiationInterfaceTest/dev/.documenter-siteinfo.json +++ b/DifferentiationInterfaceTest/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-25T04:48:59","documenter_version":"1.4.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-25T07:35:08","documenter_version":"1.4.0"}} \ No newline at end of file diff --git a/DifferentiationInterfaceTest/dev/api/index.html b/DifferentiationInterfaceTest/dev/api/index.html index bedb98a87..075ddccda 100644 --- a/DifferentiationInterfaceTest/dev/api/index.html +++ b/DifferentiationInterfaceTest/dev/api/index.html @@ -1,5 +1,5 @@ -API reference · DifferentiationInterfaceTest.jl

API reference

Entry points

DifferentiationInterfaceTest.test_differentiationFunction
test_differentiation(
+API reference · DifferentiationInterfaceTest.jl

API reference

Entry points

DifferentiationInterfaceTest.test_differentiationFunction
test_differentiation(
     backends::Vector{<:ADTypes.AbstractADType};
     ...
 )
@@ -22,12 +22,12 @@
     atol,
     rtol
 )
-

Cross-test a list of backends on a list of scenarios, running a variety of different tests.

Default arguments

Keyword arguments

Testing:

  • correctness=true: whether to compare the differentiation results with the theoretical values specified in each scenario
  • type_stability=false: whether to check type stability with JET.jl (thanks to @test_opt)
  • sparsity: whether to check sparsity of the jacobian / hessian
  • ref_backend: if not nothing, an ADTypes.AbstractADType object to use instead of the scenario-specific reference to provide true values
  • detailed=false: whether to print a detailed or condensed test log

Filtering:

  • input_type=Any: restrict scenario inputs to subtypes of this
  • output_type=Any: restrict scenario outputs to subtypes of this
  • first_order=true: include first order operators
  • second_order=true: include second order operators

Options:

  • logging=false: whether to log progress
  • isapprox=isapprox: function used to compare objects, with the standard signature isapprox(x, y; atol, rtol)
  • atol=0: absolute precision for correctness testing (when comparing to the reference outputs)
  • rtol=1e-3: relative precision for correctness testing (when comparing to the reference outputs)
source
test_differentiation(
+

Cross-test a list of backends on a list of scenarios, running a variety of different tests.

Default arguments

Keyword arguments

Testing:

  • correctness=true: whether to compare the differentiation results with the theoretical values specified in each scenario
  • type_stability=false: whether to check type stability with JET.jl (thanks to @test_opt)
  • sparsity: whether to check sparsity of the jacobian / hessian
  • ref_backend: if not nothing, an ADTypes.AbstractADType object to use instead of the scenario-specific reference to provide true values
  • detailed=false: whether to print a detailed or condensed test log

Filtering:

  • input_type=Any: restrict scenario inputs to subtypes of this
  • output_type=Any: restrict scenario outputs to subtypes of this
  • first_order=true: include first order operators
  • second_order=true: include second order operators

Options:

  • logging=false: whether to log progress
  • isapprox=isapprox: function used to compare objects, with the standard signature isapprox(x, y; atol, rtol)
  • atol=0: absolute precision for correctness testing (when comparing to the reference outputs)
  • rtol=1e-3: relative precision for correctness testing (when comparing to the reference outputs)
source
test_differentiation(
     backend::ADTypes.AbstractADType,
     args...;
     kwargs...
 )
-

Shortcut for a single backend.

source
DifferentiationInterfaceTest.benchmark_differentiationFunction
benchmark_differentiation(
     backends::Vector{<:ADTypes.AbstractADType};
     ...
 ) -> Vector{DifferentiationInterfaceTest.BenchmarkDataRow}
@@ -41,4 +41,4 @@
     excluded,
     logging
 ) -> Vector{DifferentiationInterfaceTest.BenchmarkDataRow}
-

Benchmark a list of backends for a list of operators on a list of scenarios.

Keyword arguments

  • filtering: same as test_differentiation for the filtering part.
  • logging=false: whether to log progress
source

Pre-made scenario lists

Scenario types

DifferentiationInterfaceTest.AbstractScenarioType
AbstractScenario

Store a testing scenario composed of a function and its input + output.

This abstract type should never be used directly: construct one of the subtypes corresponding to the operator you want to test.

Subtypes

Fields

All subtypes have the following fields:

  • f: function to apply
  • x: primal input
  • y: primal output
  • ref: reference to compare against

In addition, some subtypes contain an additional seed (dx or dy).

Constructor

If y is provided, f is interpreted as a 2-argument function f!(y, x) = nothing. Otherwise, f is interpreted as an 1-argument function f(x) = y.

The reference keyword ref should be a function that takes x (and a potential seed dx or dy) to return the correct object.

The operator behavior keyword operator should be either :inplace or :outofplace depending on what must be tested.

source

Internals

This is not part of the public API.

DifferentiationInterfaceTest.BenchmarkDataRowType
BenchmarkDataRow

Ad-hoc storage type for differentiation benchmarking results. If you have a vector rows::Vector{BenchmarkDataRow}, you can turn it into a DataFrame as follows:

df = DataFrames.DataFrame(rows)

Fields

These are not part of the public API.

  • backend::String

  • mode::ADTypes.AbstractMode

  • scenario::Symbol

  • operator::Symbol

  • func::Symbol

  • arguments::Int64

  • input_type::Type

  • output_type::Type

  • input_size::Tuple

  • output_size::Tuple

  • calls::Int64

  • samples::Int64

  • evals::Int64

  • time::Float64

  • bytes::Float64

  • allocs::Float64

  • compile_fraction::Float64

  • gc_fraction::Float64

source
+

Benchmark a list of backends for a list of operators on a list of scenarios.

Keyword arguments

  • filtering: same as test_differentiation for the filtering part.
  • logging=false: whether to log progress
source

Pre-made scenario lists

Scenario types

DifferentiationInterfaceTest.AbstractScenarioType
AbstractScenario

Store a testing scenario composed of a function and its input + output.

This abstract type should never be used directly: construct one of the subtypes corresponding to the operator you want to test.

Subtypes

Fields

All subtypes have the following fields:

  • f: function to apply
  • x: primal input
  • y: primal output
  • ref: reference to compare against

In addition, some subtypes contain an additional seed (dx or dy).

Constructor

If y is provided, f is interpreted as a 2-argument function f!(y, x) = nothing. Otherwise, f is interpreted as an 1-argument function f(x) = y.

The reference keyword ref should be a function that takes x (and a potential seed dx or dy) to return the correct object.

The operator behavior keyword operator should be either :inplace or :outofplace depending on what must be tested.

source

Internals

This is not part of the public API.

DifferentiationInterfaceTest.BenchmarkDataRowType
BenchmarkDataRow

Ad-hoc storage type for differentiation benchmarking results. If you have a vector rows::Vector{BenchmarkDataRow}, you can turn it into a DataFrame as follows:

df = DataFrames.DataFrame(rows)

Fields

These are not part of the public API.

  • backend::String

  • mode::ADTypes.AbstractMode

  • scenario::Symbol

  • operator::Symbol

  • func::Symbol

  • arguments::Int64

  • input_type::Type

  • output_type::Type

  • input_size::Tuple

  • output_size::Tuple

  • calls::Int64

  • samples::Int64

  • evals::Int64

  • time::Float64

  • bytes::Float64

  • allocs::Float64

  • compile_fraction::Float64

  • gc_fraction::Float64

source
diff --git a/DifferentiationInterfaceTest/dev/index.html b/DifferentiationInterfaceTest/dev/index.html index 35e950996..477092ac1 100644 --- a/DifferentiationInterfaceTest/dev/index.html +++ b/DifferentiationInterfaceTest/dev/index.html @@ -11,4 +11,4 @@ julia> Pkg.add( url="https://github.com/gdalle/DifferentiationInterface.jl", subdir="DifferentiationInterfaceTest" - ) + ) diff --git a/DifferentiationInterfaceTest/dev/tutorial/index.html b/DifferentiationInterfaceTest/dev/tutorial/index.html index 6d897d643..dd790c3d1 100644 --- a/DifferentiationInterfaceTest/dev/tutorial/index.html +++ b/DifferentiationInterfaceTest/dev/tutorial/index.html @@ -11,12 +11,12 @@ type_stability=false, # checks type stability with JET.jl detailed=true, # prints a detailed test set )Test Summary: | Pass Total Time -Testing correctness | 28 28 35.5s - ForwardDiff (forward) | 14 14 3.5s - GradientScenario{1,inplace} f : Vector{Float32} -> Float32 | 7 7 1.8s +Testing correctness | 28 28 34.7s + ForwardDiff (forward) | 14 14 3.4s + GradientScenario{1,inplace} f : Vector{Float32} -> Float32 | 7 7 1.7s GradientScenario{1,inplace} f : Matrix{Float64} -> Float64 | 7 7 1.7s - Enzyme (reverse) | 14 14 32.0s - GradientScenario{1,inplace} f : Vector{Float32} -> Float32 | 7 7 30.6s + Enzyme (reverse) | 14 14 31.3s + GradientScenario{1,inplace} f : Vector{Float32} -> Float32 | 7 7 29.9s GradientScenario{1,inplace} f : Matrix{Float64} -> Float64 | 7 7 1.4s

If you are too lazy to manually specify the reference, you can also provide an AD backend as the ref_backend keyword argument, which will serve as the ground truth for comparison.

Benchmarking

Once you are confident that your backends give the correct answers, you probably want to compare their performance. This is made easy by the benchmark_differentiation function, whose syntax should feel familiar:

julia> benchmark_result = benchmark_differentiation(backends, scenarios);

The resulting object is a Vector of structs, which can easily be converted into a DataFrame from DataFrames.jl:

julia> df = DataFrames.DataFrame(benchmark_result)12×18 DataFrame
  Row │ backend                mode           scenario          operator        ⋯
      │ String                 Abstract…      Symbol            Symbol          ⋯
@@ -51,5 +51,5 @@
     formatters=formatter
 )
 
-Markdown.parse(table)
backendmodescenariooperatorfuncargumentsinput_typeoutput_typeinput_sizeoutput_sizecallssamplesevalstimebytesallocscompile_fractiongc_fraction
ForwardDiff (forward)ForwardMode()GradientScenarioprepare_gradientf1Vector{Float32}Float32(3,)()0115.0e-065.3e+0211.00.00.0
ForwardDiff (forward)ForwardMode()GradientScenariovalue_and_gradient!f1Vector{Float32}Float32(3,)()122074121.5e-071.5e+023.70.00.0
ForwardDiff (forward)ForwardMode()GradientScenariogradient!f1Vector{Float32}Float32(3,)()127072151.3e-076.5e+011.00.00.0
ForwardDiff (forward)ForwardMode()GradientScenarioprepare_gradientf1Matrix{Float64}Float64(3, 2)()0114.3e-061.8e+0311.00.00.0
ForwardDiff (forward)ForwardMode()GradientScenariovalue_and_gradient!f1Matrix{Float64}Float64(3, 2)()12524972.8e-075.3e+027.10.00.0
ForwardDiff (forward)ForwardMode()GradientScenariogradient!f1Matrix{Float64}Float64(3, 2)()124341012.6e-074.7e+025.10.00.0
Enzyme (reverse)ReverseMode()GradientScenarioprepare_gradientf1Vector{Float32}Float32(3,)()0111.4e-070.0e+000.00.00.0
Enzyme (reverse)ReverseMode()GradientScenariovalue_and_gradient!f1Vector{Float32}Float32(3,)()1303154.6e-061.8e+0338.64.46412e-50.0
Enzyme (reverse)ReverseMode()GradientScenariogradient!f1Vector{Float32}Float32(3,)()1299173.8e-061.6e+0329.00.005702480.0
Enzyme (reverse)ReverseMode()GradientScenarioprepare_gradientf1Matrix{Float64}Float64(3, 2)()0111.4e-070.0e+000.00.00.0
Enzyme (reverse)ReverseMode()GradientScenariovalue_and_gradient!f1Matrix{Float64}Float64(3, 2)()1305747.1e-061.8e+0339.00.003465670.0
Enzyme (reverse)ReverseMode()GradientScenariogradient!f1Matrix{Float64}Float64(3, 2)()1332173.8e-061.6e+0329.00.005612820.0
-
+Markdown.parse(table)
backendmodescenariooperatorfuncargumentsinput_typeoutput_typeinput_sizeoutput_sizecallssamplesevalstimebytesallocscompile_fractiongc_fraction
ForwardDiff (forward)ForwardMode()GradientScenarioprepare_gradientf1Vector{Float32}Float32(3,)()0118.0e-065.3e+0211.00.00.0
ForwardDiff (forward)ForwardMode()GradientScenariovalue_and_gradient!f1Vector{Float32}Float32(3,)()121801861.6e-071.3e+023.00.00.0
ForwardDiff (forward)ForwardMode()GradientScenariogradient!f1Vector{Float32}Float32(3,)()129492131.3e-076.5e+011.00.00.0
ForwardDiff (forward)ForwardMode()GradientScenarioprepare_gradientf1Matrix{Float64}Float64(3, 2)()0115.5e-061.8e+0311.00.00.0
ForwardDiff (forward)ForwardMode()GradientScenariovalue_and_gradient!f1Matrix{Float64}Float64(3, 2)()125341002.8e-075.3e+027.10.00.0
ForwardDiff (forward)ForwardMode()GradientScenariogradient!f1Matrix{Float64}Float64(3, 2)()125231072.6e-074.7e+025.10.00.0
Enzyme (reverse)ReverseMode()GradientScenarioprepare_gradientf1Vector{Float32}Float32(3,)()0111.4e-070.0e+000.00.00.0
Enzyme (reverse)ReverseMode()GradientScenariovalue_and_gradient!f1Vector{Float32}Float32(3,)()1275164.5e-061.8e+0338.32.1588e-50.0
Enzyme (reverse)ReverseMode()GradientScenariogradient!f1Vector{Float32}Float32(3,)()1331464.3e-061.6e+0329.20.005804020.0
Enzyme (reverse)ReverseMode()GradientScenarioprepare_gradientf1Matrix{Float64}Float64(3, 2)()0111.6e-070.0e+000.00.00.0
Enzyme (reverse)ReverseMode()GradientScenariovalue_and_gradient!f1Matrix{Float64}Float64(3, 2)()1269255.4e-061.8e+0338.62.91993e-50.0
Enzyme (reverse)ReverseMode()GradientScenariogradient!f1Matrix{Float64}Float64(3, 2)()1348646.0e-061.6e+0329.80.005229690.0
+