onnxruntime_backend icon indicating copy to clipboard operation
onnxruntime_backend copied to clipboard

ORT_DISABLE_ALL optimization level

Open dryarullin opened this issue 3 years ago • 1 comments
trafficstars

Is your feature request related to a problem? Please describe. Our model uses a dropout layer that is removed by the ORT optimizer. It's unusual, but we use dropout in the inference. The onnxruntime_backend doesn't support setting:

GraphOptimizationLevel optimization_level = GraphOptimizationLevel::ORT_DISABLE_ALL.

From doc:

level: Refers to the graph optimization level. By default all optimizations are enabled. Allowed values are -1 and 1. -1 refers to BASIC optimizations and 1 refers to basic plus extended optimizations like fusions. Please find the details [here](https://onnxruntime.ai/docs/performance/graph-optimizations.html)

optimization {
  graph : {
    level : 1
}}

From source code:

GraphOptimizationLevel optimization_level =
    GraphOptimizationLevel::ORT_ENABLE_ALL;
{
  triton::common::TritonJson::Value optimization;
  if (ModelConfig().Find("optimization", &optimization)) {
    triton::common::TritonJson::Value graph;
    if (optimization.Find("graph", &graph)) {
      int64_t graph_level = 0;
      THROW_IF_BACKEND_MODEL_ERROR(graph.MemberAsInt("level", &graph_level));
      if (graph_level == -1) {
        optimization_level = GraphOptimizationLevel::ORT_ENABLE_BASIC;
      } else if (graph_level == 1) {
        optimization_level = GraphOptimizationLevel::ORT_ENABLE_EXTENDED;
      }
    }
  }
}
THROW_IF_BACKEND_MODEL_ORT_ERROR(
    ort_api->SetSessionGraphOptimizationLevel(soptions, optimization_level));

Describe the solution you'd like For example, add the constant 0 for ORT_DISABLE_ALL.

Describe alternatives you've considered Unfortunately there're no alternatives. Custom backend rebuild.

Additional context I can add PR. What do you think?

dryarullin avatar Jun 02 '22 17:06 dryarullin

I agree that the current implementation doesn't cover all optimization level exposed by ORT, @pranavsharma @askhade should ORT backend changes the interpretation of level field in model config so that -1 is disabling optimization and > 0 value reflects different optimization level?

GuanLuo avatar Jun 08 '22 20:06 GuanLuo