Skip to content
Permalink
Browse files

Multiinstance mode for multiline examples (#1934)

* multiinstance works (dirty)

* clear_seq_finish / finish_example unification

* more oop to learner

* cleanup

* last line handling fix

* cleanup

* finish example conflict fix

* finish example conflict fix

* build fix (forgotten merge change)

* comments

* unit tests fix
  • Loading branch information...
ataymano authored and jackgerrits committed Aug 22, 2019
1 parent 02bf43c commit 57cd4f51df65100c2ecbfd215196542534f17225
@@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(ccb_generate_interactions)
std::sort(interactions.begin(), interactions.end());

check_vectors(interactions, compare_set);
VW::clear_seq_and_finish_examples(vw, actions);
VW::finish_example(vw, actions);
VW::finish_example(vw, *shared_ex);
VW::finish(vw);
}
@@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(parse_dsjson_cb)
BOOST_CHECK_CLOSE(examples[2]->l.cb.costs[0].probability, 0.8166667, FLOAT_TOL);
BOOST_CHECK_CLOSE(examples[2]->l.cb.costs[0].cost, -1.0, FLOAT_TOL);
BOOST_CHECK_EQUAL(examples[2]->l.cb.costs[0].action, 2);
VW::clear_seq_and_finish_examples(*vw, examples);
VW::finish_example(*vw, examples);
VW::finish(*vw);
}

@@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(parse_dsjson_ccb)
BOOST_CHECK_CLOSE(label2.outcome->probabilities[0].score, .75f, .0001f);
BOOST_CHECK_EQUAL(label2.outcome->probabilities[1].action, 1);
BOOST_CHECK_CLOSE(label2.outcome->probabilities[1].score, .25f, .0001f);
VW::clear_seq_and_finish_examples(*vw, examples);
VW::finish_example(*vw, examples);
VW::finish(*vw);
}

@@ -273,6 +273,6 @@ BOOST_AUTO_TEST_CASE(parse_dsjson_cb_as_ccb)
BOOST_CHECK_EQUAL(label2.outcome->probabilities.size(), 1);
BOOST_CHECK_EQUAL(label2.outcome->probabilities[0].action, 2);
BOOST_CHECK_CLOSE(label2.outcome->probabilities[0].score, 0.8166667f, .0001f);
VW::clear_seq_and_finish_examples(*vw, examples);
VW::finish_example(*vw, examples);
VW::finish(*vw);
}
@@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(is_example_header_cb) {

BOOST_CHECK_EQUAL(CB::ec_is_example_header(*examples[2]), false);
BOOST_CHECK_EQUAL(COST_SENSITIVE::ec_is_example_header(*examples[2]), false);
VW::clear_seq_and_finish_examples(vw, examples);
VW::finish_example(vw, examples);
VW::finish(vw);
}

@@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(is_example_header_ccb) {

BOOST_CHECK_EQUAL(CCB::ec_is_example_header(*examples[0]), true);
BOOST_CHECK_EQUAL(CCB::ec_is_example_header(*examples[1]), false);
VW::clear_seq_and_finish_examples(vw, examples);
VW::finish_example(vw, examples);
VW::finish(vw);
}

@@ -52,6 +52,6 @@ BOOST_AUTO_TEST_CASE(is_example_header_csoaa) {

BOOST_CHECK_EQUAL(CB::ec_is_example_header(*examples[1]), false);
BOOST_CHECK_EQUAL(COST_SENSITIVE::ec_is_example_header(*examples[1]), false);
VW::clear_seq_and_finish_examples(vw, examples);
VW::finish_example(vw, examples);
VW::finish(vw);
}
@@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(parse_json_simple)

BOOST_CHECK_EQUAL(examples.size(), 1);
BOOST_CHECK_CLOSE(examples[0]->l.simple.label, 1.f, FLOAT_TOL);
VW::clear_seq_and_finish_examples(*vw, examples);
VW::finish_example(*vw, examples);
VW::finish(*vw);
}

@@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE(parse_json_cb)
BOOST_CHECK_CLOSE(examples[1]->l.cb.costs[0].probability, 0.5, FLOAT_TOL);
BOOST_CHECK_CLOSE(examples[1]->l.cb.costs[0].cost, 1.0, FLOAT_TOL);
BOOST_CHECK_EQUAL(examples[1]->l.cb.costs[0].action, 1);
VW::clear_seq_and_finish_examples(*vw, examples);
VW::finish_example(*vw, examples);
VW::finish(*vw);
}

