Make examples executable, formatting changes
This commit is contained in:
parent
855486c912
commit
2360aaadb4
3 changed files with 8 additions and 1 deletions
2
gguf-py/examples/dump_gguf.py
Normal file → Executable file
2
gguf-py/examples/dump_gguf.py
Normal file → Executable file
|
@ -7,6 +7,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
|||
|
||||
from gguf import GGUFReader, GGUFValueType # noqa: E402
|
||||
|
||||
|
||||
def dump_gguf(filename: str) -> None:
|
||||
print(f'* Loading: {filename}')
|
||||
reader = GGUFReader(filename, 'r')
|
||||
|
@ -34,6 +35,7 @@ def dump_gguf(filename: str) -> None:
|
|||
prettydims = ', '.join('{0:5}'.format(d) for d in list(tensor.shape) + [1] * (4 - len(tensor.shape)))
|
||||
print(f' {n:5}: {tensor.n_elements:10} | {prettydims} | {tensor.tensor_type.name:7} | {tensor.name}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
print('dump_gguf: Error: Specify an input file', file = sys.stderr)
|
||||
|
|
2
gguf-py/examples/modify_gguf.py
Normal file → Executable file
2
gguf-py/examples/modify_gguf.py
Normal file → Executable file
|
@ -7,6 +7,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
|||
|
||||
from gguf import GGUFReader # noqa: E402
|
||||
|
||||
|
||||
def change_gguf(reader: GGUFReader, key: str, value: str) -> None:
|
||||
field = reader.get_field(key)
|
||||
if field is None:
|
||||
|
@ -32,6 +33,7 @@ def change_gguf(reader: GGUFReader, key: str, value: str) -> None:
|
|||
field.parts[field.data[0]][0] = new_value
|
||||
print('* Field changed. Successful completion.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 4:
|
||||
print(
|
||||
|
|
5
gguf-py/examples/writer.py
Normal file → Executable file
5
gguf-py/examples/writer.py
Normal file → Executable file
|
@ -9,6 +9,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
|||
|
||||
from gguf import GGUFWriter # noqa: E402
|
||||
|
||||
|
||||
# Example usage:
|
||||
def writer_example() -> None:
|
||||
# Example usage with a file
|
||||
|
@ -34,4 +35,6 @@ def writer_example() -> None:
|
|||
|
||||
gguf_writer.close()
|
||||
|
||||
writer_example()
|
||||
|
||||
if __name__ == '__main__':
|
||||
writer_example()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue