Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update criterion settings #276

Merged
merged 31 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e9b5f7c
update criterion settings
oojo12 Nov 11, 2022
9a2156b
update settings
oojo12 Nov 11, 2022
8df41c0
update
oojo12 Nov 11, 2022
ecdfc1e
add benches to all targets
oojo12 Nov 11, 2022
820ce31
Merge branch 'master' into update-benchmarks
oojo12 Nov 11, 2022
90ba3c6
rustfmt
oojo12 Nov 11, 2022
a7f0e03
Remove (1_000, 5)
oojo12 Nov 13, 2022
dfc9781
fix params
oojo12 Nov 14, 2022
255802c
fix params
oojo12 Nov 14, 2022
589a3e1
add benchmarks feature
oojo12 Nov 16, 2022
800837f
add benchmarks feature
oojo12 Nov 16, 2022
676eb52
use benchmarks feature
oojo12 Nov 16, 2022
dee1d1c
add benchmarks feature
oojo12 Nov 16, 2022
61d5d92
fix empty return
oojo12 Nov 16, 2022
30f8d70
use config for profiling
oojo12 Nov 16, 2022
ae51105
upate
oojo12 Nov 16, 2022
7d6e643
Merge branch 'master' into update-benchmarks
oojo12 Nov 16, 2022
54e8d71
properly use profile config
oojo12 Nov 16, 2022
097af70
Merge branch 'update-benchmarks' of https://github.com/oojo12/linfa i…
oojo12 Nov 16, 2022
7e6d9ba
fix failing test
oojo12 Nov 16, 2022
b4a26fb
mention configurable defaults
oojo12 Nov 16, 2022
5302fb7
address review
oojo12 Nov 16, 2022
0ab482d
address review
oojo12 Nov 16, 2022
dd957e1
rustfmt
oojo12 Nov 16, 2022
8b0063e
finalize
oojo12 Nov 16, 2022
21b78b4
update to use cargo criterion
oojo12 Nov 16, 2022
f0b3056
add cargo criterion note
oojo12 Nov 16, 2022
ce93357
fix command
oojo12 Nov 16, 2022
c495998
note about profiling and windows
oojo12 Nov 16, 2022
cc0b235
address review
oojo12 Nov 16, 2022
a4de64e
grammar
oojo12 Nov 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ It is important to the project that we have benchmarks in place to evaluate the
7. In `BenchmarkId` include the values used to parametrize the benchmark. For example if we're doing Pls then we may have something like `Canonical-Nipals-5feats-1_000samples`
8. Pass data as an argument to the function being benched. This will prevent Criterion from including data creation time as part of the benchmark.
9. Add a profiler see [here](https://github.com/tikv/pprof-rs#integrate-with-criterion) for an example on how to do so with pprof, Criterion, and Flamegraph.
10. Use the benchmark feature to configure your benchmark groups and profiler. See the bench in linfa-pls as an example of this. In most cases you can just copy and paste portions of thecode. If other configurations are desired it is still easily customizable and explained in the pprof and Criterion documentation.
oojo12 marked this conversation as resolved.
Show resolved Hide resolved

Feel free to use the pls bench as a guideline. Note tha it uses functions get get default configurations for profiling and benchmarking.
oojo12 marked this conversation as resolved.
Show resolved Hide resolved

### Running Benchmarks
When running benchmarks sometimes you will want to profile the code execution. Assuming you have followed step 9 to add a pprof profiling hook for the linfa-ica package you can run the following to get your profiling results as a flamegraph.
When running benchmarks sometimes you will want to profile the code execution. Assuming you have followed step 9 to add a pprof profiling hook for the linfa-ica package you can run the following to get your profiling results as a flamegraph. Be advised that at the time of writing this profiling will not work on Windows machines.

`cargo bench -p linfa-ica --bench fast_ica -q -- --profile-time 30`

Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = [".github/"]

[features]
default = []

benchmarks = ["criterion", "pprof"]
netlib-static = ["blas", "ndarray-linalg/netlib-static"]
netlib-system = ["blas", "ndarray-linalg/netlib-system"]

Expand All @@ -45,6 +45,8 @@ ndarray-linalg = { version = "0.15", optional = true }

thiserror = "1.0"

criterion = { version = "0.4.0", optional = true}

[dependencies.serde_crate]
package = "serde"
optional = true
Expand All @@ -57,6 +59,9 @@ ndarray-rand = "0.14"
linfa-datasets = { path = "datasets", features = ["winequality", "iris", "diabetes", "generate"] }
statrs = "0.16.0"

[target.'cfg(not(windows))'.dependencies]
pprof = { version = "0.11.0", features = ["flamegraph", "criterion"], optional = true}

[workspace]
members = [
"algorithms/*",
Expand Down
4 changes: 1 addition & 3 deletions algorithms/linfa-clustering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ criterion = "0.4.0"
serde_json = "1"
approx = "0.4"
lax = "0.15.0"

[target.'cfg(not(windows))'.dev-dependencies]
pprof = { version = "0.11.0", features = ["flamegraph", "criterion"] }
linfa = { version = "0.6.0", path = "../..", features = ["benchmarks"] }

[[bench]]
name = "k_means"
Expand Down
7 changes: 4 additions & 3 deletions algorithms/linfa-clustering/benches/appx_dbscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use criterion::{
black_box, criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion,
PlotConfiguration,
};
use linfa::benchmarks::config;
use linfa::traits::Transformer;
use linfa_clustering::AppxDbscan;
use linfa_datasets::generate;
use ndarray::Array2;
use ndarray_rand::rand::SeedableRng;
use ndarray_rand::rand_distr::Uniform;
use ndarray_rand::RandomExt;
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
use rand_xoshiro::Xoshiro256Plus;

fn appx_dbscan_bench(c: &mut Criterion) {
Expand All @@ -23,7 +22,9 @@ fn appx_dbscan_bench(c: &mut Criterion) {
];

let mut benchmark = c.benchmark_group("appx_dbscan");
config::set_default_benchmark_configs(&mut benchmark);
benchmark.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));

for cluster_size_and_slack in cluster_sizes_and_slacks {
let rng = &mut rng;
benchmark.bench_with_input(
Expand Down Expand Up @@ -53,7 +54,7 @@ fn appx_dbscan_bench(c: &mut Criterion) {
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = config::get_default_profiling_configs();
targets = appx_dbscan_bench
}
#[cfg(target_os = "windows")]
Expand Down
7 changes: 4 additions & 3 deletions algorithms/linfa-clustering/benches/dbscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ use criterion::{
black_box, criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion,
PlotConfiguration,
};
use linfa::benchmarks::config;
use linfa::prelude::{ParamGuard, Transformer};
use linfa_clustering::Dbscan;
use linfa_datasets::generate;
use ndarray::Array2;
use ndarray_rand::rand::SeedableRng;
use ndarray_rand::rand_distr::Uniform;
use ndarray_rand::RandomExt;
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
use rand_xoshiro::Xoshiro256Plus;

fn dbscan_bench(c: &mut Criterion) {
let mut rng = Xoshiro256Plus::seed_from_u64(40);
let cluster_sizes = vec![10, 100, 1000, 10000];

let mut benchmark = c.benchmark_group("dbscan");
config::set_default_benchmark_configs(&mut benchmark);
benchmark.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));

for cluster_size in cluster_sizes {
let rng = &mut rng;
benchmark.bench_with_input(
Expand Down Expand Up @@ -49,7 +50,7 @@ fn dbscan_bench(c: &mut Criterion) {
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = config::get_default_profiling_configs();
targets = dbscan_bench
}
#[cfg(target_os = "windows")]
Expand Down
7 changes: 4 additions & 3 deletions algorithms/linfa-clustering/benches/gaussian_mixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use criterion::{
black_box, criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion,
PlotConfiguration,
};
use linfa::benchmarks::config;
use linfa::traits::Fit;
use linfa::DatasetBase;
use linfa_clustering::GaussianMixtureModel;
Expand All @@ -10,16 +11,16 @@ use ndarray::Array2;
use ndarray_rand::rand::SeedableRng;
use ndarray_rand::rand_distr::Uniform;
use ndarray_rand::RandomExt;
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
use rand_xoshiro::Xoshiro256Plus;

fn gaussian_mixture_bench(c: &mut Criterion) {
let mut rng = Xoshiro256Plus::seed_from_u64(40);
let cluster_sizes = vec![10, 100, 1000, 10000];

let mut benchmark = c.benchmark_group("gaussian_mixture");
config::set_default_benchmark_configs(&mut benchmark);
benchmark.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));

for cluster_size in cluster_sizes {
let rng = &mut rng;
benchmark.bench_with_input(
Expand Down Expand Up @@ -51,7 +52,7 @@ fn gaussian_mixture_bench(c: &mut Criterion) {
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = config::get_default_profiling_configs();
targets = gaussian_mixture_bench
}
#[cfg(target_os = "windows")]
Expand Down
10 changes: 7 additions & 3 deletions algorithms/linfa-clustering/benches/k_means.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use criterion::{
black_box, criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion,
PlotConfiguration,
};
use linfa::benchmarks::config;
use linfa::prelude::*;
use linfa::DatasetBase;
use linfa_clustering::{IncrKMeansError, KMeans, KMeansInit};
use linfa_datasets::generate;
use ndarray::Array2;
use ndarray_rand::RandomExt;
use ndarray_rand::{rand::SeedableRng, rand_distr::Uniform};
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
use rand_xoshiro::Xoshiro256Plus;

#[derive(Default)]
Expand Down Expand Up @@ -40,7 +39,9 @@ fn k_means_bench(c: &mut Criterion) {
let n_features = 3;

let mut benchmark = c.benchmark_group("naive_k_means");
config::set_default_benchmark_configs(&mut benchmark);
benchmark.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));

for &(cluster_size, n_clusters) in &cluster_sizes {
let rng = &mut rng;
let centroids =
Expand Down Expand Up @@ -73,7 +74,9 @@ fn k_means_incr_bench(c: &mut Criterion) {
let n_features = 3;

let mut benchmark = c.benchmark_group("incremental_k_means");
config::set_default_benchmark_configs(&mut benchmark);
benchmark.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));

for &(cluster_size, n_clusters) in &cluster_sizes {
let rng = &mut rng;
let centroids =
Expand Down Expand Up @@ -124,6 +127,7 @@ fn k_means_init_bench(c: &mut Criterion) {
let n_features = 3;

let mut benchmark = c.benchmark_group("k_means_init");
config::set_default_benchmark_configs(&mut benchmark);
benchmark.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
for init in &init_methods {
for &(cluster_size, n_clusters) in &cluster_sizes {
Expand Down Expand Up @@ -160,7 +164,7 @@ fn k_means_init_bench(c: &mut Criterion) {
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = config::get_default_profiling_configs();
targets = k_means_bench, k_means_init_bench, k_means_incr_bench
}
#[cfg(target_os = "windows")]
Expand Down
4 changes: 1 addition & 3 deletions algorithms/linfa-ftrl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ linfa = { version = "0.6.0", path = "../.."}
criterion = "0.4.0"
approx = "0.4"
linfa-datasets = { version = "0.6.0", path = "../../datasets", features = ["winequality"] }

[target.'cfg(not(windows))'.dev-dependencies]
pprof = { version = "0.11.0", features = ["flamegraph", "criterion"] }
linfa = { version = "0.6.0", path = "../..", features = ["benchmarks"] }

[[bench]]
name = "ftrl"
Expand Down
14 changes: 11 additions & 3 deletions algorithms/linfa-ftrl/benches/ftrl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use linfa::benchmarks::config;
use linfa::prelude::Predict;
use linfa::traits::FitWith;
use linfa::{Dataset, DatasetBase, ParamGuard};
Expand All @@ -7,13 +8,14 @@ use ndarray::{Array1, Array2};
use ndarray_rand::{
rand::distributions::Uniform, rand::rngs::SmallRng, rand::SeedableRng, RandomExt,
};
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};

fn fit_without_prior_model(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(42);
let params = Ftrl::params();

let mut group = c.benchmark_group("Ftrl with no initial model");
config::set_default_benchmark_configs(&mut group);

let sizes: Vec<(usize, usize)> = vec![(10, 1_000), (50, 5_000), (100, 10_000)];

for (nfeatures, nrows) in sizes.iter() {
Expand All @@ -34,7 +36,10 @@ fn fit_with_prior_model(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(42);
let params = Ftrl::params();
let valid_params = params.clone().check().unwrap();

let mut group = c.benchmark_group("Ftrl incremental model training");
config::set_default_benchmark_configs(&mut group);

let sizes: Vec<(usize, usize)> = vec![(10, 1_000), (50, 5_000), (100, 10_000)];

for (nfeatures, nrows) in sizes.iter() {
Expand All @@ -57,8 +62,11 @@ fn fit_with_prior_model(c: &mut Criterion) {
fn predict(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(42);
let params = Ftrl::params();

let valid_params = params.clone().check().unwrap();
let mut group = c.benchmark_group("Ftrl");
config::set_default_benchmark_configs(&mut group);

let sizes: Vec<(usize, usize)> = vec![(10, 1_000), (50, 5_000), (100, 10_000)];
for (nfeatures, nrows) in sizes.iter() {
let model = Ftrl::new(valid_params.clone(), *nfeatures);
Expand Down Expand Up @@ -91,7 +99,7 @@ fn get_dataset(
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = config::get_default_profiling_configs();
targets = fit_without_prior_model, fit_with_prior_model, predict
}
#[cfg(target_os = "windows")]
Expand Down
4 changes: 1 addition & 3 deletions algorithms/linfa-ica/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ linfa = { version = "0.6.0", path = "../.." }
ndarray-npy = { version = "0.8", default-features = false }
paste = "1.0"
criterion = "0.4.0"

[target.'cfg(not(windows))'.dev-dependencies]
pprof = { version = "0.11.0", features = ["flamegraph", "criterion"] }
linfa = { version = "0.6.0", path = "../..", features = ["benchmarks"] }

[[bench]]
name = "fast_ica"
Expand Down
7 changes: 4 additions & 3 deletions algorithms/linfa-ica/benches/fast_ica.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use linfa::benchmarks::config;
use linfa::{dataset::DatasetBase, traits::Fit};
use linfa_ica::fast_ica::{FastIca, GFunc};
use ndarray::{array, concatenate};
use ndarray::{Array, Array2, Axis};
use ndarray_rand::{rand::SeedableRng, rand_distr::Uniform, RandomExt};
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
use rand_xoshiro::Xoshiro256Plus;

fn perform_ica(size: usize, gfunc: GFunc) {
Expand Down Expand Up @@ -55,6 +54,8 @@ fn bench(c: &mut Criterion) {
(GFunc::Exp, "Exp"),
] {
let mut group = c.benchmark_group("Fast ICA");
config::set_default_benchmark_configs(&mut group);

let sizes: [usize; 3] = [1_000, 10_000, 100_000];
for size in sizes {
let input = (size, gfunc);
Expand All @@ -69,7 +70,7 @@ fn bench(c: &mut Criterion) {
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = config::get_default_profiling_configs();
targets = bench
}
#[cfg(target_os = "windows")]
Expand Down
4 changes: 1 addition & 3 deletions algorithms/linfa-linear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ linfa-datasets = { version = "0.6.0", path = "../../datasets", features = ["diab
approx = "0.4"
criterion = "0.4.0"
statrs = "0.16.0"

[target.'cfg(not(windows))'.dev-dependencies]
pprof = { version = "0.11.0", features = ["flamegraph", "criterion"] }
linfa = { version = "0.6.0", path = "../..", features = ["benchmarks"] }

[[bench]]
name = "ols_bench"
Expand Down
7 changes: 4 additions & 3 deletions algorithms/linfa-linear/benches/ols_bench.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use linfa::benchmarks::config;
use linfa::traits::Fit;
use linfa::Dataset;
use linfa_datasets::generate::make_dataset;
use linfa_linear::{LinearRegression, TweedieRegressor};
use ndarray::Ix1;
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
use statrs::distribution::{DiscreteUniform, Laplace};

#[allow(unused_must_use)]
Expand All @@ -22,6 +21,8 @@ fn perform_glm(dataset: &Dataset<f64, f64, Ix1>) {

fn bench(c: &mut Criterion) {
let mut group = c.benchmark_group("Linfa_linear");
config::set_default_benchmark_configs(&mut group);

let params: [(usize, usize); 4] = [(1_000, 5), (10_000, 5), (100_000, 5), (100_000, 10)];

let feat_distr = Laplace::new(0.5, 5.).unwrap();
Expand Down Expand Up @@ -62,7 +63,7 @@ fn bench(c: &mut Criterion) {
#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = config::get_default_profiling_configs();
targets = bench
}
#[cfg(target_os = "windows")]
Expand Down
4 changes: 1 addition & 3 deletions algorithms/linfa-nn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ approx = "0.4"
criterion = "0.4.0"
rand_xoshiro = "0.6"
ndarray-rand = "0.14"

[target.'cfg(not(windows))'.dev-dependencies]
pprof = { version = "0.11.0", features = ["flamegraph", "criterion"] }
linfa = { version = "0.6.0", path = "../..", features = ["benchmarks"] }

[[bench]]
name = "nn"
Expand Down
Loading