Skip to content

Commit dc552d0

Browse files
committed
gguf-py: handle numpy 2.0 byte-ordering changes
this commit fixes this error: ```python Traceback (most recent call last): File "/home/poweruser/python-goddamn-venv/bin/gguf-dump", line 8, in <module> sys.exit(gguf_dump_entrypoint()) ^^^^^^^^^^^^^^^^^^^^^^ File "/home/poweruser/python-goddamn-venv/lib/python3.12/site-packages/gguf/scripts/gguf_dump.py", line 450, in main dump_metadata(reader, args) File "/home/poweruser/python-goddamn-venv/lib/python3.12/site-packages/gguf/scripts/gguf_dump.py", line 35, in dump_metadata host_endian, file_endian = get_file_host_endian(reader) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/poweruser/python-goddamn-venv/lib/python3.12/site-packages/gguf/scripts/gguf_dump.py", line 24, in get_file_host_endian host_endian = 'LITTLE' if np.uint32(1) == np.uint32(1).newbyteorder("<") else 'BIG' ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: newbyteorder was removed from scalar types in NumPy 2.0. Use sc.view(sc.dtype.newbyteorder(order)) instead. ```
1 parent 6dde178 commit dc552d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

gguf-py/gguf/scripts/gguf_dump.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222

2323
def get_file_host_endian(reader: GGUFReader) -> tuple[str, str]:
24-
host_endian = 'LITTLE' if np.uint32(1) == np.uint32(1).newbyteorder("<") else 'BIG'
24+
host_val = np.array(1, dtype=np.uint32)
25+
little_val = host_val.view(host_val.dtype.newbyteorder("<"))
26+
host_endian = "LITTLE" if host_val.item() == little_val.item() else "BIG"
2527
if reader.byte_order == 'S':
2628
file_endian = 'BIG' if host_endian == 'LITTLE' else 'LITTLE'
2729
else:

0 commit comments

Comments
 (0)