Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion onnxruntime/core/graph/graph_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,14 @@ bool IsSupportedOptypeVersionAndDomain(const Node& node,
bool IsSupportedOptypeVersionAndDomain(const Node& node, std::string_view op_type,
gsl::span<const ONNX_NAMESPACE::OperatorSetVersion> versions,
std::string_view domain) {
#if !defined(ORT_MINIMAL_BUILD)
// node.Op() can be null for a node whose schema is not yet resolved.
const auto* op_schema = node.Op();
#endif
return (node.OpType() == op_type &&
// we don't have op schemas in the minimal build so there's no way to check the deprecated flag
#if !defined(ORT_MINIMAL_BUILD)
!node.Op()->Deprecated() &&
op_schema != nullptr && !op_schema->Deprecated() &&
#endif
MatchesOpSinceVersion(node, versions) && MatchesOpSetDomain(node, domain));
Comment on lines 403 to 408

@tairenpiao tairenpiao Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pulled node.Op() into a local op_schema and reused it. Thanks!

}
Expand Down
10 changes: 10 additions & 0 deletions onnxruntime/test/optimizer/nchwc_optimizer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ void NchwcOptimizerTester(const std::function<void(NchwcTestHelper& helper)>& bu

#ifndef DISABLE_CONTRIB_OPS

// Regression test for #28392: NchwcTransformer must not crash when a node's schema is unresolved (node.Op() == nullptr).
TEST(NchwcOptimizerTests, MatMulCastDoesNotCrashOnUnresolvedSchema) {
SessionOptions session_options;
session_options.graph_optimization_level = TransformerLevel::Level3;
session_options.session_logid = "NchwcOptimizerTests";
InferenceSessionWrapper session{session_options, GetEnvironment()};
ASSERT_STATUS_OK(session.Load(ORT_TSTR("testdata/transform/transpose_cast_matmul_fp16.onnx")));
ASSERT_STATUS_OK(session.Initialize());
}

TEST(NchwcOptimizerTests, ConvNchw) {
auto test_case = [&](const std::string& activation_op_type) {
auto build_test_case = [&](NchwcTestHelper& helper) {
Expand Down
Binary file not shown.
Loading