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 register custom operator with attributes of a list? #785

Open
CapJunkrat opened this issue Aug 2, 2024 · 3 comments
Open

how to register custom operator with attributes of a list? #785

CapJunkrat opened this issue Aug 2, 2024 · 3 comments

Comments

@CapJunkrat
Copy link

CapJunkrat commented Aug 2, 2024

In the provided documents, it showed an example of custom operator with attribute "padding_length", which has type int64. (code listed below.) What if this attribute is a list? How should I modify the example code to accommadate this change?
Since attribute with list type is pretty common, such as the kernel of a conv op, I assume the list type attribute is already supported.

@onnx_op(op_type="GPT2Tokenizer",
            inputs=[PyCustomOpDef.dt_string],
            outputs=[PyCustomOpDef.dt_int64, PyCustomOpDef.dt_int64],
            attrs={"padding_length": PyCustomOpDef.dt_int64})
def bpe_tokenizer(s, **kwargs):
    padding_length = kwargs["padding_length"]
    input_ids, attention_mask = cls.tokenizer.tokenizer_sentence([s[0]], padding_length)
    return input_ids, attention_mask
@CapJunkrat
Copy link
Author

@wenbingl I found that in the function cast_attributes, only int, float and string types are supported. Is it true that list of ints/floats is not supported?

@wenbingl
Copy link
Member

@wenbingl I found that in the function cast_attributes, only int, float and string types are supported. Is it true that list of ints/floats is not supported?

Yes, if they are vector, they can be input as an ONNX initializer, i.e. a tensor-like type.

@CapJunkrat
Copy link
Author

Yes, if they are vector, they can be input as an ONNX initializer, i.e. a tensor-like type.

@wenbingl What if the operator attribute need to be a vector? Since it is quite common to have vector attributes(such as conv kernel & paddings), will this feature be supported soon?

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

No branches or pull requests

2 participants