Skip to content

gguf-py : fix and simplify quantized shape round-trip#7483

Merged
mofosyne merged 2 commits into
masterfrom
compilade/gguf-py-fix-q-shape
May 25, 2024
Merged

gguf-py : fix and simplify quantized shape round-trip#7483
mofosyne merged 2 commits into
masterfrom
compilade/gguf-py-fix-q-shape

Conversation

@compilade

@compilade compilade commented May 23, 2024

Copy link
Copy Markdown
Collaborator

#7234 has broken quantized tensor copy in gguf-new-metadata.py. (thanks @CISC for finding this! ref: #7234 (comment))

This was originally reported for IQ4_NL, but I think it affects all quantized tensor types.

(Converted models are fine, no worries. This fixes a crash of gguf-new-metadata.py)

Summary of changes

  • add quant_shape_from_byte_shape and quant_shape_to_byte_shape to convert between shapes
  • GGUFReader reshapes the Numpy array in each ReaderTensor to the shape GGUFWriter expects to receive
  • The shape of the ReaderTensors are left unchanged to avoid changing the behavior of gguf-dump.py

Testing

  • Q8_0
    • @compilade I've tested a round-trip of a Q8_0 bloom model when adding general.description with gguf-new-metadata.py, then removing it, and the resulting model file has the same checksum as the original model.
  • IQ4_NL
    • @compilade Again, a round-trip of bloom, but this time with IQ4_NL. The checksums match.

@compilade compilade added bugfix fixes an issue or bug Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix python python script changes labels May 23, 2024
tensor_names.add(tensor_name)
ggml_type = GGMLQuantizationType(raw_dtype[0])
n_elems = int(np.prod(dims))
np_dims = tuple(reversed(dims.tolist()))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.tolist() is necessary here to avoid an error when reshaping afterwards, something about the shape being of type np.float64 for some reason.

@compilade compilade added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label May 23, 2024
@mofosyne
mofosyne merged commit b83bab1 into master May 25, 2024
@compilade compilade mentioned this pull request Jul 27, 2024
4 tasks
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
* gguf-py : fix and simplify quantized shape round-trip

* gguf-py : remove unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix fixes an issue or bug merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. python python script changes Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants