Skip to content

Commit 6327d48

Browse files
authored
Improve the documentation for custom exec envs (triton-inference-server#192)
1 parent 5225e39 commit 6327d48

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

README.md

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ any C++ code.
5050
- [Known Issues](#known-issues)
5151
- [`finalize`](#finalize)
5252
- [Model Config File](#model-config-file)
53-
- [Using Custom Python Execution Environments](#using-custom-python-execution-environments)
54-
- [1. Building Custom Python Backend Stub](#1-building-custom-python-backend-stub)
55-
- [2. Packaging the Conda Environment](#2-packaging-the-conda-environment)
53+
- [Managing Python Runtime and Libraries](#managing-python-runtime-and-libraries)
54+
- [Building Custom Python Backend Stub](#building-custom-python-backend-stub)
55+
- [Creating Custom Execution Environments](#creating-custom-execution-environments)
5656
- [Important Notes](#important-notes)
5757
- [Error Handling](#error-handling)
5858
- [Managing Shared Memory](#managing-shared-memory)
@@ -547,21 +547,26 @@ models
547547
└── config.pbtxt
548548
```
549549

550-
## Using Custom Python Execution Environments
550+
## Managing Python Runtime and Libraries
551551

552552
Python backend shipped in the [NVIDIA GPU Cloud](https://ngc.nvidia.com/)
553-
containers uses Python 3.8. If your Python model is compatible with Python 3.8
554-
and requires only modules already included in the Triton container, then you can
555-
skip this section. If you need to use a different version of Python or if you
556-
have additional dependencies, you need to recompile the stub executable and
557-
create an execution environment as described below and include that with your
558-
model.
559-
560-
### 1. Building Custom Python Backend Stub
561-
562-
**Important Note: If your Python model and its dependencies use Python 3.8,
563-
you can skip this section and start from section 2 since the Python backend stub
564-
shipped in Triton containers uses Python 3.8 by default.**
553+
containers uses Python 3.8. Python backend is able to use the libaries
554+
that exist in the current Python environment. These libraries can
555+
be installed in a virtualenv, conda environment, or the global system
556+
Python. These libraries will only be used if the Python version matches
557+
the Python version of the Python backend's stub executable. For example,
558+
if you install a set of libraries in a Python 3.9 environment and your
559+
Python backend stub is compiled with Python 3.8 these libraries will NOT
560+
be available in your Python model served using Triton. You would need to
561+
compile the stub executble with Python 3.9 using the instructions in
562+
[Building Custom Python Backend Stub](#building-custom-python-backend-stub)
563+
section.
564+
565+
### Building Custom Python Backend Stub
566+
567+
**Important Note: You only need to compile a custom Python backend stub if the
568+
Python version is different from Python 3.8 which is shipped by
569+
default in the Triton containers.**
565570

566571
Python backend uses a *stub* process to connect your `model.py` file to the
567572
Triton C++ core. This stub process has an embedded Python interpreter with
@@ -570,19 +575,19 @@ different version from the default Python backend stub, you need to compile your
570575
Python backend stub by following the steps below:
571576

572577
1. Install the software packages below:
573-
* [conda](https://docs.conda.io/en/latest/)
574578
* [cmake](https://cmake.org)
575579
* rapidjson and libarchive (instructions for installing these packages in Ubuntu or Debian are included in [Building from Source Section](#building-from-source))
576580

581+
2. Make sure that the expected Python version is available in your environment.
577582

578-
2. Create and activate a [conda](https://docs.conda.io/en/latest/) environment with your desired Python version. In this example, we will be using Python 3.6:
579-
```bash
580-
conda create -n python-3-6 python=3.6
581-
conda activate python-3-6
583+
If you are using `conda`, you should make sure to activate the environment by
584+
`conda activate <conda-env-name>`. Note that you don't have to use `conda` and
585+
can install Python however you wish. Python backend relies on
586+
[pybind11](https://github.com/pybind/pybind11) to find the correct Python
587+
version. If you noticed that the correct Python version is not picked up, you
588+
can read more on how
589+
[pybind11 decides which Python to use](https://pybind11.readthedocs.io/en/stable/faq.html?highlight=cmake#cmake-doesn-t-detect-the-right-python-version).
582590

583-
# NumPy is required for Python models
584-
conda install numpy
585-
```
586591
3. Clone the Python backend repository and compile the Python backend stub
587592
(replace \<GIT\_BRANCH\_NAME\> with the branch name that you want to use,
588593
for release branches it should be r\<xx.yy\>):
@@ -595,7 +600,7 @@ $ cmake -DTRITON_ENABLE_GPU=ON -DTRITON_BACKEND_REPO_TAG=<GIT_BRANCH_NAME> -DTRI
595600
$ make triton-python-backend-stub
596601
```
597602

598-
Now, you have access to a Python backend stub with Python 3.6. You can verify
603+
Now, you have access to a Python backend stub with your Python version. You can verify
599604
that using `ldd`:
600605

601606
```
@@ -606,10 +611,11 @@ libpython3.6m.so.1.0 => /home/ubuntu/envs/miniconda3/envs/python-3-6/lib/libpyth
606611
```
607612

608613
There are many other shared libraries printed in addition to the library posted
609-
above. However, it is important to see `libpython3.6m.so.1.0` in the list of
610-
linked shared libraries. If you use a different Python version, you should see
611-
that version instead. You need to copy the `triton_python_backend_stub` to the
612-
model directory of the models that want to use the custom Python backend
614+
above. However, it is important to see `libpython<major>.<minor>m.so.1.0` in the
615+
list of linked shared libraries. If you use a different Python version, you
616+
should see that version instead. You need to copy the
617+
`triton_python_backend_stub` to the model directory of the models that want to
618+
use the custom Python backend
613619
stub. For example, if you have `model_a` in your
614620
[model repository](https://github.com/triton-inference-server/server/blob/main/docs/user_guide/model_repository.md),
615621
the folder structure should look like below:
@@ -625,9 +631,11 @@ models
625631

626632
Note the location of `triton_python_backend_stub` in the directory structure above.
627633

628-
### 2. Packaging the Conda Environment
634+
### Creating Custom Execution Environments
629635

630-
It is also required to create a tar file that contains your conda environment.
636+
If you want to create a tar file that contains all your Python dependencies or
637+
you want to use different Python environments for each Python model you need to
638+
create a *Custom Execution Environment* in Python backend.
631639
Currently, Python backend only supports
632640
[conda-pack](https://conda.github.io/conda-pack/) for this purpose.
633641
[conda-pack](https://conda.github.io/conda-pack/) ensures that your conda
@@ -648,8 +656,9 @@ have exported [`PYTHONNOUSERSITE`](https://docs.python.org/3/using/cmdline.html#
648656
export PYTHONNOUSERSITE=True
649657
```
650658

651-
If this variable is not exported and similar packages are installed outside your conda environment,
652-
your tar file may not contain all the dependencies required for an isolated Python environment.
659+
If this variable is not exported and similar packages are installed outside your
660+
conda environment, your tar file may not contain all the dependencies required
661+
for an isolated Python environment.
653662

654663
After creating the tar file from the conda environment, you need to tell Python
655664
backend to use that environment for your model. You can do this by adding the
@@ -707,7 +716,7 @@ storage service.
707716
the version of triton_python_backend_stub.
708717

709718
2. If you don't want to use a different Python interpreter, you can skip
710-
[Building Custom Python Backend Stub Step](#1-building-custom-python-backend-stub).
719+
[Building Custom Python Backend Stub](#building-custom-python-backend-stub).
711720
In this case you only need to pack your environment using `conda-pack` and
712721
provide the path to tar file in the model config. However, the previous note
713722
still applies here and the version of the Python interpreter inside the conda

0 commit comments

Comments
 (0)