Bird
Raised Fist0
MLOpsdevops~20 mins

GPU support in containers in MLOps - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
GPU Container Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding GPU Access in Docker Containers

Which of the following Docker run commands correctly enables GPU support for a container?

Adocker run --enable-gpu nvidia/cuda:latest
Bdocker run --device=/dev/gpu nvidia/cuda:latest
Cdocker run --gpus all nvidia/cuda:latest
Ddocker run --gpu-enabled nvidia/cuda:latest
Attempts:
2 left
💡 Hint

Think about the official Docker flag that grants GPU access.

💻 Command Output
intermediate
2:00remaining
Output of GPU Detection Inside Container

What is the output of running docker run --gpus all nvidia/cuda:11.0-runtime nvidia-smi on a system with one NVIDIA GPU?

ADisplays GPU details including model, driver version, and usage stats
BCommand not found error
CNo devices were found
DPermission denied error
Attempts:
2 left
💡 Hint

Consider what nvidia-smi shows when GPU is accessible.

Configuration
advanced
2:30remaining
Configuring NVIDIA Container Toolkit

Which configuration file must be modified to enable the NVIDIA Container Toolkit to automatically provide GPU support for Docker containers?

A/etc/docker/daemon.json
B/usr/local/nvidia/toolkit.conf
C/etc/nvidia-container-runtime/config.toml
D/etc/docker/docker-compose.yml
Attempts:
2 left
💡 Hint

Think about Docker daemon configuration files.

Troubleshoot
advanced
2:30remaining
Diagnosing GPU Access Failure in Container

You run docker run --gpus all nvidia/cuda:11.0-base nvidia-smi but get the error nvidia-smi: command not found. What is the most likely cause?

AThe <code>--gpus</code> flag is misspelled
BThe host GPU drivers are not installed
CThe Docker daemon is not running
DThe container image does not include the <code>nvidia-smi</code> tool
Attempts:
2 left
💡 Hint

Consider what is inside the container image.

🔀 Workflow
expert
3:00remaining
Steps to Enable GPU Support in Kubernetes Pods

What is the correct order of steps to enable GPU support for a Kubernetes pod?

A3,1,2,4
B1,2,3,4
C2,1,3,4
D1,3,2,4
Attempts:
2 left
💡 Hint

Think about preparing nodes first, then enabling Kubernetes to manage GPUs, then using them in pods.

Practice

(1/5)
1. What is the main purpose of enabling GPU support in containers?
easy
A. To reduce the container's memory usage
B. To increase the container's disk space
C. To enable network access inside the container
D. To allow containers to use the host's GPU for faster computing

Solution

  1. Step 1: Understand GPU role in containers

    GPUs speed up computing tasks by handling parallel processing efficiently.
  2. Step 2: Identify GPU support purpose

    Enabling GPU support allows containers to access the host's GPU hardware for faster computation.
  3. Final Answer:

    To allow containers to use the host's GPU for faster computing -> Option D
  4. Quick Check:

    GPU support = faster computing [OK]
Hint: GPU support means using host GPU inside container [OK]
Common Mistakes:
  • Confusing GPU support with disk or memory changes
  • Thinking GPU enables network access
  • Assuming GPU support reduces container size
2. Which Docker command flag is used to enable GPU support when running a container?
easy
A. --gpus
B. --enable-gpu
C. --gpu-access
D. --use-gpu

Solution

  1. Step 1: Recall Docker GPU flag syntax

    The official Docker flag to enable GPU support is --gpus.
  2. Step 2: Verify other options

    Options like --enable-gpu, --gpu-access, and --use-gpu are incorrect or do not exist.
  3. Final Answer:

    --gpus -> Option A
  4. Quick Check:

    Docker GPU flag = --gpus [OK]
Hint: Docker GPU flag is exactly --gpus [OK]
Common Mistakes:
  • Using incorrect flag names like --enable-gpu
  • Confusing GPU flag with network or volume flags
  • Omitting the flag entirely
3. What will be the output of the command docker run --gpus all nvidia/cuda:11.0-base nvidia-smi if the host has a compatible NVIDIA GPU and drivers installed?
medium
A. Displays the NVIDIA GPU status and driver information
B. Shows an error: 'nvidia-smi command not found'
C. Runs the container but shows no GPU information
D. Fails with 'GPU not accessible' error

Solution

  1. Step 1: Understand the command purpose

    The command runs a container with full GPU access and executes nvidia-smi to show GPU info.
  2. Step 2: Check host requirements

    If the host has compatible NVIDIA GPU and drivers, nvidia-smi runs successfully inside the container.
  3. Final Answer:

    Displays the NVIDIA GPU status and driver information -> Option A
  4. Quick Check:

    Host GPU + drivers + --gpus = nvidia-smi output [OK]
Hint: If host GPU ready, nvidia-smi shows GPU info inside container [OK]
Common Mistakes:
  • Assuming nvidia-smi is missing inside official CUDA image
  • Ignoring host driver requirements
  • Expecting GPU info without --gpus flag
4. You run docker run --gpus all nvidia/cuda:11.0-base nvidia-smi but get the error: 'docker: Error response from daemon: could not select device driver'. What is the most likely cause?
medium
A. The container command syntax is incorrect
B. The Docker image does not support GPUs
C. The NVIDIA Container Toolkit is not installed on the host
D. The host has no internet connection

Solution

  1. Step 1: Analyze the error message

    The error indicates Docker cannot find a GPU device driver to assign to the container.
  2. Step 2: Identify missing component

    This usually happens if the NVIDIA Container Toolkit (nvidia-docker2) is not installed or configured on the host.
  3. Final Answer:

    The NVIDIA Container Toolkit is not installed on the host -> Option C
  4. Quick Check:

    Missing NVIDIA toolkit = device driver error [OK]
Hint: Device driver error means NVIDIA Container Toolkit missing [OK]
Common Mistakes:
  • Blaming Docker image for GPU support
  • Assuming syntax error causes this message
  • Thinking internet is required for this error
5. You want to run a container with access to only GPUs 0 and 1 on a host with 4 GPUs. Which Docker run command correctly limits GPU access?
hard
A. docker run --gpus 2 nvidia/cuda:11.0-base nvidia-smi
B. docker run --gpus 'device=0,1' nvidia/cuda:11.0-base nvidia-smi
C. docker run --gpus all nvidia/cuda:11.0-base nvidia-smi
D. docker run --gpus 'count=2' nvidia/cuda:11.0-base nvidia-smi

Solution

  1. Step 1: Understand GPU selection syntax

    To limit to specific GPUs 0 and 1, Docker uses the --gpus 'device=0,1' syntax to specify GPU IDs.
  2. Step 2: Evaluate options

    docker run --gpus 2 nvidia/cuda:11.0-base nvidia-smi requests any 2 GPUs but does not specify GPUs 0 and 1. docker run --gpus 'count=2' nvidia/cuda:11.0-base nvidia-smi uses invalid syntax count=2. docker run --gpus all nvidia/cuda:11.0-base nvidia-smi uses all GPUs.
  3. Final Answer:

    docker run --gpus 'device=0,1' nvidia/cuda:11.0-base nvidia-smi -> Option B
  4. Quick Check:

    Specify GPUs by device IDs with --gpus 'device=...' [OK]
Hint: Use --gpus 'device=0,1' to pick specific GPUs [OK]
Common Mistakes:
  • Using --gpus 2 without device IDs
  • Using invalid syntax like count=2
  • Assuming --gpus all limits GPUs