-
Notifications
You must be signed in to change notification settings - Fork 68
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
[python] Create model level virtualenv #811
Conversation
engines/python/src/main/java/ai/djl/python/engine/PyProcess.java
Outdated
Show resolved
Hide resolved
5fd8a01
to
553a3df
Compare
@@ -122,6 +122,9 @@ synchronized void startPythonProcess() { | |||
int id = restartCount.get(); | |||
int port = connections.get(0).getPort(); | |||
logger.info("Start process: {} - retry: {}", port, id); | |||
if (pyEnv.isEnableVenv()) { |
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.
create/delete venv should happen at model loading and close time, not at StartPyProcess time
one model may have multiple workers.
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.
Changed.
Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
/** | ||
* Constructs a new {@code PyEnv} instance. | ||
* | ||
* @param mpiMode true to use MPI launcher | ||
*/ | ||
public PyEnv(boolean mpiMode) { | ||
this.mpiMode = mpiMode; | ||
pythonExecutable = Utils.getenv("PYTHON_EXECUTABLE"); |
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.
With your implementation, no need to lazy get
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.
Changed.
logger.warn("{}", logOutput); | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
logger.warn("Python virtual failed.", e); |
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.
We should fail the model loading
setPythonExecutable(path.resolve("bin").resolve("python").toString()); | ||
venvCreated = true; | ||
} else { | ||
logger.warn("Failed to create virtual environment with error code: {}", ret); |
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.
We should fail here
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.
We need add a unit test
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.
throwed EngineException.
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 unit test
Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
21cee2f
to
84072e1
Compare
* [python] Create model level virtualenv * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Review changes * Review changes * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Review changes --------- Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
* [python] Create model level virtualenv * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Review changes * Review changes * Update engines/python/src/main/java/ai/djl/python/engine/PyEnv.java Co-authored-by: Frank Liu <frankfliu2000@gmail.com> * Review changes --------- Co-authored-by: Frank Liu <frankfliu2000@gmail.com>
Description
Brief description of what this PR is about
Create model-specific virtualenv. I discussed with Frank about two options:
In my experiment, the time creating the venv on the fly is not noticeable. So I had this PR for option 1.