@@ -457,24 +457,26 @@ def collect_model_stats(model_path, device, log_prompt):
457457 num_inputs = len (argument_name2types ) - num_params
458458
459459 def dict_to_string (d ):
460- kv_list = [f"{ k } ={ v } " for k , v in d .items ()]
461- return "{" + "," .join (kv_list ) + "}"
462-
463- log_fields = [log_prompt , "[ModelStats]" ]
464- log_fields .append (f"model_path:{ model_path } " )
465- log_fields .append (f"num_inputs:{ num_inputs } " )
466- log_fields .append (f"num_params:{ num_params } " )
467- log_fields .append (f"num_outputs:{ num_outputs } " )
468- log_fields .append (f"num_ops:{ num_ops } " )
469- log_fields .append (f"model_size:{ model_size_in_billion } B" )
470- log_fields .append (f"input_dtypes:{ dict_to_string (input_dtypes )} " )
471- log_fields .append (f"param_dtypes:{ dict_to_string (param_dtypes )} " )
472- log_fields .append (f"op_dtypes:{ dict_to_string (op_dtypes )} " )
473- log_fields .append (f"ops:{ dict_to_string (ops_count_dict )} " )
474- log_fields .append (f"method:{ method } " )
475- log_fields .append (f"is_complete:{ is_complete } " )
476-
477- print (" " .join (log_fields ), flush = True )
460+ kv_list = [f"{ k } :{ v } " for k , v in d .items ()]
461+ return " " .join (kv_list )
462+
463+ def print_with_log_prompt (key , value ):
464+ print (
465+ f"{ log_prompt } [ModelStats.{ key } ] model_path:{ model_path } { value } " ,
466+ flush = True ,
467+ )
468+
469+ print_with_log_prompt ("num_inputs" , num_inputs )
470+ print_with_log_prompt ("num_params" , num_params )
471+ print_with_log_prompt ("num_outputs" , num_outputs )
472+ print_with_log_prompt ("num_ops" , num_ops )
473+ print_with_log_prompt ("model_size" , f"{ model_size_in_billion } B" )
474+ print_with_log_prompt ("input_dtypes" , dict_to_string (input_dtypes ))
475+ print_with_log_prompt ("param_dtypes" , dict_to_string (param_dtypes ))
476+ print_with_log_prompt ("op_dtypes" , dict_to_string (op_dtypes ))
477+ print_with_log_prompt ("ops" , dict_to_string (ops_count_dict ))
478+ print_with_log_prompt ("method" , method )
479+ print_with_log_prompt ("is_complete" , is_complete )
478480
479481
480482def main (args ):
0 commit comments