Repository: microsoft/onnxruntime
File: onnxruntime/test/framework/inference_session_test.cc (C++)

Code before:

  VerifyThreadPoolWithDenormalAsZero(session1.GetIntraOpThreadPoolToUse(), true);
  VerifyThreadPoolWithDenormalAsZero(session1.GetInterOpThreadPoolToUse(), true);

  // inference session without denormal as zero.
  ASSERT_STATUS_OK(so.config_options.AddConfigEntry(kOrtSessionOptionsConfigSetDenormalAsZero, "0"));

  // Since only the first session option for flush-to-zero and denormal-as-zero are effective,
  // set them manually here for a test.
  SetDenormalAsZero(false);

  InferenceSessionTestGlobalThreadPools session2{so, *env};
  ASSERT_STATUS_OK(session2.Load("testdata/matmul_1.onnx"));
  ASSERT_STATUS_OK(session2.Initialize());

  // Since it's parallel, it runs on threads.
  RunModelWithDenormalAsZero(session2, run_options, false);

  VerifyThreadPoolWithDenormalAsZero(session2.GetIntraOpThreadPoolToUse(), false);
  VerifyThreadPoolWithDenormalAsZero(session2.GetInterOpThreadPoolToUse(), false);
}
#endif

TEST(InferenceSessionTests, BadDataTypeInInitializerIsHandled) {
  // model has an initializer with a bogus data type. Graph ctor should detect and throw.
  auto model_uri = ORT_TSTR("testdata/msrc-31000000518082.onnx");

  SessionOptions so;
  so.session_logid = "TempTest.LoadModel";
  InferenceSession session{so, GetEnvironment()};
  ASSERT_STATUS_NOT_OK_AND_HAS_SUBSTR(session.Load(model_uri), "does not have valid data type");
}

TEST(InferenceSessionTests, GraphResolveHandlesNodeWithSubgraphBeingRemoved) {
  // model has a subgraph with output that is not consumed. the node with the subgraph should get removed in
  // Graph::BuildConnections and Graph::Resolve should adjust its list of subgraphs to not access the removed subgraph.
  auto model_uri = ORT_TSTR("testdata/msrc-31000000518483.onnx");

  SessionOptions so;
  so.session_logid = "TempTest.LoadModel";
  InferenceSession session{so, GetEnvironment()};
  ASSERT_STATUS_OK(session.Load(model_uri));
}

}  // namespace test
}  // namespace onnxruntime


Review comment (suggestion):
consider giving the models more descriptive names. e.g., `testdata/initializer_with_bogus_data_type.onnx`

Code after:
  VerifyThreadPoolWithDenormalAsZero(session1.GetIntraOpThreadPoolToUse(), true);
  VerifyThreadPoolWithDenormalAsZero(session1.GetInterOpThreadPoolToUse(), true);

  // inference session without denormal as zero.
  ASSERT_STATUS_OK(so.config_options.AddConfigEntry(kOrtSessionOptionsConfigSetDenormalAsZero, "0"));

  // Since only the first session option for flush-to-zero and denormal-as-zero are effective,
  // set them manually here for a test.
  SetDenormalAsZero(false);

  InferenceSessionTestGlobalThreadPools session2{so, *env};
  ASSERT_STATUS_OK(session2.Load("testdata/matmul_1.onnx"));
  ASSERT_STATUS_OK(session2.Initialize());

  // Since it's parallel, it runs on threads.
  RunModelWithDenormalAsZero(session2, run_options, false);

  VerifyThreadPoolWithDenormalAsZero(session2.GetIntraOpThreadPoolToUse(), false);
  VerifyThreadPoolWithDenormalAsZero(session2.GetInterOpThreadPoolToUse(), false);
}
#endif

TEST(InferenceSessionTests, BadDataTypeInInitializerIsHandled) {
  // model has an initializer with a bogus data type. Graph ctor should detect and throw.
  auto model_uri = ORT_TSTR("testdata/icm-31000000518082.onnx");

  SessionOptions so;
  so.session_logid = "TempTest.LoadModel";
  InferenceSession session{so, GetEnvironment()};
  ASSERT_STATUS_NOT_OK_AND_HAS_SUBSTR(session.Load(model_uri), "does not have valid data type");
}

TEST(InferenceSessionTests, GraphResolveHandlesNodeWithSubgraphBeingRemoved) {
  // model has a subgraph with output that is not consumed. the node with the subgraph should get removed in
  // Graph::BuildConnections and Graph::Resolve should adjust its list of subgraphs to not access the removed subgraph.
  auto model_uri = ORT_TSTR("testdata/icm-31000000518483.onnx");

  SessionOptions so;
  so.session_logid = "TempTest.LoadModel";
  InferenceSession session{so, GetEnvironment()};
  ASSERT_STATUS_OK(session.Load(model_uri));
}

}  // namespace test
}  // namespace onnxruntime