Skip to content
Permalink
Browse files

vw_slim into master (#2028)

* added vw slim predict library w/o cmake dependency

* Add vwslim to CMake

* Moved files to match new structure

* Manual merge and adjustments with Skype

* Fixed VS build for vwslim

* Added GTest unit tests

* fix sample_after_normalizing

* removed sample_after_normalization that has scores and ranking

* Added gtest to cmake

* Fix interaction and num_bits bug in vw_slim.

* Test data files

* fix LGTM flagged issues

* Fixed travis build

* removed v_array get

* restore gtest package

* Changed location of packages folder for vw_slim_test

* Addressed PR comments

* added THROW_OR_RETURN macro that handles VW_NOEXCEPT

* Fix throw macro expansion in MSVC

*  used extra () to replace COMMA with , in macros

* replaced tabs with spaces

* Update CMakeLists and fix linux build

* Add test to verify that action set is not reordered

* rollback gunit changes

* Roll back Resource.rc changes

* removed thread_local from vw_slim

* Address PR comments (sort in place)

* Remove unused code

* fixed master-merge conflicts

* auto-merge fixes

* fixed auto-merge issues

* Trigger rebuild
  • Loading branch information...
rajan-chari authored and jackgerrits committed Aug 26, 2019
1 parent b7ccfea commit 07ac3db2afc30a5f2f90fc02707f978fbd5db61d
Showing with 3,389 additions and 154 deletions.
  1. +57 −53 .scripts/restore.cmd
  2. +5 −0 CMakeLists.txt
  3. +2 −0 vowpalwabbit/array_parameters.h
  4. +30 −27 vowpalwabbit/array_parameters_dense.h
  5. +18 −0 vowpalwabbit/constant.h
  6. +0 −17 vowpalwabbit/example.h
  7. +8 −1 vowpalwabbit/example_predict.cc
  8. +14 −7 vowpalwabbit/example_predict.h
  9. +5 −3 vowpalwabbit/feature_group.h
  10. +32 −0 vowpalwabbit/hashstring.h
  11. +1 −1 vowpalwabbit/memory.h
  12. +0 −22 vowpalwabbit/parse_primitives.cc
  13. +1 −8 vowpalwabbit/parse_primitives.h
  14. +11 −0 vowpalwabbit/slim/CMakeLists.txt
  15. +23 −0 vowpalwabbit/slim/include/example_predict_builder.h
  16. +151 −0 vowpalwabbit/slim/include/model_parser.h
  17. +15 −0 vowpalwabbit/slim/include/opts.h
  18. +586 −0 vowpalwabbit/slim/include/vw_slim_predict.h
  19. +15 −0 vowpalwabbit/slim/include/vw_slim_return_codes.h
  20. +5 −0 vowpalwabbit/slim/src/CMakeLists.txt
  21. +37 −0 vowpalwabbit/slim/src/example_predict_builder.cc
  22. +57 −0 vowpalwabbit/slim/src/model_parser.cc
  23. +78 −0 vowpalwabbit/slim/src/opts.cc
  24. +68 −0 vowpalwabbit/slim/src/vw_slim_predict.cc
  25. +12 −0 vowpalwabbit/slim/test/CMakeLists.txt
  26. +482 −0 vowpalwabbit/slim/test/data.h
  27. +1 −0 vowpalwabbit/slim/test/data/Delay_Margin_AudioNetworkPCR_all__unique_context.json
  28. BIN vowpalwabbit/slim/test/data/Delay_Margin_AudioNetworkPCR_all_cb_FF8.model
  29. BIN vowpalwabbit/slim/test/data/cb_data_5.model
  30. +4 −0 vowpalwabbit/slim/test/data/cb_data_5.pred
  31. +10 −0 vowpalwabbit/slim/test/data/cb_data_5.txt
  32. BIN vowpalwabbit/slim/test/data/cb_data_6.model
  33. +4 −0 vowpalwabbit/slim/test/data/cb_data_6.pred
  34. +4 −0 vowpalwabbit/slim/test/data/cb_data_6.pred2
  35. +4 −0 vowpalwabbit/slim/test/data/cb_data_6.pred3
  36. BIN vowpalwabbit/slim/test/data/cb_data_7.model
  37. +4 −0 vowpalwabbit/slim/test/data/cb_data_7.pred
  38. BIN vowpalwabbit/slim/test/data/cb_data_8.model
  39. +4 −0 vowpalwabbit/slim/test/data/cb_data_8.pred
  40. BIN vowpalwabbit/slim/test/data/cb_data_9.model
  41. +4 −0 vowpalwabbit/slim/test/data/cb_data_9.pred
  42. BIN vowpalwabbit/slim/test/data/cold_start.model
  43. +110 −0 vowpalwabbit/slim/test/data/generate-data.sh
  44. BIN vowpalwabbit/slim/test/data/multiclass_data_4.model
  45. +2 −0 vowpalwabbit/slim/test/data/multiclass_data_4.pred
  46. +5 −0 vowpalwabbit/slim/test/data/multiclass_data_4.txt
  47. BIN vowpalwabbit/slim/test/data/regression_data_1.model
  48. +2 −0 vowpalwabbit/slim/test/data/regression_data_1.pred
  49. +2 −0 vowpalwabbit/slim/test/data/regression_data_1.txt
  50. BIN vowpalwabbit/slim/test/data/regression_data_2.model
  51. +2 −0 vowpalwabbit/slim/test/data/regression_data_2.pred
  52. +2 −0 vowpalwabbit/slim/test/data/regression_data_2.txt
  53. BIN vowpalwabbit/slim/test/data/regression_data_3.model
  54. +2 −0 vowpalwabbit/slim/test/data/regression_data_3.pred
  55. +2 −0 vowpalwabbit/slim/test/data/regression_data_3.txt
  56. BIN vowpalwabbit/slim/test/data/regression_data_4.model
  57. +2 −0 vowpalwabbit/slim/test/data/regression_data_4.pred
  58. +2 −0 vowpalwabbit/slim/test/data/regression_data_4.txt
  59. BIN vowpalwabbit/slim/test/data/regression_data_5.model
  60. +2 −0 vowpalwabbit/slim/test/data/regression_data_5.pred
  61. BIN vowpalwabbit/slim/test/data/regression_data_6.model
  62. +2 −0 vowpalwabbit/slim/test/data/regression_data_6.pred
  63. BIN vowpalwabbit/slim/test/data/regression_data_7.model
  64. +2 −0 vowpalwabbit/slim/test/data/regression_data_7.pred
  65. +2 −0 vowpalwabbit/slim/test/data/regression_data_7.txt
  66. BIN vowpalwabbit/slim/test/data/regression_data_ignore_linear.model
  67. +2 −0 vowpalwabbit/slim/test/data/regression_data_ignore_linear.pred
  68. BIN vowpalwabbit/slim/test/data/regression_data_no-constant.model
  69. +2 −0 vowpalwabbit/slim/test/data/regression_data_no-constant.pred
  70. BIN vowpalwabbit/slim/test/data/regression_data_no_constant.model
  71. +2 −0 vowpalwabbit/slim/test/data/regression_data_no_constant.pred
  72. +4 −0 vowpalwabbit/slim/test/packages.config
  73. +288 −0 vowpalwabbit/slim/test/ut_explore.cc
  74. +6 −0 vowpalwabbit/slim/test/ut_main.cc
  75. +47 −0 vowpalwabbit/slim/test/ut_opts.cc
  76. +8 −0 vowpalwabbit/slim/test/ut_util.h
  77. +748 −0 vowpalwabbit/slim/test/ut_vw.cc
  78. +116 −0 vowpalwabbit/slim/test/vw_slim_test.vcxproj
  79. +143 −0 vowpalwabbit/slim/vw_slim.vcxproj
  80. +48 −0 vowpalwabbit/slim/vw_slim.vcxproj.filters
  81. +25 −14 vowpalwabbit/v_array.h
  82. +15 −0 vowpalwabbit/vw.sln
  83. +42 −1 vowpalwabbit/vw_exception.h
@@ -1,54 +1,58 @@
@ECHO OFF
IF DEFINED DebugBuildScripts (
@ECHO ON
)

SETLOCAL

CALL %~dp0init.cmd
PUSHD %~dp0

REM TODO: This really should be out-of-source
ECHO Restoring "%vwRoot%\cs\common\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\common\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs_console\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs_console\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs_json\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs_json\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs_parallel\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs_parallel\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\examples\simulator\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\examples\simulator\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\setup_bundle\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\setup_bundle\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\unittest\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\unittest\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\python\windows27\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\python\windows27\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\vowpalwabbit\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\vowpalwabbit\packages.config"
ECHO.

POPD

@ECHO OFF
IF DEFINED DebugBuildScripts (
@ECHO ON
)

SETLOCAL

CALL %~dp0init.cmd
PUSHD %~dp0

REM TODO: This really should be out-of-source
ECHO Restoring "%vwRoot%\cs\common\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\common\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs_console\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs_console\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs_json\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs_json\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\cs_parallel\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\cs_parallel\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\examples\simulator\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\examples\simulator\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\setup_bundle\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\setup_bundle\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\cs\unittest\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\cs\unittest\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\python\windows27\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\python\windows27\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\vowpalwabbit\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\vowpalwabbit\packages.config"
ECHO.

ECHO Restoring "%vwRoot%\vowpalwabbit\slim\test\packages.config"
"%nugetPath%" restore -o "%vwRoot%\vowpalwabbit\packages" "%vwRoot%\vowpalwabbit\slim\test\packages.config"
ECHO.

POPD

ENDLOCAL
@@ -56,6 +56,7 @@ option(BUILD_JAVA "Add Java targets." Off)
option(BUILD_PYTHON "Add Python targets." Off)
option(BUILD_DOCS "Add documentation targets." Off)
option(LTO "Enable Link Time optimization (Requires Release build, only works with clang and linux/mac for now)." Off)
option(BUILD_SLIM_VW "Add targets for slim version of VW which implements only predict() for a subset of VW reductions." OFF)

string(TOUPPER "${CMAKE_BUILD_TYPE}" CONFIG)

@@ -182,6 +183,10 @@ if(BUILD_PYTHON)
add_subdirectory(python)
endif()

if(BUILD_SLIM_VW)
add_subdirectory(vowpalwabbitslim)
endif()

if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
@@ -287,13 +287,15 @@ class parameters
dense_weights.set_zero(offset);
}
#ifndef _WIN32
#ifndef DISABLE_SHARED_WEIGHTS
inline void share(size_t length)
{
if (sparse)
sparse_weights.share(length);
else
dense_weights.share(length);
}
#endif
#endif

