Container Profile (Dockerfile)
HyperGAN provides a pinned, multi-stage OCI container profile in Dockerfile built from the installed wheel rather than a raw repository checkout.
Container Contract#
- Base image:
python:3.12-slim-bookworm(multi-stagebuilderandruntimestages) - Installed artifact: The
builderstage builds a wheel into/dist(python -m pip wheel --no-cache-dir --no-deps --wheel-dir /dist .), and theruntimestage installs that wheel into the system environment. - Unprivileged user: Runs as
hypergan:hypergan(uid=1000,gid=1000) with working directory/workspace. - Mount points:
/data: Input dataset directory (mount read-only when training or validating image folders)./runs: Output run directory and persistent global registry (HYPERGAN_STATE_DIR=/runs/.hypergan)./workspace: Project working directory for.tomlrecipes andhypergan.tomlworkspace configs.
- Entrypoint & signals:
ENTRYPOINT ["python", "-m", "hypergan"](exec form, sopython -m hyperganruns as PID 1 without an intermediate shell wrapper and preserves exit codes).CMD ["--help"]STOPSIGNAL SIGINT, matchinghypergan.run_signals.GracefulStopsodocker stoptriggers a clean checkpoint-and-exit at the next update boundary.
Building the Image#
1. Lightweight CLI Image (Default)#
The default build installs the zero-dependency core package (new, validate, inspect, ps, status, logs, runs, diff, report, doctor):
docker build -t hypergan:cli .Verify the image outside the source tree:
docker run --rm hypergan:cli --version
docker run --rm hypergan:cli --help2. Training & Web Observatory Image#
Pass --build-arg EXTRAS=... to install optional runtime extras (for example train,image,web):
docker build --build-arg EXTRAS=train,image,web -t hypergan:train .Recording the Source Commit#
.dockerignore keeps .git out of the build context, so the image cannot read its own commit. Pass it with --build-arg HYPERGAN_COMMIT=... and the wheel stamps it into _build_provenance.json, which every run then records as hypergan_commit:
docker build --build-arg HYPERGAN_COMMIT="$(git rev-parse HEAD)" --build-arg EXTRAS=train,image,web -t hypergan:train .Without the argument the image records the commit as unknown (null). The image cannot tell whether the checkout had uncommitted changes, so dirty is always unknown (null).
Data, Workspace, and Run Mounts#
Mount /data read-only and /runs read-write so training artifacts, checkpoints, and the run registry (HYPERGAN_STATE_DIR=/runs/.hypergan) persist on the host:
mkdir -p ./workspace ./runs
# Scaffold a starter project inside /workspace sized from /data
docker run --rm \
--mount type=bind,src="$(pwd)/data",dst=/data,readonly \
--mount type=bind,src="$(pwd)/runs",dst=/runs \
--mount type=bind,src="$(pwd)/workspace",dst=/workspace \
hypergan:cli new --project /workspace/my_gan --dataset /data
# Validate the generated configuration and dataset inventory
docker run --rm \
--mount type=bind,src="$(pwd)/data",dst=/data,readonly \
--mount type=bind,src="$(pwd)/runs",dst=/runs \
--mount type=bind,src="$(pwd)/workspace",dst=/workspace \
hypergan:train validate /workspace/my_gan/configs/dcgan.toml --dataRunning Training, Viewer, and Signals#
Headless Training (--no-server)#
For batch or automated container runs without a web listener, pass --no-server:
docker run --rm \
--mount type=bind,src="$(pwd)/data",dst=/data,readonly \
--mount type=bind,src="$(pwd)/runs",dst=/runs \
--mount type=bind,src="$(pwd)/workspace",dst=/workspace \
hypergan:train train /workspace/my_gan/configs/dcgan.toml \
--run-dir /runs/dcgan-exp1 \
--steps 1000 \
--no-serverPublishing the Web Observatory (-p 8765:8765)#
The container exposes port 8765. Publish -p 8765:8765 to access the Web Observatory from the host browser:
docker run --rm \
-p 8765:8765 \
--mount type=bind,src="$(pwd)/runs",dst=/runs \
hypergan:train view /runs --host 0.0.0.0 --port 8765 --no-browserGraceful Stop (STOPSIGNAL SIGINT)#
Because Dockerfile sets STOPSIGNAL SIGINT and uses the exec-form ENTRYPOINT ["python", "-m", "hypergan"], stopping a running training container with docker stop (or docker kill --signal=SIGINT) delivers SIGINT directly to PID 1:
docker stop --time 30 <container_id>HyperGAN catches SIGINT, finishes the current update, writes an atomic checkpoint and updated manifest.json (status = "stopped"), and exits. Docker sends SIGKILL when the grace period runs out: 10 seconds unless you pass --time (-t). Choose a time longer than one update plus one checkpoint write for your model. Otherwise the container is killed before the checkpoint is durable, and the run resumes from its previous checkpoint.
GPU Pass-Through (--gpus all)#
When running with a CUDA-enabled PyTorch installation and the NVIDIA Container Toolkit on Linux, pass --gpus all:
docker run --rm --gpus all \
--mount type=bind,src="$(pwd)/data",dst=/data,readonly \
--mount type=bind,src="$(pwd)/runs",dst=/runs \
--mount type=bind,src="$(pwd)/workspace",dst=/workspace \
hypergan:train doctorQualification Boundaries#
- The default
Dockerfilevalidates the installed package, CLI entrypoints, volume mounts, and signal handling onpython:3.12-slim-bookworm. - Multi-GPU and multi-node cluster container profiles follow their respective hardware and cluster qualification gates in
docs/distributed.mdanddocs/cuda.md.