Skip to content

Commit

Permalink
[onnx][importer] Merge character sanitization into regex (#3914)
Browse files Browse the repository at this point in the history
Refactors #3901 by merging
illegal character sanitization into the regex and removing call to
`replace()`.
  • Loading branch information
vinayakdsci authored Dec 9, 2024
1 parent 1994983 commit a99e378
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions python/torch_mlir/extras/onnx_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,9 @@ def _sanitize_name(self, name):
if not name.isidentifier():
name = "_" + name

# The presence of '-' characters in the initializer names can cause
# unintended side-effects when the IR is parsed during compilation.
# Simply replace all the occurrences of '-' in the name string when the
# dense resource is created.
name = name.replace("-", "_")

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

def tensor_proto_to_attr(self, tp: onnx.TensorProto) -> Attribute:
tensor_type = self.tensor_proto_to_builtin_type(tp)
Expand Down

0 comments on commit a99e378

Please sign in to comment.