microsoft / microsoft/onnxruntime

[Feature Request] C-API: Allow determining whether an attribute was specified

Open
#17,241 3 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the feature request

When implementing a custom operator with the C or C++ API, you can try to access an attribute with a function like `KernelInfoGetAttribute_string`, but this will return the same error code (`ORT_FAIL`) when the attribute is not provided as when there is some other error like it was of the wrong type. When you have an optional attribute with a default value, ideally you would raise an error if the attribute was provided but with the wrong type, rather than just using the default value without any indication that something went wrong.

Could a new API function be added to determine whether an attribute was specified? Eg. something like:

```
OrtStatusPtr* KernelInfoHasAttribute(const OrtKernelInfo* info, const char* name, int* out);
```

Or alternatively, a way to get the names of all specified attributes might be useful.

I'd be happy to make a PR to implement this if it would be acceptable.

### Describe scenario use case

I'm implementing a custom operator with a similar interface to the standard `TreeEnsembleRegressor` operator, where a lot of the attributes are optional.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the C/C++ API entry point KernelInfoGetAttribute_string and the custom-operator attribute handling it uses. Compare the proposed KernelInfoHasAttribute behavior with the alternative of listing specified attribute names, then define how absent attributes differ from wrong-type errors. Done means the chosen API is exposed consistently and distinguishes those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.