Skip to content

Commit cf9f5dd

Browse files
authored
Fix develop/editable install mode (horovod#3074)
Signed-off-by: Nicolas Castet <[email protected]>
1 parent bc8c71b commit cf9f5dd

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1818

1919
### Fixed
2020

21+
- Fix Horovod develop/editable install mode and incremental builds. ([#3074](https://github.com/horovod/horovod/pull/3074))
22+
2123
## [v0.22.1] - 2021-06-10
2224

2325
### Added

docs/contributors.rst

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@ Develop within a virtual environment to avoid dependency issues:
2020

2121
.. code-block:: bash
2222
23-
$ virtualenv env
23+
$ python3 -m venv env
2424
$ . env/bin/activate
2525
2626
We recommend installing package versions that match with those under test in
2727
`Buildkite <https://github.com/horovod/horovod/blob/master/.buildkite/gen-pipeline.sh>`__.
2828
The following versions are recommended (see default versions defined through :code:`ARG` in
2929
`Dockerfile.test.cpu <https://github.com/horovod/horovod/blob/master/Dockerfile.test.cpu>`__ and
3030
`Dockerfile.test.gpu <https://github.com/horovod/horovod/blob/master/Dockerfile.test.gpu>`__ file.
31-
The versions with CPU support can be installed through the provided :code:`setup.py` file:
32-
33-
.. code-block:: bash
34-
35-
pip install -e .[dev,test]
3631

3732
You can find all other non-Python packages that need to be installed on your system for Horovod to build
3833
in the `Dockerfile.test.cpu <https://github.com/horovod/horovod/blob/master/Dockerfile.test.cpu>`__ and
@@ -42,30 +37,27 @@ Specifically, see all :code:`RUN apt-get install` lines.
4237
Build and Install
4338
-----------------
4439

45-
First, uninstall any existing version of Horovod. Be sure to do this *outside* the Horovod root directory:
40+
From *inside* the Horovod root directory, install Horovod in develop/editable mode:
4641

4742
.. code-block:: bash
4843
49-
$ cd $HOME
50-
$ pip uninstall -y horovod
51-
$ cd -
52-
53-
From *inside* the Horovod root directory, remove any previous build artifacts and then install Horovod:
54-
55-
.. code-block:: bash
56-
57-
$ rm -rf build/ dist/
58-
$ HOROVOD_WITH_PYTORCH=1 HOROVOD_WITH_TENSORFLOW=1 python setup.py install
44+
$ HOROVOD_WITH_PYTORCH=1 HOROVOD_WITH_TENSORFLOW=1 pip install -v -e .
5945
6046
Set ``HOROVOD_WITHOUT_[FRAMEWORK]=1`` to disable building Horovod plugins for that framework.
6147
This is useful when you’re testing a feature of one framework in particular and wish to save time.
6248

63-
For a debug build with checked assertions etc. replace the invocation of setup.py by:
49+
Set ``HOROVOD_WITH_[FRAMEWORK]=1`` to generate an error if the Horovod plugin for that framework failed to build.
6450

65-
.. code-block:: bash
51+
Set ``HOROVOD_DEBUG=1`` for a debug build with checked assertions, disabled compiler optimizations etc.
52+
53+
Other environmental variables can be found in the `install documentation <https://github.com/horovod/horovod/blob/master/docs/install.rst#environment-variables>`__.
6654

67-
$ HOROVOD_WITH_PYTORCH=1 HOROVOD_WITH_TENSORFLOW=1 python setup.py build_ext --debug install
55+
You can install optional dependencies defined in `setup.py <https://github.com/horovod/horovod/blob/master/setup.py>`__ by adding brackets
56+
at the end of the command line e.g. ``[test]`` for test dependencies.
57+
If you have not installed specific DL frameworks yet, add ``[dev]`` to install the CPU version of all supported DL frameworks.
6858

59+
In develop mode, you can edit the Horovod source directly in the repo folder. For Python code, the changes will take effect
60+
immediately. For **C++/CUDA code**, the ``... pip install -v -e .`` command needs to be invoked again to perform an incremental build.
6961

7062
Testing
7163
-------

docs/install.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Optional environment variables that can be set to configure the installation pro
226226

227227
Possible values are given in curly brackets: {}.
228228

229+
* ``HOROVOD_DEBUG`` - {1}. Install a debug build of Horovod with checked assertions, disabled compiler optimizations etc.
229230
* ``HOROVOD_BUILD_ARCH_FLAGS`` - additional C++ compilation flags to pass in for your build architecture.
230231
* ``HOROVOD_CUDA_HOME`` - path where CUDA include and lib directories can be found.
231232
* ``HOROVOD_BUILD_CUDA_CC_LIST`` - List of compute capabilities to build Horovod CUDA kernels for (example: ``HOROVOD_BUILD_CUDA_CC_LIST=60,70,75``)

setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# ==============================================================================
1717

1818
import os
19+
import shutil
1920
import subprocess
2021
import sys
2122
import textwrap
@@ -25,6 +26,7 @@
2526

2627
from horovod import __version__
2728

29+
_FRAMEWORK_METADATA_FILE = 'horovod/metadata.json'
2830

2931
class CMakeExtension(Extension):
3032
def __init__(self, name, cmake_lists_dir='.', sources=[], **kwa):
@@ -52,6 +54,8 @@ def is_build_action():
5254
if sys.argv[1].startswith('install'):
5355
return True
5456

57+
if sys.argv[1].startswith('develop'):
58+
return True
5559

5660
def get_cmake_bin():
5761
return os.environ.get('HOROVOD_CMAKE', 'cmake')
@@ -66,7 +70,7 @@ def build_extensions(self):
6670

6771
cmake_bin = get_cmake_bin()
6872

69-
config = 'Debug' if self.debug else 'RelWithDebInfo'
73+
config = 'Debug' if self.debug or os.environ.get('HOROVOD_DEBUG') == "1" else 'RelWithDebInfo'
7074

7175
ext_name = self.extensions[0].name
7276
build_dir = self.get_ext_fullpath(ext_name).replace(self.get_ext_filename(ext_name), '')
@@ -98,6 +102,13 @@ def build_extensions(self):
98102
except OSError as e:
99103
raise RuntimeError('CMake failed: {}'.format(str(e)))
100104

105+
if sys.argv[1].startswith('develop'):
106+
# Copy over metadata.json file from build directory
107+
shutil.copyfile(os.path.join(build_dir, _FRAMEWORK_METADATA_FILE),
108+
os.path.join(self.extensions[0].cmake_lists_dir, _FRAMEWORK_METADATA_FILE))
109+
# Remove unfound frameworks, otherwise develop mode will fail the install
110+
self.extensions = [x for x in self.extensions if os.path.exists(self.get_ext_fullpath(x.name))]
111+
101112

102113
# python packages required to use horovod in general
103114
require_list = ['cloudpickle', 'psutil', 'pyyaml', 'dataclasses;python_version<"3.7"']

0 commit comments

Comments
 (0)