Skip to content

Commit

Permalink
feat(python): make time costs printing available
Browse files Browse the repository at this point in the history
According to the [install guide](https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html):
> Users who want to perform benchmarking can make LightGBM output time costs for different internal routines by adding -DUSE_TIMETAG=ON to CMake flags.

This feature was unfortunately not available when installing LightGBM from the Python package. This commit fixes this.
  • Loading branch information
Remy-Luciani committed Sep 22, 2022
1 parent dc4794b commit 086be2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions python-package/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ By default, installation in environment with 32-bit Python is prohibited. Howeve

It is **strongly not recommended** to use this version of LightGBM!

Build with time costs output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: sh
pip install lightgbm --install-option=--time-costs
Users who want to perform benchmarking can make LightGBM output time costs for different internal routines thanks to this install parameter

Install from `conda-forge channel <https://anaconda.org/conda-forge/lightgbm>`_
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Expand Down
12 changes: 10 additions & 2 deletions python-package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
('hdfs', 'h', 'Compile HDFS version'),
('bit32', None, 'Compile 32-bit version'),
('precompile', 'p', 'Use precompiled library'),
('time-costs', None, 'Output time costs for different internal routines'),
('boost-root=', None, 'Boost preferred installation prefix'),
('boost-dir=', None, 'Directory with Boost package configuration file'),
('boost-include-dir=', None, 'Directory containing Boost headers'),
Expand Down Expand Up @@ -116,7 +117,8 @@ def compile_cpp(
opencl_library: Optional[str] = None,
nomp: bool = False,
bit32: bool = False,
integrated_opencl: bool = False
integrated_opencl: bool = False,
time_costs: bool = False
) -> None:
build_dir = CURRENT_DIR / "build_cpp"
rmtree(build_dir, ignore_errors=True)
Expand Down Expand Up @@ -154,6 +156,8 @@ def compile_cpp(
cmake_cmd.append("-DUSE_OPENMP=OFF")
if use_hdfs:
cmake_cmd.append("-DUSE_HDFS=ON")
if time-costs:
cmake_cmd.append("-DUSE_TIMETAG=ON")

if system() in {'Windows', 'Microsoft'}:
if use_mingw:
Expand Down Expand Up @@ -241,6 +245,7 @@ def initialize_options(self) -> None:
self.mpi = False
self.hdfs = False
self.precompile = False
self.time_costs = False
self.nomp = False
self.bit32 = False

Expand All @@ -259,7 +264,8 @@ def run(self) -> None:
use_hdfs=self.hdfs, boost_root=self.boost_root, boost_dir=self.boost_dir,
boost_include_dir=self.boost_include_dir, boost_librarydir=self.boost_librarydir,
opencl_include_dir=self.opencl_include_dir, opencl_library=self.opencl_library,
nomp=self.nomp, bit32=self.bit32, integrated_opencl=self.integrated_opencl)
nomp=self.nomp, bit32=self.bit32, integrated_opencl=self.integrated_opencl,
time_costs=self.time_costs)
install.run(self)
if LOG_PATH.is_file():
LOG_PATH.unlink()
Expand All @@ -285,6 +291,7 @@ def initialize_options(self) -> None:
self.mpi = False
self.hdfs = False
self.precompile = False
self.print_timecosts = False
self.nomp = False
self.bit32 = False

Expand All @@ -307,6 +314,7 @@ def finalize_options(self) -> None:
install.mpi = self.mpi
install.hdfs = self.hdfs
install.precompile = self.precompile
install.time_costs = self.time_costs
install.nomp = self.nomp
install.bit32 = self.bit32

Expand Down

0 comments on commit 086be2f

Please sign in to comment.