Vowpal Wabbit
Classes | Functions
parse_args.h File Reference
#include "global_data.h"
#include "options.h"

Go to the source code of this file.

Classes

struct  input_options
 

Functions

vwparse_args (VW::config::options_i &options, trace_message_t trace_listener=nullptr, void *trace_context=nullptr)
 
void parse_modules (VW::config::options_i &options, vw &all)
 
void parse_sources (VW::config::options_i &options, vw &all, io_buf &model, bool skipModelLoad=false)
 
LEARNER::base_learnersetup_base (VW::config::options_i &options, vw &all)
 
std::string spoof_hex_encoded_namespaces (const std::string &arg)
 

Function Documentation

◆ parse_args()

vw& parse_args ( VW::config::options_i options,
trace_message_t  trace_listener = nullptr,
void *  trace_context = nullptr 
)

Definition at line 1308 of file parse_args.cc.

References VW::config::option_group_definition::add(), add(), VW::config::options_i::add_and_parse(), vw::all_reduce, vw::all_reduce_type, vw::eta, vw::eta_decay_rate, vw::feature_mask, VW::finish(), vw::init_time, vw::initial_regressors, vw::initial_t, vw::initial_weight, VW::config::make_option(), vw::normal_weights, vw::options, vw::p, parse_diagnostics(), vw::per_feature_regularizer_input, vw::power_t, vw::quiet, vw::random_weights, vw::sd, Socket, parameters::sparse, shared_data::t, THROW, vw::tnormal_weights, vw_ostream::trace_context, vw_ostream::trace_listener, vw::trace_message, VW::config::options_i::was_supplied(), and vw::weights.

Referenced by VW::initialize().

