Templates
Base Python
For applications that only need pip packages and basic system tools.PyTorch and HuggingFace
For deep learning applications using PyTorch and the HuggingFace ecosystem.Custom CUDA Version
When you need a specific CUDA runtime version.Best Practices
Use a small base image
python:3.11-slim is small, which reduces container pull times during cold starts. The PyTorch CUDA wheels include the CUDA libraries, so GPU apps do not need a CUDA base image.
Pin all package versions
Unpinned versions can break your app when a new release introduces incompatibilities. Pin everything for reproducible builds.Clean up package caches
Removing caches reduces image size, which speeds up container pulls during cold starts.Use multi-stage builds for smaller images
Separate your build dependencies from your runtime to reduce the final image size.Store model weights on /data, not in the image
Download model weights to persistent storage (/data) in your setup() method rather than baking them into the Docker image. This keeps your image small, speeds up container pulls, and allows weights to be cached across runner restarts.
Common Issues
Python binary not found
Problem:python: command not found when using a custom base image.
Solution: Create symlinks so fal can find the Python binary:
CUDA not available
Problem:RuntimeError: No CUDA GPUs are available
Solution: Install the CUDA build of PyTorch. On python:3.11-slim, use the PyTorch index URL, for example --extra-index-url https://download.pytorch.org/whl/cu124.
If you use an nvidia/cuda base image, set the CUDA environment variables in your Dockerfile:
Dependency version conflicts
Problem:ImportError or version conflicts with pydantic, protobuf, or boto3.
Solution: Install the fal package (or these three packages) as the last RUN pip install step in your Dockerfile so they override any conflicting versions installed by earlier layers.