Package ai.djl.python.engine
Class PyEnv
- java.lang.Object
-
- ai.djl.python.engine.PyEnv
-
public class PyEnv extends java.lang.Object
Python engine environment.
-
-
Constructor Summary
Constructors Constructor Description PyEnv(boolean mpiMode)
Constructs a newPyEnv
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEnv(java.lang.String key, java.lang.String value)
Adds an environment variable.void
addParameter(java.lang.String key, java.lang.String value)
Adds a model initialization parameter.void
createVirtualEnv(java.lang.String name)
Creates python virtual environment if needed.void
deleteVirtualEnv(java.lang.String name)
Deletes python virtual environment.java.lang.String
getEntryPoint()
Returns the model's entrypoint file path.java.lang.String
getHandler()
Returns the python model's handler function.java.util.Map<java.lang.String,java.lang.String>
getInitParameters()
Returns the python model initialization parameters.int
getModelLoadingTimeout()
Returns the model loading timeout in seconds.int
getPredictTimeout()
Returns the prediction timeout in seconds.java.lang.String
getPythonExecutable()
Returns the python executable path.int
getTensorParallelDegree()
Returns the tensor parallel degree.void
installDependency(java.nio.file.Path modelDir)
Installs model dependencies if needed.boolean
isEnableVenv()
Returns whether the python virtual environment is enabled.boolean
isFailOnInitialize()
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(java.lang.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(java.lang.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(java.lang.String pythonExecutable)
Sets the python executable path.void
setTensorParallelDegree(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:
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
-
-