Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62eb38b

Browse files
authored
[ONNX] improve regex matching in onnx-importer name sanitization (#3955)
Instead of adding unsupported characters on a case-by-case basis, we should replace anything that isn't alphanumeric, `_`, or `.`.
1 parent 11efcda commit 62eb38b

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

python/torch_mlir/extras/onnx_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ def _sanitize_name(self, name):
742742

743743
# Remove characters that are invalid in MLIR identifier names.
744744
# https://mlir.llvm.org/docs/LangRef/#identifiers-and-keywords
745-
return re.sub("[:/-]", "_", name)
745+
return re.sub("[^\w\.]", "_", name)
746746

747747
def tensor_proto_to_attr(self, tp: onnx.TensorProto) -> Attribute:
748748
tensor_type = self.tensor_proto_to_builtin_type(tp)
124 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The original constant name : "abz_.(1, 2)[$something, %anotherthing]"
2+
3+
# RUN: %PYTHON -m torch_mlir.tools.import_onnx %S/BadName.onnx | FileCheck %s
4+
5+
# CHECK: torch.operator "onnx.Constant"() {torch.onnx.value = dense_resource<_abz_._1__2___something___anotherthing_>

0 commit comments

Comments
 (0)