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

feat: Add ftrl to dump_weights_to_json and compat CIs #4193

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions test/run_tests_model_gen_and_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def generate_model_and_weights(
weights_file.write(vw.json_weights())
except:
print(
f"{color_enum.LIGHT_PURPLE}Weights could not be generated as base learner is not GD"
f"{color_enum.LIGHT_PURPLE}Weights could not be generated as base learner is not GD or FTRL"
)
test_models_dir = working_dir / "test_models"
test_models_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -133,7 +133,7 @@ def load_model(
new_weights = json.loads(vw.json_weights())
except:
print(
f"{color_enum.LIGHT_CYAN}Weights could not be loaded as base learner is not GD"
f"{color_enum.LIGHT_CYAN}Weights could not be loaded as base learner is not GD or FTRL"
)
return
weights_dir = working_dir / "test_weights"
Expand Down
6 changes: 4 additions & 2 deletions vowpalwabbit/core/src/global_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,17 @@ std::string workspace::dump_weights_to_json_experimental()
// This could be extended to other base learners reasonably. Since this is new and experimental though keep the scope
// small.
while (current->get_learn_base() != nullptr) { current = current->get_learn_base(); }
if (current->get_name() != "gd")
if (current->get_name() != "gd" && current->get_name() != "ftrl")
{
THROW("dump_weights_to_json is currently only supported for GD base learners. The current base learner is "
THROW("dump_weights_to_json is currently only supported for GD or FTRL base learners. The current base learner is "
<< current->get_name());
}
if (dump_json_weights_include_feature_names && !hash_inv)
{ THROW("hash_inv == true is required to dump weights to json including feature names"); }
if (dump_json_weights_include_extra_online_state && !save_resume)
{ THROW("save_resume == true is required to dump weights to json including feature names"); }
if (dump_json_weights_include_extra_online_state && current->get_name() != "gd")
{ THROW("including extra online state is only allowed with GD as base learner"); }

return weights.sparse ? dump_weights_to_json_weight_typed(weights.sparse_weights, index_name_map, weights,
dump_json_weights_include_feature_names, dump_json_weights_include_extra_online_state)
Expand Down