inline void stride_shift(uint32_t stride_shift)
@@ -8,19 +8,21 @@ typedef float weight;
template <typename T>
class dense_iterator
{
private:
private:
T* _current;
T* _begin;
uint32_t _stride;

public:
public:
typedef std::forward_iterator_tag iterator_category;
typedef T value_type;
typedef std::ptrdiff_t difference_type;
typedef T* pointer;
typedef T& reference;

dense_iterator(T* current, T* begin, uint32_t stride) : _current(current), _begin(begin), _stride(stride) {}
dense_iterator(T* current, T* begin, uint32_t stride)
: _current(current), _begin(begin), _stride(stride)
{ }

T& operator*() { return *_current; }

@@ -38,37 +40,37 @@ class dense_iterator

class dense_parameters
{
private:
private:
weight* _begin;
uint64_t _weight_mask; // (stride*(1 << num_bits) -1)
uint32_t _stride_shift;
bool _seeded; // whether the instance is sharing model state with others
bool _seeded; // whether the instance is sharing model state with others

public:
public:
typedef dense_iterator<weight> iterator;
typedef dense_iterator<const weight> const_iterator;
dense_parameters(size_t length, uint32_t stride_shift = 0)
: _begin(calloc_mergable_or_throw<weight>(length << stride_shift))
, _weight_mask((length << stride_shift) - 1)
, _stride_shift(stride_shift)
, _seeded(false)
{
}
: _begin(calloc_mergable_or_throw<weight>(length << stride_shift)),
_weight_mask((length << stride_shift) - 1),
_stride_shift(stride_shift),
_seeded(false)
{ }

dense_parameters() : _begin(nullptr), _weight_mask(0), _stride_shift(0), _seeded(false) {}
dense_parameters()
: _begin(nullptr), _weight_mask(0), _stride_shift(0), _seeded(false)
{}

bool not_null() { return (_weight_mask > 0 && _begin != nullptr); }

dense_parameters(const dense_parameters& other) { shallow_copy(other); }
dense_parameters(dense_parameters&&) = delete;

weight* first() { return _begin; } // TODO: Temporary fix for allreduce.

// iterator with stride
weight* first() { return _begin; } //TODO: Temporary fix for allreduce.
//iterator with stride
iterator begin() { return iterator(_begin, _begin, stride()); }
iterator end() { return iterator(_begin + _weight_mask + 1, _begin, stride()); }

// const iterator
//const iterator
const_iterator cbegin() { return const_iterator(_begin, _begin, stride()); }
const_iterator cend() { return const_iterator(_begin + _weight_mask + 1, _begin, stride()); }

@@ -85,26 +87,27 @@ class dense_parameters

inline weight& strided_index(size_t index) { return operator[](index << _stride_shift); }

template <class R, class T>
void set_default(R& info)
template<class R, class T> void set_default(R& info)
{
iterator iter = begin();
for (size_t i = 0; iter != end(); ++iter, i += stride()) T::func(*iter, info, iter.index());
for (size_t i = 0; iter != end(); ++iter, i += stride())
T::func(*iter, info, iter.index());
}

template <class T>
void set_default()
template<class T> void set_default()
{
iterator iter = begin();
for (size_t i = 0; iter != end(); ++iter, i += stride()) T::func(*iter, iter.index());
for (size_t i = 0; iter != end(); ++iter, i += stride())
T::func(*iter, iter.index());
}

void set_zero(size_t offset)
{
for (iterator iter = begin(); iter != end(); ++iter) (&(*iter))[offset] = 0;
for (iterator iter = begin(); iter != end(); ++iter)
(&(*iter))[offset] = 0;
}

uint64_t mask() const { return _weight_mask; }
uint64_t mask() const { return _weight_mask; }

uint64_t seeded() const { return _seeded; }

@@ -118,8 +121,8 @@ class dense_parameters
#ifndef DISABLE_SHARED_WEIGHTS
void share(size_t length)
{
float* shared_weights = (float*)mmap(
0, (length << _stride_shift) * sizeof(float), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
float* shared_weights = (float*)mmap(0, (length << _stride_shift) * sizeof(float),
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
size_t float_count = length << _stride_shift;
weight* dest = shared_weights;
memcpy(dest, _begin, float_count * sizeof(float));
@@ -15,3 +15,21 @@ constexpr float probability_tolerance = 1e-5f;
// FNV-like hash constant for 32bit
// http://www.isthe.com/chongo/tech/comp/fnv/#FNV-param
constexpr uint32_t FNV_prime = 16777619;

constexpr unsigned char default_namespace = 32;
constexpr unsigned char wap_ldf_namespace = 126;
constexpr unsigned char history_namespace = 127;
constexpr unsigned char constant_namespace = 128;
constexpr unsigned char nn_output_namespace = 129;
constexpr unsigned char autolink_namespace = 130;
constexpr unsigned char neighbor_namespace = 131; // this is \x83 -- to do quadratic, say "-q a`printf "\x83"` on the command line
constexpr unsigned char affix_namespace = 132; // this is \x84
constexpr unsigned char spelling_namespace = 133; // this is \x85
constexpr unsigned char conditioning_namespace = 134;// this is \x86
constexpr unsigned char dictionary_namespace = 135; // this is \x87
constexpr unsigned char node_id_namespace = 136; // this is \x88
constexpr unsigned char message_namespace = 137; // this is \x89
constexpr unsigned char ccb_slot_namespace = 139;
constexpr unsigned char ccb_id_namespace = 140;

typedef float weight;
@@ -22,23 +22,6 @@ license as described in the file LICENSE.
#include "ccb_label.h"
#include <vector>

constexpr unsigned char default_namespace = 32;
constexpr unsigned char wap_ldf_namespace = 126;
constexpr unsigned char history_namespace = 127;
constexpr unsigned char constant_namespace = 128;
constexpr unsigned char nn_output_namespace = 129;
constexpr unsigned char autolink_namespace = 130;
constexpr unsigned char neighbor_namespace =
131; // this is \x83 -- to do quadratic, say "-q a`printf "\x83"` on the command line
constexpr unsigned char affix_namespace = 132; // this is \x84
constexpr unsigned char spelling_namespace = 133; // this is \x85
constexpr unsigned char conditioning_namespace = 134; // this is \x86
constexpr unsigned char dictionary_namespace = 135; // this is \x87
constexpr unsigned char node_id_namespace = 136; // this is \x88
constexpr unsigned char message_namespace = 137; // this is \x89
constexpr unsigned char ccb_slot_namespace = 139;
constexpr unsigned char ccb_id_namespace = 140;

typedef union {
no_label::no_label empty;
label_data simple;
@@ -9,11 +9,18 @@ license as described in the file LICENSE.
safe_example_predict::safe_example_predict()
{
indices = v_init<namespace_index>();
ft_offset = 0;
// feature_space is initialized through constructors
}

safe_example_predict::~safe_example_predict()
{
indices.delete_v();
for (size_t i = 0; i < 256; i++) feature_space[i].delete_v();
for (size_t i = 0; i < UINT8_MAX; i++) feature_space[i].delete_v();
}

void safe_example_predict::clear()
{
for (auto ns : indices) feature_space[ns].clear();
indices.clear();
}
@@ -9,18 +9,23 @@ typedef unsigned char namespace_index;

#include "v_array.h"
#include "feature_group.h"
#include <vector>

struct example_predict
{
class iterator
{
features* _feature_space;
namespace_index* _index;
public:
iterator(features* feature_space, namespace_index* index)
: _feature_space(feature_space), _index(index)
{ }

public:
iterator(features* feature_space, namespace_index* index) : _feature_space(feature_space), _index(index) {}

features& operator*() { return _feature_space[*_index]; }
features& operator*()
{
return _feature_space[*_index];
}

iterator& operator++()
{
@@ -35,8 +40,8 @@ struct example_predict
};

v_array<namespace_index> indices;
features feature_space[256]; // Groups of feature values.
uint64_t ft_offset; // An offset for all feature values.
features feature_space[256]; //Groups of feature values.
uint64_t ft_offset;//An offset for all feature values.

// Interactions are specified by this vector of strings, where each string is an interaction and each char is a namespace.
std::vector<std::string>* interactions;
@@ -48,7 +53,9 @@ struct example_predict
// make sure we have an exception safe version of example_predict
class safe_example_predict : public example_predict
{
public:
public:
safe_example_predict();
~safe_example_predict();

void clear();
};

0 comments on commit 07ac3db

Please sign in to comment.
You can’t perform that action at this time.