Editor’s introduction
Magneton, a differential energy profiler, compares operator-level energy consumption across nine machine learning systems with similar functionality to identify inefficiencies. It detects known and previously unknown software energy wastes by matching equivalent dataflow subgraphs and highlighting code regions with excessive energy use. The study confirms 15 known issues and discovers 8 new ones, seven of which have been validated by developers. The approach relies on the assumption that at least one energy-efficient peer exists for comparison, meaning inefficiencies common to all systems go undetected. Additionally, the tool requires developer-provided inputs to trigger the energy-inefficient behavior and has limited visibility into certain types of idleness, such as CPU busy-waiting or host-side scheduling delays.
Introduction
With the growing prevalence of large language models (LLMs) and other machine learning (ML) applications, the training and deployment of ML models have become massive, energy-intensive operations, often spanning thousands of GPUs in distributed clusters. For example, generating a single response from Llama3-405B consumes over 3300 Joules (enough to power a 60W lamp for a minute) on an NVIDIA H100 GPU, while training GPT-4 is estimated to consume 50 GWh. Optimizing ML system energy efficiency is therefore critical for both cost and sustainability. In response, major companies and government agencies have launched initiatives to promote energy-efficient practices.
Most existing energy optimization efforts focus on improving hardware energy efficiency, such as limiting GPU power, tuning GPU frequency, or scheduling tasks on low-power GPUs in heterogeneous clusters. However, another significant but often overlooked source of energy inefficiency is poor software design, which we call software energy waste. For example, PyTorch’s DistributedDataParallel (DDP) manager, a package commonly used for data-parallel training, requires all GPUs to perform asynchronous all-reduce operations during data-parallel training. If data is imbalanced, GPUs that finish early still have to synchronize until the slowest worker completes its computation, rather than entering an idle state. This issue is symptomatic of a broader class of problems in distributed ML systems, where subtle inefficiencies in communication or synchronization logic can lead to significant energy waste without impacting end-to-end latency. Since hardware-centric methods cannot distinguish such redundant operations from useful work, they remain ineffective at addressing software energy waste.
Addressing software energy waste requires a two-pronged approach. First is detecting (identifying the symptom of) energy waste, and second is diagnosing (finding the root cause of) it. Automating the detection is important because modern ML systems often consist of millions of lines of code, and manually detecting software energy waste would be time-consuming and error-prone. Diagnosis is important, because even when an energy hotspot is found, developers may lack clear guidance on whether and how the energy hotspot can be restructured to drain less energy.
In this paper, we first study real-world ML systems and make two observations. First, due to the widespread use of generative AI, each popular ML system—from distributed training systems like Megatron-LM and DeepSpeed to serving systems like vLLM and SGLang—typically has several competing alternatives with similar functionality. Second, we analyze 8 widely-used ML systems across three categories: LLM frameworks, ML libraries, and image generation and observe significant differences in energy consumption when performing the same tasks. These findings suggest that the energy consumption differences among functionally similar ML systems can be leveraged to identify potential opportunities for reducing waste.
Building on this insight, we propose a new energy profiling method, differential energy debugging, to detect and diagnose software energy waste in ML systems. The basic idea is that when several ML systems implement the same task, their differences in implementation can lead to different energy footprints. By comparing these systems, we can detect energy-inefficient implementations whose energy consumption is significantly higher than their peers, and we can use the more efficient implementations to provide concrete guidance on how the wasteful implementation can be corrected.
A core challenge of differential energy debugging is that ML systems have very different internal code structures, which makes direct source-code comparison unreliable. This motivates the need for a common abstraction level at which different systems can be compared. A too coarse-grained abstraction level, such as a full transformer iteration, includes many operations together and therefore hides the root cause of energy waste. A too fine-grained abstraction level such as CUDA code is impractical due to unavailable source code and lack of hardware telemetry to measure energy at that level.
Case Studies
To better understand the characteristics of software energy waste and why it is difficult to detect, we analyze three real-world cases collected from public GitHub issues and developer forums. These cases come from three widely used ML systems: PyTorch, an ML library; HuggingFace Transformers, an LLM inference framework; and Stable Diffusion, an image generation application. These cases have different root causes and exhibit different energy waste patterns. We selected these three cases to provide a representative coverage of a broad range of energy inefficiency issues in modern ML systems.
Case 1: Redundant Communication. In distributed training, the energy cost of a job is determined not only by the computation each worker performs but also by the synchronization semantics that bind workers together: a collective that requires participation from every rank forces stragglers and finishers alike to keep their GPUs resident. PyTorch’s DistributedDataParallel (DDP) is a widely used package for parallelizing model training across multiple GPUs. It provides the Join API for handling uneven inputs across GPUs, which forces finished GPUs to continue issuing all-reduce calls with zero-valued tensors so that the remaining GPUs’ collectives can complete. However, these zero-tensor all-reduces are real NCCL kernels that occupy SMs on the GPU. As a result, the early-finished GPUs cannot enter idle mode and waste energy.
To reproduce this energy waste, we need an uneven workload. This is in fact common in post-training with variable-length datasets like ShareGPT and UltraChat. To avoid wasted computation on padding, variable-length sequences are typically packed into fixed-length batches. Since length distributions differ across data-parallel shards, each GPU ends up with a different number of batches.
Because Join only adds communication on the already-finished GPUs, it does not affect end-to-end training time or model accuracy. As a result, existing performance profilers cannot flag this behavior as anomalous. Even if an energy profiler reports high power usage on the finished GPUs, it is difficult to attribute the root cause to the all-reduces inside Join that prevent the GPU from entering idle mode.
Case 2: High Energy Operator. HuggingFace Transformers has a custom Conv1D layer that invokes torch.addmm to fuse the bias addition into the GEMM kernel. In contrast, PyTorch’s nn.Linear layer invokes torch.matmul followed by a separate bias add. Intuitively, the fused torch.addmm should be more efficient. However, developers find that on large FP16 shapes, cuBLAS selects a less efficient GEMM kernel for torch.addmm than for torch.matmul, making the fused path have more global memory reads and become more energy-hungry than the unfused one.
Case 3: Configuration Mismatch. Stable Diffusion is a widely deployed image generation model. It uses PyTorch as its underlying framework, which uses higher-performance TensorFloat-32 (TF32) matrix multiplication as the default configuration before v1.11. However, PyTorch disables TF32 for matmul by default since v1.12 due to numerical-precision concerns for general-purpose users. Stable Diffusion’s default configuration does not override this setting, even though its diffusion-based generative workload is robust to the small precision loss from TF32. As a result, it incurs both performance loss and unnecessary energy consumption, increasing the end-to-end energy consumption by 12.5%.
Approach to Address Energy Inefficiency
To detect energy inefficiency, an intuitive way is to use traditional performance profilers, which primarily trace execution time and resource utilization. However, these tools are fundamentally insufficient for energy analysis because execution time may not be a perfect proxy for energy consumption. For example, in Case 2 (§2.1), a performance profiler would report no significant performance degradation since both APIs show similar execution times even if they have completely different energy consumption. More generally, operations off the critical path (most notably asynchronous collective communication, which in distributed training is overlapped with computation by design) do not affect end-to-end performance and therefore remain invisible to performance profilers, even when they consume large amounts of energy.
Since performance profilers are insufficient for detecting and diagnosing energy inefficiency, we need accurate energy profiling tools to guide the optimization. However, existing energy profilers suffer from two key limitations. First, their sampling rates are too low to provide fine-grained measurements, which is needed to capture the energy consumption of short-lived operators with milliseconds of latency. Second, and more fundamentally, even with operator-level energy data, it remains unclear whether an energy hotspot truly represents an optimization opportunity. For example, matrix multiplication is almost always an energy hotspot, but its implementation may already be optimally efficient. Thus, operator-level profiling alone cannot determine whether excess energy use is avoidable.
Another potential solution to pinpointing software energy waste is to identify code patterns associated with waste using static analysis. However, as shown in §2.1, energy waste has diverse root causes, and diagnosing them requires deep semantic and domain-specific knowledge that static analyzers lack. For example, in case 3, locating an incorrectly set allow_tf32 flag as the root cause among thousands of PyTorch configurations requires domain knowledge about NVIDIA GPUs, making static analysis alone insufficient.
Setup
Testbed. We run the evaluations on two server setups: (1) Testbed-A: 1 node with 1 NVIDIA RTX 4090 GPU and 2 AMD Threadripper Pro 5955WX CPUs; (2) Testbed-B: 1 node with 8 NVIDIA H200 GPUs connected through NVLink and 2 AMD EPYC 9534 CPUs.
Target Systems. We implement and evaluate Magneton on 9 state-of-the-art ML systems, including (1) LLM inference and training systems: SGLang, vLLM, Megatron-LM, and HuggingFace Transformers; (2) Image generation systems: Stable Diffusion and Diffusers; (3) ML frameworks: PyTorch, JAX, and TensorFlow.
Baselines and Configurations. We compare Magneton with two state-of-the-art profilers for ML systems and their variants: (1) Zeus is an energy monitoring and optimization tool. (2) PyTorch profiler is a widely used performance profiler for PyTorch. It can obtain the latency of each operator in the model. (3) Zeus-replay, which we implement on top of Zeus with operator-level replay to address limitations described in §5.2 and enable accurate power monitoring. Prior differential analysis works for traditional software are excluded because they cannot capture the asynchronous GPU activities and cross-layer events critical to ML workloads.
Notably, these baselines are not designed for diagnosing the root cause of energy inefficiencies. We tried to use the basic troubleshooting functionality in PyTorch profiler, but it could not detect any energy waste in our evaluation. Therefore, for fair comparison, we only use them to monitor the model, profile the operator-level performance and energy statistics, and report the rank of each operator. The rationale here is that if these tools rank a particular problematic operator as a large energy consumer, that will make it easier for the developer to diagnose the underlying potential software energy waste.
As no differential energy profiler exists for ML systems, we ask whether these single-system profilers make the problematic operator stand out. For PyTorch profiler, we use the key_averages API to get the latency of each operator of all PyTorch-based systems. For Zeus and Zeus-replay, we first locate the code of each operator in the model, and then manually instrument the source code by wrapping operators with the begin_window and end_window APIs. For Zeus-replay specifically, we implement a loop to execute each operator 1,000 times with identical inputs, verifying outputs to ensure no side effects are introduced. However, this instrumentation requires manually locating and modifying the source code for every operator, which is time-consuming and not practical for large end-to-end systems. Consequently, we limit the evaluation of Zeus-based baselines to cases with not more than 100 operators.
For Magneton, we configure the detection threshold for energy inefficiency at a 10% per-subgraph (not end-to-end) energy difference between the semantically equivalent subgraphs. We set it from measurement noise: when the same GPT-2 or Llama-3-8B workload is recorded three times, twice from an idle GPU and once after a three-minute heat soak, and compared through the full pipeline, matched subgraphs of over a millijoule differ by at most 3.2%. To strictly classify an inefficiency as software energy waste rather than a performance-energy trade-off or an accuracy-energy trade-off, we enforce a tight tolerance: the efficient variant must not have a performance degradation by more than 1% or an accuracy loss of more than 1% (measured by element-wise relative difference in output values). As subgraph comparison cannot see energy saved elsewhere, we validate each candidate by measuring the end-to-end energy with the alternative applied.
Discussion
Limitations. Magneton makes several assumptions about how it is used. First, it assumes that a more energy-efficient peer exists, so an inefficiency shared by all peers goes undetected; intra-system comparison (§4) widens the choice of peers. Second, it assumes that the developer provides inputs that trigger the issue. The current implementation of Magneton also has some limitations, including (1) operator-level visibility: idleness that adds operators, like the zero-valued all-reduces of Case 1, is visible, while CPU busy-waiting (c11) or host-side scheduling delays are not; and (2) hardware dependency: diagnoses that depend on library heuristics (e.g., c10) should be re-validated on the target GPU.
Future Work. Differential debugging over dataflow graphs is not specific to energy: comparing latency, memory, or values instead can locate performance, memory, or numerical issues. We also plan to extend Magneton to multi-node deployments and to other accelerators beyond NVIDIA GPUs.
Related Work
Energy Consumption of ML. Previous work has focused on optimizing ML energy consumption through hardware tuning and model configuration. EnvPipe and Perseus leverage DVFS during pipeline bubbles, Zeus combines adaptive batch sizing with DVFS, and DynamoLLM explores parallelization strategies for inference. While these systems achieve energy savings through model-level optimizations, Magneton targets operator-level software inefficiencies.
Differential Analysis Diffing has been broadly applied across diverse domains. In data systems, data diffing has been used for storage, computer networks, and in-memory data structures, as well as in mobile applications. Beyond data, execution-trace diffing has been exploited to detect deviations from expected behavior in systems, including failure diagnosis (PeerPressure ) and mobile inefficiency (DiffProf ). Magneton extends this line of work by applying differential analysis of program traces with energy profiling to the broader setting of ML frameworks and applications, comparing two executions through graph matching on their dataflow rather than through their configurations or code structure.
Prior work on detecting semantically similar code operates under assumptions that break in ML systems. Approaches like DiffProf assume application behavior can be grouped as contiguous blocks of code or call-graph slices, which are treated as coarse-grained tasks for differential energy analysis. In ML systems, however, an operator’s behavior spans Python code, C++ dispatch, GPU libraries, and asynchronous GPU events that cannot be easily grouped into stable code segments via bottom-up analysis. To address this, Magneton takes an operator-centric differential analysis. It first partitions the execution using ML operators as the semantic units. It then matches equivalent subgraphs of the two systems’ dataflow graphs by the tensors their operators exchange, independent of their code. When Magneton detects energy inefficiency in an operator, it then examines the operator’s source code and the control- and data-flow to diagnose how the operator is invoked and how it invokes underlying GPU kernels.
Comparing Divergent Executions. The idea of leveraging divergent execution to locate root causes has been explored in systems like Kairux. Kairux diagnoses failures by identifying the divergent point of the entire control-flow across failing and non-failing executions, isolating the minimal root cause. Kairux compares two executions of the same program, whose control flows coincide until the failure; two ML systems that implement the same model share no control flow to align, so Magneton aligns them by dataflow instead. In contrast, Magneton restricts analysis to the specific invocation path of the inefficient GPU kernel, effectively bypassing the irrelevant framework-level divergences that often precede the actual root cause of energy waste.


