question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ONNX Converter] Allow for specification of ONNX Initializers

See original GitHub issue

I have a regression model trained and converted to ONNX using ML.NET. When I take the ONNX model and try to optimize it using Hummingbird I get an error because of incompatible operators / data types.

Given the following Python code:

import onnx
import numpy as np
from hummingbird.ml import convert, constants

# Define model path
model_path = "taxi-fare.onnx"

# Load ONNX model
onnx_model = onnx.load_model(model_path)

# Define sample input
input = np.array([("CMT",1.0,1.0,1.0,1.0,"CRD",1.0)])

# Convert to HB-ONNX
hb_onnx = convert(onnx_model,"onnx", test_input=input)

# Save HB-ONNX model
hb_onnx.save("hb-taxi-fare")

The result is the following.

Traceback (most recent call last):
  File "/anaconda/envs/hb-mlnet-onnx/lib/python3.8/site-packages/hummingbird/ml/_topology.py", line 153, in convert
    converter = get_converter(operator.type)
  File "/anaconda/envs/hb-mlnet-onnx/lib/python3.8/site-packages/onnxconverter_common/registration.py", line 40, in get_converter
    raise ValueError('Unsupported conversion for operator %s' % operator_name)
ValueError: Unsupported conversion for operator None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "convert.py", line 21, in <module>
    hb_onnx = convert(onnx_model,"onnx", test_input=test_data)
  File "/anaconda/envs/hb-mlnet-onnx/lib/python3.8/site-packages/hummingbird/ml/convert.py", line 431, in convert
    return _convert_common(model, backend, test_input, device, extra_config)
  File "/anaconda/envs/hb-mlnet-onnx/lib/python3.8/site-packages/hummingbird/ml/convert.py", line 387, in _convert_common
    return _convert_onnxml(model, backend, test_input, device, extra_config)
  File "/anaconda/envs/hb-mlnet-onnx/lib/python3.8/site-packages/hummingbird/ml/convert.py", line 260, in _convert_onnxml
    hb_model = topology_converter(topology, backend, test_input, device, extra_config=extra_config)
  File "/anaconda/envs/hb-mlnet-onnx/lib/python3.8/site-packages/hummingbird/ml/_topology.py", line 165, in convert
    raise MissingConverter(
hummingbird.ml.exceptions.MissingConverter: Unable to find converter for None type <class 'NoneType'> with extra config: {'test_input': array([['CMT', '1.0', '1.0', '1.0', '1.0', 'CRD', '1.0']], dtype='<U3'), 'container': True, 'n_threads': 4, 'n_features': 7, 'onnx_initializers': {'uint64': data_type: 12
name: "uint64"
uint64_data: 16
, 'int64': data_type: 7
int64_data: 1
name: "int64"
, 'uint640': data_type: 12
name: "uint640"
uint64_data: 16
, 'int640': data_type: 7
int64_data: 1
name: "int640"
, 'mlnet.vendor_id.SlotNames': dims: 1
dims: 1
data_type: 8
string_data: "one"
name: "mlnet.vendor_id.SlotNames"
, 'mlnet.payment_type.SlotNames': dims: 1
dims: 1
data_type: 8
string_data: "one"
name: "mlnet.payment_type.SlotNames"
, 'mlnet.Features.SlotNames': dims: 1
dims: 1
data_type: 8
string_data: "one"
name: "mlnet.Features.SlotNames"
}, 'tree_implementation': 'tree_trav', 'max_string_length': 4}.
It usually means the pipeline being converted contains a
transformer or a predictor with no corresponding converter implemented.
Please fill an issue at https://github.com/microsoft/hummingbird.

It’s unclear how to specify ONNX Initializers. I see how it’s done in sklearn. Given my data sample above, is there a way for me to specify the initializers once I already have an ONNX model? In ML.NET I don’t believe there’s an option to specify the initial types ahead of time. It’d be great to be able to specify these after the fact. I see it might be possible via the extra_config parameter. But given the output, it’s not clear what the type or format of it should be.

Attached is the ONNX model

taxi-fare.zip

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
interesaaatcommented, Jan 26, 2021

Thanks @luisquintanilla for reporting this. I think that the problem is that we don’t currently support strings from onnx models. With sklearn models we do, so it is just a matter of enabling this. I will work on this.

0reactions
interesaaatcommented, Feb 4, 2021

Thanks @luisquintanilla. Please keep us posted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ONNX Concepts — ONNX 1.12.0 documentation
Input, Output, Node, Initializer, Attributes#. Building an ONNX graph means implementing a function with the ONNX language or more precisely the ONNX Operators....
Read more >
Creating ONNX from scratch - Towards Data Science
ONNX specifies a list of operations which jointly allow one to specify virtually any AI/ML operation you might want to carry out (and...
Read more >
API — ONNX Runtime 1.14.0 documentation
ONNX Runtime loads and runs inference on a model in ONNX graph format, or ORT format (for memory and disk constrained environments). The...
Read more >
Exporting to ONNX format — Apache MXNet documentation
Check validity of ONNX model¶ ... If the converted protobuf format doesn't qualify to ONNX proto specifications, the checker will throw errors, but...
Read more >
NVIDIA Deep Learning TensorRT Documentation
This can often solve TensorRT conversion issues in the ONNX parser and generally ... TensorRT has a Plugin interface to allow applications to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found