Skip to content

Commit

Permalink
removed all profiling (#364)
Browse files Browse the repository at this point in the history
Co-authored-by: Fritjof Bengtsson <[email protected]>
  • Loading branch information
fritjof-b and Fritjof Bengtsson authored Mar 6, 2024
1 parent e3d4fd8 commit 8024b69
Show file tree
Hide file tree
Showing 5 changed files with 955 additions and 1,275 deletions.
38 changes: 1 addition & 37 deletions baler/baler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from .modules import helper
import gzip
from .modules.profiling import energy_profiling
from .modules.profiling import pytorch_profile


Expand Down Expand Up @@ -54,23 +53,14 @@ def main():
workspace_name,
project_name,
verbose,
pytorch_profile,
energy_profile,
) = helper.get_arguments()
project_path = os.path.join("workspaces", workspace_name, project_name)
output_path = os.path.join(project_path, "output")

if mode == "newProject":
helper.create_new_project(workspace_name, project_name, verbose)
elif mode == "train":
check_enabled_profilers(
perform_training,
pytorch_profile,
energy_profile,
output_path,
config,
verbose,
)
perform_training(output_path=output_path, config=config, verbose=verbose)
elif mode == "diagnose":
perform_diagnostics(output_path, verbose)
elif mode == "compress":
Expand All @@ -91,32 +81,6 @@ def main():
)


def check_enabled_profilers(
f, pytorchProfile=False, energyProfile=False, *args, **kwargs
):
"""
Conditionally apply profiling based on the given boolean flags.
Args:
f (callable): The function to be potentially profiled.
pytorchProfile (bool): Whether to apply PyTorch profiling.
energyProfile (bool): Whether to apply energy profiling.
Returns:
result: The result of the function `f` execution.
"""
if pytorchProfile and not energyProfile:
return pytorch_profile(f, *args, **kwargs)
elif energyProfile and not pytorchProfile:
return energy_profiling(f, "baler_training", 1, *args, **kwargs)
elif pytorchProfile and energyProfile:
return pytorch_profile(
energy_profiling, f, "baler_training", 1, *args, **kwargs
)
else:
return f(*args, **kwargs)


def perform_training(output_path, config, verbose: bool):
"""Main function calling the training functions, ran when --mode=train is selected.
The three functions called are: `helper.process`, `helper.mode_init` and `helper.training`.
Expand Down
8 changes: 0 additions & 8 deletions baler/modules/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ def get_arguments():
" 2. If workspace exists but project does not, create project in workspace.\n"
" 3. If workspace does not exist, create workspace directory and project.",
)
parser.add_argument(
"--pytorchProfile", action="store_true", help="Enable PyTorch profiling"
)
parser.add_argument(
"--energyProfile", action="store_true", help="Enable Energy profiling"
)
parser.add_argument(
"--verbose", dest="verbose", action="store_true", help="Verbose mode"
)
Expand All @@ -104,8 +98,6 @@ def get_arguments():
workspace_name,
project_name,
args.verbose,
args.pytorchProfile,
args.energyProfile,
)


Expand Down
34 changes: 0 additions & 34 deletions baler/modules/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pstats import SortKey
import torch
from torch.profiler import profile, record_function, ProfilerActivity
import codecarbon


def pytorch_profile(f, *args, **kwargs):
Expand Down Expand Up @@ -54,39 +53,6 @@ def pytorch_profile(f, *args, **kwargs):
return result


def energy_profiling(f, project_name, measure_power_secs, *args, **kwargs):
"""
Energy Profiling measures the amount of electricity that
was consumed by the given function f and the amount of CO2 emission.
It utilizes the codecarbon package for tracking this information.
Args:
f (callable): The function to be profiled.
project_name (str): The name of the project.
measure_power_secs (int): The number of seconds to measure power.
Returns:
result: The result of the function `f` execution.
"""

tracker = codecarbon.EmissionsTracker(
project_name=project_name, measure_power_secs=measure_power_secs
)
tracker.start_task(f"{f.__name__}")

# Execute the function and get its result
result = f(*args, **kwargs)

emissions = tracker.stop_task()
print("CO2 emission [kg]: ", emissions.emissions)
print("CO2 emission rate [kg/h]: ", 3600 * emissions.emissions_rate)
print("CPU energy consumed [kWh]: ", emissions.cpu_energy)
print("GPU energy consumed [kWh]: ", emissions.gpu_energy)
print("RAM energy consumed [kWh]: ", emissions.ram_energy)

return result


def c_profile(func, *args, **kwargs):
"""
Profile the function func with cProfile.
Expand Down
Loading

0 comments on commit 8024b69

Please sign in to comment.