Bird
Raised Fist0
MLOpsdevops~20 mins

GPU vs CPU inference tradeoffs in MLOps - Practice Questions

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
🎖️
Inference Hardware Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding latency differences between GPU and CPU inference

Which statement best explains why GPU inference can have higher latency for small batch sizes compared to CPU inference?

AGPUs have higher clock speeds than CPUs, causing delays in small tasks.
BCPUs use more cores than GPUs, making them faster for all batch sizes.
CGPUs require data transfer overhead and kernel launch time, which dominate at small batch sizes.
DGPUs cannot run inference on neural networks with small input sizes.
Attempts:
2 left
💡 Hint

Think about the extra steps GPUs need before starting computation.

💻 Command Output
intermediate
2:00remaining
Comparing CPU and GPU memory usage during inference

Given the command outputs below showing memory usage during inference, which output corresponds to GPU inference?

MLOps
CPU memory usage: 2.5 GB
GPU memory usage: 6.8 GB
ACPU memory usage: 2.5 GB
BGPU memory usage: 2.5 GB
CCPU memory usage: 6.8 GB
DGPU memory usage: 6.8 GB
Attempts:
2 left
💡 Hint

GPUs usually allocate more dedicated memory for model weights and activations.

🔀 Workflow
advanced
3:00remaining
Optimizing inference deployment for mixed CPU/GPU environments

You have a service that must handle both low-latency single requests and high-throughput batch requests. Which deployment strategy best balances GPU and CPU usage?

AUse CPU only to avoid GPU overhead and simplify deployment.
BUse CPU for single requests and GPU for batch requests to optimize latency and throughput.
CRoute all requests to GPU to maximize throughput, ignoring latency.
DUse GPU only for single requests and CPU for batch requests.
Attempts:
2 left
💡 Hint

Consider the strengths of CPU and GPU for different request sizes.

Troubleshoot
advanced
3:00remaining
Diagnosing slow GPU inference despite high GPU utilization

Your GPU inference shows high GPU utilization but slow overall response time. What is the most likely cause?

AData transfer between CPU and GPU is a bottleneck causing delays.
BThe model is too small to benefit from GPU acceleration.
CGPU drivers are outdated causing incorrect utilization reporting.
DThe batch size is too large causing GPU memory overflow.
Attempts:
2 left
💡 Hint

High GPU usage but slow response often means waiting on data movement.

Best Practice
expert
4:00remaining
Choosing hardware for cost-effective inference at scale

You manage a cloud deployment for ML inference with fluctuating demand. Which approach best balances cost and performance?

AUse CPU instances for low demand and scale GPU instances only when batch sizes increase.
BAlways use GPU instances to maximize speed regardless of cost.
CUse only CPU instances to minimize complexity and cost.
DUse GPU instances for all requests to simplify autoscaling.
Attempts:
2 left
💡 Hint

Think about matching hardware to workload patterns to save money.

Practice

(1/5)
1. Which of the following is a main advantage of using a GPU over a CPU for machine learning inference?
easy
A. Lower power consumption for small tasks
B. Cheaper hardware cost
C. Better performance on single-threaded tasks
D. Faster processing for large batches of data

Solution

  1. Step 1: Understand GPU design for parallelism

    GPUs have many cores designed to handle many operations at once, making them faster for large data batches.
  2. Step 2: Compare CPU and GPU strengths

    CPUs are better for single-threaded or small tasks, but GPUs excel at parallel processing, speeding up large inference jobs.
  3. Final Answer:

    Faster processing for large batches of data -> Option D
  4. Quick Check:

    GPU parallelism = Faster large batch inference [OK]
Hint: GPUs excel at many tasks at once, CPUs at few tasks fast [OK]
Common Mistakes:
  • Thinking GPUs always use less power
  • Assuming CPUs are cheaper for large-scale inference
  • Confusing single-threaded speed with parallel speed
