File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed
pytensor/link/pytorch/dispatch Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change 11import inspect
22import sys
3+ from collections import defaultdict
34from functools import singledispatch
45from types import NoneType
56
@@ -58,23 +59,19 @@ def pytorch_funcify_FunctionGraph(
5859 fgraph_name = "pytorch_funcified_fgraph" ,
5960 ** kwargs ,
6061):
62+ fnames_counter = defaultdict (int )
63+
6164 def conversion_func_register (* args , ** kwargs ):
6265 last_frame = inspect .currentframe ().f_back
6366 functor = pytorch_funcify (* args , ** kwargs )
6467 if last_frame :
6568 module = sys .modules [last_frame .f_globals ["__name__" ]]
6669 name = functor .__name__
67- i = 0
68- prefix = ""
69- while True :
70- name = functor .__name__ + prefix
71- if name in dir (module ):
72- i += 1
73- prefix = f"_{ i } "
74- else :
75- print ("Registering functor" , name )
76- setattr (module , name , functor )
77- break
70+ if fnames_counter [name ]:
71+ name = f"{ name } _{ fnames_counter [name ]} "
72+ print ("Registering functor" , name )
73+ setattr (module , name , functor )
74+ fnames_counter [functor .__name__ ] += 1
7875 return functor
7976
8077 return fgraph_to_python (
You can’t perform that action at this time.
0 commit comments