@@ -2810,6 +2810,55 @@ including arg name, arg type (contains both type and shape).)pbdoc")
28102810 ORT_THROW (" TunableOp and get_tuning_results are not supported in this build." );
28112811#endif
28122812 })
2813+ .def (
2814+ " set_ep_dynamic_options" , [](PyInferenceSession* sess, const py::dict& options) {
2815+ std::vector<const char *> keys;
2816+ std::vector<const char *> values;
2817+ std::vector<std::string> key_strings;
2818+ std::vector<std::string> value_strings;
2819+
2820+ // Reserve space to avoid reallocations
2821+ key_strings.reserve (options.size ());
2822+ value_strings.reserve (options.size ());
2823+ keys.reserve (options.size ());
2824+ values.reserve (options.size ());
2825+
2826+ // Convert Python dict to C-style arrays
2827+ for (const auto & item : options) {
2828+ key_strings.emplace_back (py::str (item.first ));
2829+ value_strings.emplace_back (py::str (item.second ));
2830+ keys.push_back (key_strings.back ().c_str ());
2831+ values.push_back (value_strings.back ().c_str ());
2832+ }
2833+
2834+ if (keys.empty ()) {
2835+ ORT_THROW (" No options were provided" );
2836+ }
2837+
2838+ auto status = sess->GetSessionHandle ()->SetEpDynamicOptions (
2839+ gsl::make_span (keys.data (), keys.size ()),
2840+ gsl::make_span (values.data (), values.size ()));
2841+
2842+ if (!status.IsOK ()) {
2843+ ORT_THROW (" Failed to set EP dynamic options: " + status.ErrorMessage ());
2844+ }
2845+ },
2846+ R"pbdoc( Set dynamic options for execution providers.
2847+
2848+ Args:
2849+ options (dict): Dictionary of key-value pairs where both keys and values are strings.
2850+ These options will be passed to the execution providers to modify
2851+ their runtime behavior.
2852+
2853+ Example:
2854+ session.set_ep_dynamic_options({
2855+ "option1": "value1",
2856+ "option2": "value2"
2857+ })
2858+
2859+ Raises:
2860+ RuntimeError: If no options are provided or if setting the options fails.
2861+ )pbdoc" )
28132862 .def (" set_tuning_results" , [](PyInferenceSession* sess, py::list results, bool error_on_invalid) -> void {
28142863#if !defined(ORT_MINIMAL_BUILD)
28152864 std::vector<TuningResults> tuning_results;
0 commit comments