Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2A template to benchmark a model 

3with :epkg:`asv`. The benchmark can be run through 

4file :epkg:`run_asv.sh` on Linux or :epkg:`run_asv.bat` on 

5Windows. 

6 

7.. warning:: 

8 On Windows, you should avoid cloning the repository 

9 on a folder with a long full name. Visual Studio tends to 

10 abide by the rule of the maximum path length even though 

11 the system is told otherwise. 

12""" 

13import numpy # pylint: disable=W0611 

14from mlprodict.tools.asv_options_helper import get_opset_number_from_onnx 

15# Import specific to this model. 

16from sklearn.linear_model import LinearRegression # pylint: disable=C0411 

17 

18from mlprodict.asv_benchmark import _CommonAsvSklBenchmarkRegressor # pylint: disable=C0412 

19from mlprodict.onnx_conv import to_onnx # pylint: disable=W0611, C0412 

20from mlprodict.onnxrt import OnnxInference # pylint: disable=W0611, C0412 

21 

22 

23class TemplateBenchmarkRegressor(_CommonAsvSklBenchmarkRegressor): 

24 """ 

25 :epkg:`asv` example for a regressor, 

26 Full template can be found in 

27 `common_asv_skl.py <https://github.com/sdpython/mlprodict/ 

28 blob/master/mlprodict/asv_benchmark/common_asv_skl.py>`_. 

29 """ 

30 params = [ 

31 ['skl', 'pyrtc', 'ort'], # values for runtime 

32 [1, 10, 100, 1000, 10000], # values for N 

33 [4, 20], # values for nf 

34 [get_opset_number_from_onnx()], # values for opset 

35 ['float', 'double'], # values for dtype 

36 [None], # values for optim 

37 ] 

38 

39 # additional parameters 

40 

41 def setup_cache(self): # pylint: disable=W0235 

42 super().setup_cache() 

43 

44 def _create_model(self): 

45 return LinearRegression()