Skip to content

Operator task guide

How to troubleshoot Singularity and Apptainer GPU container failures

A GPU container that works under Docker on a workstation often fails on an HPC cluster because Singularity and Apptainer require explicit host driver bind flags (--nv for NVIDIA or --rocm for AMD), preserve or strip environment variables differently under --contain and --cleanenv, and inherit small default /dev/shm limits from the host or scheduler.

Verify host-to-container driver binding, visible device variables, shared memory sizing, and Slurm srun rank launch inside an interactive allocation before rewriting application code. When external remote build endpoints are unavailable or deprecated, use local unprivileged or --fakeroot builds with verified base images.

Reviewed . Reference guidance is not a diagnosis of your workload.

Step-by-step method

  1. 1

    Verify --nv or --rocm driver bind mounts inside the allocation

    First confirm the host scheduler actually allocated a GPU and that the container runtime binds the host kernel-matched user-space driver libraries. A mismatched or missing --nv or --rocm flag leaves PyTorch unable to locate libcuda.so.1 or libamdhip64.so even when the base image contains CUDA or ROCm toolkits.

    nvidia-smi
    apptainer exec --nv image.sif nvidia-smi
    apptainer exec --nv image.sif ldconfig -p | grep -E 'libcuda|libnvidia-ml'
    apptainer exec --nv image.sif python3 -c "import torch; print(torch.cuda.is_available(), torch.cuda.device_count())"
  2. 2

    Audit --contain, --cleanenv, and Slurm environment forwarding

    Strict isolation flags such as --cleanenv or --containall can drop CUDA_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES, NCCL transport settings, and SLURM_* variables needed by distributed launchers. Inspect the exact environment seen by a rank inside the container rather than assuming login-shell exports carry over.

    srun --ntasks=2 --gpus-per-task=1 apptainer exec --nv image.sif env | grep -E 'CUDA|ROCR|HIP|SLURM|NCCL|RCCL|OMPI'
    # Forward explicit variables when --cleanenv is required:
    APPTAINERENV_NCCL_DEBUG=INFO apptainer exec --nv --cleanenv image.sif python3 -c "import os; print(os.environ.get('CUDA_VISIBLE_DEVICES'))"
  3. 3

    Check /dev/shm capacity and container writable-tmpfs paths

    Multi-GPU PyTorch DataLoader workers and NCCL shared-memory transports fail with Bus error or shm allocation failures when /dev/shm is capped or read-only inside the container. Measure available /dev/shm from inside the running container and bind a scratch directory if the image needs temporary runtime space.

    apptainer exec --nv image.sif df -h /dev/shm
    apptainer exec --nv --bind "$TMPDIR:/tmp" image.sif python3 -c "import torch.multiprocessing as mp; print(mp.get_sharing_strategy())"
  4. 4

    Replace defunct remote build calls with local --fakeroot or scratch builds

    Legacy Singularity workflows that call retired external remote builders fail at DNS resolution or authentication before a container ever runs. Pull OCI images directly via docker:// into a local SIF or build locally with --fakeroot on clusters that enable user namespaces, keeping the definition file pinned to exact digests.

    apptainer pull pytorch_24.sif docker://nvcr.io/nvidia/pytorch:24.07-py3
    apptainer build --fakeroot custom_gpu.sif custom.def

Container GPU symptom matrix

