Skip to content

quantize: Handle user-defined pruning of whole layers (blocks) - #13037

Merged
CISC merged 22 commits into
ggml-org:masterfrom
EAddario:prune
Jun 22, 2025
Merged

CISC merged 22 commits into
ggml-org:masterfrom
EAddario:prune

Conversation

@EAddario

@EAddario EAddario commented Apr 20, 2025 •

Copy link
Copy Markdown
Contributor

This PR adds the ability to prune all tensors from user-defined layers (blocks) by providing a comma-separated list in the --prune-layers command line option. It will renumber remaining layers to avoid gaps in the sequence, update the relevant model metadata and, if an imatrix is available, it will use the correct importance score vector.

Pruning is restricted to repeating layers only (i.e. blk.n, blk.n+1, etc.) and will not affect single tensors like output, token_embd, etc.

This option can be used alongside --tensor-type to perform tensor/layer-wise quantization on selected tensor types, whilst at the same time pruning others. For example:

llama-quantize --tensor-type attn=q6_k --prune-layers 3,7,11 --imatrix imatrix.dat model-f32.gguf model-q4_k_m.gguf q4_k_m

It was inspired partly by ShortGPT: Layers in Large Language Models are More Redundant Than You Expect and partly as the next logical step from #12511. It could be used alongside #12718 to guide the layer selection.

Opening a draft PR for now until split tensor testing is completed, but feedback and suggestions are encouraged in the meantime.

@EAddario
EAddario marked this pull request as draft April 20, 2025 21:47
@EAddario
EAddario marked this pull request as ready for review June 14, 2025 12:56
@EAddario

EAddario commented Jun 14, 2025 •

Copy link
Copy Markdown
Contributor Author

Finally finished testing several combinations with split files and it seems to work 100%

Examples of pruned models here and here

@EAddario

Copy link
Copy Markdown
Contributor Author

Apologies for shotgun approach @slaren / @CISC / @ggerganov, not sure what the proper process to request a review is. Happy to close or move to draft if it's not suitable for merging

Comment thread src/llama-quant.cpp Outdated
Comment thread src/llama-quant.cpp
Comment thread src/llama-quant.cpp Outdated
Comment thread src/llama-quant.cpp Outdated
Comment thread src/llama-quant.cpp Outdated
Comment thread tools/quantize/quantize.cpp Outdated
Comment thread src/llama-quant.cpp Outdated
Comment thread src/llama-quant.cpp Outdated
Comment thread src/llama-quant.cpp Outdated
@EAddario

Copy link
Copy Markdown
Contributor Author

Thank you @CISC!

Comment thread src/llama-quant.cpp

@CISC CISC left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nits :)

Comment thread src/llama-quant.cpp Outdated
Comment thread tools/quantize/quantize.cpp Outdated
EAddario and others added 2 commits June 22, 2025 13:08
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
Comment thread src/llama-quant.cpp Outdated
@EAddario

Copy link
Copy Markdown
Contributor Author

@CISC, much appreciated for spending time on this. Fixed the issues and ran different combinations of tests (split files in -> single out; single file in -> split out; split in -> split out; single in -> single out) pruning different layers (first, last, mix, non-existent, etc). Code is much more robust thanks to your feedback.

🤞

@CISC
CISC merged commit fa4a9f2 into ggml-org:master Jun 22, 2025
@EAddario
EAddario deleted the prune branch June 23, 2025 07:59
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants