microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.11k stars 2.84k forks source link

[Feature Request] C-API: Implement KernelInfoGetAttribute for all possible attribute types #15079

Open cbourjau opened 1 year ago

cbourjau commented 1 year ago

Describe the feature request

The current C-API only offers the following functions for loading attributes:

The standard allows the following types:

  enum AttributeType {
    UNDEFINED = 0;
    FLOAT = 1;
    INT = 2;
    STRING = 3;
    TENSOR = 4;
    GRAPH = 5;
    SPARSE_TENSOR = 11;
    TYPE_PROTO = 13;

    FLOATS = 6;
    INTS = 7;
    STRINGS = 8;
    TENSORS = 9;
    GRAPHS = 10;
    SPARSE_TENSORS = 12;
    TYPE_PROTOS = 14;
  }

The following functions are therefore missing from the C-API and should be added:

Describe scenario use case

Several of the above attribute types are used in the standard. Others might be useful to C-API authors precisely because the operator that would use them is not in the standard. Either way, it is an unfortunate surprise for C-API users to find out that the API does not support an attribute type they were planning to use.

skottmckay commented 1 year ago

Do you have a production use case that cannot be satisfied by the existing types and requires the API to be expanded?

There are many places where we implement a subset of the spec due to things being rarely or never used. The implementation/testing/maintenance/binary size cost of doing so is not worth it, at least not until we no longer have to pay developers to do their jobs.

cbourjau commented 1 year ago

Thanks for your reply!

Please let me explain my motivation for creating this issue. I have experienced the opposite cost calculation in the past with onnxruntime: While developing a model or custom operator I found some functionality (surprisingly) missing. Having to open a PR against onnxruntime and waiting for the next release in those cases tanks productivity and makes the development process around the onnxruntime unpredictable. This PR aims to smothen the development process in the future by providing a more complete API.

That said, adding APIs which are not usable due to some other blockers would not make sense and on closer inspection that may apply to some of the above apis. Below are a few comments/use cases about the different functions:

All in all, I think there reasonable utility in adding KernelInfoGetAttribute_sparse_tensor, KernelInfoGetAttributeArray_string, KernelInfoGetAttributeArray_tensor, KernelInfoGetAttributeArray_sparse_tensors. Does that sound reasonable, @skottmckay ?