build_from_source.rst 3.13 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
3
Build from Source
=================

4
This article describes how to build and install NNI from `source code <https://github.com/microsoft/nni>`__.
liuzhe-lz's avatar
liuzhe-lz committed
5

6
7
8
9
10
11
12
13
14
15
16
Preparation
-----------

Fetch source code from GitHub:

.. code-block:: bash

    git clone https://github.com/microsoft/nni.git
    cd nni

Upgrade to latest toolchain:
liuzhe-lz's avatar
liuzhe-lz committed
17

liuzhe-lz's avatar
liuzhe-lz committed
18
.. code-block:: text
liuzhe-lz's avatar
liuzhe-lz committed
19

liuzhe-lz's avatar
liuzhe-lz committed
20
    pip install --upgrade setuptools pip wheel
liuzhe-lz's avatar
liuzhe-lz committed
21

22
23
24
25
26
27
28
.. note::

    Please make sure ``python`` and ``pip`` executables have correct Python version.

    For Apple Silicon M1, if ``python`` command is not available, you may need to manually fix dependency building issues.
    (`GitHub issue <https://github.com/mapbox/node-sqlite3/issues/1413>`__ |
    `Stack Overflow question <https://stackoverflow.com/questions/70874412/sqlite3-on-m1-chip-npm-is-failing>`__)
liuzhe-lz's avatar
liuzhe-lz committed
29
30
31
32
33
34

Development Build
-----------------

If you want to build NNI for your own use, we recommend using `development mode`_.

liuzhe-lz's avatar
liuzhe-lz committed
35
.. code-block:: text
liuzhe-lz's avatar
liuzhe-lz committed
36
37
38
39
40
41
42

    python setup.py develop

This will install NNI as symlink, and the version number will be ``999.dev0``.

.. _development mode: https://setuptools.pypa.io/en/latest/userguide/development_mode.html

43
44
Then if you want to modify NNI source code, please check :doc:`contribution guide <contributing>`.

liuzhe-lz's avatar
liuzhe-lz committed
45
46
47
48
49
50
51
52
Release Build
-------------

To install in release mode, you must first build a wheel.
NNI does not support setuptools' "install" command.

A release package requires jupyterlab to build the extension:

liuzhe-lz's avatar
liuzhe-lz committed
53
.. code-block:: text
liuzhe-lz's avatar
liuzhe-lz committed
54

55
    pip install jupyterlab==3.0.9
liuzhe-lz's avatar
liuzhe-lz committed
56

57
58
You need to set ``NNI_RELEASE`` environment variable to the version number,
and compile TypeScript modules before "bdist_wheel".
liuzhe-lz's avatar
liuzhe-lz committed
59
60
61

In bash:

liuzhe-lz's avatar
liuzhe-lz committed
62
.. code-block:: bash
liuzhe-lz's avatar
liuzhe-lz committed
63

64
    export NNI_RELEASE=2.0
liuzhe-lz's avatar
liuzhe-lz committed
65
66
67
68
69
    python setup.py build_ts
    python bdist_wheel

In PowerShell:

liuzhe-lz's avatar
liuzhe-lz committed
70
.. code-block:: powershell
liuzhe-lz's avatar
liuzhe-lz committed
71

72
    $env:NNI_RELEASE=2.0
liuzhe-lz's avatar
liuzhe-lz committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    python setup.py build_ts
    python bdist_wheel

If successful, you will find the wheel in ``dist`` directory.

.. note::

    NNI's build process is somewhat complicated.
    This is due to setuptools and TypeScript not working well together.

    Setuptools require to provide ``package_data``, the full list of package files, before running any command.
    However it is nearly impossible to predict what files will be generated before invoking TypeScript compiler.

    If you have any solution for this problem, please open an issue to let us know.

Build Docker Image
------------------

liuzhe-lz's avatar
liuzhe-lz committed
91
You can build a Docker image with :githublink:`Dockerfile <Dockerfile>`:
liuzhe-lz's avatar
liuzhe-lz committed
92

liuzhe-lz's avatar
liuzhe-lz committed
93
.. code-block:: bash
liuzhe-lz's avatar
liuzhe-lz committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

    export NNI_RELEASE=2.7
    python setup.py build_ts
    python setup.py bdist_wheel -p manylinux1_x86_64
    docker build --build-arg NNI_RELEASE=${NNI_RELEASE} -t my/nni .

To build image for other platforms, please edit Dockerfile yourself.

Other Commands and Options
--------------------------

Clean
^^^^^

If the build fails, please clean up and try again:

liuzhe-lz's avatar
liuzhe-lz committed
110
.. code:: text
liuzhe-lz's avatar
liuzhe-lz committed
111
112
113
114
115
116
117
118
119
120

    python setup.py clean

Skip compiling TypeScript modules
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is useful when you have uninstalled NNI from development mode and want to install again.

It will not work if you have never built TypeScript modules before.

liuzhe-lz's avatar
liuzhe-lz committed
121
.. code:: text
liuzhe-lz's avatar
liuzhe-lz committed
122
123

    python setup.py develop --skip-ts