2. Which command correctly runs a TensorFlow model inference on CPU only, ignoring GPUs?
easy
A. CUDA_VISIBLE_DEVICES=0 python inference.py
B. CUDA_VISIBLE_DEVICES='' python inference.py
C. CUDA_VISIBLE_DEVICES=-1 python inference.py
D. CUDA_VISIBLE_DEVICES=all python inference.py

Solution

  1. Step 1: Understand CUDA_VISIBLE_DEVICES usage

    Setting CUDA_VISIBLE_DEVICES to an empty string disables GPU visibility, forcing CPU usage.
  2. Step 2: Check each option's effect

    CUDA_VISIBLE_DEVICES='' python inference.py disables GPUs correctly; others either select GPUs or use invalid values.
  3. Final Answer:

    CUDA_VISIBLE_DEVICES='' python inference.py -> Option B
  4. Quick Check:

    Empty CUDA_VISIBLE_DEVICES disables GPU [OK]
Hint: Empty CUDA_VISIBLE_DEVICES means no GPU used [OK]
Common Mistakes:
  • Using 0 disables only GPU 0, not all GPUs
  • Using -1 is invalid for CUDA_VISIBLE_DEVICES
  • Assuming 'all' enables all GPUs but not disables
3. Given this Python snippet for inference timing:
import time
start = time.time()
# Run model inference here
end = time.time()
print(round(end - start, 2))

If GPU inference takes 0.05 seconds and CPU inference takes 0.5 seconds, what will be printed when running on CPU?
medium
A. 0.05
B. 50.0
C. 0.5
D. 5.0

Solution

  1. Step 1: Understand timing code output

    The code prints the elapsed time rounded to 2 decimals, so it shows seconds taken.
  2. Step 2: Match CPU inference time to output

    CPU inference takes 0.5 seconds, so the printed output is 0.5.
  3. Final Answer:

    0.5 -> Option C
  4. Quick Check:

    CPU time = 0.5 seconds printed [OK]
Hint: Printed time matches actual elapsed seconds rounded [OK]
Common Mistakes:
  • Confusing milliseconds with seconds
  • Choosing GPU time instead of CPU time
  • Misreading rounding precision
4. You run inference on a GPU but notice it is slower than CPU. Which fix is most likely to improve GPU inference speed?
medium
A. Increase batch size to better use GPU parallelism
B. Reduce batch size to avoid GPU overload
C. Disable GPU and force CPU usage
D. Use single-threaded CPU mode

Solution

  1. Step 1: Identify GPU performance factors

    GPUs perform best with larger batch sizes to utilize many cores efficiently.
  2. Step 2: Evaluate options for improving GPU speed

    Increasing batch size improves GPU throughput; reducing batch size or disabling GPU lowers performance.
  3. Final Answer:

    Increase batch size to better use GPU parallelism -> Option A
  4. Quick Check:

    GPU speed improves with larger batches [OK]
Hint: Bigger batches = better GPU use [OK]
Common Mistakes:
  • Thinking smaller batches speed up GPU
  • Disabling GPU to fix GPU slowness
  • Using single-thread CPU instead of GPU
5. You have a small model and low input volume but a tight budget. Which inference setup is best to minimize cost while maintaining reasonable speed?
hard
A. Use CPU inference with small batch sizes
B. Use GPU inference with large batch sizes
C. Use GPU inference with small batch sizes
D. Use CPU inference with large batch sizes

Solution

  1. Step 1: Analyze model size and input volume impact

    Small models and low input do not benefit much from GPU parallelism, so GPU cost is less justified.
  2. Step 2: Consider budget and batch size tradeoffs

    CPU inference with small batches reduces cost and matches low volume needs without GPU overhead.
  3. Final Answer:

    Use CPU inference with small batch sizes -> Option A
  4. Quick Check:

    Small model + low volume + budget = CPU small batch [OK]
Hint: Small model + low volume = CPU for cost savings [OK]
Common Mistakes:
  • Choosing GPU despite low volume and budget
  • Using large batches on CPU causing delays
  • Ignoring cost when selecting GPU