Skip to content

Commit

Permalink
fix: sparse weights iterator end->end
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmang committed Sep 29, 2023
1 parent de52303 commit 443f31b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
28 changes: 28 additions & 0 deletions test/core.vwtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6017,5 +6017,33 @@
"input_files": [
"train-sets/single_empty_lines.txt"
]
},
{
"id": 465,
"desc": "cb_explore_adf with epsilon-greedy exploration using --sparse_weights and saving model",
"vw_command": "--cb_explore_adf --epsilon 0.1 -d train-sets/cb_test.ldf --noconstant --sparse_weights -f standard_sparse_model.vw",
"diff_files": {
"stderr": "train-sets/ref/sparse_save_check.stderr",
"stdout": "train-sets/ref/sparse_save_check.stdout"
},
"input_files": [
"train-sets/cb_test.ldf"
]
},
{
"id": 466,
"desc": "cb_explore_adf with epsilon-greedy exploration using --sparse_weights and loading model",
"vw_command": "--cb_explore_adf --epsilon 0.1 -d train-sets/cb_test.ldf --noconstant --sparse_weights -i standard_sparse_model.vw",
"diff_files": {
"stderr": "train-sets/ref/sparse_load_check.stderr",
"stdout": "train-sets/ref/sparse_load_check.stdout"
},
"input_files": [
"train-sets/cb_test.ldf",
"standard_sparse_model.vw"
],
"depends_on": [
465
]
}
]
22 changes: 22 additions & 0 deletions test/train-sets/ref/sparse_load_check.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using no cache
Reading datafile = train-sets/cb_test.ldf
num sources = 1
Num weight bits = 18
learning rate = 0.5
initial_t = 3
power_t = 0.5
cb_type = mtr
Enabled learners: gd, scorer-identity, csoaa_ldf-rank, cb_adf, cb_explore_adf_greedy, shared_feature_merger
Input label = CB
Output pred = ACTION_PROBS
average since example example current current current
loss last counter weight label predict features
0.066667 0.066667 1 1.0 0:1:0.5 1:0.48 15
0.033333 0.000000 2 2.0 1:0:0.5 1:0.95 6

finished run
number of examples = 3
weighted example sum = 3.000000
weighted label sum = 0.000000
average loss = 0.033333
total feature number = 27
Empty file.
23 changes: 23 additions & 0 deletions test/train-sets/ref/sparse_save_check.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
final_regressor = standard_sparse_model.vw
using no cache
Reading datafile = train-sets/cb_test.ldf
num sources = 1
Num weight bits = 18
learning rate = 0.5
initial_t = 0
power_t = 0.5
cb_type = mtr
Enabled learners: gd, scorer-identity, csoaa_ldf-rank, cb_adf, cb_explore_adf_greedy, shared_feature_merger
Input label = CB
Output pred = ACTION_PROBS
average since example example current current current
loss last counter weight label predict features
0.666667 0.666667 1 1.0 0:1:0.5 0:0.33 15
0.333333 0.000000 2 2.0 1:0:0.5 1:0.95 6

finished run
number of examples = 3
weighted example sum = 3.000000
weighted label sum = 0.000000
average loss = 0.333333
total feature number = 27
Empty file.
4 changes: 2 additions & 2 deletions vowpalwabbit/core/include/vw/core/array_parameters_sparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class sparse_parameters

// iterator with stride
iterator begin() { return iterator(_map.begin()); }
iterator end() { return iterator(_map.begin()); }
iterator end() { return iterator(_map.end()); }

// const iterator
const_iterator cbegin() const { return const_iterator(_map.begin()); }
const_iterator cend() const { return const_iterator(_map.begin()); }
const_iterator cend() const { return const_iterator(_map.end()); }

inline VW::weight& operator[](size_t i) { return *(get_or_default_and_get(i)); }

Expand Down

0 comments on commit 443f31b

Please sign in to comment.