HyperAIHyperAI

Dependency Management

If you need to install additional dependencies, you can configure them as follows. These configuration files will be automatically executed when the deployment service starts, without manual intervention.

Dependency Management for Workspace and Model Deployment

Before deploying a model, it is generally recommended to complete model development and testing in the "Workspace" first. This approach has the following benefits:

  1. You can interactively install and test dependencies in the workspace
  2. Prepare the required dependency environment using pip install --user or by creating a conda environment
  3. After the environment is ready, you can directly bind the workspace directory (/openbayes/home) to the model deployment
  4. Avoid repeatedly installing dependencies during the model deployment phase, improving deployment efficiency

Best Practice Workflow

  1. In the workspace:

    • Use pip install --user xxx to install Python packages to /openbayes/home/.pylibs
    • Or create a conda environment in /openbayes/home/your_env_name
    • Complete model development and testing
  2. During model deployment:

    • Bind the workspace's /openbayes/home directory to the model deployment
    • If using a custom conda environment, activate it in start.sh
    • The model deployment will automatically inherit the dependency environment prepared in the workspace

This approach is particularly suitable for model deployment scenarios that require complex dependency environments.

Overview of Dependency Management Methods

1. PyPI Dependency Management

Installing via requirements.txt

If a file named requirements.txt exists in the root directory of the model deployment folder, the model deployment will automatically execute the pip install -r requirements.txt command before startup to install the PyPI libraries declared in it.

The file format follows the standard Python requirements.txt format. Example:

requirements.txt
jieba
tqdm==4.11.2

Using pip --user to Install Persistent Dependencies

  • Dependencies installed using the pip install --user xxx command will be saved in the /openbayes/home/.pylibs directory
  • These dependencies remain available after container restarts
  • Note: Do not use the --user parameter in newly created conda environments to avoid dependency conflicts

2. Conda Dependency Management

Installing via conda-packages.txt

Model deployment supports Conda package installation. Before the deployment service starts, it will automatically look for a file named conda-packages.txt in the root directory of the deployment. The file format follows:

[channel::]package[=version[=buildid]]

Example:

conda-packages.txt
conda-forge::rdkit
conda-forge::pygpu

Creating a Custom Conda Environment

  • You can create a new conda environment under /openbayes/home
  • Example:
conda create -p /openbayes/home/open-mmlab python=3.9 -y
conda activate /openbayes/home/open-mmlab

Activating Conda Environment in start.sh

:::note All images of HyperAI use Conda for environment management, so start.sh typically needs to activate the default base environment first, even when not using a custom conda environment. :::

If using a custom conda environment, you need to explicitly activate that environment in start.sh. Example:

start.sh
#!/bin/bash

# First activate the default base environment
source /usr/local/etc/profile.d/conda.sh
conda activate base

# If using a custom environment, continue to activate the custom environment
conda activate /openbayes/home/open-mmlab

# Start the model service
python app.py

:::note If not using a custom conda environment, but instead using the system default environment or dependencies installed via pip install --user, you still need to activate the base environment, but no additional environment activation steps are required. :::

3. System Dependency Management

Installing via dependencies.sh

For dependencies that are not from Conda or PyPI, you can provide a file named dependencies.sh in the root directory. It will be automatically executed by bash when the model deployment starts, and its execution occurs before the installation of dependencies from requirements.txt and conda-packages.txt.

Example:

dependencies.sh
apt update && apt install tree -y

Dependency Installation Order

When multiple dependency configuration files exist simultaneously, the installation order is:

  1. dependencies.sh
  2. conda-packages.txt
  3. requirements.txt

Best Practice Recommendations

  1. For Python dependencies that need to be persisted:

    • Use pip install --user xxx to install to the user directory
    • Create a custom Conda environment under /openbayes/home
    • Include requirements.txt/conda-packages.txt files in the code repository
    • If using a custom conda environment, ensure proper activation in start.sh
  2. For system dependencies:

    • Save installation commands in dependencies.sh
    • They will be automatically executed each time the container starts
  3. Notes:

    • Dependencies on the system disk will be lost after container restart
    • Content in the working directory /openbayes/home will be persisted
    • It is recommended to save important dependency environments in the working directory
    • When using a custom conda environment, ensure the environment path in start.sh is correct