Skip to content

Commit

Permalink
Fix: Enable Energy Calculation in Benchmarking by Implementing Subtra…
Browse files Browse the repository at this point in the history
…ction Method (#149)
  • Loading branch information
karthickai authored Mar 13, 2024
1 parent d719e6e commit c4854ab
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions optimum_benchmark/trackers/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def log(self, prefix: str = "forward"):
LOGGER.info(f"\t\t+ {prefix} RAM energy: {self.ram:f} ({self.unit})")
LOGGER.info(f"\t\t+ {prefix} total energy: {self.total:f} ({self.unit})")

def __sub__(self, other: "Energy") -> "Energy":
"""Enables subtraction of two Energy instances using the '-' operator."""
if self.unit != other.unit:
raise ValueError("Energy units must match to perform subtraction")

return Energy(
cpu=self.cpu - other.cpu,
gpu=self.gpu - other.gpu,
ram=self.ram - other.ram,
total=self.total - other.total,
unit=self.unit
)


@dataclass
class Efficiency:
Expand Down

0 comments on commit c4854ab

Please sign in to comment.