Skip to content
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

How to pass input to onnxscript functions correctly? #1089

Open
paranjapeved15 opened this issue Apr 26, 2024 · 1 comment
Open

How to pass input to onnxscript functions correctly? #1089

paranjapeved15 opened this issue Apr 26, 2024 · 1 comment
Assignees

Comments

@paranjapeved15
Copy link

paranjapeved15 commented Apr 26, 2024

I was trying to follow along this tutorial: https://onnx.ai/sklearn-onnx/auto_tutorial/plot_jfunction_transformer.html#custom-converter-with-onnxscript

df = pandas.DataFrame(
    [["car", 0.1, 0.2, 0.3, 0.4, 0.5], ["car", 0.1, 0.2, 0.3, 0.4, 0.5], ["suv", 0.1, 0.2, 0.3, 0.4, 0.5]],
    columns=['vehicleType', 'features_car', 'features_suv', 'features_truck', 'features_van', 'features_minivan'])

from onnx.helper import make_tensor
from onnx import TensorProto
from onnxscript.onnx_types import FLOAT, INT64, STRING, BOOL

@onnxscript.script()
def converter_function(X) -> FLOAT[1,1]:
    zero_constant = op.Constant(value=make_tensor("zero_constant", TensorProto.FLOAT, [1,1], [0.0]))
    car_constant = op.Constant(value=make_tensor(
        name = "car_constant",
        data_type = TensorProto.STRING,
        dims=[1,1],
        vals = ["car"]
    ))
    vehicle = op.Slice(X, [0], [1], [1])
    x1 = op.Slice(X, [1], [2], [1])
    isVehicleTypeCar = vehicle == car_constant
    if isVehicleTypeCar:
        result = x1
    else:
        result = zero_constant
    return result



def get_score_transformer_converter(scope, operator, container):  # type: ignore
    """Convert overprice sklearn custom transformer to onnx."""
    opv = container.target_opset
    X = operator.inputs[0]
    
    proto = converter_function().to_model_proto()
    proto_version = convert_version(proto, opv)
    add_onnx_graph(scope, operator, container, proto_version)

update_registered_converter(
    GetScore,
    "GetScore",
    get_score_transformer_shape_calculator,
    get_score_transformer_converter,
)

model_onnx = to_onnx(pipeline, df[:1], target_opset=18, options={"zipmap": False})

It gives me the following error:
File "/Users/vedparanjape/code/onnx-converters/src/onnx/converters/trial.py", line 117, in get_score_transformer_converter
proto = converter_function().to_model_proto()
^^^^^^^^^^^^^^^^^^^^
File "/Users/vedparanjape/Library/Caches/pypoetry/virtualenvs/onnx-converters-gTr4GyPW-py3.12/lib/python3.12/site-packages/onnxscript/values.py", line 526, in call
return evaluator.default().eval_function(self, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vedparanjape/Library/Caches/pypoetry/virtualenvs/onnx-converters-gTr4GyPW-py3.12/lib/python3.12/site-packages/onnxscript/evaluator.py", line 282, in eval_function
tagged_args, tagged_kwargs = param_manipulation.tag_arguments_with_param_schemas(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vedparanjape/Library/Caches/pypoetry/virtualenvs/onnx-converters-gTr4GyPW-py3.12/lib/python3.12/site-packages/onnxscript/_internal/param_manipulation.py", line 129, in tag_arguments_with_param_schemas
raise TypeError(f"Required input/attribute '{param}' was not provided")
TypeError: Required input/attribute 'X: Input[None]' was not provided

I am not sure what I am doing differently than the tutorial code or I am missing something else.

@xadupre
Copy link
Collaborator

xadupre commented May 20, 2024

I tried to replicate your issue but there are still missing pieces (see #1094). Could you complete it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants