From 4d375d015f24ea7dd7e1cd874e10ec9aea5a1a0d Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Wed, 7 Apr 2021 11:05:03 -0400 Subject: [PATCH 1/3] refactor: Remove delete_label --- vowpalwabbit/cb.cc | 7 +------ vowpalwabbit/cb_algs.cc | 5 ----- vowpalwabbit/cb_continuous_label.cc | 2 -- vowpalwabbit/cb_label_parser.h | 6 ------ vowpalwabbit/ccb_label.cc | 14 +------------- vowpalwabbit/ccb_label.h | 1 - vowpalwabbit/cost_sensitive.cc | 6 +----- vowpalwabbit/cost_sensitive.h | 1 - vowpalwabbit/label_parser.h | 1 - vowpalwabbit/multiclass.cc | 4 +--- vowpalwabbit/multilabel.cc | 6 +----- vowpalwabbit/no_label.cc | 2 -- vowpalwabbit/search.cc | 10 +++++----- vowpalwabbit/simple_label.cc | 4 +--- vowpalwabbit/slates.cc | 1 - vowpalwabbit/slates_label.cc | 6 +----- vowpalwabbit/slates_label.h | 1 - vowpalwabbit/warm_cb.cc | 12 ++++-------- 18 files changed, 16 insertions(+), 73 deletions(-) diff --git a/vowpalwabbit/cb.cc b/vowpalwabbit/cb.cc index 1807035331a..e46171ef2dd 100644 --- a/vowpalwabbit/cb.cc +++ b/vowpalwabbit/cb.cc @@ -95,8 +95,6 @@ label_parser cb_label = { [](polylabel* v, reduction_features&, io_buf& cache) { CB::cache_label(v->cb, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return CB::read_cached_label(sd, v->cb, cache); }, - // delete_label - [](polylabel* v) { CB::delete_label(v->cb); }, // get_weight [](polylabel*, const reduction_features&) { return 1.f; }, // copy_label @@ -190,7 +188,6 @@ void default_label(CB_EVAL::label& ld) bool test_label(CB_EVAL::label& ld) { return CB::is_test_label(ld.event); } -void delete_label(CB_EVAL::label& ld) { CB::delete_label(ld.event); } void copy_label(CB_EVAL::label& dst, CB_EVAL::label& src) { @@ -224,9 +221,7 @@ label_parser cb_eval = { [](polylabel* v, reduction_features&, io_buf& cache) { CB_EVAL::cache_label(v->cb_eval, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return CB_EVAL::read_cached_label(sd, v->cb_eval, cache); }, - // delete_label - [](polylabel* v) { CB_EVAL::delete_label(v->cb_eval); }, - // get_weight + // get_weight [](polylabel*, const reduction_features&) { return 1.f; }, // copy_label [](polylabel* dst, polylabel* src) { diff --git a/vowpalwabbit/cb_algs.cc b/vowpalwabbit/cb_algs.cc index 61f3a0c3072..350483fe6f9 100644 --- a/vowpalwabbit/cb_algs.cc +++ b/vowpalwabbit/cb_algs.cc @@ -26,11 +26,6 @@ namespace CB_ALGS struct cb { cb_to_cs cbcs; - - ~cb() - { - COST_SENSITIVE::delete_label(cbcs.pred_scores); - } }; bool know_all_cost_example(CB::label& ld) diff --git a/vowpalwabbit/cb_continuous_label.cc b/vowpalwabbit/cb_continuous_label.cc index 7508083ff12..ee37cef8732 100644 --- a/vowpalwabbit/cb_continuous_label.cc +++ b/vowpalwabbit/cb_continuous_label.cc @@ -142,8 +142,6 @@ label_parser the_label_parser = { [](polylabel* v, reduction_features&, io_buf& cache) { CB::cache_label(v->cb_cont, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return CB::read_cached_label(sd, v->cb_cont, cache); }, - // delete_label - [](polylabel* v) { CB::delete_label(v->cb_cont); }, // get_weight // CB::weight just returns 1.f? This seems like it could be a bug... [](polylabel*, const reduction_features&) { return 1.f; }, diff --git a/vowpalwabbit/cb_label_parser.h b/vowpalwabbit/cb_label_parser.h index 27efb93c8be..2bc816c9ea9 100644 --- a/vowpalwabbit/cb_label_parser.h +++ b/vowpalwabbit/cb_label_parser.h @@ -118,12 +118,6 @@ bool is_test_label(LabelT& ld) return true; } -template -void delete_label(LabelT& ld) -{ - ld.costs.delete_v(); -} - template void copy_label_additional_fields(LabelT& dst, LabelT& src) { diff --git a/vowpalwabbit/ccb_label.cc b/vowpalwabbit/ccb_label.cc index 638682e788a..fd764fbf654 100644 --- a/vowpalwabbit/ccb_label.cc +++ b/vowpalwabbit/ccb_label.cc @@ -174,16 +174,6 @@ void default_label(label& ld) bool test_label(CCB::label& ld) { return ld.outcome == nullptr; } -void delete_label(label& ld) -{ - if (ld.outcome) - { - delete ld.outcome; - ld.outcome = nullptr; - } - ld.explicit_included_actions.delete_v(); -} - void copy_label(label& ldDst, label& ldSrc) { if (ldSrc.outcome) @@ -330,9 +320,7 @@ label_parser ccb_label_parser = { [](polylabel* v, ::reduction_features&, io_buf& cache) { cache_label(v->conditional_contextual_bandit, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, ::reduction_features&, io_buf& cache) { return read_cached_label(sd, v->conditional_contextual_bandit, cache); }, - // delete_label - [](polylabel* v) { delete_label(v->conditional_contextual_bandit); }, - // get_weight + // get_weight [](polylabel* v, const ::reduction_features&) { return ccb_weight(v->conditional_contextual_bandit); }, // copy_label [](polylabel* dst, polylabel* src) { diff --git a/vowpalwabbit/ccb_label.h b/vowpalwabbit/ccb_label.h index 5f3f8147a9a..2e57662b777 100644 --- a/vowpalwabbit/ccb_label.h +++ b/vowpalwabbit/ccb_label.h @@ -104,7 +104,6 @@ struct label }; void default_label(CCB::label& ld); -void delete_label(CCB::label& ld); void parse_label(parser* p, shared_data*, CCB::label& ld, std::vector& words, ::reduction_features&); void cache_label(CCB::label& ld, io_buf& cache); size_t read_cached_label(shared_data*, CCB::label& ld, io_buf& cache); diff --git a/vowpalwabbit/cost_sensitive.cc b/vowpalwabbit/cost_sensitive.cc index 8808a0c8df7..15a7e08d09d 100644 --- a/vowpalwabbit/cost_sensitive.cc +++ b/vowpalwabbit/cost_sensitive.cc @@ -99,8 +99,6 @@ bool test_label(label& ld) return true; } -void delete_label(label& ld) { ld.costs.delete_v(); } - void copy_label(label& dst, label& src) { dst.costs = src.costs; } void parse_label(parser* p, shared_data* sd, label& ld, std::vector& words, reduction_features&) @@ -179,9 +177,7 @@ label_parser cs_label = { [](polylabel* v, reduction_features&, io_buf& cache) { cache_label(v->cs, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return read_cached_label(sd, v->cs, cache); }, - // delete_label - [](polylabel* v) { if (v) delete_label(v->cs); }, - // get_weight + // get_weight [](polylabel* v, const reduction_features&) { return weight(v->cs); }, // copy_label [](polylabel* dst, polylabel* src) { diff --git a/vowpalwabbit/cost_sensitive.h b/vowpalwabbit/cost_sensitive.h index 1fabccd2140..2321bba35a4 100644 --- a/vowpalwabbit/cost_sensitive.h +++ b/vowpalwabbit/cost_sensitive.h @@ -37,7 +37,6 @@ void finish_example(vw& all, T&, example& ec) finish_example(all, ec); } -void delete_label(label& ld); void default_label(label& ld); extern label_parser cs_label; diff --git a/vowpalwabbit/label_parser.h b/vowpalwabbit/label_parser.h index ef9f02069a8..5af4e4060bd 100644 --- a/vowpalwabbit/label_parser.h +++ b/vowpalwabbit/label_parser.h @@ -36,7 +36,6 @@ struct label_parser void (*parse_label)(parser*, shared_data*, polylabel*, std::vector&, reduction_features&); void (*cache_label)(polylabel*, reduction_features&, io_buf& cache); size_t (*read_cached_label)(shared_data*, polylabel*, reduction_features&, io_buf& cache); - void (*delete_label)(polylabel*); float (*get_weight)(polylabel*, const reduction_features&); void (*copy_label)( polylabel*, polylabel*); // copy_label(dst,src) performs a DEEP copy of src into dst (dst is allocated diff --git a/vowpalwabbit/multiclass.cc b/vowpalwabbit/multiclass.cc index 3c9da21492e..40b0b1e0a65 100644 --- a/vowpalwabbit/multiclass.cc +++ b/vowpalwabbit/multiclass.cc @@ -97,9 +97,7 @@ label_parser mc_label = { [](polylabel* v, reduction_features&, io_buf& cache) { cache_label(v->multi, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return read_cached_label(sd, v->multi, cache); }, - // delete_label - [](polylabel*) {}, - // get_weight + // get_weight [](polylabel* v, const reduction_features&) { return weight(v->multi); }, // copy_label nullptr, diff --git a/vowpalwabbit/multilabel.cc b/vowpalwabbit/multilabel.cc index 45416835705..6e685b49ece 100644 --- a/vowpalwabbit/multilabel.cc +++ b/vowpalwabbit/multilabel.cc @@ -74,8 +74,6 @@ void default_label(MULTILABEL::labels& ld) { ld.label_v.clear(); } bool test_label(MULTILABEL::labels& ld) { return ld.label_v.size() == 0; } -void delete_label(MULTILABEL::labels& ld) { ld.label_v.delete_v(); } - void copy_label(MULTILABEL::labels& dst, MULTILABEL::labels& src) { dst.label_v = src.label_v; } void parse_label( @@ -111,9 +109,7 @@ label_parser multilabel = { [](polylabel* v, reduction_features&, io_buf& cache) { cache_label(v->multilabels, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return read_cached_label(sd, v->multilabels, cache); }, - // delete_label - [](polylabel* v) { if (v) delete_label(v->multilabels); }, - // get_weight + // get_weight [](polylabel* v, const reduction_features&) { return weight(v->multilabels); }, // copy_label [](polylabel* dst, polylabel* src) { diff --git a/vowpalwabbit/no_label.cc b/vowpalwabbit/no_label.cc index b9e955e69b4..a0ecff92130 100644 --- a/vowpalwabbit/no_label.cc +++ b/vowpalwabbit/no_label.cc @@ -46,8 +46,6 @@ label_parser no_label_parser = { [](polylabel*, reduction_features&, io_buf&) {}, // read_cached_label [](shared_data*, polylabel*, reduction_features&, io_buf&) -> size_t { return 1; }, - // delete_label - [](polylabel*) {}, // get_weight [](polylabel*, const reduction_features&) { return 1.f; }, // copy_label diff --git a/vowpalwabbit/search.cc b/vowpalwabbit/search.cc index 0c60d883b89..941d51b4e83 100644 --- a/vowpalwabbit/search.cc +++ b/vowpalwabbit/search.cc @@ -2237,13 +2237,13 @@ void train_single_example(search& sch, bool is_test_ex, bool is_holdout_ex, mult cdbg << "gte" << endl; generate_training_example(priv, priv.learn_losses, 1., true); // , min_loss); // TODO: weight if (!priv.examples_dont_change) - for (size_t n = 0; n < priv.learn_ec_copy.size(); n++) + { + for(auto& ex : priv.learn_ec_copy) { - if (sch.priv->is_ldf) - CS::cs_label.delete_label(&priv.learn_ec_copy[n].l); - else - MC::mc_label.delete_label(&priv.learn_ec_copy[n].l); + // Reset the state of the polylabel + ex.l = polylabel{}; } + } if (priv.cb_learner) priv.learn_losses.cb.costs.clear(); else diff --git a/vowpalwabbit/simple_label.cc b/vowpalwabbit/simple_label.cc index acc489264cf..62ae73b312c 100644 --- a/vowpalwabbit/simple_label.cc +++ b/vowpalwabbit/simple_label.cc @@ -124,9 +124,7 @@ label_parser simple_label_parser = { [](polylabel* v, reduction_features&, io_buf& cache) { cache_simple_label(v->simple, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return read_cached_simple_label(sd, v->simple, cache); }, - // delete_label - [](polylabel*) {}, - // get_weight + // get_weight [](polylabel* v, const reduction_features&) { return get_weight(v->simple); }, // copy_label nullptr, diff --git a/vowpalwabbit/slates.cc b/vowpalwabbit/slates.cc index a9a8b1b9810..0964ee74913 100644 --- a/vowpalwabbit/slates.cc +++ b/vowpalwabbit/slates.cc @@ -99,7 +99,6 @@ void slates_data::learn_or_predict(VW::LEARNER::multi_learner& base, multi_ex& e for (size_t i = 0; i < examples.size(); i++) { - CCB::delete_label(examples[i]->l.conditional_contextual_bandit); examples[i]->l.slates = std::move(_stashed_labels[i]); } _stashed_labels.clear(); diff --git a/vowpalwabbit/slates_label.cc b/vowpalwabbit/slates_label.cc index ff03ab56ce7..1e9a978232e 100644 --- a/vowpalwabbit/slates_label.cc +++ b/vowpalwabbit/slates_label.cc @@ -78,8 +78,6 @@ void default_label(slates::label& ld) { ld.reset_to_default(); } bool test_label(slates::label& ld) { return ld.labeled == false; } -void delete_label(slates::label& ld) { ld.probabilities.delete_v(); } - void copy_label(slates::label& dst, slates::label& src) { dst.type = src.type; @@ -192,9 +190,7 @@ label_parser slates_label_parser = { [](polylabel* v, reduction_features&, io_buf& cache) { cache_label(v->slates, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return read_cached_label(sd, v->slates, cache); }, - // delete_label - [](polylabel* v) { delete_label(v->slates); }, - // get_weight + // get_weight [](polylabel* v, const reduction_features&) { return weight(v->slates); }, // copy_label [](polylabel* dst, polylabel* src) { diff --git a/vowpalwabbit/slates_label.h b/vowpalwabbit/slates_label.h index 241ed56f941..f8f2a999db4 100644 --- a/vowpalwabbit/slates_label.h +++ b/vowpalwabbit/slates_label.h @@ -57,7 +57,6 @@ struct label void default_label(VW::slates::label& v); void parse_label( parser* p, shared_data* /*sd*/, VW::slates::label& ld, std::vector& words, reduction_features&); -void delete_label(VW::slates::label& ld); void cache_label(VW::slates::label& ld, io_buf& cache); size_t read_cached_label(shared_data* /*sd*/, VW::slates::label& ld, io_buf& cache); void copy_label(VW::slates::label& dst, VW::slates::label& src); diff --git a/vowpalwabbit/warm_cb.cc b/vowpalwabbit/warm_cb.cc index 5626d136d58..3665a56659a 100644 --- a/vowpalwabbit/warm_cb.cc +++ b/vowpalwabbit/warm_cb.cc @@ -85,16 +85,12 @@ struct warm_cb uint32_t inter_iter; MULTICLASS::label_t mc_label; COST_SENSITIVE::label cs_label; - COST_SENSITIVE::label* csls; - CB::label* cbls; + std::vector csls; + std::vector cbls; bool use_cs; ~warm_cb() { - for (size_t a = 0; a < num_actions; ++a) { COST_SENSITIVE::delete_label(csls[a]); } - free(csls); - free(cbls); - for (size_t a = 0; a < num_actions; ++a) { VW::dealloc_examples(ecs[a], 1); } for (auto* ex : ws_vali) { VW::dealloc_examples(ex, 1); } @@ -511,13 +507,13 @@ void init_adf_data(warm_cb& data, const uint32_t num_actions) } // The rest of the initialization is for warm start CB - data.csls = calloc_or_throw(num_actions); + data.csls.resize(num_actions); for (uint32_t a = 0; a < num_actions; ++a) { COST_SENSITIVE::default_label(data.csls[a]); data.csls[a].costs.push_back({0, a + 1, 0, 0}); } - data.cbls = calloc_or_throw(num_actions); + data.cbls.resize(num_actions); data.ws_train_size = data.ws_period; data.ws_vali_size = 0; From a060a27b0dd442776ce69baeb780b2378eb20b06 Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Wed, 7 Apr 2021 11:05:25 -0400 Subject: [PATCH 2/3] Formatting --- vowpalwabbit/search.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vowpalwabbit/search.cc b/vowpalwabbit/search.cc index 941d51b4e83..8d9b13b38de 100644 --- a/vowpalwabbit/search.cc +++ b/vowpalwabbit/search.cc @@ -2238,7 +2238,7 @@ void train_single_example(search& sch, bool is_test_ex, bool is_holdout_ex, mult generate_training_example(priv, priv.learn_losses, 1., true); // , min_loss); // TODO: weight if (!priv.examples_dont_change) { - for(auto& ex : priv.learn_ec_copy) + for (auto& ex : priv.learn_ec_copy) { // Reset the state of the polylabel ex.l = polylabel{}; From 019f9088cbe7617829395af38ecc23f769282b80 Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Wed, 7 Apr 2021 14:37:19 -0400 Subject: [PATCH 3/3] Update simple_label_parser.cc --- vowpalwabbit/simple_label_parser.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/vowpalwabbit/simple_label_parser.cc b/vowpalwabbit/simple_label_parser.cc index 7504f925659..415414cb458 100644 --- a/vowpalwabbit/simple_label_parser.cc +++ b/vowpalwabbit/simple_label_parser.cc @@ -112,8 +112,6 @@ label_parser simple_label_parser = { [](polylabel* v, reduction_features& red_features, io_buf& cache) { cache_simple_label(v->simple, red_features, cache); }, // read_cached_label [](shared_data* sd, polylabel* v, reduction_features& red_features, io_buf& cache) { return read_cached_simple_label(sd, v->simple, red_features, cache); }, - // delete_label - [](polylabel*) {}, // get_weight [](polylabel* v, const reduction_features& red) { return get_weight(v->simple, red); }, // test_label