@@ -154,15 +154,16 @@ def translate_tensor_name(name):
154
154
155
155
def dump_markdown_metadata (reader : GGUFReader , args : argparse .Namespace ) -> None :
156
156
host_endian , file_endian = get_file_host_endian (reader )
157
- print (f'# { args .model } - GGUF Internal File Dump' ) # noqa: NP100
158
- print (f'* Endian: { file_endian } endian' ) # noqa: NP100
159
- print ('' ) # noqa: NP100
160
- print ('## Key Value Metadata Store' ) # noqa: NP100
161
- print (f'There is { len (reader .fields )} key/value pair(s) in this file' ) # noqa: NP100
162
- print ('' ) # noqa: NP100
157
+ markdown_content = ""
158
+ markdown_content += f'# { args .model } - GGUF Internal File Dump\n '
159
+ markdown_content += f'* Endian: { file_endian } endian\n '
160
+ markdown_content += '\n '
161
+ markdown_content += '## Key Value Metadata Store\n '
162
+ markdown_content += f'There is { len (reader .fields )} key/value pair(s) in this file\n '
163
+ markdown_content += '\n '
163
164
164
- print ( '| POS | TYPE | Elements | Key | Value |' ) # noqa: NP100
165
- print ( '|-----|------------|----------|----------------------------------------|--------------------------------------------------------------------------------|' ) # noqa: NP100
165
+ markdown_content += '| POS | TYPE | Elements | Key | Value |\n '
166
+ markdown_content += '|-----|------------|----------|----------------------------------------|--------------------------------------------------------------------------------|\n '
166
167
167
168
for n , field in enumerate (reader .fields .values (), 1 ):
168
169
if not field .types :
@@ -179,9 +180,9 @@ def dump_markdown_metadata(reader: GGUFReader, args: argparse.Namespace) -> None
179
180
value = repr (str (bytes (field .parts [- 1 ]), encoding = 'utf-8' )[:60 ])
180
181
elif field .types [0 ] in reader .gguf_scalar_to_np :
181
182
value = field .parts [- 1 ][0 ]
182
- print ( f'| { n :3} | { pretty_type :10} | { len (field .data ):8} | { field .name :38} | { value :<78} |' ) # noqa: NP100
183
+ markdown_content += f'| { n :3} | { pretty_type :10} | { len (field .data ):8} | { field .name :38} | { value :<78} |\n '
183
184
184
- print ( "\n " ) # noqa: NP100
185
+ markdown_content += "\n "
185
186
186
187
if not args .no_tensors :
187
188
# Group tensors by their prefix and maintain order
@@ -203,24 +204,33 @@ def dump_markdown_metadata(reader: GGUFReader, args: argparse.Namespace) -> None
203
204
tensor_groups [tensor_prefix ].append (tensor )
204
205
205
206
# Generate Markdown metadata
207
+ markdown_content += "## Tensor Groups\n "
206
208
for group in tensor_prefix_order :
207
209
tensors = tensor_groups [group ]
208
210
group_elements = sum (tensor .n_elements for tensor in tensors )
209
- group_percentage = group_elements / total_elements * 100
211
+ markdown_content += f"- [ { translate_tensor_name ( group ) } Tensor Group - { element_count_rounded_notation ( group_elements ) } Elements](# { group . replace ( '.' , '_' ) } ) \n "
210
212
211
- print (f"## { translate_tensor_name (group )} Tensor Group : { element_count_rounded_notation (group_elements )} Elements" ) # noqa: NP100
212
- print ("| Tensor Name | Human Friendly Name | Elements | Shape | Type |" ) # noqa: NP100
213
- print ("|----------------------|-------------------------------------|----------------|---------------------------------|------|" ) # noqa: NP100
213
+ markdown_content += "\n "
214
+
215
+ for group in tensor_prefix_order :
216
+ tensors = tensor_groups [group ]
217
+ group_elements = sum (tensor .n_elements for tensor in tensors )
218
+ group_percentage = group_elements / total_elements * 100
219
+ markdown_content += f"### { translate_tensor_name (group )} Tensor Group : { element_count_rounded_notation (group_elements )} Elements <a name=\" { group .replace ('.' , '_' )} \" ></a>\n "
220
+ markdown_content += "| Tensor Name | Human Friendly Name | Elements | Shape | Type |\n "
221
+ markdown_content += "|----------------------|-------------------------------------|----------------|---------------------------------|------|\n "
214
222
215
223
for tensor in tensors :
216
224
tensor_name = tensor .name .replace (".weight" , "" )
217
225
human_friendly_name = translate_tensor_name (tensor .name .replace (".weight" , "" ))
218
226
prettydims = ' x ' .join ('{0:^5}' .format (d ) for d in list (tensor .shape ) + [1 ] * (4 - len (tensor .shape )))
219
- print (f"| { tensor_name :20} | { human_friendly_name :35} | ({ element_count_rounded_notation (tensor .n_elements ):>4} ) { tensor .n_elements :7} | [{ prettydims :29} ] | { tensor .tensor_type .name :4} |" ) # noqa: NP100
220
- print ("" ) # noqa: NP100
221
- print (f"- Total elements in { group } : ({ element_count_rounded_notation (group_elements ):>4} ) { group_elements } " ) # noqa: NP100
222
- print (f"- Percentage of total elements: { group_percentage :.2f} %" ) # noqa: NP100
223
- print ("\n " ) # noqa: NP100
227
+ markdown_content += f"| { tensor_name :20} | { human_friendly_name :35} | ({ element_count_rounded_notation (tensor .n_elements ):>4} ) { tensor .n_elements :7} | [{ prettydims :29} ] | { tensor .tensor_type .name :4} |\n "
228
+ markdown_content += "\n "
229
+ markdown_content += f"- Total elements in { group } : ({ element_count_rounded_notation (group_elements ):>4} ) { group_elements } \n "
230
+ markdown_content += f"- Percentage of total elements: { group_percentage :.2f} %\n "
231
+ markdown_content += "\n \n "
232
+
233
+ print (markdown_content ) # noqa: NP100
224
234
225
235
226
236
def main () -> None :
0 commit comments