Signals, meanings and actions for how to troubleshoot singularity and apptainer gpu container failures.
SignalWhat it meansNext action
torch.cuda.is_available() is False inside containerHost driver libraries were not bound or CUDA_VISIBLE_DEVICES was stripped or masked.Re-test with explicit --nv (or --rocm), verify host nvidia-smi inside the same Slurm job, and inspect --cleanenv variable forwarding.
cudaErrorInsufficientDriver or symbol lookup errorContainer CUDA runtime or compatibility layer disagrees with the host NVIDIA kernel driver.Compare host driver version against the container CUDA version and remove conflicting user-site LD_LIBRARY_PATH entries.
Bus error or NCCL shared-memory allocation failureContainer /dev/shm is exhausted by PyTorch DataLoader workers or NCCL SHM segments.Check df -h /dev/shm inside the container, reduce num_workers or set NCCL_SHM_DISABLE only as a controlled diagnostic step.
Remote build endpoint or unprivileged build failureThe definition or script targets a retired external remote builder or lacks user-namespace privileges.Switch to local docker:// pulls or cluster-supported --fakeroot / build-node workflows and record the exact SIF digest.

Evidence checklist

  • Exact singularity or apptainer CLI flags and Slurm sbatch/srun command
  • Container SIF build source or base image tag and digest
  • Host nvidia-smi or rocm-smi output inside the same allocation
  • Container-side env output for CUDA, ROCR, NCCL, and SLURM variables
  • Output of df -h /dev/shm and the earliest failing rank stderr

Common mistakes

Testing the SIF on a CPU login node

Login nodes frequently lack GPUs or matching driver devices. Always validate --nv or --rocm bindings inside an interactive GPU allocation.

Hardcoding host LD_LIBRARY_PATH from Conda or modules

Injecting host toolkit libraries over container libraries causes ABI and symbol collisions. Clear unintended host paths with --cleanenv and forward only required runtime variables.

Ignoring /dev/shm limits on multi-worker DataLoaders

A container can have plenty of GPU HBM and host RAM while still crashing with SIGBUS because /dev/shm is capped to a small fraction of node memory.

Frequently asked questions

Why does nvidia-smi work on the host node but fail inside Singularity or Apptainer?

Singularity and Apptainer do not mount host NVIDIA driver libraries or device nodes automatically. You must pass --nv (or --rocm for AMD GPUs) and run inside a job allocation where devices are exposed.

Should I use --nv or install the NVIDIA driver inside the container image?

Never install kernel drivers inside the container image. Always rely on --nv so the runtime binds user-space driver libraries from the host that match the host Linux kernel module.

How do I pass NCCL debug variables when using --cleanenv?

Prefix variables with APPTAINERENV_ (or SINGULARITYENV_) on the host, or pass --env NCCL_DEBUG=INFO directly on the exec command so they survive --cleanenv isolation.

Live diagnosis, no signup

Upload your GPU log. Find what happened first.

Get the likely cause, supporting evidence, and next safe steps with the same cloud reasoning used by paid plans. A crash the engine recognizes is answered in seconds, then checked by an independent AI review that updates this page when it finishes. A crash it does not recognize waits for the AI's own answer, which can take a few minutes. No account, card, or installation. Logs are masked at Denpex API ingress and are not saved to account history.

Before uploading, review cloud data handling and local options.

training_logs.txt
No log to hand? Try one:

Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.

3 free cloud diagnoses per day

Try Denpex for 30 days. FREE.

No credit card. No automatic subscription. See whether Denpex helps with an incident you already understand.

Start your free 30-day Team evaluation

Up to 50 diagnoses a day for 30 days. Verify your work email to activate an eligible company evaluation, then replay a resolved incident and compare the evidence and next steps with your team's confirmed cause.

Use your company email, for example alex@yourcompany.com.

Who qualifies?

Company email domains activate the free 30-day Team evaluation (up to 50 diagnoses a day) after an email and domain check, whatever mail provider you use. If we cannot verify your domain automatically, support reviews it: write to support@denpex.com. Free local diagnosis in the editor extension needs no account.

Using a personal email (Gmail, Outlook, Naver, QQ) or solo cluster? Create a free $0 account (no work email required) to save 7-day history and unlock AI fallback, or send a cluster crash log for a live walkthrough.

Apply the method to your incident

Use the three free diagnoses to review your error and relevant evidence. Keep reference guidance separate from the cause and recovery status of your own workload.

Diagnose your incident