Skip to content

Conversation

@AlekseiNikiforovIBM
Copy link
Contributor

Fix gguf_new_metadata.py for non-native endian files

gguf_new_metadata.py reads data from reader.
Reader doesn't byteswap tensors to native endianness.
But writer does expect tensors in native endianness to convert them
into requested endianness.

There are two ways to fix this: update reader and do conversion to native endianness and back,
or skip converting endianness in writer in this particular USE-case.

Let's go with second approach to skip excessive in this case conversions.

Fix gguf_editor_gui.py for non-native endian files

Since it doesn't allow editing or viewing tensor data,
just skip byteswapping when writing data back into file.

If eventually capability to view or edit tensor data is added,
tensor data should be instead byteswapped when reading it.

These changes can be verified even on little endian systems.
For that 2 copies of files are needed.
One copy is modified first and then byteswapped to non-native endian.
Second copy is byteswapped to non-native endian first and then modified same way as first copy.
Both copies should be identical after such modifications.

@CISC
Copy link
Collaborator

CISC commented Nov 27, 2025

Actually, would it not be a more sensible approach to add an endianess parameter to add_tensor/write_tensor_data that defaults to None (meaning native) and byteswap based on this and target endianess?

@AlekseiNikiforovIBM
Copy link
Contributor Author

That will probably work too, but I prefer to keep this info in 1 place and not look for each call to add_tensor/write_tensor_data.

@CISC
Copy link
Collaborator

CISC commented Nov 28, 2025

That will probably work too, but I prefer to keep this info in 1 place and not look for each call to add_tensor/write_tensor_data.

Well, the reason I say it's more sensible is because that moves the implementation from "I'm going to stuff random data into tensors, don't do anything to correct endianess" to "If tensors are not native endian I will tell you so that you can store them correctly according to file endianess". :)

@AlekseiNikiforovIBM
Copy link
Contributor Author

Sounds reasonable, I'll update PR.

… files

gguf_new_metadata.py reads data from reader.
Reader doesn't byteswap tensors to native endianness.
But writer does expect tensors in native endianness to convert them
into requested endianness.

There are two ways to fix this: update reader and do conversion to native endianness and back,
or skip converting endianness in writer in this particular USE-case.

gguf_editor_gui.py doesn't allow editing or viewing tensor data.
Let's go with skipping excessive byteswapping.

If eventually capability to view or edit tensor data is added,
tensor data should be instead byteswapped when reading it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python python script changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants