|
1 | | -Installation |
2 | | -============ |
3 | | - |
4 | | -Building ``torch::deploy`` via Docker |
5 | | -------------------------------------- |
6 | | - |
7 | | -The easiest way to build ``torch::deploy``, along with fetching all interpreter |
8 | | -dependencies, is to do so via docker. |
9 | | - |
10 | | -.. code:: shell |
11 | | -
|
12 | | - git clone https://github.com/pytorch/multipy.git |
13 | | - cd multipy |
14 | | - export DOCKER_BUILDKIT=1 |
15 | | - docker build -t multipy . |
16 | | -
|
17 | | -The built artifacts are located in ``multipy/runtime/build``. |
18 | | - |
19 | | -To run the tests: |
20 | | - |
21 | | -.. code:: shell |
22 | | -
|
23 | | - docker run --rm multipy multipy/runtime/build/test_deploy |
24 | | -
|
25 | | -Installing via ``pip install`` |
26 | | ------------------------------- |
27 | | - |
28 | | -We support installing both the python modules and the c++ bits (through ``CMake``) |
29 | | -using a single ``pip install -e .`` command, with the caveat of having to manually |
30 | | -install the dependencies first. |
31 | | - |
32 | | -First clone multipy and update the submodules: |
33 | | - |
34 | | -.. code:: shell |
35 | | -
|
36 | | - git clone https://github.com/pytorch/multipy.git |
37 | | - cd multipy |
38 | | - git submodule sync && git submodule update --init --recursive |
39 | | -
|
40 | | -Installing system dependencies |
41 | | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
42 | | - |
43 | | -The runtime system dependencies are specified in |
44 | | -``build-requirements.txt``. To install them on Debian-based systems, one |
45 | | -could run: |
46 | | - |
47 | | -.. code:: shell |
48 | | -
|
49 | | - sudo apt update |
50 | | - xargs sudo apt install -y -qq --no-install-recommends < build-requirements.txt |
51 | | -
|
52 | | -Installing environment encapsulators |
53 | | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
54 | | - |
55 | | -We recommend using the isolated python environments of either `conda |
56 | | -<https://docs.conda.io/projects/continuumio-conda/en/latest/user-guide/install/index.html#regular-installation>`__ |
57 | | -or `pyenv + virtualenv <https://github.com/pyenv/pyenv.git>`__ |
58 | | -because ``torch::deploy`` requires a |
59 | | -position-independent version of python to launch interpreters with. For |
60 | | -``conda`` environments we use the prebuilt ``libpython-static=3.x`` |
61 | | -libraries from ``conda-forge`` to link with at build time. For |
62 | | -``virtualenv``/``pyenv``, we compile python with the ``-fPIC`` flag to create the |
63 | | -linkable library. |
64 | | - |
65 | | -.. warning:: |
66 | | - While `torch::deploy` supports Python versions 3.7 through 3.10, |
67 | | - the ``libpython-static`` libraries used with ``conda`` environments |
68 | | - are only available for ``3.8`` onwards. With ``virtualenv``/``pyenv`` |
69 | | - any version from 3.7 through 3.10 can be |
70 | | - used, as python can be built with the ``-fPIC`` flag explicitly. |
71 | | - |
72 | | -Installing pytorch and related dependencies |
73 | | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
74 | | -``torch::deploy`` requires the latest version of pytorch to run models |
75 | | -successfully, and we recommend fetching the latest *nightlies* for |
76 | | -pytorch and also cuda. |
77 | | - |
78 | | -Installing the python dependencies in a ``conda`` environment: |
79 | | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
80 | | - |
81 | | -.. code:: shell |
82 | | -
|
83 | | - conda create -n newenv |
84 | | - conda activate newenv |
85 | | -
|
86 | | - conda install python=3.8 # or 3.8/3.10 |
87 | | - conda install -c conda-forge libpython-static=3.8 # or 3.8/3.10 |
88 | | -
|
89 | | - # install your desired flavor of pytorch from https://pytorch.org/get-started/locally/ |
90 | | - conda install pytorch torchvision torchaudio cpuonly -c pytorch-nightly |
91 | | -
|
92 | | -Installing the python dependencies in a ``pyenv`` / ``virtualenv`` setup |
93 | | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
94 | | - |
95 | | -.. code:: shell |
96 | | -
|
97 | | - # feel free to replace 3.8.6 with any python version > 3.7.0 |
98 | | - export CFLAGS="-fPIC -g" |
99 | | - ~/.pyenv/bin/pyenv install --force 3.8.6 |
100 | | - virtualenv -p ~/.pyenv/versions/3.8.6/bin/python3 ~/venvs/multipy |
101 | | - source ~/venvs/multipy/bin/activate |
102 | | - pip install -r dev-requirements.txt |
103 | | -
|
104 | | - # install your desired flavor of pytorch from https://pytorch.org/get-started/locally/ |
105 | | - pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu |
106 | | -
|
107 | | -Running ``pip install`` |
108 | | -~~~~~~~~~~~~~~~~~~~~~~~ |
109 | | - |
110 | | -Once all the dependencies are successfully installed, |
111 | | -including a ``-fPIC`` enabled build of python and the latest nightly of pytorch, we |
112 | | -can run the following, in either ``conda`` or ``virtualenv``, to install |
113 | | -both the python modules and the runtime/interpreter libraries: |
114 | | - |
115 | | -.. code:: shell |
116 | | -
|
117 | | - # from base torch::deploy directory |
118 | | - pip install -e . |
119 | | - # alternatively one could run |
120 | | - python setup.py develop |
121 | | -
|
122 | | -The C++ binaries should be available in ``/opt/dist``. |
123 | | - |
124 | | -Alternatively, one can install only the python modules without invoking |
125 | | -``cmake`` as follows: |
126 | | - |
127 | | -.. code:: shell |
128 | | -
|
129 | | - # from base multipy directory |
130 | | - pip install -e . --install-option="--cmakeoff" |
131 | | -
|
132 | | -.. warning:: |
133 | | - As of 10/11/2022 the linking of prebuilt static ``-fPIC`` |
134 | | - versions of python downloaded from ``conda-forge`` can be problematic |
135 | | - on certain systems (for example Centos 8), with linker errors like |
136 | | - ``libpython_multipy.a: error adding symbols: File format not recognized``. |
137 | | - This seems to be an issue with ``binutils``, and `these steps |
138 | | - <https://wiki.gentoo.org/wiki/Project:Toolchain/Binutils_2.32_upgrade_notes/elfutils_0.175:_unable_to_initialize_decompress_status_for_section_.debug_info>`__ |
139 | | - can help. Alternatively, the user can go with the |
140 | | - ``virtualenv``/``pyenv`` flow above. |
141 | | - |
142 | | -Running ``torch::deploy`` build steps from source |
143 | | -------------------------------------------------- |
144 | | - |
145 | | -Both ``docker`` and ``pip install`` options above are wrappers around |
146 | | -the cmake build of `torch::deploy`. If the user wishes to run the |
147 | | -build steps manually instead, as before the dependencies would have to |
148 | | -be installed in the user’s (isolated) environment of choice first. After |
149 | | -that the following steps can be executed: |
150 | | - |
151 | | -Building |
152 | | -~~~~~~~~ |
153 | | - |
154 | | -.. code:: bash |
155 | | -
|
156 | | - # checkout repo |
157 | | - git checkout https://github.com/pytorch/multipy.git |
158 | | - git submodule sync && git submodule update --init --recursive |
159 | | -
|
160 | | - cd multipy |
161 | | - # install python parts of `torch::deploy` in multipy/multipy/utils |
162 | | - pip install -e . --install-option="--cmakeoff" |
163 | | -
|
164 | | - cd multipy/runtime |
165 | | -
|
166 | | - # build runtime |
167 | | - mkdir build |
168 | | - cd build |
169 | | - # use cmake -DABI_EQUALS_1=ON .. instead if you want ABI=1 |
170 | | - cmake .. |
171 | | - cmake --build . --config Release |
172 | | -
|
173 | | -Running unit tests for ``torch::deploy`` |
174 | | ----------------------------------------- |
175 | | - |
176 | | -We first need to generate the neccessary examples. First make sure your |
177 | | -python enviroment has `torch <https://pytorch.org>`__. Afterwards, once |
178 | | -``torch::deploy`` is built, run the following (executed automatically |
179 | | -for ``docker`` and ``pip`` above): |
180 | | - |
181 | | -.. code:: bash |
182 | | -
|
183 | | - cd multipy/multipy/runtime |
184 | | - python example/generate_examples.py |
185 | | - cd build |
186 | | - ./test_deploy |
| 1 | +.. literalinclude:: ../../../README.md |
| 2 | + :language: markdown |
| 3 | + :lines: 22-176 |
0 commit comments