Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorariel faigon <github.2009@yendor.com>2014-07-24 19:06:43 +0400
committerariel faigon <github.2009@yendor.com>2014-07-24 19:06:43 +0400
commitb32eba9144f80e7981f68953aca4227bf2daa89c (patch)
tree28351fd9e4742d1797d95f9794a5ab526a84c8e1
parent295d532b4e7c6b648c02c7b35b8ebde4a0b6c937 (diff)
parent59996cd7ba3f0e9b6fab1d74b4413381ab237a9d (diff)
Merge branch 'master' of git://github.com/JohnLangford/vowpal_wabbit
-rw-r--r--vowpalwabbit/allreduce.h9
-rw-r--r--vowpalwabbit/gd.cc80
-rw-r--r--vowpalwabbit/stagewise_poly.cc2
3 files changed, 45 insertions, 46 deletions
diff --git a/vowpalwabbit/allreduce.h b/vowpalwabbit/allreduce.h
index 07ecafc7..ecac009b 100644
--- a/vowpalwabbit/allreduce.h
+++ b/vowpalwabbit/allreduce.h
@@ -62,15 +62,16 @@ template <class T, void (*f)(T&, const T&)> void addbufs(T* buf1, const T* buf2,
void all_reduce_init(const string master_location, const size_t unique_id, const size_t total, const size_t node, node_socks& socks);
template <class T> void pass_up(char* buffer, size_t left_read_pos, size_t right_read_pos, size_t& parent_sent_pos, socket_t parent_sock, size_t n) {
- size_t my_bufsize = min(ar_buf_size, ((int)(floor(left_read_pos/((float)sizeof(T)))*sizeof(T)) - parent_sent_pos));
- my_bufsize = min(my_bufsize, ((int)(floor(right_read_pos/((float)sizeof(T)))*sizeof(T)) - parent_sent_pos));
+ size_t my_bufsize = min(ar_buf_size, min(left_read_pos, right_read_pos) / sizeof(T) * sizeof(T) - parent_sent_pos);
if(my_bufsize > 0) {
//going to pass up this chunk of data to the parent
int write_size = send(parent_sock, buffer+parent_sent_pos, (int)my_bufsize, 0);
- if(write_size < (int)my_bufsize)
+ if(write_size < 0) {
cerr<<"Write to parent failed "<<my_bufsize<<" "<<write_size<<" "<<parent_sent_pos<<" "<<left_read_pos<<" "<<right_read_pos<<endl ;
- parent_sent_pos += my_bufsize;
+ throw exception();
+ }
+ parent_sent_pos += write_size;
}
}
diff --git a/vowpalwabbit/gd.cc b/vowpalwabbit/gd.cc
index 36beff8b..5b46cf29 100644
--- a/vowpalwabbit/gd.cc
+++ b/vowpalwabbit/gd.cc
@@ -42,7 +42,6 @@ namespace GD
void (*predict)(gd&, learner&, example&);
vw* all;
- shared_data* sd;
};
void sync_weights(vw& all);
@@ -353,12 +352,12 @@ void predict(gd& g, learner& base, example& ec)
vw& all = *g.all;
if (l1)
- ec.partial_prediction = trunc_predict(all, ec, g.sd->gravity);
+ ec.partial_prediction = trunc_predict(all, ec, all.sd->gravity);
else
ec.partial_prediction = inline_predict(all, ec);
label_data& ld = *(label_data*)ec.ld;
- ld.prediction = finalize_prediction(g.sd, ec.partial_prediction * (float)g.sd->contraction);
+ ld.prediction = finalize_prediction(all.sd, ec.partial_prediction * (float)all.sd->contraction);
if (audit)
print_audit_features(all, ec);
@@ -469,7 +468,7 @@ float compute_update(gd& g, example& ec)
label_data* ld = (label_data*)ec.ld;
vw& all = *g.all;
- if (all.loss->getLoss(g.sd, ld->prediction, ld->label) > 0.)
+ if (all.loss->getLoss(all.sd, ld->prediction, ld->label) > 0.)
{
float pred_per_update;
if(adaptive || normalized)
@@ -480,7 +479,7 @@ float compute_update(gd& g, example& ec)
float delta_pred = pred_per_update * all.eta * ld->weight;
if(!adaptive)
{
- float t = (float)(ec.example_t - g.sd->weighted_holdout_examples);
+ float t = (float)(ec.example_t - all.sd->weighted_holdout_examples);
delta_pred *= powf(t, g.neg_power_t);
}
@@ -493,12 +492,12 @@ float compute_update(gd& g, example& ec)
ec.updated_prediction = ec.partial_prediction + pred_per_update * update;
if (all.reg_mode && fabs(update) > 1e-8) {
- double dev1 = all.loss->first_derivative(g.sd, ld->prediction, ld->label);
+ double dev1 = all.loss->first_derivative(all.sd, ld->prediction, ld->label);
double eta_bar = (fabs(dev1) > 1e-8) ? (-update / dev1) : 0.0;
if (fabs(dev1) > 1e-8)
- g.sd->contraction *= (1. - all.l2_lambda * eta_bar);
- update /= (float)g.sd->contraction;
- g.sd->gravity += eta_bar * all.l1_lambda;
+ all.sd->contraction *= (1. - all.l2_lambda * eta_bar);
+ update /= (float)all.sd->contraction;
+ all.sd->gravity += eta_bar * all.l1_lambda;
}
return update;
}
@@ -513,7 +512,7 @@ void update(gd& g, learner& base, example& ec)
if ( (update = compute_update<invariant, sqrt_rate, feature_mask_off, adaptive, normalized, spare> (g, ec)) != 0.)
train<sqrt_rate, feature_mask_off, adaptive, normalized, spare>(g, ec, update);
- if (g.sd->contraction < 1e-10) // updating weights now to avoid numerical instability
+ if (g.all->sd->contraction < 1e-10) // updating weights now to avoid numerical instability
sync_weights(*g.all);
}
@@ -625,70 +624,70 @@ void save_load_online_state(gd& g, io_buf& model_file, bool read, bool text)
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "t %f\n", g.sd->t);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->t, sizeof(g.sd->t),
+ text_len = sprintf(buff, "t %f\n", all.sd->t);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->t, sizeof(all.sd->t),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "sum_loss %f\n", g.sd->sum_loss);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->sum_loss, sizeof(g.sd->sum_loss),
+ text_len = sprintf(buff, "sum_loss %f\n", all.sd->sum_loss);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->sum_loss, sizeof(all.sd->sum_loss),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "sum_loss_since_last_dump %f\n", g.sd->sum_loss_since_last_dump);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->sum_loss_since_last_dump, sizeof(g.sd->sum_loss_since_last_dump),
+ text_len = sprintf(buff, "sum_loss_since_last_dump %f\n", all.sd->sum_loss_since_last_dump);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->sum_loss_since_last_dump, sizeof(all.sd->sum_loss_since_last_dump),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "dump_interval %f\n", g.sd->dump_interval);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->dump_interval, sizeof(g.sd->dump_interval),
+ text_len = sprintf(buff, "dump_interval %f\n", all.sd->dump_interval);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->dump_interval, sizeof(all.sd->dump_interval),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "min_label %f\n", g.sd->min_label);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->min_label, sizeof(g.sd->min_label),
+ text_len = sprintf(buff, "min_label %f\n", all.sd->min_label);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->min_label, sizeof(all.sd->min_label),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "max_label %f\n", g.sd->max_label);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->max_label, sizeof(g.sd->max_label),
+ text_len = sprintf(buff, "max_label %f\n", all.sd->max_label);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->max_label, sizeof(all.sd->max_label),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "weighted_examples %f\n", g.sd->weighted_examples);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->weighted_examples, sizeof(g.sd->weighted_examples),
+ text_len = sprintf(buff, "weighted_examples %f\n", all.sd->weighted_examples);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->weighted_examples, sizeof(all.sd->weighted_examples),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "weighted_labels %f\n", g.sd->weighted_labels);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->weighted_labels, sizeof(g.sd->weighted_labels),
+ text_len = sprintf(buff, "weighted_labels %f\n", all.sd->weighted_labels);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->weighted_labels, sizeof(all.sd->weighted_labels),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "weighted_unlabeled_examples %f\n", g.sd->weighted_unlabeled_examples);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->weighted_unlabeled_examples, sizeof(g.sd->weighted_unlabeled_examples),
+ text_len = sprintf(buff, "weighted_unlabeled_examples %f\n", all.sd->weighted_unlabeled_examples);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->weighted_unlabeled_examples, sizeof(all.sd->weighted_unlabeled_examples),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "example_number %u\n", (uint32_t)g.sd->example_number);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->example_number, sizeof(g.sd->example_number),
+ text_len = sprintf(buff, "example_number %u\n", (uint32_t)all.sd->example_number);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->example_number, sizeof(all.sd->example_number),
"", read,
buff, text_len, text);
- text_len = sprintf(buff, "total_features %u\n", (uint32_t)g.sd->total_features);
- bin_text_read_write_fixed(model_file,(char*)&g.sd->total_features, sizeof(g.sd->total_features),
+ text_len = sprintf(buff, "total_features %u\n", (uint32_t)all.sd->total_features);
+ bin_text_read_write_fixed(model_file,(char*)&all.sd->total_features, sizeof(all.sd->total_features),
"", read,
buff, text_len, text);
if (!all.training) // reset various things so that we report test set performance properly
{
- g.sd->sum_loss = 0;
- g.sd->sum_loss_since_last_dump = 0;
- g.sd->dump_interval = 1.;
- g.sd->weighted_examples = 0.;
- g.sd->weighted_labels = 0.;
- g.sd->weighted_unlabeled_examples = 0.;
- g.sd->example_number = 0;
- g.sd->total_features = 0;
+ all.sd->sum_loss = 0;
+ all.sd->sum_loss_since_last_dump = 0;
+ all.sd->dump_interval = 1.;
+ all.sd->weighted_examples = 0.;
+ all.sd->weighted_labels = 0.;
+ all.sd->weighted_unlabeled_examples = 0.;
+ all.sd->example_number = 0;
+ all.sd->total_features = 0;
}
uint32_t length = 1 << all.num_bits;
@@ -844,7 +843,6 @@ learner* setup(vw& all, po::variables_map& vm)
{
gd* g = (gd*)calloc_or_die(1, sizeof(gd));
g->all = &all;
- g->sd = all.sd;
g->normalized_sum_norm_x = 0;
g->no_win_counter = 0;
g->total_weight = 0.;
diff --git a/vowpalwabbit/stagewise_poly.cc b/vowpalwabbit/stagewise_poly.cc
index 8c99f4f0..24f149f3 100644
--- a/vowpalwabbit/stagewise_poly.cc
+++ b/vowpalwabbit/stagewise_poly.cc
@@ -56,7 +56,7 @@ namespace StagewisePoly
example *original_ec;
uint32_t cur_depth;
bool training;
- int64_t last_example_counter;
+ uint64_t last_example_counter;
size_t numpasses;
uint32_t next_batch_sz;
bool update_support;