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

ci: [epsilon_decay] benchmarks #4494

Merged
merged 5 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 2 additions & 0 deletions test/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ if (NOT BUILD_ONLY_STANDALONE_BENCHMARKS)
set(all_sources ${all_sources}
input_format_benchmarks.cc
benchmark_funcs.cc
benchmark_epsilon_decay.cc
../../vowpalwabbit/core/tests/simulator.cc

# These are just for benchmarking specific standard library operations
#benchmark_std_function.cc
Expand Down
57 changes: 57 additions & 0 deletions test/benchmarks/benchmark_epsilon_decay.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "../../vowpalwabbit/core/tests/simulator.h"
#include "benchmarks_common.h"
#include "vw/cache_parser/parse_example_cache.h"
#include "vw/config/options_cli.h"
#include "vw/core/learner.h"
#include "vw/core/metric_sink.h"
#include "vw/core/parser.h"
#include "vw/core/reductions/epsilon_decay.h"
#include "vw/core/setup_base.h"
#include "vw/core/vw.h"
#include "vw/io/io_adapter.h"
#include "vw/text_parser/parse_example_text.h"

#include <benchmark/benchmark.h>

template <class... ExtraArgs>
static void bench_epsilon_decay(benchmark::State& state, ExtraArgs&&... extra_args)
{
std::array<std::string, sizeof...(extra_args)> res = {extra_args...};
std::string use_decay = res[0];
std::string model_count = res[1];
std::string bit_size = res[2];
std::string tolerance = res[3];

using callback_map =
typename std::map<size_t, std::function<bool(simulator::cb_sim&, VW::workspace&, VW::multi_ex&)>>;
callback_map test_hooks;

for (auto _ : state)
{
const size_t num_iterations = 1000;
const size_t seed = 99;
const std::vector<uint64_t> swap_after = {500};
if (use_decay == "decay")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this variable used like a boolean? if so maybe it should be of type bool.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure just did this get all the args in a consistent way, updated to bool

{
simulator::_test_helper_hook(
std::vector<std::string>{"-l", "1e-3", "--power_t", "0", "-q::", "--cb_explore_adf", "--epsilon_decay",
"--model_count", model_count, "-b", bit_size, "--tol_x", tolerance, "--quiet"},
test_hooks, num_iterations, seed, swap_after);
}
else
{
simulator::_test_helper_hook(
std::vector<std::string>{"-l", "1e-3", "--power_t", "0", "-q::", "--cb_explore_adf", "--quiet"}, test_hooks,
num_iterations, seed, swap_after);
}
benchmark::ClobberMemory();
}
}

BENCHMARK_CAPTURE(bench_epsilon_decay, epsilon_decay_1_model_big_tol, "decay", "1", "18", "1e-2");
BENCHMARK_CAPTURE(bench_epsilon_decay, epsilon_decay_2_model_big_tol, "decay", "2", "19", "1e-2");
BENCHMARK_CAPTURE(bench_epsilon_decay, epsilon_decay_4_model_big_tol, "decay", "4", "20", "1e-2");
BENCHMARK_CAPTURE(bench_epsilon_decay, epsilon_decay_1_model_small_tol, "decay", "1", "18", "1e-6");
BENCHMARK_CAPTURE(bench_epsilon_decay, epsilon_decay_2_model_small_tol, "decay", "2", "19", "1e-6");
BENCHMARK_CAPTURE(bench_epsilon_decay, epsilon_decay_4_model_small_tol, "decay", "4", "20", "1e-6");
BENCHMARK_CAPTURE(bench_epsilon_decay, without_epsilon_decay, "nondecay", "", "", "");