Skip to content

Commit

Permalink
build: reduce header includes to improve buildtime (VowpalWabbit#3803)
Browse files Browse the repository at this point in the history
* build: reduce header includes to improve buildtime

* add missing test header

* add header

* test ref files

* add header

* formatting
  • Loading branch information
jackgerrits authored Mar 16, 2022
1 parent e2446a0 commit dde8b11
Show file tree
Hide file tree
Showing 72 changed files with 194 additions and 99 deletions.
2 changes: 1 addition & 1 deletion test/train-sets/ref/bfgs_save_resume_fail.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[info] Generating 3-grams for all namespaces.
[info] Generating 1-skips for all namespaces.
[info] m = 15, allocated 34M for weights and mem
[critical] vw (bfgs.cc:1053): model load failed. Error Details: BFGS does not support models with save_resume data. Only models produced and consumed with --predict_only_model can be used with BFGS., model files = models/0001_1.model
[critical] vw (bfgs.cc:1055): model load failed. Error Details: BFGS does not support models with save_resume data. Only models produced and consumed with --predict_only_model can be used with BFGS., model files = models/0001_1.model
2 changes: 1 addition & 1 deletion test/train-sets/ref/corrupt_weights_gd.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[critical] vw (gd_mf.cc:266): model load failed. Error Details: Model weights object was not initialized when trying to data load into it., model files = model-sets/corrupted_weights_gd.model
[critical] vw (gd_mf.cc:268): model load failed. Error Details: Model weights object was not initialized when trying to data load into it., model files = model-sets/corrupted_weights_gd.model
2 changes: 1 addition & 1 deletion test/train-sets/ref/corrupt_weights_gd_mf.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[critical] vw (io_buf.h:367): model load failed. Error Details: Unexpected end of file encountered., model files = model-sets/corrupted_weights_gd_mf.model
[critical] vw (io_buf.h:365): model load failed. Error Details: Unexpected end of file encountered., model files = model-sets/corrupted_weights_gd_mf.model
4 changes: 2 additions & 2 deletions test/train-sets/ref/malformed-onethread-strict_parse.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[error] vw example #0(parse_example.cc:100): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"
[error] vw example #0(parse_example.cc:101): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"

[critical] vw (parse_example.cc:100): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"
[critical] vw (parse_example.cc:101): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"

4 changes: 2 additions & 2 deletions test/train-sets/ref/malformed-strict_parse.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[error] vw example #0(parse_example.cc:100): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"
[error] vw example #0(parse_example.cc:101): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"

[critical] vw (parse_example.cc:100): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"
[critical] vw (parse_example.cc:101): malformed example! '|',space, or EOL expected after : "| x:0.7"in Example #0: "| x:0.7"

13 changes: 7 additions & 6 deletions test/unit_test/parse_args_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// individual contributors. All rights reserved. Released under a BSD (revised)
// license as described in the file LICENSE.

#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/mpl/vector.hpp>

#include "parse_args.h"
#include "config/options_cli.h"

#include <vector>
#include <boost/mpl/vector.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>

#include "config/options_cli.h"
#include "memory.h"

using namespace VW::config;

Expand Down
9 changes: 8 additions & 1 deletion vowpalwabbit/accumulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

// This implements various accumulate functions building on top of allreduce.
#pragma once
#include "global_data.h"

#include <cstddef>

class parameters;
namespace VW
{
struct workspace;
}

void accumulate(VW::workspace& all, parameters& weights, size_t o);
float accumulate_scalar(VW::workspace& all, float local_sum);
Expand Down
12 changes: 10 additions & 2 deletions vowpalwabbit/action_score.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@

#pragma once

#include <iosfwd>
#include <iterator>

#include "constant.h"
#include "io/io_adapter.h"
#include "io/logger.h"
#include "v_array.h"

namespace VW
{
namespace io
{
struct logger;
struct writer;
} // namespace io
} // namespace VW

namespace ACTION_SCORE
{
struct action_score
Expand Down
5 changes: 4 additions & 1 deletion vowpalwabbit/allreduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
#include <utility>

#ifdef _WIN32
# define NOMINMAX
# ifndef NOMINMAX
# define NOMINMAX
# endif

# include <WS2tcpip.h>
# include <WinSock2.h>
# include <Windows.h>
Expand Down
5 changes: 4 additions & 1 deletion vowpalwabbit/allreduce_sockets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ Alekh Agarwal and John Langford, with help Olivier Chapelle.
#include <iostream>
#include <sstream>
#ifdef _WIN32
# define NOMINMAX
# ifndef NOMINMAX
# define NOMINMAX
# endif

# define _WINSOCK_DEPRECATED_NO_WARNINGS
# include <WS2tcpip.h>
# include <WinSock2.h>
Expand Down
7 changes: 5 additions & 2 deletions vowpalwabbit/array_parameters_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
# include <sys/mman.h>
#endif

#include <bitset>
#ifdef PRIVACY_ACTIVATION
# include <bitset>
# include <unordered_map>
#endif

#include <cassert>
#include <unordered_map>

#include "memory.h"

Expand Down
8 changes: 4 additions & 4 deletions vowpalwabbit/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

#pragma once

#include "feature_group.h"
#include "io/logger.h"
#include "io_buf.h"
#include "label_parser.h"
#include "v_array.h"

class io_buf;
struct features;

namespace VW
{
struct workspace;
struct example;
struct label_parser;
namespace details
{
struct cache_temp_buffer;
Expand Down
1 change: 0 additions & 1 deletion vowpalwabbit/cb_label_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "cb.h"
#include "cb_continuous_label.h"
#include "future_compat.h"
#include "io/logger.h"
#include "io_buf.h"

namespace CB
Expand Down
2 changes: 2 additions & 0 deletions vowpalwabbit/config/cli_help_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "config/cli_help_formatter.h"

#include <fmt/format.h>

#include <sstream>
#include <string>

Expand Down
1 change: 1 addition & 0 deletions vowpalwabbit/config/cli_help_formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <string>
#include <vector>

#include "config/help_formatter.h"

Expand Down
16 changes: 12 additions & 4 deletions vowpalwabbit/config/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

#pragma once

#include <fmt/format.h>

#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <typeinfo>
Expand Down Expand Up @@ -90,9 +89,18 @@ struct typed_option : base_option
}
std::string invalid_choice_error(const std::string& value)
{
return fmt::format("Error: '{}' is not a valid choice for option --{}. Please select from {{{}}}", value, m_name,
fmt::join(m_one_of, ", "));
std::ostringstream ss;
ss << "Error: '" << value << "' is not a valid choice for option --" << m_name << ". Please select from {";
std::string delim = "";
for (const auto& choice : m_one_of)
{
ss << delim << choice;
delim = ", ";
}
ss << "}";
return ss.str();
}

std::string invalid_choice_error(const int32_t& value) { return invalid_choice_error(std::to_string(value)); }
std::string invalid_choice_error(const int64_t& value) { return invalid_choice_error(std::to_string(value)); }
std::string invalid_choice_error(const uint32_t& value) { return invalid_choice_error(std::to_string(value)); }
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/config/option_group_definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#pragma once

#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

#include "config/option.h"
Expand Down
1 change: 0 additions & 1 deletion vowpalwabbit/config/options_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#pragma once

#include <iostream>
#include <set>
#include <string>
#include <unordered_map>
Expand Down
1 change: 1 addition & 0 deletions vowpalwabbit/config/options_name_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <set>
#include <string>
#include <vector>

#include "config/options.h"
#include "future_compat.h"
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/cost_sensitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <cstdint>
#include <vector>

#include "io_buf.h"
#include "label_parser.h"
#include "v_array.h"

class io_buf;
namespace VW
{
struct example;
Expand Down
4 changes: 1 addition & 3 deletions vowpalwabbit/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// license as described in the file LICENSE.
#pragma once

#include <iostream>
#include <ostream>
#include <utility>
#include <vector>

#include "v_array.h"

namespace VW
{
struct example;
Expand Down
9 changes: 5 additions & 4 deletions vowpalwabbit/decision_scores.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

#pragma once

#include <iomanip>
#include <iostream>
#include <vector>

#include "constant.h"
#include "io/io_adapter.h"
#include "io/logger.h"
#include "v_array.h"

namespace ACTION_SCORE
Expand All @@ -23,6 +19,11 @@ namespace VW
{
struct example;
struct workspace;
namespace io
{
struct logger;
struct writer;
} // namespace io
} // namespace VW

namespace VW
Expand Down
4 changes: 2 additions & 2 deletions vowpalwabbit/distributionally_robust.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

#include <algorithm>
#include <limits>
#include <string>
#include <tuple>

#include "io_buf.h"

constexpr float DEFAULT_TAU = 0.999f;
constexpr float DEFAULT_ALPHA = 0.05f;

class io_buf;
namespace VW
{
namespace distributionally_robust
Expand Down
2 changes: 0 additions & 2 deletions vowpalwabbit/example.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#pragma once

#include <cstdint>
#include <iostream>
#include <vector>

#include "action_score.h"
Expand All @@ -15,7 +14,6 @@
#include "cb_continuous_label.h"
#include "ccb_label.h"
#include "constant.h"
#include "continuous_actions_reduction_features.h"
#include "cost_sensitive.h"
#include "decision_scores.h"
#include "example_predict.h"
Expand Down
2 changes: 2 additions & 0 deletions vowpalwabbit/global_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <sstream>

#include "array_parameters.h"
#include "future_compat.h"
#include "named_labels.h"
#include "parser.h"
#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"
#include "reduction_stack.h"
Expand Down
2 changes: 0 additions & 2 deletions vowpalwabbit/io_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include <fmt/format.h>

#include <algorithm>
#include <cassert>
#include <cstddef>
Expand Down
14 changes: 14 additions & 0 deletions vowpalwabbit/learner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "parse_dispatch_loop.h"
#include "parse_regressor.h"
#include "parser.h"
#include "reductions/conditional_contextual_bandit.h"
#include "vw.h"

namespace VW
Expand Down Expand Up @@ -304,6 +305,19 @@ void generic_driver_onethread(VW::workspace& all)
}

float recur_sensitivity(void*, base_learner& base, example& ec) { return base.sensitivity(ec); }
bool ec_is_example_header(const example& ec, label_type_t label_type)
{
if (label_type == VW::label_type_t::cb) { return CB::ec_is_example_header(ec); }
else if (label_type == VW::label_type_t::ccb)
{
return CCB::ec_is_example_header(ec);
}
else if (label_type == VW::label_type_t::cs)
{
return COST_SENSITIVE::ec_is_example_header(ec);
}
return false;
}

} // namespace LEARNER
} // namespace VW
Loading

0 comments on commit dde8b11

Please sign in to comment.