ML Cost Optimization
Intermediate 14 min read ML Cost Optimization

ML Workload Profiling

Measure the workload before you pay for it

Profile before you spend: utilization, memory, data pipeline, and latency footprints—this separates invoices into honest cost levers. Every optimization decision without a profile is astrology with a credit card.

profilingutilizationmemorybottleneckinstrumentation
Prerequisites: GPU Cost Drivers
Before we start

What you will learn

  • Instrument training and serving workloads for profiling
  • Identify utilization, memory, and I/O bottlenecks
  • Turn profile findings into cost decisions
Introduction

What is this?

ML workload profiling instruments compute, memory, data, and I/O over time — GPU%, memory footprint, data-load stalls, checkpoint costs, and latency percentiles — giving every cost decision a measured basis instead of a guess.

Motivation

Why do you need it?

  • You can't right-size a workload you've never measured.
  • Most 'GPU problems' are data or scheduling problems wearing GPU glasses.
  • Profiling exposes idle money: low utilization, oversized reservation, wasted checkpoint churn.
  • Profiles turn cost meetings from opinion into evidence.
Think about it

Mental model

Imagine

Sportscasters with lap timers and heart monitors

Think of

A live, granular MLOps profile

You could fit the stadium by feel, or you can time every heat, watch pulse (utilization), and count the refresh stops (stalls). The evidence says which runner (workload) to train harder and which lane (shape) they actually need.

Mechanics

How it works

  • Pick the profile: training run, or serve-time latency under load.
  • Instrument: GPU% and memory over time, load stalls, I/O and checkpoint duration, latency p50/p99.
  • Correlate: what was happening (data load? sync? queue) at each low-utilization interval.
  • Model it: replace the 'big number' with a per-phase decimal balance — train, eval, checkpoint.
  • Act: right-size shape, tune batch, move I/O off critical path, then re-profile.

Profile-to-decision loop.

Instrument
Correlate
Model phases
Act
Re-profile
Real world

In production

  • A training team's profiler finds 55% of time is eval+checkpoint, not training — they shrink eval frequency and trim checkpoints.
  • A serving team's latency profile under load reveals a GPU stall per request — data serialization, fixed, not instance size.
  • A profiling run shows memory is 20% of the box — the team downsizes 3 instances and keeps SLO.
Guidelines

Best practices

  • Profile the real workload under representative load — not a dimmed toy.
  • Automate a lightweight profile into each release pipeline.
  • Report profiles in cost reviews; 'here's the measurement' beats 'I feel like'.
  • Re-profile after every tuning change; profiles decay as data and traffic shift.
Watch out

Common mistakes

  • Profiling during lunch-hour logs and calling it 'the workload'.
  • Ignoring memory, staring only at GPU clocks.
  • Treating profile and cost as separate silos (both just hang on the same numbers).
  • Optimizing a phase that's 3% of the runtime (spending hours to shave nothing).
When things break

Debugging tips

  • GPU% low while waiting on logs — I/O is the bottleneck; prefetch/augment off the critical path.
  • Memory pinned at 99% — either correctly dense or shape-mismatched; check the memory/compute weighting.
  • Latency p99 swings while p50 is fine — one noisy phase (serialization, cold start) dominates; isolate it.
Interviews

Interview checkpoint

Practice

Hands-on lab

Profile a Training Loop
35 min · intermediate
In progress
Objectives
  • Instrument phases of a simulated training loop
  • Find the dominating cost phase
  • Decide a cost lever from the evidence

Profile a Training Loop

35 min · intermediate

0/2 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

A low GPU% while waiting suggests…

2

A profile taken once is valid forever.

Go deeper

Official documentation