When to use CPU mode
CPU profiling is useful when:- Developing on machines without GPU
- Testing code before GPU deployment
- Profiling data preprocessing pipelines
- Monitoring CPU memory in hybrid workflows
- Running on Apple Silicon without Metal support
CPU profiler
TheCPUMemoryProfiler mirrors the GPU profiler API:
Initialize profiler
Create a CPU memory profiler:No device configuration needed - automatically uses current process.
Profile functions
Profile function memory usage:The result includes:
name: Function nameduration: Execution time in secondssnapshot_before: Memory state before executionsnapshot_after: Memory state after executionpeak_rss: Peak resident set size
CPU memory tracker
TheCPUMemoryTracker provides real-time tracking with event history:
Event filtering
Query specific events:Memory timeline
Get memory usage over time:Export tracking data
Export CPU tracking events:- JSON export
- CSV export
- Timestamped export
CLI usage
The CLI automatically uses CPU mode when GPU is unavailable:Metrics explained
RSS (Resident Set Size)
RSS (Resident Set Size)
The portion of memory occupied by a process that is held in RAM:
- Includes all allocated pages in RAM
- Excludes swapped pages
- Can include shared libraries
VMS (Virtual Memory Size)
VMS (Virtual Memory Size)
Total virtual memory allocated to the process:
- Includes memory not yet paged in
- Larger than RSS
- Represents maximum potential memory usage
CPU percent
CPU percent
CPU utilization of the process:
- Percentage of one CPU core
- Can exceed 100% on multi-core systems
- Averaged over the interval
Integration with PyTorch/TensorFlow
Combine CPU profiling with framework profiling:- PyTorch CPU tensors
- TensorFlow CPU ops
- Data preprocessing
Best practices
Use for development
Profile locally before GPU deployment:
Monitor preprocessing
Profile data pipelines:
Export for analysis
Save tracking data:
Use consistent APIs
Same API as GPU profiling:
Next steps
PyTorch guide
GPU profiling for PyTorch
TensorFlow guide
GPU profiling for TensorFlow
CLI usage
Command-line profiling tools
Visualization
Generate memory usage plots