Class PyEnv

java.lang.Object
ai.djl.python.engine.PyEnv

public class PyEnv extends Object
Python engine environment.
  • Constructor Details

    • PyEnv

      public PyEnv(boolean mpiMode)
      Constructs a new PyEnv instance.
      Parameters:
      mpiMode - true to use MPI launcher
  • Method Details

    • addEnv

      public void addEnv(String key, String value)
      Adds an environment variable.
      Parameters:
      key - the environment variable name
      value - the environment variable value
    • addParameter

      public void addParameter(String key, String value)
      Adds a model initialization parameter.
      Parameters:
      key - the environment variable name
      value - the environment variable value
    • getInitParameters

      public Map<String,String> getInitParameters()
      Returns the python model initialization parameters.
      Returns:
      the python model initialization parameters
    • createVirtualEnv

      public void createVirtualEnv(String name)
      Creates python virtual environment if needed.
      Parameters:
      name - the virtual environment name
    • deleteVirtualEnv

      public void deleteVirtualEnv(String name)
      Deletes python virtual environment.
      Parameters:
      name - the virtual environment name
    • installDependency

      public void installDependency(Path modelDir)
      Installs model dependencies if needed.
      Parameters:
      modelDir - the model directory
    • getPythonExecutable

      public String getPythonExecutable()
      Returns the python executable path.
      Returns:
      the python executable path
    • setPythonExecutable

      public void setPythonExecutable(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 String getEntryPoint()
      Returns the model's entrypoint file path.
      Returns:
      the model's entrypoint file path
    • setEntryPoint

      public void setEntryPoint(String entryPoint)
      Sets the model's entrypoint file path.
      Parameters:
      entryPoint - the model's entrypoint file path
    • getHandler

      public String getHandler()
      Returns the python model's handler function.
      Returns:
      the python file's handler function
    • setHandler

      public void setHandler(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