hummingbird.ml.convert¶
Hummingbird main (converters) API.
- hummingbird.ml.convert._convert_common(model, backend, test_input=None, device='cpu', extra_config={})[source]¶
A common function called by convert(…) and convert_batch(…) below.
- hummingbird.ml.convert._convert_lightgbm(model, backend, test_input, device, extra_config={})[source]¶
This function is used to generate a backend model from a given input [LightGBM] model. [LightGBM]: https://lightgbm.readthedocs.io/
- hummingbird.ml.convert._convert_onnxml(model, backend, test_input, device, extra_config={})[source]¶
This function converts the specified [ONNX-ML] model into its backend counterpart. The supported operators can be found at hummingbird.ml.supported.
- hummingbird.ml.convert._convert_sklearn(model, backend, test_input, device, extra_config={})[source]¶
This function converts the specified scikit-learn (API) model into its backend counterpart. The supported operators and backends can be found at hummingbird.ml.supported.
- hummingbird.ml.convert._convert_sparkml(model, backend, test_input, device, extra_config={})[source]¶
This function converts the specified Spark-ML (API) model into its backend counterpart. The supported operators and backends can be found at hummingbird.ml.supported.
- hummingbird.ml.convert._convert_xgboost(model, backend, test_input, device, extra_config={})[source]¶
This function is used to generate a backend model from a given input [XGBoost] model. [XGBoost]: https://xgboost.readthedocs.io/
- hummingbird.ml.convert._is_onnx_model(model)[source]¶
Function returning whether the input model is an ONNX model or not.
- hummingbird.ml.convert._is_sparkml_model(model)[source]¶
Function returning whether the input model is a Spark-ML model or not.
- hummingbird.ml.convert._supported_backend_check(backend_formatted, backend_original)[source]¶
Function used to check whether the specified backend is supported or not.
- hummingbird.ml.convert._supported_backend_check_config(model, backend, extra_config)[source]¶
Function used to check whether the specified backend and configuration pair is supported or not.
- hummingbird.ml.convert.convert(model, backend, test_input=None, device='cpu', extra_config={})[source]¶
This function converts the specified input model into an implementation targeting backend. Convert supports [Sklearn], [LightGBM], [XGBoost], [ONNX], and [SparkML] models. For LightGBM and XGBoost currently only the Sklearn API is supported. The detailed list of models and backends can be found at hummingbird.ml.supported. The onnx backend works best with a test_input, but we try to generate one if none is provided. The torch.jit and tvm backends require a test_input. For tvm backend, the output container can do prediction only on the test data with the same size as test_input. [Sklearn]: https://scikit-learn.org/ [LightGBM]: https://lightgbm.readthedocs.io/ [XGBoost]: https://xgboost.readthedocs.io/ [ONNX]: https://onnx.ai/ [ONNX-ML]: https://github.com/onnx/onnx/blob/master/docs/Operators-ml.md [ONNX operators]: https://github.com/onnx/onnx/blob/master/docs/Operators.md [Spark-ML]: https://spark.apache.org/docs/latest/api/python/pyspark.ml.html
- Args:
model: An input model backend: The target for the conversion test_input: Some input data used to trace the model execution.
Multiple inputs can be passed as tuple objects or pandas Dataframes. When possible, (numpy)`arrays` are suggested. The number of rows becomes the batch size when tracing PyTorch models and compiling with TVM.
- device: The target device the model should be run. This parameter is only used by the torch* backends and tvm, and
the devices supported are the one supported by PyTorch, i.e., ‘cpu’ or ‘cuda’.
- extra_config: Extra configurations to be used by the individual operator converters.
The set of supported extra configurations can be found at hummingbird.ml.supported
- Examples:
>>> pytorch_model = convert(sklearn_model,`torch`)
- Returns:
A model implemented in backend, which is equivalent to the input model
- hummingbird.ml.convert.convert_batch(model, backend, test_input, remainder_size=0, device='cpu', extra_config={})[source]¶
A convert function for batch by batch prediction use cases. For some backends such as TVM, a container returned by convert(…) function above has a strict requirement on the allowable input shape. The container returned by this function is more flexible in that it can predict on the input of size test_input.shape[0] * k + remainder_size, where k is any integer. test_input.shape[0], the number of rows in the test_input, is interpreted as a batch size, and at test time prediction proceeds in a batch by batch fashion. See the documentation for convert(…) above for more information.
- Args:
model: An input model backend: The target for the conversion test_input: Some input data used to trace the model execution.
Multiple inputs can be passed as tuple objects or pandas Dataframes. When possible, (numpy)`arrays` are suggested. The number of rows becomes the batch size when tracing PyTorch models and compiling with TVM.
- remainder_size: An integer that together with test_input determines the size of test data that can be predicted.
The input to the returned container can be of size test_input.shape[0] * k + remainder_size, where k is any integer.
- device: The target device the model should be run. This parameter is only used by the torch* backends and tvm, and
the devices supported are the one supported by PyTorch, i.e., ‘cpu’ or ‘cuda’.
- extra_config: Extra configurations to be used by the individual operator converters.
The set of supported extra configurations can be found at hummingbird.ml.supported
- Examples:
>>> tvm_model = convert_batch(sklearn_model,`tvm`, X) >>> tvm_model = convert_batch(sklearn_model,`tvm`, X, remainder_size=50)
- Returns:
A BatchContainer object that wraps one or two containers created by convert(…) function above.