Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record block execution time #128

Merged
merged 8 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions mlblocks/mlpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import warnings
from collections import Counter, OrderedDict, defaultdict
from copy import deepcopy
from datetime import datetime

import numpy as np

Expand Down Expand Up @@ -223,6 +224,7 @@ def __init__(self, pipeline=None, primitives=None, init_params=None,
self.set_hyperparameters(hyperparameters)

self._re_block_name = re.compile(r'(^[^#]+#\d+)(\..*)?')
self.time = dict()

def _get_str_output(self, output):
"""Get the outputs that correspond to the str specification."""
Expand Down Expand Up @@ -390,6 +392,18 @@ def get_output_variables(self, outputs='default'):
outputs = self.get_outputs(outputs)
return [output['variable'] for output in outputs]

def get_time(self):
"""Get the execution time of each block.

If called before fitting the pipeline, it will return an empty dictionary.

Returns:
dict:
A dictionary containing the block names as keys and
the execution time in seconds as values.
"""
return self.time.copy()

def _extract_block_name(self, variable_name):
return self._re_block_name.search(variable_name).group(1)

Expand Down Expand Up @@ -616,7 +630,10 @@ def _fit_block(self, block, block_name, context):
LOGGER.debug("Fitting block %s", block_name)
try:
fit_args = self._get_block_args(block_name, block.fit_args, context)
start = datetime.utcnow()
block.fit(**fit_args)
elapsed = datetime.utcnow() - start
self.time[block_name] = elapsed.total_seconds()
except Exception:
if self.verbose:
LOGGER.exception("Exception caught fitting MLBlock %s", block_name)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


install_requires = [
'Keras>=2.1.6,<2.4'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be added here, since Keras is not a direct dependency of mlblocks.
Also note that current MLPrimitives master already fixed this problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test dependency to use MLPrimitives master to fix this.

Also I apologize for the multiple commits/pushes, tests were passing just fine locally as they were using different versions of dependencies. I capped the issues that arise from newer versions.

]


Expand Down