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

refactor: Remove delete_label #2925

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 1 addition & 6 deletions vowpalwabbit/cb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; },
// test_label
Expand Down Expand Up @@ -184,7 +182,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 parse_label(parser* p, shared_data* sd, CB_EVAL::label& ld, std::vector<VW::string_view>& words,
reduction_features& red_features)
Expand Down Expand Up @@ -212,9 +209,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; },
// test_label
[](polylabel* v) { return CB_EVAL::test_label(v->cb_eval); },
Expand Down
5 changes: 0 additions & 5 deletions vowpalwabbit/cb_algs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions vowpalwabbit/cb_continuous_label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ label_parser the_label_parser = {
[](polylabel* v, reduction_features&, io_buf& cache) { CB::cache_label<continuous_label, continuous_label_elm>(v->cb_cont, cache); },
// read_cached_label
[](shared_data* sd, polylabel* v, reduction_features&, io_buf& cache) { return CB::read_cached_label<continuous_label, continuous_label_elm>(sd, v->cb_cont, cache); },
// delete_label
[](polylabel* v) { CB::delete_label<continuous_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; },
Expand Down
6 changes: 0 additions & 6 deletions vowpalwabbit/cb_label_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,4 @@ bool is_test_label(LabelT& ld)
return true;
}

template <typename LabelT = CB::label>
void delete_label(LabelT& ld)
{
ld.costs.delete_v();
}

} // namespace CB
14 changes: 1 addition & 13 deletions vowpalwabbit/ccb_label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

ACTION_SCORE::action_score convert_to_score(
const VW::string_view& action_id_str, const VW::string_view& probability_str)
{
Expand Down Expand Up @@ -314,9 +304,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); },
// test_label
[](polylabel* v) { return test_label(v->conditional_contextual_bandit); },
Expand Down
1 change: 0 additions & 1 deletion vowpalwabbit/ccb_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VW::string_view>& 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);
Expand Down
6 changes: 1 addition & 5 deletions vowpalwabbit/cost_sensitive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ bool test_label(label& ld)
return true;
}

void delete_label(label& ld) { ld.costs.delete_v(); }

void parse_label(parser* p, shared_data* sd, label& ld, std::vector<VW::string_view>& words, reduction_features&)
{
ld.costs.clear();
Expand Down Expand Up @@ -177,9 +175,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); },
// test_label
[](polylabel* v) { return test_label(v->cs); },
Expand Down
1 change: 0 additions & 1 deletion vowpalwabbit/cost_sensitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion vowpalwabbit/label_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct label_parser
void (*parse_label)(parser*, shared_data*, polylabel*, std::vector<VW::string_view>&, 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&);
bool (*test_label)(polylabel*);
void (*post_parse_setup)(example*);
Expand Down
4 changes: 1 addition & 3 deletions vowpalwabbit/multiclass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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); },
// test_label
[](polylabel* v) { return test_label(v->multi); },
Expand Down
6 changes: 1 addition & 5 deletions vowpalwabbit/multilabel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 parse_label(
parser* p, shared_data*, MULTILABEL::labels& ld, std::vector<VW::string_view>& words, reduction_features&)
{
Expand Down Expand Up @@ -109,9 +107,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); },
// test_label
[](polylabel* v) { return test_label(v->multilabels); },
Expand Down
2 changes: 0 additions & 2 deletions vowpalwabbit/no_label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; },
// test_label
Expand Down
10 changes: 5 additions & 5 deletions vowpalwabbit/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2234,13 +2234,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
Expand Down
4 changes: 1 addition & 3 deletions vowpalwabbit/simple_label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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); },
// test_label
[](polylabel* v) { return test_label(v->simple); },
Expand Down
1 change: 0 additions & 1 deletion vowpalwabbit/slates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 1 addition & 5 deletions vowpalwabbit/slates_label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

// Slates labels come in three types, shared, action and slot with the following structure:
// slates shared [global_cost]
// slates action <slot_id>
Expand Down Expand Up @@ -182,9 +180,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); },
// test_label
[](polylabel* v) { return test_label(v->slates); },
Expand Down
1 change: 0 additions & 1 deletion vowpalwabbit/slates_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VW::string_view>& 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);

Expand Down
12 changes: 4 additions & 8 deletions vowpalwabbit/warm_cb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<COST_SENSITIVE::label> csls;
std::vector<CB::label> 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); }
Expand Down Expand Up @@ -506,13 +502,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<COST_SENSITIVE::label>(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<CB::label>(num_actions);
data.cbls.resize(num_actions);

data.ws_train_size = data.ws_period;
data.ws_vali_size = 0;
Expand Down