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:
- You can interactively install and test dependencies in the workspace
- Prepare the required dependency environment using pip install --useror by creating a conda environment
- After the environment is ready, you can directly bind the workspace directory (/openbayes/home) to the model deployment
- Avoid repeatedly installing dependencies during the model deployment phase, improving deployment efficiency
Best Practice Workflow
- 
In the workspace: - Use pip install --user xxxto install Python packages to/openbayes/home/.pylibs
- Or create a conda environment in /openbayes/home/your_env_name
- Complete model development and testing
 
- Use 
- 
During model deployment: - Bind the workspace's /openbayes/homedirectory 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
 
- Bind the workspace's 
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:
jieba
tqdm==4.11.2Using pip --user to Install Persistent Dependencies
- Dependencies installed using the pip install --user xxxcommand will be saved in the/openbayes/home/.pylibsdirectory
- These dependencies remain available after container restarts
- Note: Do not use the --userparameter 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-forge::rdkit
conda-forge::pygpuCreating 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-mmlabActivating 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:
#!/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:
apt update && apt install tree -yDependency Installation Order
When multiple dependency configuration files exist simultaneously, the installation order is:
- dependencies.sh
- conda-packages.txt
- requirements.txt
Best Practice Recommendations
- 
For Python dependencies that need to be persisted: - Use pip install --user xxxto 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
 
- Use 
- 
For system dependencies: - Save installation commands in dependencies.sh
- They will be automatically executed each time the container starts
 
- 
Notes: - Dependencies on the system disk will be lost after container restart
- Content in the working directory /openbayes/homewill 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.shis correct