Repository: microsoft/onnxruntime
File: onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.cc (C++)

Code before:
          }

          // ORT's default topological sort is using reversed DFS.
          // When creating model proto from graph viewer, let ORT use priority-based topological sort based on node index.
          // The reason is, in some cases, for example ResNet50, using default topological sort will end up with generating
          // the model proto that has different node ordering compared to original onnx model.
          graph_viewer->ToProto(*model_proto->mutable_graph(), true, true, 1 /*priority-based topological sort*/, !use_external_data_initializer_ /*include raw initializers*/);
          model_proto->set_ir_version(ONNX_NAMESPACE::Version::IR_VERSION);

          std::string string_buf;
          model_proto->SerializeToString(string_buf);

          if (dump_subgraphs_) {
            // Dump TensorRT subgraph for debugging
            std::fstream dump("NvExecutionProvider_TRT_Subgraph.onnx", std::ios::out | std::ios::trunc | std::ios::binary);
            model_proto->SerializeToOstream(dump);
          }

          // Get supported node list recursively
          SubGraphCollection_t parser_nodes_list;
          TensorrtLogger& trt_logger = GetTensorrtLogger(detailed_build_log_);
          auto trt_builder = GetBuilder(trt_logger);
          auto network_flags = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kSTRONGLY_TYPED);
          auto trt_network = std::unique_ptr<nvinfer1::INetworkDefinition>(trt_builder->createNetworkV2(network_flags));

          bool is_model_supported = false;

          // limit the scope of trt_parser so that model gets unloaded from memory asap
          {
            auto trt_parser = tensorrt_ptr::unique_pointer<nvonnxparser::IParser>(nvonnxparser::createParser(*trt_network, trt_logger));

            if (use_external_data_initializer_) {
#if TRT_MAJOR_RTX > 1 || TRT_MINOR_RTX >= 1
              trt_parser->loadModelProto(string_buf.data(), string_buf.size(), model_path_);
              for (auto const& userWeight : userWeights) {
                trt_parser->loadInitializer(userWeight.Name(), userWeight.Data(), userWeight.Size());
              }
              is_model_supported = trt_parser->parseModelProto();
#else
              ORT_THROW("'nv_use_external_data_initializer' is only supported on TensorRT RTX 1.1.x.x and above.");
#endif
            } else {
              is_model_supported = trt_parser->supportsModelV2(string_buf.data(), string_buf.size(), model_path_);
            }

            // Note: Calling getNbSubgraphs or getSubgraphNodes before calling supportsModelV2 results in undefined behavior.
            auto num_subgraphs = trt_parser->getNbSubgraphs();
            parser_nodes_list.reserve(num_subgraphs);

            for (int64_t i = 0; i < num_subgraphs; ++i) {
              int64_t subgraph_len = 0;

Review comment (bug):
Lacking "`}`" for the above code block `if (use_external_data_initializer_) {}`
It makes NV TRT RTX EP failed to be built.

Code after:
          }
        }

        // ORT's default topological sort is using reversed DFS.
        // When creating model proto from graph viewer, let ORT use priority-based topological sort based on node index.
        // The reason is, in some cases, for example ResNet50, using default topological sort will end up with generating
        // the model proto that has different node ordering compared to original onnx model.
        graph_viewer->ToProto(*model_proto->mutable_graph(), true, true, 1 /*priority-based topological sort*/, !use_external_data_initializer_ /*include raw initializers*/);
        model_proto->set_ir_version(ONNX_NAMESPACE::Version::IR_VERSION);

        std::string string_buf;
        model_proto->SerializeToString(string_buf);

        if (dump_subgraphs_) {
          // Dump TensorRT subgraph for debugging
          std::fstream dump("NvExecutionProvider_TRT_Subgraph.onnx", std::ios::out | std::ios::trunc | std::ios::binary);
          model_proto->SerializeToOstream(dump);
        }

        // Get supported node list recursively
        SubGraphCollection_t parser_nodes_list;
        TensorrtLogger& trt_logger = GetTensorrtLogger(detailed_build_log_);
        auto trt_builder = GetBuilder(trt_logger);
        auto network_flags = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kSTRONGLY_TYPED);
        auto trt_network = std::unique_ptr<nvinfer1::INetworkDefinition>(trt_builder->createNetworkV2(network_flags));

        bool is_model_supported = false;

        // limit the scope of trt_parser so that model gets unloaded from memory asap
        {
          auto trt_parser = tensorrt_ptr::unique_pointer<nvonnxparser::IParser>(nvonnxparser::createParser(*trt_network, trt_logger));

          if (use_external_data_initializer_) {
#if TRT_MAJOR_RTX > 1 || TRT_MINOR_RTX >= 1
            trt_parser->loadModelProto(string_buf.data(), string_buf.size(), model_path_);
            for (auto const& userWeight : userWeights) {
              trt_parser->loadInitializer(userWeight.Name(), userWeight.Data(), userWeight.Size());
            }
            is_model_supported = trt_parser->parseModelProto();
#else
            ORT_THROW("'nv_use_external_data_initializer' is only supported on TensorRT RTX 1.1.x.x and above.");
#endif
          } else {
            is_model_supported = trt_parser->supportsModelV2(string_buf.data(), string_buf.size(), model_path_);
          }

          // Note: Calling getNbSubgraphs or getSubgraphNodes before calling supportsModelV2 results in undefined behavior.
          auto num_subgraphs = trt_parser->getNbSubgraphs();
          parser_nodes_list.reserve(num_subgraphs);

          for (int64_t i = 0; i < num_subgraphs; ++i) {