llama.cpp
gguf-py: fix gguf-py/examples/writer.py
#8952
Merged

gguf-py: fix gguf-py/examples/writer.py #8952

tarilabs
tarilabs1 year ago

Double-call to add_architecture() in example results in ValueError.

Example is instantiating GGUFWriter in example:
https://github.com/ggerganov/llama.cpp/blob/3071c0a5f218f107dabd13b73f6090af683ef5ec/gguf-py/examples/writer.py#L16-L18

But constructor already has the add_architecture() call here:
https://github.com/ggerganov/llama.cpp/blob/3071c0a5f218f107dabd13b73f6090af683ef5ec/gguf-py/gguf/gguf_writer.py#L108

Before (today)

(gguf-py3.11) gguf-py % python examples/writer.py
Traceback (most recent call last):
  File "/Users/mmortari/git/llama.cpp/gguf-py/examples/writer.py", line 40, in <module>
    writer_example()
  File "/Users/mmortari/git/llama.cpp/gguf-py/examples/writer.py", line 18, in writer_example
    gguf_writer.add_architecture()
  File "/Users/mmortari/git/llama.cpp/gguf-py/gguf/gguf_writer.py", line 484, in add_architecture
    self.add_string(Keys.General.ARCHITECTURE, self.arch)
  File "/Users/mmortari/git/llama.cpp/gguf-py/gguf/gguf_writer.py", line 312, in add_string
    self.add_key_value(key, val, GGUFValueType.STRING)
  File "/Users/mmortari/git/llama.cpp/gguf-py/gguf/gguf_writer.py", line 272, in add_key_value
    raise ValueError(f'Duplicated key name {key!r}')
ValueError: Duplicated key name 'general.architecture'

After

(gguf-py3.11) gguf-py % python examples/writer.py                                  
(gguf-py3.11) gguf-py % ls -la *.gguf
-rw-r--r--@ 1 mmortari  staff  1088 Aug  9 16:36 example.gguf
tarilabs gguf-py: fix examples/reader.py
886f44de
github-actions github-actions added python
tarilabs tarilabs changed the title gguf-py: fix gguf-py/examples/reader.py gguf-py: fix gguf-py/examples/writer.py 1 year ago
compilade
compilade approved these changes on 2024-08-10
ggerganov ggerganov merged 911b437f into master 1 year ago

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone