Skip to main content

Virtual Environment

Training large models can require more memory than a machine has in RAM or VRAM. GoodWoolf extends the available memory with disk-backed swap. This page describes two ways to do that: add swap directly on a host dedicated to training, or use the GoodWoolf Makefile to run Podman with isolated CPU, memory, and swap resources. Follow the section that matches your setup.

Host virtual memory​

Use host swap when the machine is fully dedicated to training and you want the host itself to provide additional virtual memory. This affects every process on the host, so it is a good fit only for dedicated training machines.

Create a swap file. This example creates a 90G swap file at /swapfile:

sudo fallocate -l 90G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile

On btrfs, replace the fallocate command with:

sudo btrfs filesystem mkswapfile --size 90g /swapfile

Enable the swap file immediately:

sudo swapon /swapfile

Make the swap file persistent by adding it to /etc/fstab:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Verify that the swap file is active:

swapon --show
free -h

After a reboot, the entry in /etc/fstab enables the swap file automatically.

Container virtual memory​

Use a Podman machine when you want to increase virtual resources in isolation from the host. The GoodWoolf Makefile provides machine-*, image-*, and container-* targets that call Podman directly.

Configure Podman helpers​

Install podman, gvproxy, and virtiofsd. Add the Podman helper directories so Podman can find gvproxy:

cat << 'EOF' >> ~/.config/containers/containers.conf

[engine]
helper_binaries_dir = [
"/usr/local/libexec/podman",
"/usr/local/lib/podman",
"/usr/libexec/podman",
"/usr/lib/podman",
"/usr/bin"
]
EOF

If virtiofsd is installed in /usr/libexec, add that directory to your shell path:

export PATH="$PATH:/usr/libexec"

GoodWoolf does not generate a helper config in the project directory. Podman reads the configuration from ~/.config/containers/containers.conf.

Create and manage a Podman machine​

A Podman machine is optional, but it gives the container a separate virtual memory environment. The Makefile uses the machine name goodwoolf-machine by default:

make machine-create

machine-create initializes the machine with MACHINE_ARGS, starts it, and then runs machine-swap. The default arguments are:

--cpus 2 --memory 2096 --disk-size 500 --swap 0

--swap 0 disables Podman's default zram swap. machine-swap then creates a real swap file at /var/swapfile sized by MACHINE_SWAP (default 480 GiB), enables it, and adds it to /etc/fstab. The disk must be larger than the swap file.

Override the defaults on the command line:

make machine-create \
MACHINE_ARGS="--cpus 4 --memory 8192 --disk-size 500 --swap 0" \
MACHINE_SWAP=480

Manage the machine with:

make machine-list
make machine-start
make machine-shell
make machine-stop
make machine-remove

Build the image and create the container​

Build the GoodWoolf image from the project Dockerfile, then create the container:

make image-create
make container-create

image-create builds localhost/goodwoolf:latest with PYTHON_VERSION from .python-version. The Dockerfile installs GoodWoolf with the CPU extra.

container-create creates $HOME/.goodwoolf and mounts it at /app, which is also the working directory. It also mounts GOODWOOLF_DATA at /app/data and GOODWOOLF_MODELS at /app/models, and sets those variables inside the container. If the host variables are not set, the defaults are $HOME/.goodwoolf/data and $HOME/.goodwoolf/models. The container uses --userns=keep-id, is named goodwoolf, and is not started. Start it and open a shell:

make container-start
make container-shell

The image runs as appuser. To run the shell as another image user, pass CONTAINER_USER:

make container-shell CONTAINER_USER=root

Manage the container with:

make container-list
make container-start
make container-stop
make container-shell
make container-remove

container-shell requires the container to be running. Multiple shells can be opened from separate terminals.

Makefile variables​

All Podman targets accept these variables. Override them on the command line, for example make image-create IMAGE=localhost/goodwoolf:dev or make container-shell CONTAINER_USER=root.

VariableUsed byMeaningDefault
MACHINEMachine, image, and container targetsPodman machine name and connection namegoodwoolf-machine
MACHINE_ARGSmachine-createArguments passed to podman machine init--cpus 2 --memory 2096 --disk-size 500 --swap 0
MACHINE_SWAPmachine-create and machine-swapReal swap file size in GiB480
IMAGEimage-* and container-createImage name and taglocalhost/goodwoolf:latest
CONTAINER_USERcontainer-shellOptional --user value for the shellUnset; image default is appuser
PYTHON_VERSIONimage-createPython base image version passed to the buildFirst line of .python-version
GOODWOOLF_DATAcontainer-createHost data directory mounted at /app/data$HOME/.goodwoolf/data
GOODWOOLF_MODELScontainer-createHost models directory mounted at /app/models$HOME/.goodwoolf/models

MACHINE_ARGS is passed directly to Podman, so Podman's own defaults apply to omitted options. Memory uses Podman's --memory value, in MiB. If GOODWOOLF_DATA or GOODWOOLF_MODELS are set in your environment, container-create uses those host paths; otherwise it uses the defaults above.