Skip to content

Commit

Permalink
[dynamo] simplify module_key creation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ydwu4 committed Feb 15, 2023
1 parent 63bf767 commit f278420
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions torch/_dynamo/output_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import itertools
import logging
import operator
import re
import traceback
from dataclasses import dataclass
from typing import Any, Dict, List, NamedTuple, Optional, OrderedDict, Set, Union
Expand Down Expand Up @@ -58,6 +57,11 @@
log = logging.getLogger(__name__)


def _create_name(names: List[str]) -> str:
name = ".".join(names)
return name.replace(".", ">")


class OutputGraphState(NamedTuple):
graphargs: List[GraphArg]
tracked_fakes: List[TrackedFake]
Expand Down Expand Up @@ -417,12 +421,7 @@ def wrap_name(module_key):
# it already exists
return wrap_name(k)

# create a new unique name
name = "_".join(map(str, names))
# e.g. repalce abc.xyz[123].qkv with abc.xyz_123.qkv
name = re.sub(r"\[(\d+)\]", r"_\g<1>", name)
# e.g. replace abc.xyz_123.qkv with abc_xyz_123_qkv
name = re.sub(r"[^a-zA-Z0-9]", "_", name)
name = _create_name(list(map(str, names)))

if not name or not name[0].isalpha():
name = "sub" + name
Expand Down

0 comments on commit f278420

Please sign in to comment.