Lambda Stack
Introduction¶
Lambda Stack is an AI software stack from Lambda containing PyTorch, TensorFlow, CUDA, cuDNN and more. On the HPC you can run Lambda Stack via Apptainer (based on the official Dockerfiles). We have provided some pre-built container images (under /opt/nesi/containers/lambda-stack/) or you can build your own. In the following sections, we will show you how to run Lambda Stack in a Slurm job or interactively via JupyterLab.
You can list the available Lambda Stack version on NeSI by running:
$ ls /opt/nesi/containers/lambda-stack
lambda-stack-focal-20201130.sif
lambda-stack-focal-20201221.sif
lambda-stack-focal-20210105.sif
lambda-stack-focal-latest.sif
README
In the filenames above, the dates correspond to the date the image was built and the file with -latest will correspond to the most recent version.
Lambda Stack via Slurm¶
The following Slurm script can be used as a template for running jobs using Lambda Stack.
#!/bin/bash -e
#SBATCH --account nesi12345
#SBATCH --job-name lambdastack
#SBATCH --time 00:15:00 # required walltime
#SBATCH --ntasks 1 # number of MPI tasks
#SBATCH --cpus-per-task 1 # number of threads per MPI task
#SBATCH --gpus-per-task 1 # optional, only if a GPU is required
# path to the container image file (optionally replace with your own)
SIF=/opt/nesi/containers/lambda-stack/lambda-stack-focal-latest.sif
# clean environment
module purge
# for convenience store the apptainer command in an environment variable
# feel free to add additional binds if you need them
CONTAINER="apptainer exec --nv -B ${PWD} ${SIF}"
# run a command in the container
${CONTAINER} echo "Hello World"
Lambda Stack via Jupyter¶
The following steps will create a custom Lambda Stack kernel that can be accessed via NeSI's Jupyter service (based on the instructions at Jupyter_on_NeSI).
First, we need to create a kernel definition and wrapper that will launch the container image. Run the following commands on the Mahuika login node:
# path to the container image file (optionally replace with your own)
export SIF=/opt/nesi/containers/lambda-stack/lambda-stack-focal-latest.sif
# create a jupyter kernel using the Python within the container image
apptainer exec -B $HOME $SIF python -m ipykernel install --user \
--name lambdastack --display-name="Lambda Stack Python 3"
If successful this should report that a kernelspec has been installed.
Change to the kernelspec directory:
cd $HOME/.local/share/jupyter/kernels/lambdastack
and create a wrapper script for launching the kernel, named wrapper.sh:
#!/usr/bin/env bash
# path to the container image file (optionally replace with your own)
SIF=/opt/nesi/containers/lambda-stack/lambda-stack-focal-latest.sif
# clean environment
module purge
# unfortunately $HOME is not the canonical path to your home directory,
# we need to bind in canonical home path too so jupyter can find kernel
# connection file
homefull=$(readlink -e $HOME)
# for convenience store the container command in an environment variable
# feel free to add additional binds if you need them
CONTAINER="apptainer exec --nv -B ${HOME},${homefull},${PWD} ${SIF}"
# run a command in the container
echo ${CONTAINER} python3 $@
${CONTAINER} python3 $@
Make the wrapper script executable:
chmod +x wrapper.sh
Next, edit the kernel.json to change the first element of the argv
list to point to the wrapper script we just created. The file should
look like this (change <username> to your NeSI username):
{
"argv": [
"/home/<username>/.local/share/jupyter/kernels/lambdastack/wrapper.sh",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Lambda Stack Python 3",
"language": "python"
}
After refreshing the NeSI JupyterLab your Lambda Stack Python kernel should show up as "Lambda Stack Python 3".