1309 {
1310  vw& all = *(new vw());
1311  all.options = &options;
1312 
1313  if (trace_listener)
1314  {
1315  all.trace_message.trace_listener = trace_listener;
1316  all.trace_message.trace_context = trace_context;
1317  }
1318 
1319  try
1320  {
1321  time(&all.init_time);
1322 
1323  bool strict_parse = false;
1324  size_t ring_size;
1325  option_group_definition vw_args("VW options");
1326  vw_args.add(make_option("ring_size", ring_size).default_value(256).help("size of example ring"))
1327  .add(make_option("strict_parse", strict_parse).help("throw on malformed examples"));
1328  options.add_and_parse(vw_args);
1329 
1330  all.p = new parser{ring_size, strict_parse};
1331 
1332  option_group_definition update_args("Update options");
1333  update_args.add(make_option("learning_rate", all.eta).help("Set learning rate").short_name("l"))
1334  .add(make_option("power_t", all.power_t).help("t power value"))
1335  .add(make_option("decay_learning_rate", all.eta_decay_rate)
1336  .help("Set Decay factor for learning_rate between passes"))
1337  .add(make_option("initial_t", all.sd->t).help("initial t value"))
1338  .add(make_option("feature_mask", all.feature_mask)
1339  .help("Use existing regressor to determine which parameters may be updated. If no initial_regressor "
1340  "given, also used for initial weights."));
1341  options.add_and_parse(update_args);
1342 
1343  option_group_definition weight_args("Weight options");
1344  weight_args
1345  .add(make_option("initial_regressor", all.initial_regressors).help("Initial regressor(s)").short_name("i"))
1346  .add(make_option("initial_weight", all.initial_weight).help("Set all weights to an initial value of arg."))
1347  .add(make_option("random_weights", all.random_weights).help("make initial weights random"))
1348  .add(make_option("normal_weights", all.normal_weights).help("make initial weights normal"))
1349  .add(make_option("truncated_normal_weights", all.tnormal_weights).help("make initial weights truncated normal"))
1350  .add(make_option("sparse_weights", all.weights.sparse).help("Use a sparse datastructure for weights"))
1351  .add(make_option("input_feature_regularizer", all.per_feature_regularizer_input)
1352  .help("Per feature regularization input file"));
1353  options.add_and_parse(weight_args);
1354 
1355  std::string span_server_arg;
1356  int span_server_port_arg;
1357  // bool threads_arg;
1358  size_t unique_id_arg;
1359  size_t total_arg;
1360  size_t node_arg;
1361  option_group_definition parallelization_args("Parallelization options");
1362  parallelization_args
1363  .add(make_option("span_server", span_server_arg).help("Location of server for setting up spanning tree"))
1364  //(make_option("threads", threads_arg).help("Enable multi-threading")) Unused option?
1365  .add(make_option("unique_id", unique_id_arg).default_value(0).help("unique id used for cluster parallel jobs"))
1366  .add(
1367  make_option("total", total_arg).default_value(1).help("total number of nodes used in cluster parallel job"))
1368  .add(make_option("node", node_arg).default_value(0).help("node number in cluster parallel job"))
1369  .add(make_option("span_server_port", span_server_port_arg)
1370  .default_value(26543)
1371  .help("Port of the server for setting up spanning tree"));
1372  options.add_and_parse(parallelization_args);
1373 
1374  // total, unique_id and node must be specified together.
1375  if ((options.was_supplied("total") || options.was_supplied("node") || options.was_supplied("unique_id")) &&
1376  !(options.was_supplied("total") && options.was_supplied("node") && options.was_supplied("unique_id")))
1377  {
1378  THROW("you must specificy unique_id, total, and node if you specify any");
1379  }
1380 
1381  if (options.was_supplied("span_server"))
1382  {
1384  all.all_reduce =
1385  new AllReduceSockets(span_server_arg, span_server_port_arg, unique_id_arg, total_arg, node_arg, all.quiet);
1386  }
1387 
1388  parse_diagnostics(options, all);
1389 
1390  all.initial_t = (float)all.sd->t;
1391  return all;
1392  }
1393  catch (...)
1394  {
1395  VW::finish(all);
1396  throw;
1397  }
1398 }
void parse_diagnostics(options_i &options, vw &all)
Definition: parse_args.cc:357
parameters weights
Definition: global_data.h:537
bool tnormal_weights
Definition: global_data.h:495
float initial_t
Definition: global_data.h:530
VW::config::options_i * options
Definition: global_data.h:428
float initial_weight
Definition: global_data.h:409
time_t init_time
Definition: global_data.h:533
float power_t
Definition: global_data.h:447
bool quiet
Definition: global_data.h:487
virtual void add_and_parse(const option_group_definition &group)=0
void finish(vw &all, bool delete_all)
Definition: parse_args.cc:1823
parser * p
Definition: global_data.h:377
AllReduce * all_reduce
Definition: global_data.h:381
shared_data * sd
Definition: global_data.h:375
vw_ostream trace_message
Definition: global_data.h:424
virtual bool was_supplied(const std::string &key)=0
std::string feature_mask
Definition: global_data.h:438
AllReduceType all_reduce_type
Definition: global_data.h:380
bool random_weights
Definition: global_data.h:492
float eta
Definition: global_data.h:531
int add(svm_params &params, svm_example *fec)
Definition: kernel_svm.cc:546
std::vector< std::string > initial_regressors
Definition: global_data.h:436
typed_option< T > make_option(std::string name, T &location)
Definition: options.h:80
void * trace_context
trace_message_t trace_listener
Definition: parser.h:38
std::string per_feature_regularizer_input
Definition: global_data.h:440
#define THROW(args)
Definition: vw_exception.h:181
bool normal_weights
Definition: global_data.h:494
float eta_decay_rate
Definition: global_data.h:532

◆ parse_modules()

void parse_modules ( VW::config::options_i options,
vw all 
)

◆ parse_sources()

void parse_sources ( VW::config::options_i options,
vw all,
io_buf model,
bool  skipModelLoad = false 
)

Definition at line 1551 of file parse_args.cc.

References io_buf::close_file(), enable_sources(), LEARNER::learner< T, E >::increment, vw::l, load_input_model(), vw::numpasses, parse_source(), vw::quiet, parameters::stride_shift(), vw::weights, and vw::wpp.

Referenced by VW::initialize().

