@@ -148,11 +148,8 @@ def _convert_casting_operators(self, node: torch.fx.Node):
148148 if input_dtype == torch .int32 :
149149 users = [user for user in node .users if node != user ]
150150 for user in users :
151- logger .warning (
152- f"Removing int32->int64 casting node { node .name } defined in"
153- f" { node .meta .get ('stack_trace' ,'[no stack trace found]' )} "
154- )
155151 user .replace_input_with (node , input_node )
152+ self ._removed_casts += 1
156153 # Case 2: other types -> int64 - rewrites to cast to int32
157154 else :
158155 if node .target in self .cast_ops_kwargs :
@@ -161,11 +158,7 @@ def _convert_casting_operators(self, node: torch.fx.Node):
161158 set_node_arg (node , 1 , torch .int32 )
162159 else :
163160 raise RuntimeError (f"Unexpected target { node .target } in { node .name } " )
164- output_dtype = get_first_fake_tensor (node ).dtype
165- logger .warning (
166- f"Converting casting node { node .name } from { input_dtype } ->{ output_dtype } to"
167- f" { input_dtype } ->torch.int32 defined in { node .meta .get ('stack_trace' ,'[no stack trace found]' )} "
168- )
161+ self ._converted_casts += 1
169162
170163 def _range_fits_int32 (self , value_range : Tuple [int , int ]) -> bool :
171164 return - self ._INT32_MAX - 1 <= value_range [0 ] and (
@@ -471,15 +464,25 @@ def _cast_safe_index_paths_to_int32(
471464 )
472465 user .replace_input_with (node , boundary )
473466
474- logger .warning (
475- f"Inserting a casting node { cast_to_int32 .name } after "
476- f"{ source .name } for range-safe index consumers defined in "
477- f"{ source .meta .get ('stack_trace' ,'[no stack trace found]' )} "
478- )
467+ self ._safe_index_casts += 1
479468 return True
480469
470+ def _log_summary (self ) -> None :
471+ if self ._removed_casts or self ._converted_casts or self ._safe_index_casts :
472+ logger .warning (
473+ "ConvertInt64OutputOpsToInt32Pass: removed %d int32-to-int64 "
474+ "cast(s), rewrote %d cast(s) to int32, and inserted %d "
475+ "range-safe index cast(s)." ,
476+ self ._removed_casts ,
477+ self ._converted_casts ,
478+ self ._safe_index_casts ,
479+ )
480+
481481 def call (self , graph_module : torch .fx .GraphModule ):
482482 modified = False
483+ self ._removed_casts = 0
484+ self ._converted_casts = 0
485+ self ._safe_index_casts = 0
483486 graph = graph_module .graph
484487 for node in list (graph .nodes ):
485488 if node .op != "call_function" :
@@ -523,4 +526,6 @@ def call(self, graph_module: torch.fx.GraphModule):
523526 graph_module .recompile ()
524527 graph_module = super ().call (graph_module ).graph_module
525528
529+ self ._log_summary ()
530+
526531 return PassResult (graph_module , modified )
0 commit comments