Package ai.djl.python.engine
Class PyEnv
- java.lang.Object
-
- ai.djl.python.engine.PyEnv
-
public class PyEnv extends java.lang.ObjectPython engine environment.
-
-
Constructor Summary
Constructors Constructor Description PyEnv(boolean mpiMode)Constructs a newPyEnvinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEnv(java.lang.String key, java.lang.String value)Adds an environment variable.voidaddParameter(java.lang.String key, java.lang.String value)Adds a model initialization parameter.voidcreateVirtualEnv(java.lang.String name)Creates python virtual environment if needed.voiddeleteVirtualEnv(java.lang.String name)Deletes python virtual environment.java.lang.StringgetEntryPoint()Returns the model's entrypoint file path.java.lang.StringgetHandler()Returns the python model's handler function.java.util.Map<java.lang.String,java.lang.String>getInitParameters()Returns the python model initialization parameters.intgetModelLoadingTimeout()Returns the model loading timeout in seconds.intgetPredictTimeout()Returns the prediction timeout in seconds.java.lang.StringgetPythonExecutable()Returns the python executable path.intgetTensorParallelDegree()Returns the tensor parallel degree.voidinstallDependency(java.nio.file.Path modelDir)Installs model dependencies if needed.booleanisEnableVenv()Returns whether the python virtual environment is enabled.booleanisFailOnInitialize()Returns true to forcibly fail if initialize process in python failed.voidsetEnableVenv(boolean enableVenv)Sets whether to enable the python virtual environment.voidsetEntryPoint(java.lang.String entryPoint)Sets the model's entrypoint file path.voidsetFailOnInitialize(boolean failOnInitialize)Enables to forcibly fail if initialize process in python failed.voidsetHandler(java.lang.String handler)Sets the python model's handler function.voidsetModelLoadingTimeout(int modelLoadingTimeout)Sets the model loading timeout in seconds.voidsetPredictTimeout(int predictTimeout)Sets the prediction timeout in seconds.voidsetPythonExecutable(java.lang.String pythonExecutable)Sets the python executable path.voidsetTensorParallelDegree(int tensorParallelDegree)Sets the tensor parallel degree.
-
-
-
Method Detail
-
addEnv
public void addEnv(java.lang.String key, java.lang.String value)Adds an environment variable.- Parameters:
key- the environment variable namevalue- the environment variable value
-
addParameter
public void addParameter(java.lang.String key, java.lang.String value)Adds a model initialization parameter.- Parameters:
key- the environment variable namevalue- the environment variable value
-
getInitParameters
public java.util.Map<java.lang.String,java.lang.String> getInitParameters()
Returns the python model initialization parameters.- Returns:
- the python model initialization parameters
-
createVirtualEnv
public void createVirtualEnv(java.lang.String name)
Creates python virtual environment if needed.- Parameters:
name- the virtual environment name
-
deleteVirtualEnv
public void deleteVirtualEnv(java.lang.String name)
Deletes python virtual environment.- Parameters:
name- the virtual environment name
-
installDependency
public void installDependency(java.nio.file.Path modelDir)
Installs model dependencies if needed.- Parameters:
modelDir- the model directory
-
getPythonExecutable
public java.lang.String getPythonExecutable()
Returns the python executable path.- Returns:
- the python executable path
-
setPythonExecutable
public void setPythonExecutable(java.lang.String pythonExecutable)
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
public java.lang.String getEntryPoint()
Returns the model's entrypoint file path.- Returns:
- the model's entrypoint file path
-
setEntryPoint
public void setEntryPoint(java.lang.String entryPoint)
Sets the model's entrypoint file path.- Parameters:
entryPoint- the model's entrypoint file path
-
getHandler
public java.lang.String getHandler()
Returns the python model's handler function.- Returns:
- the python file's handler function
-
setHandler
public void setHandler(java.lang.String handler)
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:
trueif the virtual environment is enabled,falseotherwise.
-
setEnableVenv
public void setEnableVenv(boolean enableVenv)
Sets whether to enable the python virtual environment.- Parameters:
enableVenv-trueto enable the virtual environment,falseto disable it.
-
setModelLoadingTimeout
public void setModelLoadingTimeout(int modelLoadingTimeout)
Sets the model loading timeout in seconds.- Parameters:
modelLoadingTimeout- the model loading timeout in seconds
-
-