Skip to content

Commit 68edebf

Browse files
committed
Shorten ReadMe
ghstack-source-id: ece754a3b610716b79d945134133d466079d0fc7 Pull Request resolved: #237
1 parent 6ac5360 commit 68edebf

File tree

3 files changed

+8
-354
lines changed

3 files changed

+8
-354
lines changed

README.md

+5-164
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Requirements:
1717

1818
> ℹ️ `torch::deploy` is ready for use in production environments, but is in Beta and may have some rough edges that we're continuously working on improving. We're always interested in hearing feedback and usecases that you might have. Feel free to reach out!
1919
20+
## The Easy Path to Installation
21+
2022
## Installation
2123

2224
### Building via Docker
@@ -183,170 +185,9 @@ cd build
183185
./test_deploy
184186
```
185187

186-
## Examples
187-
188-
See the [examples directory](./examples) for complete examples.
189-
190-
### Packaging a model `for multipy::runtime`
191-
192-
``multipy::runtime`` can load and run Python models that are packaged with
193-
``torch.package``. You can learn more about ``torch.package`` in the ``torch.package`` [documentation](https://pytorch.org/docs/stable/package.html#tutorials).
194-
195-
For now, let's create a simple model that we can load and run in ``multipy::runtime``.
196-
197-
```python
198-
from torch.package import PackageExporter
199-
import torchvision
200-
201-
# Instantiate some model
202-
model = torchvision.models.resnet.resnet18()
203-
204-
# Package and export it.
205-
with PackageExporter("my_package.pt") as e:
206-
e.intern("torchvision.**")
207-
e.extern("numpy.**")
208-
e.extern("sys")
209-
e.extern("PIL.*")
210-
e.extern("typing_extensions")
211-
e.save_pickle("model", "model.pkl", model)
212-
```
213-
214-
Note that since "numpy", "sys", "PIL" were marked as "extern", `torch.package` will
215-
look for these dependencies on the system that loads this package. They will not be packaged
216-
with the model.
217-
218-
Now, there should be a file named ``my_package.pt`` in your working directory.
219-
220-
<br>
221-
222-
### Load the model in C++
223-
```cpp
224-
#include <multipy/runtime/deploy.h>
225-
#include <multipy/runtime/path_environment.h>
226-
#include <torch/script.h>
227-
#include <torch/torch.h>
228-
229-
#include <iostream>
230-
#include <memory>
231-
232-
int main(int argc, const char* argv[]) {
233-
if (argc != 2) {
234-
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
235-
return -1;
236-
}
237-
238-
// Start an interpreter manager governing 4 embedded interpreters.
239-
std::shared_ptr<multipy::runtime::Environment> env =
240-
std::make_shared<multipy::runtime::PathEnvironment>(
241-
std::getenv("PATH_TO_EXTERN_PYTHON_PACKAGES") // Ensure to set this environment variable (e.g. /home/user/anaconda3/envs/multipy-example/lib/python3.8/site-packages)
242-
);
243-
multipy::runtime::InterpreterManager manager(4, env);
244-
245-
try {
246-
// Load the model from the multipy.package.
247-
multipy::runtime::Package package = manager.loadPackage(argv[1]);
248-
multipy::runtime::ReplicatedObj model = package.loadPickle("model", "model.pkl");
249-
} catch (const c10::Error& e) {
250-
std::cerr << "error loading the model\n";
251-
std::cerr << e.msg();
252-
return -1;
253-
}
254-
255-
std::cout << "ok\n";
256-
}
257-
258-
```
259-
260-
This small program introduces many of the core concepts of ``multipy::runtime``.
261-
262-
An ``InterpreterManager`` abstracts over a collection of independent Python
263-
interpreters, allowing you to load balance across them when running your code.
264-
265-
``PathEnvironment`` enables you to specify the location of Python
266-
packages on your system which are external, but necessary, for your model.
267-
268-
Using the ``InterpreterManager::loadPackage`` method, you can load a
269-
``multipy.package`` from disk and make it available to all interpreters.
270-
271-
``Package::loadPickle`` allows you to retrieve specific Python objects
272-
from the package, like the ResNet model we saved earlier.
273-
274-
Finally, the model itself is a ``ReplicatedObj``. This is an abstract handle to
275-
an object that is replicated across multiple interpreters. When you interact
276-
with a ``ReplicatedObj`` (for example, by calling ``forward``), it will select
277-
an free interpreter to execute that interaction.
278-
279-
<br>
280-
281-
### Build and execute the C++ example
282-
283-
Assuming the above C++ program was stored in a file called, `example-app.cpp`, a
284-
minimal `CMakeLists.txt` file would look like:
285-
286-
```cmake
287-
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
288-
project(multipy_tutorial)
289-
290-
set(MULTIPY_PATH ".." CACHE PATH "The repo where multipy is built or the PYTHONPATH")
291-
292-
# include the multipy utils to help link against
293-
include(${MULTIPY_PATH}/multipy/runtime/utils.cmake)
294-
295-
# add headers from multipy
296-
include_directories(${MULTIPY_PATH})
297-
298-
# link the multipy prebuilt binary
299-
add_library(multipy_internal STATIC IMPORTED)
300-
set_target_properties(multipy_internal
301-
PROPERTIES
302-
IMPORTED_LOCATION
303-
${MULTIPY_PATH}/multipy/runtime/build/libtorch_deploy.a)
304-
caffe2_interface_library(multipy_internal multipy)
305-
306-
add_executable(example-app example-app.cpp)
307-
target_link_libraries(example-app PUBLIC "-Wl,--no-as-needed -rdynamic" dl pthread util multipy c10 torch_cpu)
308-
```
309-
310-
Currently, it is necessary to build ``multipy::runtime`` as a static library.
311-
In order to correctly link to a static library, the utility ``caffe2_interface_library``
312-
is used to appropriately set and unset ``--whole-archive`` flag.
313-
314-
Furthermore, the ``-rdynamic`` flag is needed when linking to the executable
315-
to ensure that symbols are exported to the dynamic table, making them accessible
316-
to the deploy interpreters (which are dynamically loaded).
317-
318-
**Updating LIBRARY_PATH and LD_LIBRARY_PATH**
319-
320-
In order to locate dependencies provided by PyTorch (e.g. `libshm`), we need to update the `LIBRARY_PATH` and `LD_LIBRARY_PATH` environment variables to include the path to PyTorch's C++ libraries. If you installed PyTorch using pip or conda, this path is usually in the site-packages. An example of this is provided below.
321-
322-
```bash
323-
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/user/anaconda3/envs/multipy-example/lib/python3.8/site-packages/torch/lib"
324-
export LIBRARY_PATH="$LIBRARY_PATH:/home/user/anaconda3/envs/multipy-example/lib/python3.8/site-packages/torch/lib"
325-
```
326-
327-
The last step is configuring and building the project. Assuming that our code
328-
directory is laid out like this:
329-
330-
```
331-
example-app/
332-
CMakeLists.txt
333-
example-app.cpp
334-
```
335-
336-
337-
We can now run the following commands to build the application from within the
338-
``example-app/`` folder:
339-
340-
```bash
341-
cmake -S . -B build -DMULTIPY_PATH="/home/user/repos/multipy" # the parent directory of multipy (i.e. the git repo)
342-
cmake --build build --config Release -j
343-
```
344-
345-
Now we can run our app:
346-
347-
```bash
348-
./example-app /path/to/my_package.pt
349-
```
188+
## Getting Started with `torch::deploy`
189+
Once you have `torch::deploy` built, check out our [tutorials](https://pytorch.org/multipy/latest/tutorials/tutorial_root.html) and
190+
[API documentation](https://pytorch.org/multipy/latest/api/library_root.html).
350191

351192
## Contributing
352193

docs/source/index.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
``torch::deploy`` [Beta]
44
=====================
55

6-
``torch::deploy`` is a system that allows you to load multiple python interpreters which execute PyTorch models, and run them in a single C++ process. Effectively, it allows people to multithread their pytorch models.
7-
For more information on how torch::deploy works please see the related `arXiv paper <https://arxiv.org/pdf/2104.00254.pdf>`_. We plan to further generalize ``torch::deploy`` into a more generic system, ``multipy::runtime``,
8-
which is more suitable for arbitrary python programs rather than just pytorch applications.
6+
``torch::deploy`` (MultiPy for non-PyTorch use cases) is a C++ library that enables you to run eager mode PyTorch models in production without any modifications to your model to support tracing. ``torch::deploy`` provides a way to run using multiple independent Python interpreters in a single process without a shared global interpreter lock (GIL).
7+
For more information on how ``torch::deploy`` works please see the related `arXiv paper <https://arxiv.org/pdf/2104.00254.pdf>`_.
98

9+
The most up to date installation instructions for ``torch::deploy`` can be found in our `README <https://github.com/pytorch/multipy>`__.
1010

1111
Documentation
1212
---------------
@@ -15,7 +15,6 @@ Documentation
1515
:maxdepth: 2
1616
:caption: Usage
1717

18-
setup.md
1918
tutorials/tutorial_root
2019
api/library_root
2120

docs/source/setup.rst

-186
This file was deleted.

0 commit comments

Comments
 (0)