gguf-py : do not align the data start offset#18291
Merged
Conversation
The safetensors format doesn't require alignment.
CISC
approved these changes
Dec 22, 2025
fairydreaming
approved these changes
Dec 22, 2025
Collaborator
fairydreaming
left a comment
There was a problem hiding this comment.
Looks good, works fine. I think we can worry about possible alignment problems (if any) when they appear.
Anico2
added a commit
to Anico2/llama.cpp
that referenced
this pull request
Jan 15, 2026
The safetensors format doesn't require alignment.
blime4
referenced
this pull request
in blime4/llama.cpp
Feb 5, 2026
The safetensors format doesn't require alignment.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The safetensors format doesn't require alignment. Fixes: #18282 (which was a regression caused by #15667).
I assumed wrong since GGUF does align its data offset, and the writer for safetensors aligns to 8 bytes (see https://github.com/huggingface/safetensors/blob/806426784adb43631e9a1102d4621126bb589347/safetensors/src/tensor.rs#L256-L258), and also because the data offset alignment was implemented in the same way in #12820. But apparently some models aren't aligned.
It seems like PyTorch and Numpy can handle unaligned tensors, but I'm not completely sure (is it only for shape transformations, or does it also support arithmetic on unaligned tensors? (would need an unaligned model which has some arithmetic in its
modify_tensorstransformations to test this)). Copying the tensor (with e.g.data.copy()) wouldn't necessarily always be sufficient, because that doesn't seem to align to 8 bytes when the dtype isnp.uint8. I'll try to figure out how to make an aligned copy. But if it's not really necessary in practice, then this is ready.EDIT: I've looked at the
.data_ptr()addresses when using thesafetensorslibrary with an unaligned model, and it doesn't make an aligned copy (at least when usingget_slicelike since #8482). So the new behavior is pretty much the same as with thesafetensorslibrary.Tested on https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
Thanks @fairydreaming for finding this problem! (and finding the rationale behind why unaligned safetensors exist)
Make sure to read the contributing guidelines before submitting a PR