Skip to content

Commit

Permalink
Add a stop method to EnergyTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
regisss committed Sep 18, 2024
1 parent c2f0afc commit 723d10d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions optimum_benchmark/scenarios/inference/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def run_model_loading_tracking(self, backend: Backend[BackendConfigT]):
self.report.load.memory = memory_tracker.get_max_memory()
if self.config.energy:
self.report.load.energy = energy_tracker.get_energy()
energy_tracker.stop()

## Memory tracking
def run_text_generation_memory_tracking(self, backend: Backend[BackendConfigT]):
Expand Down Expand Up @@ -367,6 +368,7 @@ def run_text_generation_energy_tracking(self, backend: Backend[BackendConfigT]):
self.report.decode.efficiency = Efficiency.from_energy(
decode_energy, decode_volume, unit=TEXT_GENERATION_EFFICIENCY_UNIT
)
energy_tracker.stop()

def run_image_diffusion_energy_tracking(self, backend: Backend[BackendConfigT]):
self.logger.info("\t+ Running Image Diffusion energy tracking")
Expand All @@ -391,6 +393,7 @@ def run_image_diffusion_energy_tracking(self, backend: Backend[BackendConfigT]):
self.report.call.efficiency = Efficiency.from_energy(
call_energy, call_volume, unit=IMAGE_DIFFUSION_EFFICIENCY_UNIT
)
energy_tracker.stop()

def run_inference_energy_tracking(self, backend: Backend[BackendConfigT]):
self.logger.info("\t+ Running energy tracking")
Expand All @@ -415,6 +418,7 @@ def run_inference_energy_tracking(self, backend: Backend[BackendConfigT]):
self.report.forward.efficiency = Efficiency.from_energy(
forward_energy, forward_volume, unit=INFERENCE_EFFICIENCY_UNIT
)
energy_tracker.stop()

@property
def atomic_forward_volume(self) -> int: # in samples
Expand Down
1 change: 1 addition & 0 deletions optimum_benchmark/scenarios/training/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def run(self, backend: Backend[BackendConfigT]) -> BenchmarkReport:
self.report.overall.efficiency = Efficiency.from_energy(
self.report.overall.energy, volume=self.overall_volume, unit=TRAIN_EFFICIENCY_UNIT
)
energy_tracker.stop()

return self.report

Expand Down
3 changes: 3 additions & 0 deletions optimum_benchmark/trackers/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,6 @@ def get_energy(self) -> Energy:
return Energy(
unit=ENERGY_UNIT, cpu=self.cpu_energy, gpu=self.gpu_energy, ram=self.ram_energy, total=self.total_energy
)

def stop(self):
self.emission_tracker.stop()

0 comments on commit 723d10d

Please sign in to comment.