Skip to content

Commit

Permalink
perf: only format model values if writing text model (#4613)
Browse files Browse the repository at this point in the history
* perf: only format model values if writing text model

* formatting
  • Loading branch information
jackgerrits authored Jun 9, 2023
1 parent 4a43d09 commit b8c4ee3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions vowpalwabbit/core/src/reductions/gd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,28 +1055,31 @@ void save_load_online_state_weights(VW::workspace& all, VW::io_buf& model_file,
if (ftrl3_write)
{
brw = write_index(model_file, msg, text, all.initial_weights_config.num_bits, i);
msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << "\n";
if (text) { msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << "\n"; }
brw += VW::details::bin_text_write_fixed(model_file, (char*)&(*v), 3 * sizeof(*v), msg, text);
}
else if (ftrl4_write)
{
brw = write_index(model_file, msg, text, all.initial_weights_config.num_bits, i);
msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << " " << (&(*v))[3] << "\n";
if (text) { msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << " " << (&(*v))[3] << "\n"; }
brw += VW::details::bin_text_write_fixed(model_file, (char*)&(*v), 4 * sizeof(*v), msg, text);
}
else if (ftrl6_write)
{
brw = write_index(model_file, msg, text, all.initial_weights_config.num_bits, i);
msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << " " << (&(*v))[3] << " " << (&(*v))[4] << " "
<< (&(*v))[5] << "\n";
if (text)
{
msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << " " << (&(*v))[3] << " " << (&(*v))[4] << " "
<< (&(*v))[5] << "\n";
}
brw += VW::details::bin_text_write_fixed(model_file, (char*)&(*v), 6 * sizeof(*v), msg, text);
}
else if (g == nullptr || (!all.weights.adaptive && !all.weights.normalized))
{
if (*v != 0.)
{
brw = write_index(model_file, msg, text, all.initial_weights_config.num_bits, i);
msg << ":" << *v << "\n";
if (text) { msg << ":" << *v << "\n"; }
brw += VW::details::bin_text_write_fixed(model_file, (char*)&(*v), sizeof(*v), msg, text);
}
}
Expand All @@ -1086,7 +1089,7 @@ void save_load_online_state_weights(VW::workspace& all, VW::io_buf& model_file,
if (*v != 0. || (&(*v))[1] != 0.)
{
brw = write_index(model_file, msg, text, all.initial_weights_config.num_bits, i);
msg << ":" << *v << " " << (&(*v))[1] << "\n";
if (text) { msg << ":" << *v << " " << (&(*v))[1] << "\n"; }
brw += VW::details::bin_text_write_fixed(model_file, (char*)&(*v), 2 * sizeof(*v), msg, text);
}
}
Expand All @@ -1096,7 +1099,7 @@ void save_load_online_state_weights(VW::workspace& all, VW::io_buf& model_file,
if (*v != 0. || (&(*v))[1] != 0. || (&(*v))[2] != 0.)
{
brw = write_index(model_file, msg, text, all.initial_weights_config.num_bits, i);
msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << "\n";
if (text) { msg << ":" << *v << " " << (&(*v))[1] << " " << (&(*v))[2] << "\n"; }
brw += VW::details::bin_text_write_fixed(model_file, (char*)&(*v), 3 * sizeof(*v), msg, text);
}
}
Expand Down

0 comments on commit b8c4ee3

Please sign in to comment.