-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gguf_dump.py: fix markddown kv array print #8588
Merged
mofosyne
merged 6 commits into
ggerganov:master
from
mofosyne:gguf-dump-fix-markdown-kv-array-print
Jul 20, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d99a34b
gguf_dump.py: fix markddown kv array print
mofosyne 130d396
Update gguf-py/scripts/gguf_dump.py
mofosyne 923886f
gguf_dump.py: refactor kv array string handling
mofosyne 1d37843
gguf_dump.py: escape backticks inside of strings
mofosyne 50d55d6
gguf_dump.py: inline code markdown escape handler added
mofosyne 1949847
gguf_dump.py: handle edge case about backticks on start or end of a s…
mofosyne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,21 +249,29 @@ def dump_markdown_metadata(reader: GGUFReader, args: argparse.Namespace) -> None | |
if len(field.types) == 1: | ||
curr_type = field.types[0] | ||
if curr_type == GGUFValueType.STRING: | ||
value = repr(str(bytes(field.parts[-1]), encoding='utf-8')[:60]) | ||
value = "\"`{strval}`\"".format(strval=str(bytes(field.parts[-1]), encoding='utf-8')[:60]) | ||
elif curr_type in reader.gguf_scalar_to_np: | ||
value = str(field.parts[-1][0]) | ||
else: | ||
if field.types[0] == GGUFValueType.ARRAY: | ||
curr_type = field.types[1] | ||
array_elements = [] | ||
if curr_type == GGUFValueType.STRING: | ||
render_element = min(5, total_elements) | ||
for element_pos in range(render_element): | ||
value += repr(str(bytes(field.parts[-1 - element_pos]), encoding='utf-8')[:5]) + (", " if total_elements > 1 else "") | ||
truncate_length = 30 | ||
value_string = str(bytes(field.parts[-1 - (total_elements - element_pos - 1) * 2]), encoding='utf-8') | ||
if len(value_string) > truncate_length: | ||
array_elements.append(value_string[:truncate_length // 2] + "`...`" + value_string[-truncate_length // 2:]) | ||
else: | ||
array_elements.append(value_string) | ||
value_array_inner = ["\"`{strval}`\"".format(strval=strval) for strval in array_elements] | ||
value = f'[ {", ".join(value_array_inner).strip()}{", ..." if total_elements > len(array_elements) else ""} ]' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good, but conditionally appending |
||
elif curr_type in reader.gguf_scalar_to_np: | ||
render_element = min(7, total_elements) | ||
for element_pos in range(render_element): | ||
value += str(field.parts[-1 - element_pos][0]) + (", " if total_elements > 1 else "") | ||
value = f'[ {value}{" ..." if total_elements > 1 else ""} ]' | ||
array_elements.append(str(field.parts[-1 - (total_elements - element_pos - 1)][0])) | ||
value = f'[ {", ".join(array_elements).strip()}{", ..." if total_elements > len(array_elements) else ""} ]' | ||
kv_dump_table.append({"n":n, "pretty_type":pretty_type, "total_elements":total_elements, "field_name":field.name, "value":value}) | ||
|
||
kv_dump_table_header_map = [ | ||
|
@@ -382,7 +390,7 @@ def dump_markdown_metadata(reader: GGUFReader, args: argparse.Namespace) -> None | |
markdown_content += f"- Percentage of total elements: {group_percentage:.2f}%\n" | ||
markdown_content += "\n\n" | ||
|
||
print(markdown_content) # noqa: NP100 | ||
print(markdown_content) # noqa: NP100 | ||
|
||
|
||
def main() -> None: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quotes render a bit weird, and what if the string contains
`
? I suggest to remove the quotes or to include them inside the inline code blocks, and... Hmm not sure how to escape`
except by adding more surrounding`
than the longest inner occurrence, and separate the delimiters by spaces if the string happens to start or finish with`
.I don't know if there's a limit, let's see:
````````````````````
(20 inner, 21 outer`
) seems to work, so there might be no limit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the inline code blocks because of
<unk>
rendering weirdly... I'm inclined to just remove"