Skip to content

Commit

Permalink
build: make lda optional with compile feature (VowpalWabbit#4555)
Browse files Browse the repository at this point in the history
* build: make lda optional with compile feature

* formatting

* Create README

* add to python vcpkg

* dont add boost dep

* try fix python

* add comment

---------

Co-authored-by: Eduardo Salinas <[email protected]>
  • Loading branch information
jackgerrits and lalo authored Apr 6, 2023
1 parent 6ee7721 commit 8b9a750
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ if(VW_FEAT_FLATBUFFERS)
list(APPEND VCPKG_MANIFEST_FEATURES "flatbuffers")
endif()

# This is a hack around the fact the Python build does not seem to be capable of
# dealing with manifest features.
if(VW_FEAT_LDA AND NOT BUILD_PYTHON)
list(APPEND VCPKG_MANIFEST_FEATURES "lda")
endif()

option(BUILD_TESTING "Build tests" ON)
if(BUILD_TESTING)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
Expand Down
9 changes: 2 additions & 7 deletions cmake/VowpalWabbitFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
# If a feature called X is enabled then:
# - The cmake variable VW_FEAT_X is set to ON, otherwise it is OFF
# - The C++ macro VW_FEAT_X_ENABLED is defined if the feature is enabled, otherwise it is not defined
#
# Features:
# FLATBUFFERS: Enable flatbuffers support
# CSV: Enable csv parser
# LAS_SIMD: Enable large action space with explicit simd (only work with linux for now)

# set(VW_ALL_FEATURES "LAS_SIMD;FLATBUFFERS;CSV")
set(VW_ALL_FEATURES "CSV;FLATBUFFERS")
set(VW_ALL_FEATURES "CSV;FLATBUFFERS;LDA")

option(VW_FEAT_FLATBUFFERS "Enable flatbuffers support" OFF)
option(VW_FEAT_CSV "Enable csv parser" OFF)
option(VW_FEAT_LDA "Enable lda reduction" ON)
# option(VW_FEAT_LAS_SIMD "Enable large action space with explicit simd (only works with linux for now)" ON)

# Legacy options for feature enablement
Expand Down
9 changes: 9 additions & 0 deletions ext_libs/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
boost_math - optional
eigen - optional
fmt
rapidjson
spdlog
sse2neon - optional
string-view-lite
vcpkg
zlib
17 changes: 10 additions & 7 deletions ext_libs/ext_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ else()
target_include_directories(RapidJSON SYSTEM INTERFACE "${CMAKE_CURRENT_LIST_DIR}/rapidjson/include")
endif()

if(VW_BOOST_MATH_SYS_DEP)
find_package(Boost REQUIRED)
set(boost_math_target Boost::boost)
else()
set(BOOST_MATH_STANDALONE ON CACHE BOOL "Use Boost math vendored dep in standalone mode" FORCE)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/boost_math EXCLUDE_FROM_ALL)
set(boost_math_target Boost::math)
# Boost math only required if LDA is enabled.
if(VW_FEAT_LDA)
if(VW_BOOST_MATH_SYS_DEP)
find_package(Boost REQUIRED)
set(boost_math_target Boost::boost)
else()
set(BOOST_MATH_STANDALONE ON CACHE BOOL "Use Boost math vendored dep in standalone mode" FORCE)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/boost_math EXCLUDE_FROM_ALL)
set(boost_math_target Boost::math)
endif()
endif()

