Skip to content

Commit 8a81fb2

Browse files
Rajat MongaCopilot
andcommitted
Fix CSE crash on string tensor attributes
The CSE optimizer crashed with ORT_ENFORCE when encountering a node with a string tensor attribute (e.g., LabelEncoder with keys_tensor of type STRING). Replace the enforce with an early return of hash 0, treating such nodes as distinct (consistent with AreScalarTensorAttributeEqual). Fixes #28413 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 46273ea commit 8a81fb2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

onnxruntime/core/optimizer/common_subexpression_elimination.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,14 @@ bool AreEqual(const ONNX_NAMESPACE::AttributeProto& lhs, const ONNX_NAMESPACE::A
224224
return false;
225225
}
226226

227-
// Support scalar tensor attribute only for now.
227+
// Support scalar tensor attribute only for now. String tensors are not supported and return 0.
228228
std::size_t GetTensorAttributeHash(const ONNX_NAMESPACE::TensorProto& attr_t) {
229229
std::size_t hash = 0;
230230
if (utils::HasDataType(attr_t) && attr_t.dims_size() == 1 && attr_t.dims()[0] == 1) {
231231
int data_type = attr_t.data_type();
232-
ORT_ENFORCE(data_type != onnx::TensorProto_DataType_STRING, "Unexpected tensor string type");
232+
if (data_type == onnx::TensorProto_DataType_STRING) {
233+
return hash;
234+
}
233235
std::vector<uint8_t> unpacked_tensor;
234236
if (utils::UnpackInitializerData(attr_t, unpacked_tensor).IsOK()) {
235237
UpdateHash(data_type, hash);

0 commit comments

Comments
 (0)