Running jobs with conda environment

Conda is known for its ability to create isolated environments for different projects. When running jobs on Lepton, you can use Conda to ensure your code runs with the exact dependencies needed, making your workloads more reliable and reproducible.

Here is an example of running a job with conda environment management on Lepton.

Prepare the conda environment

Let's say we have already set up a Dev Pod running with a conda installed image and file system mounted at /mnt. We can create a conda environment with pytorch and pack it to the file system.

# Create a conda environment with pytorch
conda create -n foo python=3.10.12
conda activate foo
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

# Pack the conda environment to file system
pip install conda-pack
conda pack -n foo -o /mnt/foo.tar.gz

The foo.tar.gz file contains the conda environment.

Create a job with conda environment

You can then load the conda environment in the job by adding the following command in the Run Command field during job creation. Making sure conda is installed in the container image.

# Load the conda environment
mkdir -p foo
cp /mnt/foo.tar.gz ./
tar -xzf foo.tar.gz -C foo

# Activate the conda environment
source foo/bin/activate

# Verify that the environment was installed
conda list

Once the job is created, you can view the job in the dashboard.

Lepton AI

© 2025