if(VW_ZLIB_SYS_DEP)
Expand Down
16 changes: 11 additions & 5 deletions python/vcpkg_default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"name": "demo",
"version": "1.0.0",
"builtin-baseline": "773516ecf6014d89cc69b11bb54605ad4be56694",
"dependencies": [ "zlib","boost-python","python3","flatbuffers" ]
}
"name": "demo",
"version": "1.0.0",
"builtin-baseline": "773516ecf6014d89cc69b11bb54605ad4be56694",
"dependencies": ["zlib", "boost-python", "python3", "flatbuffers"],
"features": {
"lda": {
"description": "",
"dependencies": []
}
}
}
22 changes: 14 additions & 8 deletions python/vcpkg_python310.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"name": "demo",
"version": "1.0.0",
"builtin-baseline": "773516ecf6014d89cc69b11bb54605ad4be56694",
"dependencies": [ "zlib","boost-python","python3","flatbuffers" ],
"overrides": [
{ "name": "python3", "version-string": "3.10.2", "port-version": 1 }
]
}
"name": "demo",
"version": "1.0.0",
"builtin-baseline": "773516ecf6014d89cc69b11bb54605ad4be56694",
"dependencies": ["zlib", "boost-python", "python3", "flatbuffers"],
"overrides": [
{ "name": "python3", "version-string": "3.10.2", "port-version": 1 }
],
"features": {
"lda": {
"description": "",
"dependencies": []
}
}
}
6 changes: 4 additions & 2 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"name": "vowpal-wabbit",
"version": "9.8.0",
"dependencies": [
"boost-math",
"eigen3",
"flatbuffers",
"fmt",
"rapidjson",
"spdlog",
Expand All @@ -17,6 +15,10 @@
"description": "Build Tests",
"dependencies": ["gtest"]
},
"lda": {
"description": "Enable LDA reduction",
"dependencies": ["boost-math"]
},
"flatbuffers": {
"description": "Enable flatbuffers support",
"dependencies": ["flatbuffers"]
Expand Down
13 changes: 10 additions & 3 deletions vowpalwabbit/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ set(vw_core_headers
include/vw/core/reductions/interact.h
include/vw/core/reductions/interaction_ground.h
include/vw/core/reductions/kernel_svm.h
include/vw/core/reductions/lda_core.h
include/vw/core/reductions/log_multi.h
include/vw/core/reductions/lrq.h
include/vw/core/reductions/lrqfa.h
Expand Down Expand Up @@ -314,7 +313,6 @@ set(vw_core_sources
src/reductions/interact.cc
src/reductions/interaction_ground.cc
src/reductions/kernel_svm.cc
src/reductions/lda_core.cc
src/reductions/log_multi.cc
src/reductions/lrq.cc
src/reductions/lrqfa.cc
Expand Down Expand Up @@ -361,6 +359,11 @@ set(vw_core_sources
src/vw.cc
)

if(VW_FEAT_LDA)
list(APPEND vw_core_headers include/vw/core/reductions/lda_core.h)
list(APPEND vw_core_sources src/reductions/lda_core.cc)
endif()

vw_add_library(
NAME "core"
TYPE "STATIC_ONLY"
Expand All @@ -370,13 +373,17 @@ vw_add_library(
# Special case for dealing with header-only INTERFACE dependencies of a STATIC library
# Use BUILD_INTERFACE to prevent them from being exported, i.e. treat them as PRIVATE
# https://gitlab.kitware.com/cmake/cmake/issues/15415
${CMAKE_DL_LIBS} ${LINK_THREADS} vw_io $<BUILD_INTERFACE:${boost_math_target}> $<BUILD_INTERFACE:RapidJSON>
${CMAKE_DL_LIBS} ${LINK_THREADS} vw_io $<BUILD_INTERFACE:RapidJSON>
$<BUILD_INTERFACE:eigen> $<BUILD_INTERFACE:sse2neon>
DESCRIPTION "This contains all remaining VW code, all reduction implementations, driver, option handling"
EXCEPTION_DESCRIPTION "Yes"
ENABLE_INSTALL
)

if(VW_FEAT_LDA)
target_link_libraries(vw_core PRIVATE $<BUILD_INTERFACE:${boost_math_target}>)
endif()

target_include_directories(vw_core PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src)

if (VW_BUILD_LAS_WITH_SIMD AND (UNIX AND NOT APPLE) AND (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64"))
Expand Down
6 changes: 5 additions & 1 deletion vowpalwabbit/core/include/vw/core/reductions/lda_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <memory>

#ifdef VW_FEAT_LDA_ENABLED

namespace VW
{
namespace reductions
Expand All @@ -19,4 +21,6 @@ namespace lda
void get_top_weights(VW::workspace* all, int top_words_count, int topic, std::vector<feature>& output);
}
} // namespace reductions
} // namespace VW
} // namespace VW

#endif
6 changes: 5 additions & 1 deletion vowpalwabbit/core/src/reduction_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
#include "vw/core/reductions/interact.h"
#include "vw/core/reductions/interaction_ground.h"
#include "vw/core/reductions/kernel_svm.h"
#include "vw/core/reductions/lda_core.h"
#ifdef VW_FEAT_LDA_ENABLED
# include "vw/core/reductions/lda_core.h"
#endif
#include "vw/core/reductions/log_multi.h"
#include "vw/core/reductions/lrq.h"
#include "vw/core/reductions/lrqfa.h"
Expand Down Expand Up @@ -163,7 +165,9 @@ void prepare_reductions(std::vector<std::tuple<std::string, VW::reduction_setup_
reductions.push_back(VW::reductions::lrqfa_setup);
reductions.push_back(VW::reductions::stagewise_poly_setup);
reductions.push_back(VW::reductions::scorer_setup);
#ifdef VW_FEAT_LDA_ENABLED
reductions.push_back(VW::reductions::lda_setup);
#endif
reductions.push_back(VW::reductions::cbzo_setup);

// Reductions
Expand Down

0 comments on commit 8b9a750

Please sign in to comment.