-
Notifications
You must be signed in to change notification settings - Fork 863
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
Enable venv to inherit site packages from base python environment #2946
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namannandan
changed the title
Venv inherit site packages
Enable venv to inherit site packages from base python environment
Feb 14, 2024
agunapal
approved these changes
Feb 20, 2024
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
8 tasks
muthuraj-i2i
pushed a commit
to muthuraj-i2i/serve
that referenced
this pull request
Mar 1, 2024
…torch#2946) * Enable inheriting site-packages from base python env to venv * Use a .pth file instead of sitecustomize.py * Add support to inherit user site packages if enabled * Run custom dependencies test at the end * Change info logs to debug logs and update tests * Revert test filename to original name * Update venv creation log level to info
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The current implementation to support installation of model custom dependencies and running model workers in a python virtual environment(#2910) works when
torchserve
is installed to and started from system site-packages but fails when torchserve itself is installed to and started from a virtual environment.This is because the newly created virtual environment does not inherit site-packages from the current virtual environment where
torchserve
is installed, which is expected behavior.Just using the
--system-site-packages
flag when creating the virtual environment is not a complete solution because torchserve may have not been installed to the system site directory as shown above.serve/frontend/server/src/main/java/org/pytorch/serve/wlm/ModelManager.java
Line 224 in bef3b63
A more generic solution would be is to identify site-packages directories setup in the python environment in which
torchserve
is started and inherit those into the new virtual environment.For example:
In the base python environment(torchserve running in a virtual-environment):
In the new virtual-environment created to install model custom dependencies and run model workers:
As can be seen above,
/home/venv/lib/python3.9/site-packages
is added tosys.path
in the newly created environment, which is inherited from the base python environment. Also, the packages in the local venv site-packages/home/model-server/tmp/models/1b1c30114f0b451087e2123af09eea2e/venv/lib/python3.9/site-packages
take precedence over the inherited site-packages directory/home/venv/lib/python3.9/site-packages
.Fixes #2942
Type of change
Feature/Issue validation/testing