Skip to content

Add available devices and dtypes selection to runner.py #101

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def parse_args(parser, size=None, loop_types=(),
action='store_true',
help='Use no intel optimized version. '
'Now avalible for scikit-learn benchmarks')
parser.add_argument('--device', default='None', type=str,
choices=('host', 'cpu', 'gpu', 'None'),
parser.add_argument('--device', default='none', type=str,
choices=('host', 'cpu', 'gpu', 'none'),
help='Execution context device')

for data in ['X', 'y']:
Expand All @@ -198,15 +198,15 @@ def parse_args(parser, size=None, loop_types=(),
except ImportError:
logging.info('Failed to import sklearnex.patch_sklearn.'
'Use stock version scikit-learn', file=sys.stderr)
params.device = 'None'
params.device = 'none'
else:
if params.device != 'None':
if params.device != 'none':
logging.info(
'Device context is not supported for stock scikit-learn.'
'Please use --no-intel-optimized=False with'
f'--device={params.device} parameter. Fallback to --device=None.',
f'--device={params.device} parameter. Fallback to --device=none.',
file=sys.stderr)
params.device = 'None'
params.device = 'none'

# disable finiteness check (default)
if not params.check_finiteness:
Expand Down Expand Up @@ -554,7 +554,7 @@ def print_output(library, algorithm, stages, params, functions,


def run_with_context(params, function):
if params.device != 'None':
if params.device != 'none':
from daal4py.oneapi import sycl_context
with sycl_context(params.device):
function()
Expand Down
2 changes: 1 addition & 1 deletion configs/skl_xpu_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"data-format": "pandas",
"data-order": "F",
"dtype": "float64",
"device": ["host", "cpu", "gpu", "None"]
"device": ["host", "cpu", "gpu", "none"]
},
"cases": [
{
Expand Down
33 changes: 33 additions & 0 deletions runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ def get_configs(path: Path) -> List[str]:
default='configs/config_example.json',
help='The path to a configuration file or '
'a directory that contains configuration files')
parser.add_argument('--device', '--devices', default='host cpu gpu none', type=str, nargs='+',
choices=('host', 'cpu', 'gpu', 'none'),
help='Availible execution context devices. '
'This parameter only marks devices as available, '
'make sure to add the device to the config file '
'to run it on a specific device')
parser.add_argument('--dummy-run', default=False, action='store_true',
help='Run configuration parser and datasets generation '
'without benchmarks running')
parser.add_argument('--dtype', '--dtypes', type=str, default="float32 float64", nargs='+',
choices=("float32", "float64"),
Comment on lines +56 to +57
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of PR scope, but int32 might be added

Choose a reason for hiding this comment

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

It is better to add this kind of changes in other PR

help='Available floating point data types'
'This parameter only marks dtype as available, '
'make sure to add the dtype parameter to the config file ')
parser.add_argument('--no-intel-optimized', default=False, action='store_true',
help='Use Scikit-learn without Intel optimizations')
parser.add_argument('--output-file', default='results.json',
Expand Down Expand Up @@ -93,6 +104,28 @@ def get_configs(path: Path) -> List[str]:
for params_set in config['cases']:
params = common_params.copy()
params.update(params_set.copy())

device = []
if 'device' not in params:
if 'sklearn' in params['lib']:
logging.info('The device parameter value is not defined in config, '
'none is used')
Comment on lines +111 to +112
Copy link
Contributor

Choose a reason for hiding this comment

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

Move up from if because --device might be added later for xgboost, for example.

Copy link
Contributor Author

@dmitrii-kriukov dmitrii-kriukov Dec 23, 2021

Choose a reason for hiding this comment

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

For now other configs do not support device parameter and such message may be confusing

device = ['none']
elif not isinstance(params['device'], list):
device = [params['device']]
else:
device = params['device']
params["device"] = [dv for dv in device if dv in args.device]

dtype = []
if 'dtype' not in params:
dtype = ['float64']
elif not isinstance(params['dtype'], list):
dtype = [params['dtype']]
else:
dtype = params['dtype']
params['dtype'] = [dt for dt in dtype if dt in args.dtype]

algorithm = params['algorithm']
libs = params['lib']
if not isinstance(libs, list):
Expand Down