MCPcopy Create free account
hub / github.com/mlco2/codecarbon / flush

Method flush

codecarbon/emissions_tracker.py:821–851  ·  view source on GitHub ↗

Write the emissions to disk or call the API depending on the configuration, but keep running the experiment. :return: CO2 emissions in kgs

(self)

Source from the content-addressed store, hash-verified

819
820 @suppress(Exception)
821 def flush(self) -> Optional[float]:
822 """
823 Write the emissions to disk or call the API depending on the configuration,
824 but keep running the experiment.
825 :return: CO2 emissions in kgs
826 """
827 # if another instance of codecarbon is already running, Nothing to do here
828 if (
829 hasattr(self, "_another_instance_already_running")
830 and self._another_instance_already_running
831 ):
832 logger.warning(
833 "Another instance of codecarbon is already running. Exiting."
834 )
835 return
836 if self._start_time is None:
837 logger.error("You first need to start the tracker.")
838 return None
839
840 # Run to calculate the power used from last
841 # scheduled measurement to shutdown
842 self._measure_power_and_energy()
843
844 emissions_data = self._prepare_emissions_data()
845 emissions_data_delta = self._compute_emissions_delta(emissions_data)
846
847 self._persist_data(
848 total_emissions=emissions_data, delta_emissions=emissions_data_delta
849 )
850
851 return emissions_data.emissions
852
853 @suppress(Exception)
854 def stop(self) -> Optional[float]:

Callers 12

on_epoch_endMethod · 0.80
pytorch_matrix.pyFile · 0.80
_log_environmentFunction · 0.80
_select_deviceFunction · 0.80
_log_gpu_memory_infoFunction · 0.80
_allocate_matrixFunction · 0.80
_run_computation_loopFunction · 0.80
_cleanup_resourcesFunction · 0.80
train_modelFunction · 0.80

Calls 4

_persist_dataMethod · 0.95