Package ai.djl.python.engine
Class PyEnv
java.lang.Object
ai.djl.python.engine.PyEnv
Python engine environment.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an environment variable.void
addParameter
(String key, String value) Adds a model initialization parameter.void
createVirtualEnv
(String name) Creates python virtual environment if needed.void
deleteVirtualEnv
(String name) Deletes python virtual environment.Returns the model's entrypoint file path.Returns the python model's handler function.Returns the python model initialization parameters.int
Returns the model loading timeout in seconds.int
Returns the prediction timeout in seconds.Returns the python executable path.int
Returns the tensor parallel degree.void
installDependency
(Path modelDir) Installs model dependencies if needed.boolean
Returns whether the python virtual environment is enabled.boolean
Returns true to forcibly fail if initialize process in python failed.void
setEnableVenv
(boolean enableVenv) Sets whether to enable the python virtual environment.void
setEntryPoint
(String entryPoint) Sets the model's entrypoint file path.void
setFailOnInitialize
(boolean failOnInitialize) Enables to forcibly fail if initialize process in python failed.void
setHandler
(String handler) Sets the python model's handler function.void
setModelLoadingTimeout
(int modelLoadingTimeout) Sets the model loading timeout in seconds.void
setPredictTimeout
(int predictTimeout) Sets the prediction timeout in seconds.void
setPythonExecutable
(String pythonExecutable) Sets the python executable path.void
setTensorParallelDegree
(int tensorParallelDegree) Sets the tensor parallel degree.
-
Constructor Details
-
PyEnv
public PyEnv(boolean mpiMode) Constructs a newPyEnv
instance.- Parameters:
mpiMode
- true to use MPI launcher
-
-
Method Details
-
addEnv
Adds an environment variable.- Parameters:
key
- the environment variable namevalue
- the environment variable value
-
addParameter
Adds a model initialization parameter.- Parameters:
key
- the environment variable namevalue
- the environment variable value
-
getInitParameters
Returns the python model initialization parameters.- Returns:
- the python model initialization parameters
-
createVirtualEnv
Creates python virtual environment if needed.- Parameters:
name
- the virtual environment name
-
deleteVirtualEnv
Deletes python virtual environment.- Parameters:
name
- the virtual environment name
-
installDependency
Installs model dependencies if needed.- Parameters:
modelDir
- the model directory
-
getPythonExecutable
Returns the python executable path.- Returns:
- the python executable path
-
setPythonExecutable
Sets the python executable path.- Parameters:
pythonExecutable
- the python executable path
-
getTensorParallelDegree
public int getTensorParallelDegree()Returns the tensor parallel degree.- Returns:
- the tensor parallel degree
-
setTensorParallelDegree
public void setTensorParallelDegree(int tensorParallelDegree) Sets the tensor parallel degree.- Parameters:
tensorParallelDegree
- the tensor parallel degree
-
getEntryPoint
Returns the model's entrypoint file path.- Returns:
- the model's entrypoint file path
-
setEntryPoint
Sets the model's entrypoint file path.- Parameters:
entryPoint
- the model's entrypoint file path
-
getHandler
Returns the python model's handler function.- Returns:
- the python file's handler function
-
setHandler
Sets the python model's handler function.- Parameters:
handler
- the python file's handler function
-
getPredictTimeout
public int getPredictTimeout()Returns the prediction timeout in seconds.- Returns:
- the prediction timeout in seconds
-
setPredictTimeout
public void setPredictTimeout(int predictTimeout) Sets the prediction timeout in seconds.- Parameters:
predictTimeout
- the prediction timeout in seconds
-
getModelLoadingTimeout
public int getModelLoadingTimeout()Returns the model loading timeout in seconds.- Returns:
- the model loading timeout in seconds
-
isFailOnInitialize
public boolean isFailOnInitialize()Returns true to forcibly fail if initialize process in python failed.- Returns:
- true if forcibly failed
-
setFailOnInitialize
public void setFailOnInitialize(boolean failOnInitialize) Enables to forcibly fail if initialize process in python failed.- Parameters:
failOnInitialize
- the flag
-
isEnableVenv
public boolean isEnableVenv()Returns whether the python virtual environment is enabled.- Returns:
true
if the virtual environment is enabled,false
otherwise.
-
setEnableVenv
public void setEnableVenv(boolean enableVenv) Sets whether to enable the python virtual environment.- Parameters:
enableVenv
-true
to enable the virtual environment,false
to disable it.
-
setModelLoadingTimeout
public void setModelLoadingTimeout(int modelLoadingTimeout) Sets the model loading timeout in seconds.- Parameters:
modelLoadingTimeout
- the model loading timeout in seconds
-