Skip to content

Commit e75d7ff

Browse files
authored
Running of sklearn tests on device=cpu (#1203)
* Add CI step on lnx * Add actual dpctl installation * Pass exit code in run_sklearn_tests scripts * Modify dpcpp packages installation * Add missing 'has_aspect_fp64' attribute in DummySyclDevice
1 parent 3a4038f commit e75d7ff

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

.ci/pipeline/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ jobs:
100100
displayName: 'System info'
101101
- script: |
102102
conda update -y -q conda
103-
if [ $(echo $(PYTHON_VERSION) | grep '3.11') ]; then export DPCTL_PACKAGE=; else export DPCTL_PACKAGE=; fi
104-
conda create -q -y -n CB -c conda-forge -c intel python=$(PYTHON_VERSION) dal-devel mpich pyyaml $DPCTL_PACKAGE
103+
if [ $(echo $(PYTHON_VERSION) | grep '3.7') ] || [ $(echo $(PYTHON_VERSION) | grep '3.11') ]; then export DPCPP_PACKAGE="dpcpp-cpp-rt>=2023.0.0"; else export DPCPP_PACKAGE="dpctl>=0.14"; fi
104+
conda create -q -y -n CB -c conda-forge -c intel python=$(PYTHON_VERSION) dal-devel mpich pyyaml $DPCPP_PACKAGE
105105
displayName: 'Conda create'
106106
- script: |
107107
. /usr/share/miniconda/etc/profile.d/conda.sh
@@ -143,6 +143,11 @@ jobs:
143143
conda activate CB
144144
bash .ci/scripts/run_sklearn_tests.sh
145145
displayName: 'Sklearn testing'
146+
- script: |
147+
. /usr/share/miniconda/etc/profile.d/conda.sh
148+
conda activate CB
149+
bash .ci/scripts/run_sklearn_tests.sh cpu
150+
displayName: 'Sklearn testing [device=cpu]'
146151
- script: |
147152
. /usr/share/miniconda/etc/profile.d/conda.sh
148153
conda activate CB

.ci/scripts/run_sklearn_tests.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#===============================================================================
2+
# Copyright 2023 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#===============================================================================
16+
17+
from sklearnex import patch_sklearn
18+
patch_sklearn()
19+
20+
import os
21+
import sys
22+
import argparse
23+
import pytest
24+
import sklearn
25+
26+
27+
if __name__ == '__main__':
28+
parser = argparse.ArgumentParser()
29+
parser.add_argument(
30+
'-d', '--device',
31+
type=str,
32+
default='none',
33+
help='device name',
34+
choices=['none', 'cpu', 'gpu']
35+
)
36+
args = parser.parse_args()
37+
38+
os.chdir(os.path.dirname(sklearn.__file__))
39+
40+
pytest_args = '--verbose --pyargs --durations=100 --durations-min=0.01 ' \
41+
f'{os.environ["DESELECTED_TESTS"]} {os.environ["SELECTED_TESTS"]}'.split(' ')
42+
43+
if args.device != 'none':
44+
with sklearn.config_context(target_offload=args.device):
45+
return_code = pytest.main(pytest_args)
46+
else:
47+
return_code = pytest.main(pytest_args)
48+
sys.exit(int(return_code))

.ci/scripts/run_sklearn_tests.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
# limitations under the License.
1616
#===============================================================================
1717

18+
# Args:
19+
# 1 - device name (optional)
20+
1821
ci_dir=$( dirname $( dirname "${BASH_SOURCE[0]}" ) )
1922
cd $ci_dir
2023

2124
export SELECTED_TESTS=$(python scripts/select_sklearn_tests.py)
2225
export DESELECTED_TESTS=$(python ../.circleci/deselect_tests.py ../deselected_tests.yaml)
23-
cd $(python -c "import sklearn, os; print(os.path.dirname(sklearn.__file__))")
24-
export SKLEARNEX_VERBOSE=DEBUG
25-
python -m sklearnex -m pytest --verbose --pyargs --durations=100 --durations-min=0.01 $DESELECTED_TESTS $SELECTED_TESTS
26+
27+
python scripts/run_sklearn_tests.py -d ${1:-none}
28+
exit $?

sklearnex/_device_offload.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def __init__(self, filter_string):
4343
self._filter_string = filter_string
4444
self.is_cpu = 'cpu' in filter_string
4545
self.is_gpu = 'gpu' in filter_string
46+
# TODO: check for possibility of fp64 support
47+
# on other devices in this dummy class
48+
self.has_aspect_fp64 = self.is_cpu
4649

4750
if not (self.is_cpu):
4851
import logging

0 commit comments

Comments
 (0)