Skip to content

Conversation

@guoyu-wang
Copy link
Contributor

Description:
Add generic configurations for session options

Motivation and Context
Right now in order to change some setting within an inference sessions, we will need to either

  • Use ORTAPI, add entry if necessary, (will bloat the c/cxx_api)
  • Use environmental variables, (not really work for some environments, such as mobile)
  • Hardcode the settings (not really applicable to end users )

This proposal is to add a single function OrtApis::SetSessionConfiguration to add different configurations for the inference session

  • Exposing new options will not require updating the ORTAPI any more
  • Use a std::unordered_map as the collection of the configurations
  • Define an enum as the config key, and a std::string as the config value, the consumer of the config will be responsible to parse the string
  • EP will still using constructor for EP specific configurations

@guoyu-wang guoyu-wang requested a review from a team as a code owner August 6, 2020 04:57

typedef enum OrtSessionConfigKey {
ORT_SESSION_CONFIG_MAXIMUM, // Always leave this as the last value
} OrtSessionConfigKey;
Copy link
Contributor Author

@guoyu-wang guoyu-wang Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I don't have any EP setting to add here anymore, so I will leave this as a stub
Maybe we want to add a header file for this enum with clear naming convention and string format for each config
#WontFix

Copy link
Contributor

@pranavsharma pranavsharma Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this OrtSessionOptionKey? Adding a new vocab might confuse folks. #Resolved

Copy link
Contributor

@skottmckay skottmckay Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could go either way on this.
We have SessionOptions and we're adding essentially a collection of key:value pairs to that (so a collection within a collection).
We somewhat hide the session options in parts of the API (e.g. it's SetSessionLogId not SetSessionOptionX although the parameter is a SessionOptions instance) but make it obvious in others (CloneSessionOptions).
Due to that, OrtSessionOptionKey could potentially be confused as something to set any 'key' in SessionOptions.

Possibly the clearest is OrtSessionOptionsConfigKey.


In reply to: 466683249 [](ancestors = 466683249)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with OrtSessionOptionsConfigKey


In reply to: 466725770 [](ancestors = 466725770,466683249)


typedef enum OrtSessionConfigKey {
ORT_SESSION_CONFIG_MAXIMUM, // Always leave this as the last value
} OrtSessionConfigKey;
Copy link
Contributor

@pranavsharma pranavsharma Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this OrtSessionOptionKey? Adding a new vocab might confuse folks. #Resolved

* \param config_key An enum as the key of the configuration
* \param config_value A null terminated string representation of the config value
*/
ORT_API2_STATUS(SetSessionConfiguration, _Inout_ OrtSessionOptions* options,
Copy link
Contributor

@pranavsharma pranavsharma Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this AddSessionOption()? With the enum change from OrtSessionConfigKey -> OrtSessionOptionKey, this would be clearer. And config_value can be option_value. #Resolved

* \param config_value A null terminated string representation of the config value
*/
ORT_API2_STATUS(SetSessionConfiguration, _Inout_ OrtSessionOptions* options,
_In_ OrtSessionConfigKey config_key, _In_ const char* config_value);
Copy link
Contributor

@pranavsharma pranavsharma Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we allow users to set existing session options as well using this method? #WontFix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd have to implement logic to handle converting the string to the correct type including error checking for all options. I think it would also be confusing to have two different ways to set one value in SessionOptions in the API.


In reply to: 466694258 [](ancestors = 466694258)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to convert logid (which is a good candidate to use the map<enum, string>) into the the map, but it is used in too many places


In reply to: 466726344 [](ancestors = 466726344,466694258)

@skottmckay
Copy link
Contributor

skottmckay commented Aug 6, 2020

C# SessionOptions class needs update as does python API #Resolved

@guoyu-wang
Copy link
Contributor Author

This will be updated once the c/cxx api is settled


In reply to: 670235316 [](ancestors = 670235316)

@guoyu-wang guoyu-wang marked this pull request as draft August 11, 2020 01:45
@guoyu-wang guoyu-wang changed the title [Proposal] Add a generic collection of session configurations to the SessionOptions [WIP] Add a generic collection of session configurations to the SessionOptions Aug 11, 2020
@guoyu-wang guoyu-wang marked this pull request as ready for review August 11, 2020 05:48
@guoyu-wang guoyu-wang requested a review from yufenglee August 11, 2020 21:17

// Key for disable MatMul PrePacking,
// if the config value is set to "1" then the prepacking is disabled, otherwise prepacking is enabled
constexpr const char* kDisablePrePacking = "Math.MatMul.DisablePrePacking";
Copy link
Contributor Author

@guoyu-wang guoyu-wang Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not the best place for these keys, any suggestion?
#Resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to have them under include/onnxruntime/core/common.

We should have some naming guidelines. I'd prefer an 'area' first - like 'op' for operators. Having Math and MatMul seems unnecessary (also I didn't think pre-packing would be limited to a specific operator, and that we would enable it more globally as that's what happens in SessionState currently).


In reply to: 469027840 [](ancestors = 469027840)

@guoyu-wang
Copy link
Contributor Author

This part I have no idea, there are multiple checkins adding new apis in the past week


In reply to: 672825623 [](ancestors = 672825623)


Refers to: onnxruntime/core/session/onnxruntime_c_api.cc:1826 in 96d36fa. [](commit_id = 96d36fa, deletion_comment = False)

#endif

#pragma region Session_Options_Configs

Copy link
Contributor Author

@guoyu-wang guoyu-wang Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep these config definitions here for now.
When we have more configs defined, we can move them into a separated head file
#Closed

Copy link
Contributor

@skottmckay skottmckay Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would prefer a separate header file now. We can put the strings in an appropriate namespace like onnxruntime::config_keys, and it won't break user's builds later when we move it. #Resolved

@guoyu-wang guoyu-wang changed the title [WIP] Add a generic collection of session configurations to the SessionOptions Add a generic collection of session configurations to the SessionOptions Aug 15, 2020
inline std::string ToWideString(const std::string& s) { return s; }
#endif

// Naming Convention for a Session Options Config Key
Copy link
Contributor

@pranavsharma pranavsharma Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will the C API users discover these keys? This is a C++ file and won't be shipped as part of our packages. I suggest either (1) creating a separate file called session_options_config_keys.h and including it from the top level c_api.h or (2) adding the keys directly in c_api.h. I prefer 1 as it's a bit cleaner. #Resolved


// Key for disable PrePacking,
// If the config value is set to "1" then the prepacking is disabled, otherwise prepacking is enabled (default value)
#define ORT_SESSION_OPTIONS_CONFIG_DISABLEPREPACKING "session_state.disable_prepacking" No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is pure c api, changed to use macro instead of const char*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't follow this. What was wrong with const char*?

skottmckay
skottmckay previously approved these changes Aug 18, 2020
Copy link
Contributor

@skottmckay skottmckay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@guoyu-wang guoyu-wang merged commit dee7596 into master Aug 18, 2020
@guoyu-wang guoyu-wang deleted the onnx_session_configs_1 branch August 18, 2020 20:40
@guoyu-wang guoyu-wang restored the onnx_session_configs_1 branch August 20, 2020 05:16
@guoyu-wang guoyu-wang deleted the onnx_session_configs_1 branch September 10, 2020 09:48
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

Successfully merging this pull request may close these issues.

5 participants