Custom Images
Applications on Beam are run inside containers. A container is a lightweight VM that packages a set of software packages required by your application.
Containers are based on container images which are instructions for how a container should be built.
Because you are building a custom application, it is likely that your application depends on some custom software to run.
You can customize the container image used to run your Beam application with the Image
parameter.
Beam containers have two defaults to be aware of:
Default Container OS: Ubuntu 20.04
Default CUDA: CUDA 12.3
Adding custom base images
You can import existing images from remote Docker registries, like Dockerhub, Google Artifact Registry, ECR, Github Container Registry, Nvidia and more.
Just supply a base_image
argument to Image
.
from beam import endpoint, Image
image = (
Image(
base_image="docker.io/nvidia/cuda:12.3.1-runtime-ubuntu20.04",
python_version="python3.9",
)
.add_commands(["apt-get update -y", "apt-get install neovim -y"])
.add_python_packages(["torch"])
)
@endpoint(image=image)
def handler():
import torch
return {"torch_version": torch.__version__}
Adding Shell Commands
You can also run any shell commands you want in the environment before it starts up. Just pass them into the commands
field in your app definition.
Below, we’ll customize our image with requests
and some shell commands:
from beam import endpoint, Image
image = (
Image(python_version="python3.9")
.add_commands(["apt-get update", "pip install beautifulsoup4"])
.add_python_packages(["requests"])
)
@endpoint(cpu=1, memory="16Gi", gpu="T4", image=image)
def handler():
return {}
Adding Python packages
You can add Python packages to the runtime in the python_packages
field:
from beam import Image
Image(python_version="python3.9").add_python_packages=(["requests"])
python_version
is provided.Alternatively, you can pass in a path to a requirements.txt
file:
from beam import Image
Image(python_version="python3.9").add_python_packages=(["requirements.txt"])
Was this page helpful?