@@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(parse_json_ccb)
BOOST_CHECK_CLOSE(label3.outcome->probabilities[0].score, .75f, .0001f);
BOOST_CHECK_EQUAL(label3.outcome->probabilities[1].action, 1);
BOOST_CHECK_CLOSE(label3.outcome->probabilities[1].score, .25f, .0001f);
VW::clear_seq_and_finish_examples(*vw, examples);
VW::finish_example(*vw, examples);
VW::finish(*vw);
}

@@ -234,6 +234,6 @@ BOOST_AUTO_TEST_CASE(parse_json_cb_as_ccb)
BOOST_CHECK_EQUAL(label1.outcome->probabilities.size(), 1);
BOOST_CHECK_EQUAL(label1.outcome->probabilities[0].action, 1);
BOOST_CHECK_CLOSE(label1.outcome->probabilities[0].score, .5f, .0001f);
VW::clear_seq_and_finish_examples(*vw, examples);
VW::finish_example(*vw, examples);
VW::finish(*vw);
}
@@ -411,7 +411,7 @@ void finish_multiline_example(vw& all, cb_adf& data, multi_ex& ec_seq)
output_example_seq(all, data, ec_seq);
global_print_newline(all);
}
VW::clear_seq_and_finish_examples(all, ec_seq);
VW::finish_example(all, ec_seq);
}

void finish(cb_adf& data)
@@ -597,7 +597,7 @@ void finish_multiline_example(vw& all, cb_explore_adf& data, multi_ex& ec_seq)
}


VW::clear_seq_and_finish_examples(all, ec_seq);
VW::finish_example(all, ec_seq);
}

template <bool is_learn>
@@ -391,7 +391,7 @@ void finish_multiline_example(vw& all, cbify&, multi_ex& ec_seq)
output_example_seq(all, ec_seq);
// global_print_newline(all);
}
VW::clear_seq_and_finish_examples(all, ec_seq);
VW::finish_example(all, ec_seq);
}

base_learner* cbify_setup(options_i& options, vw& all)
@@ -626,7 +626,7 @@ void finish_multiline_example(vw& all, ccb& data, multi_ex& ec_seq)
return_v_array(ec_seq[0]->pred.decision_scores, data.action_scores_pool);
ec_seq[0]->pred.decision_scores = {0, 0, 0, 0};

VW::clear_seq_and_finish_examples(all, ec_seq);
VW::finish_example(all, ec_seq);
}

void finish(ccb& data) { data.~ccb(); }
@@ -727,7 +727,7 @@ void finish_multiline_example(vw& all, ldf& data, multi_ex& ec_seq)
output_example_seq(all, data, ec_seq);
global_print_newline(all);
}
VW::clear_seq_and_finish_examples(all, ec_seq);
VW::finish_example(all, ec_seq);
}

void finish(ldf& data)
@@ -240,13 +240,12 @@ void dealloc_example(void (*delete_label)(void*), example& ec, void (*delete_pre
void finish_example(vw&, example&);
void clean_example(vw&, example&, bool rewind);

void clear_seq_and_finish_examples(vw& all, multi_ex& ec_seq)
void finish_example(vw& all, multi_ex& ec_seq)
{
if (ec_seq.size() > 0)
for (example* ecc : ec_seq)
if (ecc->in_use)
VW::finish_example(all, *ecc);
ec_seq.clear();
}

void return_multiple_example(vw& all, v_array<example*>& examples)
@@ -138,7 +138,5 @@ typedef std::vector<example*> multi_ex;

namespace VW
{
void clear_seq_and_finish_examples(vw& all, multi_ex& ec_seq);

void return_multiple_example(vw& all, v_array<example*>& examples);
} // namespace VW
@@ -117,7 +117,7 @@ void finish_multiline_example(vw& all, explore_eval& data, multi_ex& ec_seq)
output_example_seq(all, data, ec_seq);
CB_ADF::global_print_newline(all);
}
VW::clear_seq_and_finish_examples(all, ec_seq);
VW::finish_example(all, ec_seq);
}

template <bool is_learn>

0 comments on commit 57cd4f5

Please sign in to comment.
You can’t perform that action at this time.