-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spawn worker in custom environment #1739
Conversation
@lhnwrk many thanks for your contribution to add the ability to run mlserver workers on different python versions. Internally mlserver communicates with these parallel workers using Having said that, the change you propose is slightly orthogonal to the above point as there is an argument to be made that we should set We suggest the following for us to be able to accept this change:
We can provide more pointers if you are happy to address the above. |
AFAIK we only need the worker process to have the same pickle protocol as the main process for I've updated the docs to point out the caveats for users, and extended the test suites to include custom environments with different python versions. For now they include the main process's python, the minimum tested python (3.9), and the maximum tested python (3.10) so we cover all cases of running a worker process with the same, lower, or higher python version. Let me know if there's anything else! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lhnwrk many thanks for addressing the comments. I left minor clarification questions.
tests/conftest.py
Outdated
MIN_PYTHON_VERSION, | ||
marks=pytest.mark.skipif( | ||
MIN_PYTHON_VERSION >= PYTHON_VERSION, | ||
reason="requires lower Python version", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what does the reason mean here? for example if the current system python version is 3.8
then the parameter (3, 9)
is not going to be used? and therefore the reason
is probably misleading. Could you clarify please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original thought was to test three cases of a worker environment with the same, lower, or higher Python version than the main process, so MIN_PYTHON_VERSION
is only tested when it's lower than the main Python for example. This is updated now to just test all python versions between MIN_PYTHON_VERSION
and MAX_PYTHON_VERSION
.
docs/user-guide/custom.md
Outdated
using pickled objects. Custom environments therefore **must** use the same | ||
version of MLServer and a compatible version of Python with the same [default | ||
pickle protocol](https://docs.python.org/3/library/pickle.html#pickle.DEFAULT_PROTOCOL) | ||
as the main process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you also add a note about the specific python versions that are currently supported. i.e. a table showcasing main process and parallel workers python versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a table here to clarify supported/tested worker environment!
@@ -2,7 +2,7 @@ name: custom-runtime-environment | |||
channels: | |||
- conda-forge | |||
dependencies: | |||
- python == 3.8 | |||
- python == 3.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good spot
@lhnwrk could you rebase on top of master to make sure that tests are passing on this PR? |
@sakoush Rebased on |
tests/testdata/environment.yml
Outdated
- scikit-learn == 1.0.2 | ||
- pip: | ||
- mlserver == 1.3.0.dev2 | ||
- git+${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git@${GITHUB_REF} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched to installing mlserver
from git here since worker environment has to match main process for this PR. GitHub Actions should set these environment variables to the fork/branch so the worker environment installs the same mlserver
, but default to SeldonIO/MLServer
's master
branch in tox.ini
otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lhnwrk is it possible to install from the local mlserver directory so it is easier logic and also locally we might want to be testing from changes done locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did go with this option first, but as it turns out this breaks docker build tests since the local mlserver directory is not available inside the container and the template Dockerfile only copies environment file. It has been a hassle to test locally though, what do you think if we use a separate yaml with a pinned version of mlserver for the CLI build test and install local directory for others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lhnwrk many thanks for the changes, i did add a couple more minor comments but it looks great otherwise.
I will also restart the failing CI tests.
mlserver/parallel/pool.py
Outdated
@@ -24,6 +25,14 @@ | |||
InferencePoolHook = Callable[[Worker], Awaitable[None]] | |||
|
|||
|
|||
def _spawn_worker(settings: Settings, responses: Queue, env: Optional[Environment]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add return type hint
tests/testdata/environment.yml
Outdated
- scikit-learn == 1.0.2 | ||
- pip: | ||
- mlserver == 1.3.0.dev2 | ||
- git+${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git@${GITHUB_REF} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lhnwrk is it possible to install from the local mlserver directory so it is easier logic and also locally we might want to be testing from changes done locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! nice one @lhnwrk.
As per #1461, MLServer currently spawns worker with the same Python version as the main process, so user-provided environment is forced to match the Python version of the server. However,
multiprocessing
allows setting the worker's executable path, this PR extends support for spawning workers in custom environments.