@@ -234,6 +234,8 @@ def dump_markdown_metadata(reader: GGUFReader, args: argparse.Namespace) -> None
234234 markdown_content += '## Key Value Metadata Store\n \n '
235235 markdown_content += f'There are { len (reader .fields )} key-value pairs in this file\n '
236236 markdown_content += '\n '
237+ total_model_bytes = 0
238+ total_model_elements = 0
237239
238240 kv_dump_table : list [dict [str , str | int ]] = []
239241 for n , field in enumerate (reader .fields .values (), 1 ):
@@ -377,6 +379,8 @@ def escape_markdown_inline_code(value_string):
377379 tensors = tensor_groups [group ]
378380 group_elements = sum (tensor .n_elements for tensor in tensors )
379381 group_percentage = group_elements / total_elements * 100
382+ total_group_bytes = 0
383+ total_group_elements = 0
380384 markdown_content += f"### <a name=\" { group .replace ('.' , '_' )} \" >{ translate_tensor_name (group )} Tensor Group : { element_count_rounded_notation (group_elements )} Elements</a>\n \n "
381385
382386 # Precalculate column sizing for visual consistency
@@ -397,7 +401,13 @@ def escape_markdown_inline_code(value_string):
397401 element_count_est = f"({ element_count_rounded_notation (tensor .n_elements ):>{prettify_element_est_count_size }} )"
398402 element_count_string = f"{ element_count_est } { tensor .n_elements :>{prettify_element_count_size }} "
399403 type_name_string = f"{ tensor .tensor_type .name } "
400- tensor_dump_table .append ({"t_id" :tensor_name_to_key [tensor .name ], "layer_name" :tensor .name , "human_layer_name" :human_friendly_name , "element_count" :element_count_string , "pretty_dimension" :pretty_dimension , "tensor_type" :type_name_string })
404+ if tensor .n_elements > 0 :
405+ bpw = (tensor .n_bytes * 8 ) / tensor .n_elements
406+ else :
407+ bpw = float ('nan' )
408+ tensor_dump_table .append ({"t_id" :tensor_name_to_key [tensor .name ], "layer_name" :tensor .name , "human_layer_name" :human_friendly_name , "element_count" :element_count_string , "pretty_dimension" :pretty_dimension , "tensor_type" :type_name_string , "bpw" : f"{ bpw :.4f} " })
409+ total_group_bytes += tensor .n_bytes
410+ total_group_elements += tensor .n_elements
401411
402412 tensor_dump_table_header_map = [
403413 {'key_name' :'t_id' , 'header_name' :'T_ID' , 'align' :'right' },
@@ -406,15 +416,28 @@ def escape_markdown_inline_code(value_string):
406416 {'key_name' :'element_count' , 'header_name' :'Elements' , 'align' :'left' },
407417 {'key_name' :'pretty_dimension' , 'header_name' :'Shape' , 'align' :'left' },
408418 {'key_name' :'tensor_type' , 'header_name' :'Type' , 'align' :'left' },
419+ {'key_name' :'bpw' , 'header_name' :'BPW' , 'align' :'right' },
409420 ]
410421
411422 markdown_content += markdown_table_with_alignment_support (tensor_dump_table_header_map , tensor_dump_table )
412423
413424 markdown_content += "\n "
414425 markdown_content += f"- Total elements in { group } : ({ element_count_rounded_notation (group_elements ):>4} ) { group_elements } \n "
415426 markdown_content += f"- Percentage of total elements: { group_percentage :.2f} %\n "
427+ if total_group_elements > 0 :
428+ total_group_bpw = (total_group_bytes * 8 ) / total_group_elements
429+ markdown_content += f"- Bits per Weight (BPW) for { group } : { total_group_bpw :.4f} bits\n "
430+ else :
431+ markdown_content += f"- Bits per Weight (BPW) for { group } : undefined (no elements)\n "
416432 markdown_content += "\n \n "
433+ total_model_bytes += total_group_bytes
434+ total_model_elements += total_group_elements
417435
436+ if total_model_elements > 0 :
437+ total_model_bpw = (total_model_bytes * 8 ) / total_model_elements
438+ markdown_content += f"Total BPW for { os .path .basename (args .model )} : { total_model_bpw :.4f} bits"
439+ else :
440+ markdown_content += f"Total BPW for { os .path .basename (args .model )} : undefined (no elements)"
418441 print (markdown_content ) # noqa: NP100
419442
420443
0 commit comments