Bundling external code
Bundle utilities and libraries with your ML model.
If your model depends on internal packages that are not available on PyPi, you can bundle this code with the Truss in the
packagesfolder. These bundled packages can then be imported and used in your
When you import your Truss, the import mechanism add the packages in the Truss'
packagesdirectory to the path.
Make sure to avoid namespace conflicts. The model serving environment depends on standard Python modules and popular packages, so don't give your bundled packages names like
transformers, or anything else that conflicts with standard or popular Python packages.
If you want to include helper functions or other Python code directly with the Truss, create a file in
packages/. For example, we'll create
There, we can write any code we want, for example:
a = 1
b = 2
config.yamlincludes the line
bundled_packages_dir: packages, so all you have to do to access
model/model.pyis import it:
from my_utils import MyObject, my_func
And the bundled code will be available just like packages installed from PyPi.
There are situations where you may need to maintain code separately from your Truss. For example, you may want to share code across multiple Trusses without publishing it to PyPi. External packages are built for this use case.