ML Observability with eBpf and OTel Pt. 1: Basics | ML Engineering and MLOps
Hi All
In this first part of a series on eBPF and Open Telemetry. We detail a couple of useful eBPF scripts tailored for an MLE with no background of the project(s). They focus on observability, performance monitoring and data collection - key areas where eBPF shines. I tried to make these as practical as possible, let's get to it.
1. Tracing Python Function Calls in ML Pipelines
Monitor which Python functions are being called in an ML training script (eg. PyTorch/Tensorflow) and their execution time. This helps identity bottlenecks in data loading, preprocessing or model training.
Tools:
* bpftrace (for high level scripting)
* libbpf (for custom C-based eBPF programs)
* Run the below script while your ML script is executing.
sudo bpftrace -e 'uprobe:python3:PyEval_CallObject { printf("Function called: %s\n", str(arg1)); }'
* Trace all torch.Tensor method calls in a PyTorch script
* The output will show which Python functions are being called (eg. torch.Tensor.forward)
* Useful in identifying slow functions in ML pipelines (eg. data augmentation, model inference)
* Correlate function calls with performance (eg. CPU/GPU usage).
2. Monitoring GPU Memory and Kernel Launches (CUDA)
Track GPU memory usage and CUDA kernel launches in ML workloads (eg. PyTorch/CUDA). This helps debug OOM errors or inefficient GPU memory usage.
Tools:
* bpftrace with CUDA probes
* nvidia-smi (for comparison)
sudo bpftrace -e 'tracepoint:cuda:kernel_start { printf("Kernel launched: %s\n", str(args->name)); }'
* Run this while your CUDA-accelerated ML script is running
* The output will show kernel names (eg. aten::matmul)
* Detect Memory leaks in GPU accelerated ML models
* Correlate kernel launches with GPU utilization (eg. using $nvidia-smi)
3. Measuring TCP Latency For Distributed Training
Monitor network latency between nodes in a distributed ML training setup (eg. PyTorch Distributed, Horovod). High latency can bottleneck gradient synchronization.
Tools:
* bpftrace with TCP probe
* ss or netstat (for comparison)
sudo bpftrace -e 'kprobe:tcp_retransmit_skb { @[comm] = count(); }'
* Run this on all nodes in your distributed training cluster.
* The output will show which processes are experiencing retransmissions.
* Diagnose network issues affecting distributed training performance.
* Correlate latency spikes with model convergence issues.
4. Profiling Disk I/O for Data Loading
Monitor disk I/O patterns during data loading (eg. PyTorch DataLoader). Slow I/O can bottleneck training loops.
Tools:
* bpftrace with block I/O probes
* iostat (for comparison)
sudo bpftrace -e 'tracepoint:block:block_rq_issue { printf("PID %d: %s %d bytes\n", pid, args->rwbs, args->bytes); }'
* Run this while your ML script is loading data
* The output will show which files are being read and their sizes.
* Identify slow data loading bottlenecks.
* Optimize data pipelines (eg, caching, prefetching)
5. Tracing System Calls for ML Containers
Monitor system calls made by ML containers (eg. Docker) to debug permission issues or unexpected behavior.
Tools:
* bpftrace with syscall probes
* strace (for comparison)
sudo bpftrace -e 'tracepoint:syscalls:sys_enter_open { printf("PID %d opened %s\n", pid, str(args->filename)); }'
Trace all open syscalls in a container
* Run this on the host while the container is running
* The output will show which files the container is accessing.
* Debug files access issues in ML containers
* Monitor unexpected syscalls (eg. due to misconfigured environments)
These experiments are all very practical and can be run on Linux, and provide insights that are valuable for ML workflows (eg. debugging latency, monitoring GPU usage or tracing system calls). Find the full source for this example here, that's it for now folks. Stay tuned for part 2 of this observability series where we'll look at integrating eBPF with our observability stack (Prometheus, Grafana and OTel), for device level observability at scale.
Later
- Ed

Comments
Post a Comment