Sub topic 8
What a lock file cannot pin: Python, system libraries and CUDA
This chapter assumes you know basic Python, pip, the command line, and the basics of running a model with PyTorch or scikit-learn. You should also know how to read a simple Dockerfile.
A lock file records the exact Python packages selected for a project. It can record versions, dependency relationships, and, with tools such as pip-compile, hashes for package artifacts. It does not automatically freeze everything that runs beneath those packages.
The three layers of an ML environment
An ML process usually depends on several layers:
| Layer | Example | Usually pinned by a Python lock file? |
|---|---|---|
| Python packages | `numpy==2.1.0` | Yes |
| Python interpreter | CPython 3.11.9 | No |
| System libraries | glibc, `libgomp`, OpenSSL | No |
| GPU software | NVIDIA driver and CUDA libraries | No |
A lock file can require a package version that supports Python 3.10 or later, but it does not install Python 3.10. If one machine uses Python 3.10 and another uses Python 3.12, the package resolver may select different wheels. Some packages may compile from source on one machine and use a prebuilt wheel on another.
Native libraries create another source of drift. Packages such as NumPy, SciPy, and PyTorch contain or link to compiled code. That code may depend on the system C library, compiler runtime, CPU instruction set, or shared libraries such as libgomp. A successful installation does not prove that two machines execute the same native code.
CUDA has two important sides
A GPU installation has a host side and an application side.
- The host NVIDIA driver runs outside the container and communicates with the GPU.
- The CUDA user-space libraries used by the application can be supplied by the container image.
- The driver must support the CUDA version required by those libraries.
A lock file may pin a Python package such as torch, but it cannot pin the host driver or the host kernel. A container can make the user-space environment consistent, but it cannot make an incompatible driver compatible.
How to record the missing constraints
Record these requirements alongside the lock file:
- The exact Python version, often in
.python-version,pyproject.toml, or CI configuration. - The base image and operating-system family.
- Required system packages and their versions where practical.
- The GPU model, host driver minimum, and CUDA version supported by the image.
- CPU and GPU architecture assumptions, such as
x86_64oraarch64.
Containers help pin Python, system libraries, and CUDA userland together. Pin the base image by digest rather than relying only on a tag such as python:3.11-slim, because a tag can point to a different image later.
Exercise
A locked PyTorch environment works on one host but fails on another with a CUDA driver error. Which layer should you inspect first, and why?
Show answer
Inspect the host NVIDIA driver and its compatibility with the CUDA user-space libraries required by the image. The Python lock file does not control the host driver.