1552 {
1553  if (!skipModelLoad)
1554  load_input_model(all, model);
1555  else
1556  model.close_file();
1557 
1558  auto parsed_source_options = parse_source(all, options);
1559  enable_sources(all, all.quiet, all.numpasses, parsed_source_options);
1560 
1561  // force wpp to be a power of 2 to avoid 32-bit overflow
1562  uint32_t i = 0;
1563  size_t params_per_problem = all.l->increment;
1564  while (params_per_problem > ((uint64_t)1 << i)) i++;
1565  all.wpp = (1 << i) >> all.weights.stride_shift();
1566 }
parameters weights
Definition: global_data.h:537
void enable_sources(vw &all, bool quiet, size_t passes, input_options &input_options)
Definition: parser.cc:312
void load_input_model(vw &all, io_buf &io_temp)
Definition: parse_args.cc:1200
virtual bool close_file()
Definition: io_buf.h:204
bool quiet
Definition: global_data.h:487
input_options parse_source(vw &all, options_i &options)
Definition: parse_args.cc:421
uint32_t wpp
Definition: global_data.h:432
size_t numpasses
Definition: global_data.h:451
size_t increment
Definition: learner.h:153
LEARNER::base_learner * l
Definition: global_data.h:383
uint32_t stride_shift()

◆ setup_base()

LEARNER::base_learner* setup_base ( VW::config::options_i options,
vw all 
)

Definition at line 1222 of file parse_args.cc.

References vw::reduction_stack, and setup_base().

Referenced by active_cover_setup(), active_setup(), audit_regressor_setup(), autolink_setup(), baseline_setup(), binary_setup(), boosting_setup(), bs_setup(), cb_adf_setup(), cb_algs_setup(), cb_explore_setup(), cb_sample_setup(), cbify_setup(), cbifyldf_setup(), CCB::ccb_explore_adf_setup(), classweight_setup(), confidence_setup(), cs_active_setup(), CSOAA::csldf_setup(), CSOAA::csoaa_setup(), ect_setup(), explore_eval_setup(), ExpReplay::expreplay_setup(), interact_setup(), log_multi_setup(), lrq_setup(), lrqfa_setup(), marginal_setup(), memory_tree_setup(), mf_setup(), multilabel_oaa_setup(), mwt_setup(), nn_setup(), oaa_setup(), parse_reductions(), recall_tree_setup(), scorer_setup(), VW::cb_explore_adf::softmax::setup(), VW::cb_explore_adf::greedy::setup(), VW::cb_explore_adf::first::setup(), VW::cb_explore_adf::bag::setup(), VW::cb_explore_adf::cover::setup(), VW::cb_explore_adf::regcb::setup(), Search::setup(), setup_base(), VW::shared_feature_merger::shared_feature_merger_setup(), stagewise_poly_setup(), topk_setup(), and warm_cb_setup().

1223 {
1224  auto setup_func = all.reduction_stack.top();
1225  all.reduction_stack.pop();
1226  auto base = setup_func(options, all);
1227 
1228  if (base == nullptr)
1229  return setup_base(options, all);
1230  else
1231  return base;
1232 }
LEARNER::base_learner * setup_base(options_i &options, vw &all)
Definition: parse_args.cc:1222
std::stack< LEARNER::base_learner *(*)(VW::config::options_i &, vw &)> reduction_stack
Definition: global_data.h:513

◆ spoof_hex_encoded_namespaces()

std::string spoof_hex_encoded_namespaces ( const std::string &  arg)

Definition at line 568 of file parse_args.cc.

References c.

Referenced by lrq_setup(), lrqfa_setup(), and parse_feature_tweaks().

569 {
570  std::string res;
571  int pos = 0;
572  while (pos < (int)arg.size() - 3)
573  {
574  if (arg[pos] == '\\' && arg[pos + 1] == 'x')
575  {
576  std::string substr = arg.substr(pos + 2, 2);
577  char* p;
578  unsigned char c = (unsigned char)strtoul(substr.c_str(), &p, 16);
579  if (*p == '\0')
580  {
581  res.push_back(c);
582  pos += 4;
583  }
584  else
585  {
586  cerr << "Possibly malformed hex representation of a namespace: '\\x" << substr << "'\n";
587  res.push_back(arg[pos++]);
588  }
589  }
590  else
591  res.push_back(arg[pos++]);
592  }
593 
594  while (pos < (int)arg.size()) // copy last 2 characters
595  res.push_back(arg[pos++]);
596 
597  return res;
598 }
constexpr uint64_t c
Definition: rand48.cc:12