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
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ Status Avx2WeightS8ToU8Transformer::ApplyImpl(Graph& graph, bool& modified, int
continue; // unknown operator, next
}

#if !defined(ORT_MINIMAL_BUILD)
// op_node.Op() can be null for a node whose schema is not yet resolved.
const auto* op_schema = op_node.Op();
#endif
if (
#if !defined(ORT_MINIMAL_BUILD)
!op_node.Op()->Deprecated() &&
op_schema != nullptr && !op_schema->Deprecated() &&
#endif
MatchesOpSinceVersion(op_node, it->second.versions) &&
graph_utils::MatchesOpSetDomain(op_node, it->second.domain)) {
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick (non-blocking): this regression model is a plain Transpose -> Cast -> MatMul chain of standard ONNX ops, so the test does not actually depend on contrib ops. Placing it inside the #ifndef DISABLE_CONTRIB_OPS block means the regression is not guarded in contrib-ops-disabled builds. Since the crash path is in core graph utilities, consider hoisting this test outside the contrib-ops guard so it runs in more configurations. Not blocking.

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.