Skip to content

Commit

Permalink
Fix issue baler-collaboration#322 by removing lambda functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AkkiG2401 committed Nov 1, 2023
1 parent dfe61ea commit db390e8
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions baler/baler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def main():
+ " not recognised. Use baler --help to see available modes."
)


def check_enabled_profilers(
f, pytorchProfile=False, energyProfile=False, *args, **kwargs
):
Expand All @@ -104,25 +105,17 @@ def check_enabled_profilers(
Returns:
result: The result of the function `f` execution.
"""

# Placeholder function to avoid nested conditions
def identity_func(fn, *a, **kw):
return fn(*a, **kw)

# Set the outer and inner functions based on the flags
inner_function = pytorch_profile if pytorchProfile else identity_func
outer_function = (
(
lambda fn: energy_profiling(
fn, project_name="baler_training", measure_power_secs=1
)
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
)
if energyProfile
else identity_func
)
else:
return f(*args, **kwargs)

# Nest the profiling steps and run the function only once
return outer_function(lambda: inner_function(f, *args, **kwargs))()

def perform_training(output_path, config, verbose: bool):
"""Main function calling the training functions, ran when --mode=train is selected.
Expand Down

0 comments on commit db390e8

Please # to comment.