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

feat: not self consistent speed up #4652

Merged
51 changes: 23 additions & 28 deletions vowpalwabbit/core/src/reductions/eigen_memory_tree.cc
Original file line number Diff line number Diff line change
@@ -489,15 +489,7 @@
}
}

void scorer_features(const emt_feats& f1, VW::features& out)
{
for (auto p : f1)
{
if (p.second != 0) { out.push_back(p.second, p.first); }
}
}

void scorer_features(const emt_feats& f1, const emt_feats& f2, VW::features& out)
void scorer_features_sub(const emt_feats& f1, const emt_feats& f2, VW::features& out)
{
auto iter1 = f1.begin();
auto iter2 = f2.begin();
@@ -535,15 +527,31 @@
}
}

void scorer_features_mul(const emt_feats& f1, const emt_feats& f2, VW::features& out)

Check warning on line 530 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L530

Added line #L530 was not covered by tests
{
auto iter1 = f1.begin();
auto iter2 = f2.begin();

Check warning on line 533 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L532-L533

Added lines #L532 - L533 were not covered by tests

while (iter1 != f1.end() && iter2 != f2.end())

Check warning on line 535 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L535

Added line #L535 was not covered by tests
{
if (iter1->first < iter2->first) { iter1++; }
else if (iter2->first < iter1->first) { iter2++; }

Check warning on line 538 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L537-L538

Added lines #L537 - L538 were not covered by tests
else
{
out.push_back(iter1->second * iter2->second, iter1->first);
iter1++;
iter2++;

Check warning on line 543 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L541-L543

Added lines #L541 - L543 were not covered by tests
}
}
}

Check warning on line 546 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L546

Added line #L546 was not covered by tests

void scorer_example(emt_tree& b, const emt_example& ex1, const emt_example& ex2)
{
VW::example& out = *b.ex;

static constexpr VW::namespace_index X_NS = 'x';
static constexpr VW::namespace_index Z_NS = 'z';

out.feature_space[X_NS].clear();
out.feature_space[Z_NS].clear();

if (b.scorer_type == emt_scorer_type::SELF_CONSISTENT_RANK)
{
@@ -552,7 +560,7 @@

out.interactions->clear();

scorer_features(ex1.full, ex2.full, out.feature_space[X_NS]);
scorer_features_sub(ex1.full, ex2.full, out.feature_space[X_NS]);

out.total_sum_feat_sq = out.feature_space[X_NS].sum_feat_sq;
out.num_features = out.feature_space[X_NS].size();
@@ -565,26 +573,13 @@
{
out.indices.clear();
out.indices.push_back(X_NS);
out.indices.push_back(Z_NS);

out.interactions->clear();
out.interactions->push_back({X_NS, Z_NS});

b.all->feature_tweaks_config.ignore_some_linear = true;
b.all->feature_tweaks_config.ignore_linear[X_NS] = true;
b.all->feature_tweaks_config.ignore_linear[Z_NS] = true;

scorer_features(ex1.full, out.feature_space[X_NS]);
scorer_features(ex2.full, out.feature_space[Z_NS]);
scorer_features_mul(ex1.full, ex2.full, out.feature_space[X_NS]);

Check warning on line 579 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L579

Added line #L579 was not covered by tests

// when we receive ex1 and ex2 their features are indexed on top of eachother. In order
// to make sure VW recognizes the features from the two examples as separate features
// we apply a map of multiplying by 2 and then offseting by 1 on the second example.
for (auto& j : out.feature_space[X_NS].indices) { j = j * 2; }
for (auto& j : out.feature_space[Z_NS].indices) { j = j * 2 + 1; }

out.total_sum_feat_sq = out.feature_space[X_NS].sum_feat_sq + out.feature_space[Z_NS].sum_feat_sq;
out.num_features = out.feature_space[X_NS].size() + out.feature_space[Z_NS].size();
out.total_sum_feat_sq = out.feature_space[X_NS].sum_feat_sq;
out.num_features = out.feature_space[X_NS].size();

Check warning on line 582 in vowpalwabbit/core/src/reductions/eigen_memory_tree.cc

Codecov / codecov/patch

vowpalwabbit/core/src/reductions/eigen_memory_tree.cc#L581-L582

Added lines #L581 - L582 were not covered by tests

auto initial = emt_initial(b.initial_type, ex1.full, ex2.full);
out.ex_reduction_features.get<VW::simple_label_reduction_features>().initial = initial;

Unchanged files with check annotations Beta

else { shrink_factors.resize(preds.size(), 1.f); }
}
template class cb_explore_adf_large_action_space<one_pass_svd_impl, one_rank_spanner_state>;

Check warning on line 266 in vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc

GitHub Actions / windows-latest-vcpkg-debug-Vcpkg build

'void VW::cb_explore_adf::cb_explore_adf_large_action_space<VW::cb_explore_adf::one_pass_svd_impl,VW::cb_explore_adf::one_rank_spanner_state>::save_load(VW::io_buf &,bool,bool)': no suitable definition provided for explicit template instantiation request
template class cb_explore_adf_large_action_space<two_pass_svd_impl, one_rank_spanner_state>;
} // namespace cb_explore_adf
} // namespace VW
VW::workspace* all = nullptr;
try
{
all = VW::initialize(std::move(options));

Check warning on line 32 in utl/flatbuffer/txt_to_flat.cc

GitHub Actions / asan.ubuntu-latest.vcpkg-asan-debug

‘VW::workspace* VW::initialize(std::unique_ptr<VW::config::options_i, void (*)(VW::config::options_i*)>, VW::io_buf*, bool, VW::trace_message_t, void*)’ is deprecated: Replaced with new unique_ptr based overload. [-Wdeprecated-declarations]

Check warning on line 32 in utl/flatbuffer/txt_to_flat.cc

GitHub Actions / asan.macos-latest.vcpkg-asan-debug

'initialize' is deprecated: Replaced with new unique_ptr based overload. [-Wdeprecated-declarations]

Check warning on line 32 in utl/flatbuffer/txt_to_flat.cc

GitHub Actions / asan.macos-latest.vcpkg-ubsan-debug

'initialize' is deprecated: Replaced with new unique_ptr based overload. [-Wdeprecated-declarations]
}
catch (const std::exception& ex)
{