135135from ..git_version_info import version
136136
137137from deepspeed .profiling .flops_profiler .profiler import FlopsProfiler
138- from deepspeed .utils .logging import print_json_dist , print_configuration , set_log_level_from_string
138+ from deepspeed .utils .logging import print_dist , print_json_dist , print_configuration , set_log_level_from_string
139139
140140from deepspeed .accelerator import get_accelerator
141141
@@ -703,6 +703,43 @@ def _apply_autotp_partitioning(self, model, tp_config):
703703 if hasattr (tp_config , "get_partition_config_object" ):
704704 partition_config = tp_config .get_partition_config_object ()
705705
706+ model_config = getattr (model , "config" , None )
707+ base_tp_plan = getattr (model_config , "base_model_tp_plan" , None ) if model_config is not None else None
708+ class_tp_plan = getattr (type (model ), "_tp_plan" , None )
709+ runtime_tp_plan = getattr (model , "__dict__" , {}).get ("_tp_plan" )
710+ from deepspeed .runtime .tensor_parallel .config import _get_hf_tp_plan
711+ hf_tp_plan = _get_hf_tp_plan (model )
712+
713+ def lm_head_entries (tp_plan ):
714+ if not isinstance (tp_plan , dict ):
715+ return {}
716+ return {
717+ pattern : style
718+ for pattern , style in tp_plan .items ()
719+ if any (part in ("lm_head" , "embed_out" ) for part in pattern .split ('.' ))
720+ }
721+
722+ lm_head_modules = [
723+ name for name , _ in model .named_modules ()
724+ if name and any (part in ("lm_head" , "embed_out" ) for part in name .split ('.' ))
725+ ]
726+ selected_route = "custom partition_config" if partition_config is not None else "HuggingFace tp_plan or AutoTP"
727+ model_class = f"{ type (model ).__module__ } .{ type (model ).__qualname__ } "
728+ print_dist (
729+ f"AutoTP tp_plan diagnostics: model_class={ model_class } ; route={ selected_route } ; "
730+ f"base_model_tp_plan={ base_tp_plan !r} ; type(model)._tp_plan={ class_tp_plan !r} ; "
731+ f"instance_tp_plan={ runtime_tp_plan !r} ; "
732+ f"effective_tp_plan={ hf_tp_plan !r} " ,
733+ ranks = [0 ],
734+ )
735+ print_dist (
736+ f"AutoTP lm_head diagnostics: modules={ lm_head_modules !r} ; "
737+ f"base_entries={ lm_head_entries (base_tp_plan )!r} ; class_entries={ lm_head_entries (class_tp_plan )!r} ; "
738+ f"runtime_entries={ lm_head_entries (runtime_tp_plan )!r} ; "
739+ f"effective_entries={ lm_head_entries (hf_tp_plan )!r} " ,
740+ ranks = [0 ],
741+ )
742+
706743 if partition_config is not None :
707744 autotp = AutoTP (module = model ,
708745 all_reduce_linears = (),
@@ -723,19 +760,22 @@ def _apply_autotp_partitioning(self, model, tp_config):
723760 setattr (model , "ds_autotp_parsed" , True )
724761 return
725762
726- model_config = getattr (model , "config" , None )
727763 from deepspeed .module_inject import replace_transformer_layer
728-
729- from deepspeed .runtime .tensor_parallel .config import _get_hf_tp_plan
730-
731- hf_tp_plan = _get_hf_tp_plan (model )
732764 if hf_tp_plan :
733765 from deepspeed .module_inject .tp_plan_converter import TPPlanConverter
734766 from deepspeed .module_inject .autotp_config import AutoTPConfig
735767
736768 layer_specs = TPPlanConverter .convert (hf_tp_plan )
737769 if layer_specs is not None :
738- logger .info (f"Using HuggingFace tp_plan with { len (layer_specs )} layer specifications" )
770+ gathered_output_patterns = [
771+ pattern for pattern , style in hf_tp_plan .items ()
772+ if style .lower () in ("colwise_rep" , "colwise_gather_output" )
773+ ]
774+ print_dist (
775+ f"Using HuggingFace tp_plan with { len (layer_specs )} layer specifications; "
776+ f"gathered column output patterns={ gathered_output_patterns } " ,
777+ ranks = [0 ],
778+ )
739779 tp_plan_config = AutoTPConfig (tp_size = tp_size , layer_specs = layer_specs )
740780 autotp = AutoTP (
741781 module = model ,
@@ -752,6 +792,14 @@ def _apply_autotp_partitioning(self, model, tp_config):
752792 autotp ._replace_module (model )
753793 setattr (model , "ds_autotp_parsed" , True )
754794 return
795+ print_dist (
796+ f"AutoTP: effective HuggingFace tp_plan could not be converted; falling back to heuristic AutoTP. "
797+ f"styles={ sorted (set (hf_tp_plan .values ()))!r} " ,
798+ ranks = [0 ],
799+ )
800+ else :
801+ print_dist ("AutoTP: no effective HuggingFace tp_plan was found; falling back to heuristic AutoTP." ,
802+ ranks = [0 ])
755803
756804 parser_dict = AutoTP .tp_parser (model )
757805 for client_module , injection_policy in parser_dict :
0 commit comments